+ # shapeキーで使われる頂点のあるマテリアル
+ material_with_shape=list(material_with_shape)
+ material_with_shape.sort()
+
+ # shapeキーに使われていないマテリアル
+ material_without_shape=[]
+ for i in range(len(io.materials)):
+ if not i in material_with_shape:
+ material_without_shape.append(i)
+
+ # メッシュの生成
+ def __splitList(l, length):
+ for i in range(0, len(l), length):
+ yield l[i:i+length]
+
+ def __importMeshAndShape(material16, name):
+ mesh, meshObject=bl.mesh.create(name)
+
+ # activate object
+ bl.object.deselectAll()
+ bl.object.activate(meshObject)
+
+ # shapeキーで使われる順に並べなおしたマテリアル16個分の
+ # メッシュを作成する
+ vertex_map=__import16MaerialAndMesh(
+ meshObject, io, material16, face_map, tex_dir)
+
+ # crete shape key
+ __importShape(meshObject, io, vertex_map)
+
+ mesh.update()
+ return meshObject
+
+ mesh_objects=[__importMeshAndShape(material16, 'with_shape')
+ for material16 in __splitList(material_with_shape, 16)]
+
+ mesh_objects+=[__importMeshAndShape(material16, 'mesh')
+ for material16 in __splitList(material_without_shape, 16)]
+
+ return mesh_objects
+
+
+def __importConstraints(scene, io):
+ if isBlender24():
+ return
+ print("create constraint")
+ container=bl.object.createEmpty('Constraints')
+ layer=[
+ True, False, False, False, False, False, False, False,
+ False, False, False, False, False, False, False, False,
+ False, False, False, False, False, False, False, False,
+ False, False, False, False, False, False, False, False,
+ ]
+ material=bl.material.create('constraint')
+ material.diffuse_color=(1, 0, 0)
+ constraintMeshes=[]
+ for i, c in enumerate(io.constraints):
+ bpy.ops.mesh.primitive_uv_sphere_add(
+ segments=8,
+ rings=4,
+ size=0.1,
+ location=(c.pos.x, c.pos.z, c.pos.y),
+ layer=layer
+ )
+ meshObject=scene.objects.active
+ constraintMeshes.append(meshObject)
+ mesh=bl.object.getData(meshObject)
+ bl.mesh.addMaterial(mesh, material)
+ 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]=VtoV(c.constraintPosMin)
+ meshObject[CONSTRAINT_POS_MAX]=VtoV(c.constraintPosMax)
+ meshObject[CONSTRAINT_ROT_MIN]=VtoV(c.constraintRotMin)
+ meshObject[CONSTRAINT_ROT_MAX]=VtoV(c.constraintRotMax)
+ meshObject[CONSTRAINT_SPRING_POS]=VtoV(c.springPos)
+ meshObject[CONSTRAINT_SPRING_ROT]=VtoV(c.springRot)
+
+ for meshObject in reversed(constraintMeshes):
+ bl.object.makeParent(container, meshObject)
+
+ return container
+
+
+def __importRigidBodies(scene, io):
+ if isBlender24():
+ return
+ print("create rigid bodies")
+
+ container=bl.object.createEmpty('RigidBodies')
+ layer=[
+ True, False, False, False, False, False, False, False,
+ False, False, False, False, False, False, False, False,
+ False, False, False, False, False, False, False, False,
+ False, False, False, False, False, False, False, False,
+ ]
+ material=bl.material.create('rigidBody')
+ rigidMeshes=[]
+ for rigid in io.rigidbodies:
+ if rigid.boneIndex==0xFFFF:
+ # no reference bone
+ bone=io.bones[0]
+ else:
+ bone=io.bones[rigid.boneIndex]
+ pos=bone.pos+rigid.position
+
+ if rigid.shapeType==pmd.SHAPE_SPHERE:
+ bpy.ops.mesh.primitive_ico_sphere_add(
+ location=(pos.x, pos.z, pos.y),
+ layer=layer
+ )
+ bpy.ops.transform.resize(
+ value=(rigid.w, rigid.w, rigid.w))
+ elif rigid.shapeType==pmd.SHAPE_BOX:
+ bpy.ops.mesh.primitive_cube_add(
+ location=(pos.x, pos.z, pos.y),
+ layer=layer
+ )
+ bpy.ops.transform.resize(
+ value=(rigid.w, rigid.d, rigid.h))
+ elif rigid.shapeType==pmd.SHAPE_CAPSULE:
+ bpy.ops.mesh.primitive_tube_add(
+ location=(pos.x, pos.z, pos.y),
+ layer=layer
+ )
+ bpy.ops.transform.resize(
+ value=(rigid.w, rigid.w, rigid.h))
+ else:
+ assert(False)
+
+ meshObject=scene.objects.active
+ mesh=bl.object.getData(meshObject)
+ rigidMeshes.append(meshObject)
+ bl.mesh.addMaterial(mesh, material)
+ meshObject.name=rigid.getName()
+ #meshObject.draw_transparent=True
+ #meshObject.draw_wire=True
+ meshObject.max_draw_type='WIRE'
+ rot=rigid.rotation
+ meshObject.rotation_euler=(-rot.x, -rot.z, -rot.y)
+
+ # custom properties
+ meshObject[RIGID_SHAPE_TYPE]=rigid.shapeType
+ meshObject[RIGID_PROCESS_TYPE]=rigid.processType
+
+ bone_name = englishmap.getEnglishBoneName(bone.getName())
+ if not bone_name:
+ bone_name=bone.getName()
+ meshObject[RIGID_BONE_NAME]=bone_name
+
+ 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.object.makeParent(container, meshObject)
+
+ return container