[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2771] contrib/py/scripts/addons/ io_scene_ms3d: changed mesh generation and add joints and bone handling in the importer

Alexander Nussbaumer alpha-beta-release at gmx.net
Tue Dec 13 11:16:20 CET 2011


Revision: 2771
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2771
Author:   beta-tester
Date:     2011-12-13 10:16:19 +0000 (Tue, 13 Dec 2011)
Log Message:
-----------
changed mesh generation and add joints and bone handling in the importer

changed: (0, 3, 5, "beta (2011-12-12 00:00)"),
mod: import armature bones (head-tail to tail-head + additional post process to connect for better auto IK handling)
add: import bones and joints with armature modifier
mod: changed mesh generation (take only used vertices, instead of take all vertices and delete deserted in an extra pass)

Modified Paths:
--------------
    contrib/py/scripts/addons/io_scene_ms3d/__README__.txt
    contrib/py/scripts/addons/io_scene_ms3d/ms3d_export.py
    contrib/py/scripts/addons/io_scene_ms3d/ms3d_import.py
    contrib/py/scripts/addons/io_scene_ms3d/ms3d_spec.py
    contrib/py/scripts/addons/io_scene_ms3d/ms3d_utils.py

Modified: contrib/py/scripts/addons/io_scene_ms3d/__README__.txt
===================================================================
--- contrib/py/scripts/addons/io_scene_ms3d/__README__.txt	2011-12-13 01:28:02 UTC (rev 2770)
+++ contrib/py/scripts/addons/io_scene_ms3d/__README__.txt	2011-12-13 10:16:19 UTC (rev 2771)
@@ -70,8 +70,6 @@
 
 known issues:
   importer issues:
-    - does not import bones
-    - does not import joints
     - does not import keyframes
 
   exporter issues:
@@ -85,12 +83,17 @@
 
 todo:
 - change internal data structure for more performance on searching vertex indices and double vertices
-- add support for bones and joints
+- add support for bones and joints in exporter
 - add support for keyframes
 
 
 
 changelog:
+changed: (0, 3, 5, "beta (2011-12-12 00:00)"),
+mod: import armature bones (head-tail to tail-head + additional post process to connect for better auto IK handling)
+add: import bones and joints with armature modifier
+mod: changed mesh generation (take only used vertices, instead of take all vertices and delete deserted in an extra pass)
+
 changed: (0, 3, 4, "beta (2011-12-09 00:00)"),
 fix: exporter forgot to change changed vertex_ex handling in ms3d_exporter.py
 add: importer adds ms3d_flags custom properties for some objects

Modified: contrib/py/scripts/addons/io_scene_ms3d/ms3d_export.py
===================================================================
--- contrib/py/scripts/addons/io_scene_ms3d/ms3d_export.py	2011-12-13 01:28:02 UTC (rev 2770)
+++ contrib/py/scripts/addons/io_scene_ms3d/ms3d_export.py	2011-12-13 10:16:19 UTC (rev 2771)
@@ -396,35 +396,39 @@
 
         ms3dMaterial.name = blenderMaterial.name
 
-        ms3dMaterial._ambient = tuple([
+        ms3dMaterial._ambient = (
                 blenderMaterial.diffuse_color[0],
                 blenderMaterial.diffuse_color[1],
                 blenderMaterial.diffuse_color[2],
                 blenderMaterial.ambient
-                ])
+                )
 
-        ms3dMaterial._diffuse = tuple([
+        ms3dMaterial._diffuse = (
                 blenderMaterial.diffuse_color[0],
                 blenderMaterial.diffuse_color[1],
                 blenderMaterial.diffuse_color[2],
                 blenderMaterial.diffuse_intensity
-                ])
+                )
 
-        ms3dMaterial._specular = tuple([
+        ms3dMaterial._specular = (
                 blenderMaterial.specular_color[0],
                 blenderMaterial.specular_color[1],
                 blenderMaterial.specular_color[2],
                 blenderMaterial.specular_intensity
-                ])
+                )
 
-        ms3dMaterial._emissive = tuple([
+        ms3dMaterial._emissive = (
                 blenderMaterial.diffuse_color[0],
                 blenderMaterial.diffuse_color[1],
                 blenderMaterial.diffuse_color[2],
                 blenderMaterial.emit
-                ])
+                )
 
-        ms3dMaterial.shininess = blenderMaterial.specular_hardness
+        ms3dMaterial.shininess = blenderMaterial.specular_hardness / 2.0
+        if ms3dMaterial.shininess > 128:
+            ms3dMaterial.shininess = 128
+        if ms3dMaterial.shininess < 1:
+            ms3dMaterial.shininess = 1
 
         if (blenderMaterial.use_transparency):
             ms3dMaterial.transparency = blenderMaterial.alpha
@@ -565,11 +569,11 @@
         n2 = self.CreateNormal(matrixObject, v)
 
         # put the indices of ms3d-vertices!
-        ms3dTriangle._vertexIndices = tuple([
+        ms3dTriangle._vertexIndices = (
                 ms3dVertices.index(v0),
                 ms3dVertices.index(v1),
                 ms3dVertices.index(v2)
-                ])
+                )
 
         # put the normales
         ms3dTriangle._vertexNormals = (n0, n1, n2)

Modified: contrib/py/scripts/addons/io_scene_ms3d/ms3d_import.py
===================================================================
--- contrib/py/scripts/addons/io_scene_ms3d/ms3d_import.py	2011-12-13 01:28:02 UTC (rev 2770)
+++ contrib/py/scripts/addons/io_scene_ms3d/ms3d_import.py	2011-12-13 10:16:19 UTC (rev 2771)
@@ -75,7 +75,9 @@
 
 PROP_NAME_HASH = "import_hash"
 PROP_NAME_SMOOTH_GROUP = "smoothingGroup{0}"
+PROP_NAME_BONE_ID = "boneId{0}"
 
+
 ###############################################################################
 # registered entry point import
 class ImportMS3D(
@@ -209,7 +211,6 @@
             # with same names but different content
             self.dict_armatures = {}
             self.dict_armature_objects = {}
-            self.dict_bones = {}
             self.dict_groups = {}
             self.dict_images = {}
             self.dict_materials = {}
@@ -261,11 +262,21 @@
                             ms3dTemplate.modelComment.comment
 
             if (ms3d_utils.PROP_ITEM_OBJECT_JOINT in self.prop_objects):
-                bones = self.CreateArmature(blenderContext, ms3dTemplate)
+                dict_bones = self.CreateArmature(blenderContext, ms3dTemplate)
 
+                if self.prop_animation:
+                    bpy.context.scene.render.fps = ms3dTemplate.fAnimationFPS
+                    bpy.context.scene.render.fps_base = (bpy.context.scene.render.fps
+                            / ms3dTemplate.fAnimationFPS)
+                    bpy.context.scene.frame_start = 1
+                    bpy.context.scene.frame_end = (ms3dTemplate.iTotalFrames
+                            + bpy.context.scene.frame_start) - 1
+                    bpy.context.scene.frame_current = (ms3dTemplate.fCurrentTime
+                            * bpy.context.scene.render.fps)
+
             for ms3dGroupIndex, ms3dGroup in enumerate(ms3dTemplate.groups):
                 blenderMesh = self.CreateMesh(blenderContext, ms3dTemplate,
-                        ms3dGroup, ms3dGroupIndex)
+                        ms3dGroup, ms3dGroupIndex, dict_bones)
 
                 # apply material if available
                 if ((ms3d_utils.PROP_ITEM_OBJECT_MATERIAL in self.prop_objects)
@@ -297,7 +308,6 @@
 
                 self.PostSetupMesh()
 
-
             # put all objects to group
             if (ms3d_utils.PROP_ITEM_OBJECT_GROUP in self.prop_objects):
                 blenderGroup, setupGroup = self.GetGroup(ms3dTemplate)
@@ -321,9 +331,6 @@
 
     ###########################################################################
     def CreateArmature(self, blenderContext, ms3dTemplate):
-        """
-        known issues: roll angle of the bones may be different as in ms3d
-        """
         if (ms3dTemplate.nNumJoints <= 0):
             return None
 
@@ -346,40 +353,43 @@
 
         ms3d_utils.EnableEditMode(True)
 
-        blenderBones = blenderArmature.edit_bones
-
-        bones = {}
-        bones_parentName = None
+        dict_bones = {}
         for iBone, ms3dJoint in enumerate(ms3dTemplate.joints):
 
-            blenderBone = blenderBones.new(ms3dJoint.name)
-            bones[ms3dJoint.name] = (blenderBone, ms3dJoint)
+            blenderBone = blenderArmature.edit_bones.new(ms3dJoint.name)
+            blenderBone[prop(ms3d_spec.PROP_NAME_FLAGS)] = ms3dJoint.flags
 
-            blenderBone[prop(ms3d_spec.PROP_NAME_FLAGS)] = ms3dJoint.flags
             ms3dComment = ms3dTemplate.get_joint_comment_by_key(iBone)
             if ms3dComment is not None:
                 blenderBone[prop(ms3d_spec.PROP_NAME_COMMENT)] = \
                         ms3dComment.comment
 
-            blenderBones.active = blenderBone
+            ms3dJointEx = ms3dTemplate.get_joint_ex_by_key(iBone)
+            if ms3dJointEx is not None:
+                blenderBone[prop(ms3d_spec.PROP_NAME_COLOR)] = \
+                        ms3dJointEx.color
 
+            blenderBone.select = True
+            blenderArmature.edit_bones.active = blenderBone
+
+            # [blender bone, ms3d bone, number of references, roll vector]
+            dict_bones[ms3dJoint.name] = [blenderBone, ms3dJoint, 0, None]
+
             mathVector = mathutils.Vector(ms3dJoint.position)
             mathVector = mathVector * self.matrixViewport
 
-            if (iBone == 0):
-                blenderBone.tail = mathVector
-                blenderBone.head = blenderBone.tail + mathutils.Vector(
-                        (-1.0, 0.0, 0.0))
-                bones_parentName = ms3dJoint.name
+            if (not ms3dJoint.parentName):
+                blenderBone.head = mathVector
                 matrixRotation = None
 
+                #dummy tail
+                blenderBone.tail = blenderBone.head + mathutils.Vector(
+                        (0.00001, 0.0, 0.0))
+
             else:
-                # some models have more than one initial bone (with no parent)
-                # no idea how to handle correctly
-                if (not ms3dJoint.parentName):
-                    blenderBoneParent = bones[bones_parentName][0]
-                else:
-                    blenderBoneParent = bones[ms3dJoint.parentName][0]
+                boneItem = dict_bones[ms3dJoint.parentName]
+                boneItem[2] += 1
+                blenderBoneParent = boneItem[0]
 
                 blenderBone.parent = blenderBoneParent
 
@@ -389,30 +399,55 @@
 
                     # correct rotaion axis
                     rotationAxis = mathutils.Vector((
-                            -bones[key][1].rotation[0],
-                            -bones[key][1].rotation[1],
-                            -bones[key][1].rotation[2]))
+                            -dict_bones[key][1].rotation[0],
+                            -dict_bones[key][1].rotation[1],
+                            -dict_bones[key][1].rotation[2]))
                     rotationAxis = rotationAxis * self.matrixSwapAxis
 
                     mathRotation = mathutils.Euler(rotationAxis, 'XZY')
                     matrixRotation = matrixRotation * mathRotation.to_matrix(
                             ).to_4x4()
 
-                blenderBone.tail = blenderBone.parent.tail + (mathVector
+                blenderBone.head = blenderBone.parent.head + (mathVector
                         * matrixRotation)
 
+                # dummy tail
+                blenderBone.tail = blenderBone.head + (
+                        mathutils.Vector((0.00001, 0.0, 0.0))
+                        * self.matrixSwapAxis
+                        * matrixRotation)
 
-            blenderBone.use_local_location = True
+            if matrixRotation is not None:

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list