OSDN Git Service

fix mqo hierarchy. fix pmd constraint name.
authorousttrue <ousttrue@gmail.com>
Wed, 23 Jun 2010 14:42:01 +0000 (23:42 +0900)
committerousttrue <ousttrue@gmail.com>
Wed, 23 Jun 2010 14:42:01 +0000 (23:42 +0900)
swig/blender/bl24.py
swig/blender/bl25.py
swig/blender/mqo_export.py
swig/blender/pmd_export.py
swig/blender/pmd_import.py

index 079400f..d433fd4 100644 (file)
@@ -450,3 +450,6 @@ def meshFlipNormals(mesh):
 def faceGetIndices(face):
     return [face.verts[0].index, face.verts[1].index, face.verts[2].index]
 
+def internalToCp932(s):
+    return s.decode(INTERNAL_ENCODING).encode('cp932')
+
index 74214a5..d45670e 100644 (file)
@@ -489,3 +489,6 @@ def materialHasTexture(material):
 def faceGetIndices(face):
     return [face.verts[0], face.verts[1], face.verts[2]]
 
+def internalToCp932(s):
+    return s.encode('cp932')
+
index 09b91b8..5f753d5 100644 (file)
@@ -169,15 +169,15 @@ class MqoExporter(object):
         io.write("}\r\n") \r
 \r
     def __write_object(self, io, info, scene):\r
-        #print(info)\r
+        print(info)\r
 \r
         obj=info.object\r
-        if obj.type.upper()!='MESH':\r
+        if obj.type.upper()=='MESH' or obj.type.upper()=='EMPTY':\r
+            pass\r
+        else:\r
+            print(obj.type)\r
             return\r
 \r
-        # duplicate and applyMatrix\r
-        mesh, dumy=bl.objectDuplicate(scene, obj)\r
-\r
         ############################################################\r
         # write\r
         ############################################################\r
@@ -196,49 +196,53 @@ class MqoExporter(object):
                 io.write("\tmirror 1\r\n")\r
                 io.write("\tmirror_axis 1\r\n")\r
 \r
-        # vertices\r
-        io.write("\tvertex %d {\r\n" % len(mesh.verts))\r
-        for vert in mesh.verts:\r
-            x, y, z = convert_to_mqo(vert.co)\r
-            io.write("\t\t%f %f %f\r\n" % \r
-                    (x*self.scale, y*self.scale, z*self.scale)) # rotate to y-up\r
-        io.write("\t}\r\n")\r
-\r
-        # faces\r
-        io.write("\tface %d {\r\n" % len(mesh.faces))\r
-        for i, face in enumerate(mesh.faces):\r
-            count=bl.faceVertexCount(face)\r
-            # V\r
-            io.write("\t\t%d V(" % count)\r
-            face_list=[]\r
-            for j in bl.faceVertices(face):\r
-                face_list.insert(0, j)\r
-            # flip face\r
-            for j in face_list:\r
-                io.write("%d " % j)\r
-            io.write(")")\r
-            # mat\r
-            if len(mesh.materials):\r
-                io.write(" M(%d)" % \r
-                        info.material_map[bl.faceMaterialIndex(face)])\r
-            # UV\r
-            if bl.meshHasUV(mesh) and bl.faceHasUV(mesh, i, face):\r
-                io.write(" UV(")\r
-                uv_list=[]\r
-                for uv in bl.faceGetUV(mesh, i, face, count):\r
-                    # reverse vertical value\r
-                    uv_list.insert(0, uv)\r
+        if obj.type.upper()=='MESH':\r
+            # duplicate and applyMatrix\r
+            mesh, dumy=bl.objectDuplicate(scene, obj)\r
+\r
+            # vertices\r
+            io.write("\tvertex %d {\r\n" % len(mesh.verts))\r
+            for vert in mesh.verts:\r
+                x, y, z = convert_to_mqo(vert.co)\r
+                io.write("\t\t%f %f %f\r\n" % \r
+                        (x*self.scale, y*self.scale, z*self.scale)) # rotate to y-up\r
+            io.write("\t}\r\n")\r
+\r
+            # faces\r
+            io.write("\tface %d {\r\n" % len(mesh.faces))\r
+            for i, face in enumerate(mesh.faces):\r
+                count=bl.faceVertexCount(face)\r
+                # V\r
+                io.write("\t\t%d V(" % count)\r
+                face_list=[]\r
+                for j in bl.faceVertices(face):\r
+                    face_list.insert(0, j)\r
                 # flip face\r
-                for uv in uv_list:\r
-                    io.write("%f %f " % (uv[0], 1.0-uv[1])) \r
+                for j in face_list:\r
+                    io.write("%d " % j)\r
                 io.write(")")\r
-            io.write("\r\n")\r
-        io.write("\t}\r\n") # end of faces\r
-        io.write("}\r\n") # end of object\r
-        ############################################################\r
+                # mat\r
+                if len(mesh.materials):\r
+                    io.write(" M(%d)" % \r
+                            info.material_map[bl.faceMaterialIndex(face)])\r
+                # UV\r
+                if bl.meshHasUV(mesh) and bl.faceHasUV(mesh, i, face):\r
+                    io.write(" UV(")\r
+                    uv_list=[]\r
+                    for uv in bl.faceGetUV(mesh, i, face, count):\r
+                        # reverse vertical value\r
+                        uv_list.insert(0, uv)\r
+                    # flip face\r
+                    for uv in uv_list:\r
+                        io.write("%f %f " % (uv[0], 1.0-uv[1])) \r
+                    io.write(")")\r
+                io.write("\r\n")\r
+            io.write("\t}\r\n") # end of faces\r
+\r
+            # 削除する\r
+            scene.objects.unlink(dumy)\r
 \r
-        # 削除する\r
-        scene.objects.unlink(dumy)\r
+        io.write("}\r\n") # end of object\r
 \r
 \r
 def __execute(filename, scene, scale=10):\r
index 1d863cc..73d71f1 100644 (file)
@@ -35,6 +35,7 @@ RIGID_LINEAR_DAMPING='rigid_linear_damping'
 RIGID_ANGULAR_DAMPING='rigid_angular_damping'
 RIGID_RESTITUTION='rigid_restitution'
 RIGID_FRICTION='rigid_friction'
+CONSTRAINT_NAME='constraint_name'
 CONSTRAINT_A='const_a'
 CONSTRAINT_B='const_b'
 CONSTRAINT_POS_MIN='const_pos_min'
@@ -974,7 +975,7 @@ class PmdExporter(object):
         # constraint
         for obj in self.oneSkinMesh.constraints:
             constraint=io.addConstraint()
-            constraint.setName(obj.name[1:].encode('cp932'))
+            constraint.setName(obj[CONSTRAINT_NAME].encode('cp932'))
             constraint.rigidA=rigidNameMap[obj[CONSTRAINT_A]]
             constraint.rigidB=rigidNameMap[obj[CONSTRAINT_B]]
             constraint.pos.x=obj.location[0]
index 9813deb..670a6af 100644 (file)
@@ -41,6 +41,7 @@ RIGID_LINEAR_DAMPING='rigid_linear_damping'
 RIGID_ANGULAR_DAMPING='rigid_angular_damping'
 RIGID_RESTITUTION='rigid_restitution'
 RIGID_FRICTION='rigid_friction'
+CONSTRAINT_NAME='constraint_name'
 CONSTRAINT_A='const_a'
 CONSTRAINT_B='const_b'
 CONSTRAINT_POS_MIN='const_pos_min'
@@ -544,7 +545,7 @@ def __importConstraints(scene, io):
     material=bl.createMaterial('constraint')
     material.diffuse_color=(1, 0, 0)
     constraintMeshes=[]
-    for c in io.constraints:
+    for i, c in enumerate(io.constraints):
         bpy.ops.mesh.primitive_uv_sphere_add(
                 segments=8,
                 rings=4,
@@ -556,13 +557,14 @@ def __importConstraints(scene, io):
         constraintMeshes.append(meshObject)
         mesh=bl.objectGetData(meshObject)
         bl.meshAddMaterial(mesh, material)
-        meshObject.name='c'+c.getName()
+        meshObject.name='c_%d' % i
         #meshObject.draw_transparent=True
         #meshObject.draw_wire=True
         meshObject.max_draw_type='SOLID'
         rot=c.rot
         meshObject.rotation_euler=(-rot.x, -rot.z, -rot.y)
 
+        meshObject[CONSTRAINT_NAME]=c.getName()
         meshObject[CONSTRAINT_A]=io.rigidbodies[c.rigidA].getName()
         meshObject[CONSTRAINT_B]=io.rigidbodies[c.rigidB].getName()
         meshObject[CONSTRAINT_POS_MIN]=bl.VtoV(c.constraintPosMin)