From 20b804521c97bc0b39092cda13f2bf9b744725c6 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 23 Jun 2010 23:42:01 +0900 Subject: [PATCH] fix mqo hierarchy. fix pmd constraint name. --- swig/blender/bl24.py | 3 ++ swig/blender/bl25.py | 3 ++ swig/blender/mqo_export.py | 94 ++++++++++++++++++++++++---------------------- swig/blender/pmd_export.py | 3 +- swig/blender/pmd_import.py | 6 ++- 5 files changed, 61 insertions(+), 48 deletions(-) diff --git a/swig/blender/bl24.py b/swig/blender/bl24.py index 079400f..d433fd4 100644 --- a/swig/blender/bl24.py +++ b/swig/blender/bl24.py @@ -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') + diff --git a/swig/blender/bl25.py b/swig/blender/bl25.py index 74214a5..d45670e 100644 --- a/swig/blender/bl25.py +++ b/swig/blender/bl25.py @@ -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') + diff --git a/swig/blender/mqo_export.py b/swig/blender/mqo_export.py index 09b91b8..5f753d5 100644 --- a/swig/blender/mqo_export.py +++ b/swig/blender/mqo_export.py @@ -169,15 +169,15 @@ class MqoExporter(object): io.write("}\r\n") def __write_object(self, io, info, scene): - #print(info) + print(info) obj=info.object - if obj.type.upper()!='MESH': + if obj.type.upper()=='MESH' or obj.type.upper()=='EMPTY': + pass + else: + print(obj.type) return - # duplicate and applyMatrix - mesh, dumy=bl.objectDuplicate(scene, obj) - ############################################################ # write ############################################################ @@ -196,49 +196,53 @@ class MqoExporter(object): io.write("\tmirror 1\r\n") io.write("\tmirror_axis 1\r\n") - # vertices - io.write("\tvertex %d {\r\n" % len(mesh.verts)) - for vert in mesh.verts: - x, y, z = convert_to_mqo(vert.co) - io.write("\t\t%f %f %f\r\n" % - (x*self.scale, y*self.scale, z*self.scale)) # rotate to y-up - io.write("\t}\r\n") - - # faces - io.write("\tface %d {\r\n" % len(mesh.faces)) - for i, face in enumerate(mesh.faces): - count=bl.faceVertexCount(face) - # V - io.write("\t\t%d V(" % count) - face_list=[] - for j in bl.faceVertices(face): - face_list.insert(0, j) - # flip face - for j in face_list: - io.write("%d " % j) - io.write(")") - # mat - if len(mesh.materials): - io.write(" M(%d)" % - info.material_map[bl.faceMaterialIndex(face)]) - # UV - if bl.meshHasUV(mesh) and bl.faceHasUV(mesh, i, face): - io.write(" UV(") - uv_list=[] - for uv in bl.faceGetUV(mesh, i, face, count): - # reverse vertical value - uv_list.insert(0, uv) + if obj.type.upper()=='MESH': + # duplicate and applyMatrix + mesh, dumy=bl.objectDuplicate(scene, obj) + + # vertices + io.write("\tvertex %d {\r\n" % len(mesh.verts)) + for vert in mesh.verts: + x, y, z = convert_to_mqo(vert.co) + io.write("\t\t%f %f %f\r\n" % + (x*self.scale, y*self.scale, z*self.scale)) # rotate to y-up + io.write("\t}\r\n") + + # faces + io.write("\tface %d {\r\n" % len(mesh.faces)) + for i, face in enumerate(mesh.faces): + count=bl.faceVertexCount(face) + # V + io.write("\t\t%d V(" % count) + face_list=[] + for j in bl.faceVertices(face): + face_list.insert(0, j) # flip face - for uv in uv_list: - io.write("%f %f " % (uv[0], 1.0-uv[1])) + for j in face_list: + io.write("%d " % j) io.write(")") - io.write("\r\n") - io.write("\t}\r\n") # end of faces - io.write("}\r\n") # end of object - ############################################################ + # mat + if len(mesh.materials): + io.write(" M(%d)" % + info.material_map[bl.faceMaterialIndex(face)]) + # UV + if bl.meshHasUV(mesh) and bl.faceHasUV(mesh, i, face): + io.write(" UV(") + uv_list=[] + for uv in bl.faceGetUV(mesh, i, face, count): + # reverse vertical value + uv_list.insert(0, uv) + # flip face + for uv in uv_list: + io.write("%f %f " % (uv[0], 1.0-uv[1])) + io.write(")") + io.write("\r\n") + io.write("\t}\r\n") # end of faces + + # 削除する + scene.objects.unlink(dumy) - # 削除する - scene.objects.unlink(dumy) + io.write("}\r\n") # end of object def __execute(filename, scene, scale=10): diff --git a/swig/blender/pmd_export.py b/swig/blender/pmd_export.py index 1d863cc..73d71f1 100644 --- a/swig/blender/pmd_export.py +++ b/swig/blender/pmd_export.py @@ -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] diff --git a/swig/blender/pmd_import.py b/swig/blender/pmd_import.py index 9813deb..670a6af 100644 --- a/swig/blender/pmd_import.py +++ b/swig/blender/pmd_import.py @@ -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) -- 2.11.0