OSDN Git Service

implement constraint.
authorousttrue <ousttrue@gmail.com>
Wed, 16 Jun 2010 21:45:36 +0000 (06:45 +0900)
committerousttrue <ousttrue@gmail.com>
Wed, 16 Jun 2010 22:03:12 +0000 (07:03 +0900)
swig/blender/bl25.py
swig/blender/pmd_export.py
swig/blender/pmd_import.py
swig/setup.py

index f842242..f9709be 100644 (file)
@@ -484,3 +484,6 @@ def shapeKeys(b):
     for k in b.data:
         yield k.co
 
+def VtoV(v):
+    return mathutils.Vector([v.x, v.y, v.z])
+
index f5a599b..641c00b 100644 (file)
@@ -26,8 +26,23 @@ BASE_SHAPE_NAME='Basis'
 RIGID_SHAPE_TYPE='rigid_shape_type'
 RIGID_PROCESS_TYPE='rigid_process_type'
 RIGID_BONE_NAME='rigid_bone_name'
-CONSTRAINT_A='constraint_a'
-CONSTRAINT_B='constraint_b'
+#RIGID_LOCATION='rigid_loation'
+RIGID_GROUP='ribid_group'
+RIGID_INTERSECTION_GROUP='rigid_intersection_group'
+RIGID_WEIGHT='rigid_weight'
+RIGID_LINEAR_DAMPING='rigid_linear_damping'
+RIGID_ANGULAR_DAMPING='rigid_angular_damping'
+RIGID_RESTITUTION='rigid_restitution'
+RIGID_FRICTION='rigid_friction'
+CONSTRAINT_A='const_a'
+CONSTRAINT_B='const_b'
+CONSTRAINT_POS_MIN='const_pos_min'
+CONSTRAINT_POS_MAX='const_pos_max'
+CONSTRAINT_ROT_MIN='const_rot_min'
+CONSTRAINT_ROT_MAX='const_rot_max'
+CONSTRAINT_SPRING_POS='const_spring_pos'
+CONSTRAINT_SPRING_ROT='const_spring_rot'
+
 
 ###############################################################################
 # import
@@ -905,21 +920,27 @@ class PmdExporter(object):
             boneIndex=boneNameMap[obj[RIGID_BONE_NAME]]
             if boneIndex==0:
                 boneIndex=0xFFFF
+                bone=self.builder.bones[0]
+            else:
+                bone=self.builder.bones[boneIndex]
             rigidBody.boneIndex=boneIndex
-            rigidBody.position.x=obj.location[0]
-            rigidBody.position.y=obj.location[2]
-            rigidBody.position.z=obj.location[1]
+            #rigidBody.position.x=obj[RIGID_LOCATION][0]
+            #rigidBody.position.y=obj[RIGID_LOCATION][1]
+            #rigidBody.position.z=obj[RIGID_LOCATION][2]
+            rigidBody.position.x=obj.location.x-bone.pos[0]
+            rigidBody.position.y=obj.location.z-bone.pos[2]
+            rigidBody.position.z=obj.location.y-bone.pos[2]
             rigidBody.rotation.x=-obj.rotation_euler[0]
             rigidBody.rotation.y=-obj.rotation_euler[2]
             rigidBody.rotation.z=-obj.rotation_euler[1]
             rigidBody.processType=obj[RIGID_PROCESS_TYPE]
-            rigidBody.group=0
-            rigidBody.target=0
-            rigidBody.weight=1
-            rigidBody.linearDamping=0
-            rigidBody.angularDamping=0
-            rigidBody.restitution=0
-            rigidBody.friction=0
+            rigidBody.group=obj[RIGID_GROUP]
+            rigidBody.target=obj[RIGID_INTERSECTION_GROUP]
+            rigidBody.weight=obj[RIGID_WEIGHT]
+            rigidBody.linearDamping=obj[RIGID_LINEAR_DAMPING]
+            rigidBody.angularDamping=obj[RIGID_ANGULAR_DAMPING]
+            rigidBody.restitution=obj[RIGID_RESTITUTION]
+            rigidBody.friction=obj[RIGID_FRICTION]
             if obj[RIGID_SHAPE_TYPE]==0:
                 rigidBody.shapeType=pmd.SHAPE_SPHERE
                 rigidBody.w=obj.scale[0]
@@ -939,6 +960,30 @@ class PmdExporter(object):
             constraint.setName(obj.name[1:].encode('cp932'))
             constraint.rigidA=rigidNameMap[obj[CONSTRAINT_A]]
             constraint.rigidB=rigidNameMap[obj[CONSTRAINT_B]]
+            constraint.pos.x=obj.location[0]
+            constraint.pos.y=obj.location[2]
+            constraint.pos.z=obj.location[1]
+            constraint.rot.x=-obj.rotation_euler[0]
+            constraint.rot.y=-obj.rotation_euler[2]
+            constraint.rot.z=-obj.rotation_euler[1]
+            constraint.constraintPosMin.x=obj[CONSTRAINT_POS_MIN][0]
+            constraint.constraintPosMin.y=obj[CONSTRAINT_POS_MIN][1]
+            constraint.constraintPosMin.z=obj[CONSTRAINT_POS_MIN][2]
+            constraint.constraintPosMax.x=obj[CONSTRAINT_POS_MAX][0]
+            constraint.constraintPosMax.y=obj[CONSTRAINT_POS_MAX][1]
+            constraint.constraintPosMax.z=obj[CONSTRAINT_POS_MAX][2]
+            constraint.constraintRotMin.x=obj[CONSTRAINT_ROT_MIN][0]
+            constraint.constraintRotMin.y=obj[CONSTRAINT_ROT_MIN][1]
+            constraint.constraintRotMin.z=obj[CONSTRAINT_ROT_MIN][2]
+            constraint.constraintRotMax.x=obj[CONSTRAINT_ROT_MAX][0]
+            constraint.constraintRotMax.y=obj[CONSTRAINT_ROT_MAX][1]
+            constraint.constraintRotMax.z=obj[CONSTRAINT_ROT_MAX][2]
+            constraint.springPos.x=obj[CONSTRAINT_SPRING_POS][0]
+            constraint.springPos.y=obj[CONSTRAINT_SPRING_POS][1]
+            constraint.springPos.z=obj[CONSTRAINT_SPRING_POS][2]
+            constraint.springRot.x=obj[CONSTRAINT_SPRING_ROT][0]
+            constraint.springRot.y=obj[CONSTRAINT_SPRING_ROT][1]
+            constraint.springRot.z=obj[CONSTRAINT_SPRING_ROT][2]
 
         # 書き込み
         print('write', path)
index 3a7050e..51b28ba 100644 (file)
@@ -32,8 +32,23 @@ BASE_SHAPE_NAME='Basis'
 RIGID_SHAPE_TYPE='rigid_shape_type'
 RIGID_PROCESS_TYPE='rigid_process_type'
 RIGID_BONE_NAME='rigid_bone_name'
-CONSTRAINT_A='constraint_a'
-CONSTRAINT_B='constraint_b'
+#RIGID_LOCATION='rigid_loation'
+RIGID_GROUP='ribid_group'
+RIGID_INTERSECTION_GROUP='rigid_intersection_group'
+RIGID_WEIGHT='rigid_weight'
+RIGID_LINEAR_DAMPING='rigid_linear_damping'
+RIGID_ANGULAR_DAMPING='rigid_angular_damping'
+RIGID_RESTITUTION='rigid_restitution'
+RIGID_FRICTION='rigid_friction'
+CONSTRAINT_A='const_a'
+CONSTRAINT_B='const_b'
+CONSTRAINT_POS_MIN='const_pos_min'
+CONSTRAINT_POS_MAX='const_pos_max'
+CONSTRAINT_ROT_MIN='const_rot_min'
+CONSTRAINT_ROT_MAX='const_rot_max'
+CONSTRAINT_SPRING_POS='const_spring_pos'
+CONSTRAINT_SPRING_ROT='const_spring_rot'
+
 
 ###############################################################################
 # import
@@ -600,6 +615,12 @@ def __importConstraints(scene, io):
 
         meshObject[CONSTRAINT_A]=io.rigidbodies[c.rigidA].getName()
         meshObject[CONSTRAINT_B]=io.rigidbodies[c.rigidB].getName()
+        meshObject[CONSTRAINT_POS_MIN]=bl.VtoV(c.constraintPosMin)
+        meshObject[CONSTRAINT_POS_MAX]=bl.VtoV(c.constraintPosMax)
+        meshObject[CONSTRAINT_ROT_MIN]=bl.VtoV(c.constraintRotMin)
+        meshObject[CONSTRAINT_ROT_MAX]=bl.VtoV(c.constraintRotMax)
+        meshObject[CONSTRAINT_SPRING_POS]=bl.VtoV(c.springPos)
+        meshObject[CONSTRAINT_SPRING_ROT]=bl.VtoV(c.springRot)
 
     for meshObject in reversed(constraintMeshes):
         bl.objectMakeParent(container, meshObject)
@@ -673,6 +694,15 @@ def __importRigidBodies(scene, io):
             bone_name=bone.getName()
         meshObject[RIGID_BONE_NAME]=bone_name
 
+        #meshObject[RIGID_LOCATION]=bl.VtoV(rigid.location)
+        meshObject[RIGID_GROUP]=rigid.group
+        meshObject[RIGID_INTERSECTION_GROUP]=rigid.target
+        meshObject[RIGID_WEIGHT]=rigid.weight
+        meshObject[RIGID_LINEAR_DAMPING]=rigid.linearDamping
+        meshObject[RIGID_ANGULAR_DAMPING]=rigid.angularDamping
+        meshObject[RIGID_RESTITUTION]=rigid.restitution
+        meshObject[RIGID_FRICTION]=rigid.friction
+
     for meshObject in reversed(rigidMeshes):
         bl.objectMakeParent(container, meshObject)
 
index 8c24857..e8461cf 100644 (file)
@@ -36,6 +36,7 @@ if sys.version_info[0]<3:
      data_files=[
              ('blender24', [
                  'blender24/README',
+                 'bl24.py',
                  'mqo_import.py', 
                  'mqo_export.py',
                  'pmd_import.py', 
@@ -49,6 +50,7 @@ else:
     data_files=[
             ('blender25', [
                 'blender25/README',
+                'bl25.py',
                 'import_scene_mqo.py',
                 'export_scene_mqo.py',
                 'import_scene_pmd.py',
@@ -61,7 +63,7 @@ else:
 for i in range(len(ext_modules)+1):
     try:
         setup(name="meshio",
-                version='0.6',
+                version='0.7',
                 description='polygon mesh io utilities',
                 author='ousttrue',
                 author_email='ousttrue@gmail.com',