def execute(self, context):
        obj = context.active_object
        root = mmd_model.Model.findRoot(obj)
        rig = mmd_model.Model(root)
        mmd_root = rig.rootObject().mmd_root
        joint = rig.createJoint(
            name='Joint',
            name_e='Joint_e',
            location=[0, 0, 0],
            rotation=[0, 0, 0],
            size=0.5 * mmd_root.scale,
            rigid_a=None,
            rigid_b=None,
            maximum_location=[0, 0, 0],
            minimum_location=[0, 0, 0],
            maximum_rotation=[0, 0, 0],
            minimum_rotation=[0, 0, 0],
            spring_linear=[0, 0, 0],
            spring_angular=[0, 0, 0],
        )
        if mmd_root.show_joints:
            joint.hide = False
            utils.selectAObject(joint)
        else:
            joint.hide = True
            utils.selectAObject(obj)

        if 'mmd_tools.' + mmd_root.name + '_all' in bpy.data.groups.keys(
        ):  # Add Joint to allGroup
            bpy.data.groups['mmd_tools.' + mmd_root.name + '_all'].link(joint)
        if 'mmd_tools.' + mmd_root.name + '_joints' in bpy.data.groups.keys(
        ):  # Add Joint to joints group
            bpy.data.groups['mmd_tools.' + mmd_root.name +
                            '_joints'].link(joint)
        return {'FINISHED'}
Example #2
0
    def execute(self, context):
        obj = context.active_object
        root = mmd_model.Model.findRoot(obj)
        rig = mmd_model.Model(root)
        mmd_root = rig.rootObject().mmd_root
        joint = rig.createJoint(
            name='Joint',
            name_e='Joint_e',
            location=[0, 0, 0],
            rotation=[0, 0, 0],
            size=0.5 * mmd_root.scale,
            rigid_a=None,
            rigid_b=None,
            maximum_location=[0, 0, 0],
            minimum_location=[0, 0, 0],
            maximum_rotation=[0, 0, 0],
            minimum_rotation=[0, 0, 0],
            spring_linear=[0, 0, 0],
            spring_angular=[0, 0, 0],
        )
        if mmd_root.show_joints:
            joint.hide = False
            utils.selectAObject(joint)
        else:
            joint.hide = True
            utils.selectAObject(obj)

        if 'mmd_tools.' + mmd_root.name + '_all' in bpy.data.groups.keys():  # Add Joint to allGroup
            bpy.data.groups['mmd_tools.' + mmd_root.name + '_all'].link(joint)
        if 'mmd_tools.' + mmd_root.name + '_joints' in bpy.data.groups.keys():  # Add Joint to joints group
            bpy.data.groups['mmd_tools.' + mmd_root.name + '_joints'].link(joint)
        return {'FINISHED'}
Example #3
0
    def execute(self, context):
        obj = context.active_object
        root = mmd_model.Model.findRoot(obj)
        rig = mmd_model.Model(root)

        arm = rig.armature()
        bone_map = {}
        for i in context.selected_objects:
            if mmd_model.isRigidBodyObject(i):
                bone_map[i] = arm.data.bones.get(i.mmd_rigid.bone, None)

        if len(bone_map) < 2:
            self.report({'ERROR'},
                        "Please select two or more mmd rigid objects")
            return {'CANCELLED'}

        utils.selectAObject(root)
        root.select = False
        if context.scene.rigidbody_world is None:
            bpy.ops.rigidbody.world_add()

        for pair in self.__enumerate_rigid_pair(bone_map):
            joint = self.__add_joint(rig, pair, bone_map)
            joint.select = True

        return {'FINISHED'}
 def execute(self, context):
     obj = context.active_object
     if obj.mmd_type != 'JOINT':
         self.report({'ERROR'}, "Select the Joint to be deleted")
         return {'CANCELLED'}
     utils.selectAObject(obj)  #ensure this is the only one object select
     bpy.ops.object.delete(use_global=True)
     return {'FINISHED'}
Example #5
0
 def execute(self, context):
     obj = context.active_object
     if obj.mmd_type != 'JOINT':
         self.report({'ERROR'}, "Select the Joint to be deleted")
         return {'CANCELLED'}
     utils.selectAObject(obj)  # ensure this is the only one object select
     bpy.ops.object.delete(use_global=True)
     return {'FINISHED'}
Example #6
0
 def execute(self, context):
     obj = context.active_object
     root = mmd_model.Model.findRoot(obj)
     utils.selectAObject(obj)  #ensure this is the only one object select
     bpy.ops.object.delete(use_global=True)
     if root:
         utils.selectAObject(root)
     return {'FINISHED'}
Example #7
0
def _setActiveRigidbodyObject(prop, v):
    obj = bpy.context.scene.objects[v]
    root = prop.id_data
    rig = mmd_model.Model(root)
    for i in rig.rigidBodies():
        i.hide = False
    if not obj.hide:
        utils.selectAObject(obj)
    prop['active_rigidbody_object_index'] = v
Example #8
0
def _setActiveJointObject(prop, v):
    obj = bpy.context.scene.objects[v]
    root = prop.id_data
    rig = mmd_model.Model(root)
    for i in rig.joints():
        i.hide = False
    if not obj.hide:
        utils.selectAObject(obj)
    prop['active_joint_object_index'] = v
    def execute(self, context):
        obj = context.active_object
        root = mmd_model.Model.findRoot(obj)
        rig = mmd_model.Model(root)
        mmd_root = rig.rootObject().mmd_root
        rigid_shape_list = ['SPHERE', 'BOX', 'CAPSULE']
        arm = rig.armature()
        loc = (0.0, 0.0, 0.0)
        rot = (0.0, 0.0, 0.0)
        bone = None
        if context.active_pose_bone is not None:
            loc = context.active_pose_bone.location
            bone = context.active_pose_bone.name
        elif context.active_bone is not None:
            loc = context.active_bone.head
            bone = context.active_bone.name
        elif arm is not None and len(arm.pose.bones) > 0:
            loc = arm.pose.bones[0].location
            bone = arm.pose.bones[0].name

        bpy.ops.object.mode_set(mode='OBJECT')

        rigid = rig.createRigidBody(
            name=self.name_j,
            name_e=self.name_e,
            shape_type=rigid_shape_list.index(self.rigid_shape),
            dynamics_type=int(self.rigid_type),
            location=loc,
            rotation=rot,
            size=mathutils.Vector([2, 2, 2]) * mmd_root.scale,
            collision_group_number=0,
            collision_group_mask=[False for i in range(16)],
            arm_obj=arm,
            mass=1,
            friction=0.0,
            angular_damping=0.5,
            linear_damping=0.5,
            bounce=0.5,
            bone=bone,
        )
        if mmd_root.show_rigid_bodies:
            rigid.hide = False
            utils.selectAObject(rigid)
        else:
            rigid.hide = True
            utils.selectAObject(obj)

        if 'mmd_tools.' + mmd_root.name + '_all' in bpy.data.groups.keys(
        ):  # Add Rigid to allObjectsGroup
            bpy.data.groups['mmd_tools.' + mmd_root.name +
                            '_all'].objects.link(rigid)
        if 'mmd_tools.' + mmd_root.name + '_rigids' in bpy.data.groups.keys(
        ):  # Add Rigid to RigidsGroup
            bpy.data.groups['mmd_tools.' + mmd_root.name +
                            '_rigids'].objects.link(rigid)

        return {'FINISHED'}
Example #10
0
    def execute(self, context):
        obj = context.active_object
        root = mmd_model.Model.findRoot(obj)
        rig = mmd_model.Model(root)
        mmd_root = rig.rootObject().mmd_root
        rigid_shape_list = ['SPHERE', 'BOX', 'CAPSULE']
        arm = rig.armature()
        loc = (0.0, 0.0, 0.0)
        rot = (0.0, 0.0, 0.0)
        bone = None
        if context.active_pose_bone is not None:
            loc = context.active_pose_bone.location
            bone = context.active_pose_bone.name
        elif context.active_bone is not None:
            loc = context.active_bone.head
            bone = context.active_bone.name
        elif arm is not None and len(arm.pose.bones) > 0:
            loc = arm.pose.bones[0].location
            bone = arm.pose.bones[0].name

        bpy.ops.object.mode_set(mode='OBJECT')

        rigid = rig.createRigidBody(
            name=self.name_j,
            name_e=self.name_e,
            shape_type=rigid_shape_list.index(self.rigid_shape),
            dynamics_type=int(self.rigid_type),
            location=loc,
            rotation=rot,
            size=mathutils.Vector([2, 2, 2]) * mmd_root.scale,
            collision_group_number=0,
            collision_group_mask=[False for i in range(16)],
            arm_obj=arm,
            mass=1,
            friction=0.0,
            angular_damping=0.5,
            linear_damping=0.5,
            bounce=0.5,
            bone=bone,
        )
        if mmd_root.show_rigid_bodies:
            rigid.hide = False
            utils.selectAObject(rigid)
        else:
            rigid.hide = True
            utils.selectAObject(obj)

        if 'mmd_tools.' + mmd_root.name + '_all' in bpy.data.groups.keys():  # Add Rigid to allObjectsGroup
            bpy.data.groups['mmd_tools.' + mmd_root.name + '_all'].objects.link(rigid)
        if 'mmd_tools.' + mmd_root.name + '_rigids' in bpy.data.groups.keys():  # Add Rigid to RigidsGroup
            bpy.data.groups['mmd_tools.' + mmd_root.name + '_rigids'].objects.link(rigid)

        return {'FINISHED'}
Example #11
0
    def __importVertexMorphs(self):
        pmxModel = self.__model

        utils.selectAObject(self.__meshObj)
        bpy.ops.object.shape_key_add()

        for morph in filter(lambda x: isinstance(x, pmx.VertexMorph), pmxModel.morphs):
            shapeKey = self.__meshObj.shape_key_add(morph.name)
            for md in morph.offsets:
                shapeKeyPoint = shapeKey.data[md.index]
                offset = mathutils.Vector(md.offset) * self.TO_BLE_MATRIX
                shapeKeyPoint.co = shapeKeyPoint.co + offset * self.__scale
Example #12
0
    def __importVertexMorphs(self):
        pmxModel = self.__model

        utils.selectAObject(self.__meshObj)
        bpy.ops.object.shape_key_add()

        for morph in filter(lambda x: isinstance(x, pmx.VertexMorph),
                            pmxModel.morphs):
            shapeKey = self.__meshObj.shape_key_add(morph.name)
            for md in morph.offsets:
                shapeKeyPoint = shapeKey.data[md.index]
                offset = mathutils.Vector(md.offset) * self.TO_BLE_MATRIX
                shapeKeyPoint.co = shapeKeyPoint.co + offset * self.__scale
Example #13
0
    def execute(self, context):
        obj = context.active_object
        root = mmd_model.Model.findRoot(obj)
        mmd_root = root.mmd_root
        rig = mmd_model.Model(root)
        armature = rig.armature()
        mmd_root.show_armature = True
        utils.selectAObject(armature)
        morph = mmd_root.bone_morphs[mmd_root.active_morph]
        morph_data = morph.data[morph.active_bone_data]
        if morph_data.bone not in armature.pose.bones.keys():
            self.report({'ERROR'}, "Bone not found")
            return {'CANCELLED'}
        armature.data.bones.active = armature.pose.bones[morph_data.bone].bone
        bpy.ops.object.mode_set(mode='POSE')
        armature.pose.bones[morph_data.bone].bone.select = True

        return {'FINISHED'}
Example #14
0
 def execute(self, context):
     obj = context.active_object
     root = mmd_model.Model.findRoot(obj)
     mmd_root=root.mmd_root  
     rig = mmd_model.Model(root)
     armature = rig.armature()  
     mmd_root.show_armature = True
     utils.selectAObject(armature)
     bpy.ops.object.mode_set(mode='POSE')
     morph = mmd_root.bone_morphs[mmd_root.active_morph]
     morph_data = morph.data[morph.active_bone_data]
     p_bone = armature.pose.bones[morph_data.bone]
     p_bone.bone.select = True
     bpy.ops.pose.transforms_clear()
     p_bone.location = morph_data.location
     p_bone.rotation_quaternion = morph_data.rotation
     
     return { 'FINISHED' }   
Example #15
0
 def execute(self, context):
     obj = context.active_object
     root = mmd_model.Model.findRoot(obj)
     mmd_root=root.mmd_root
     rig = mmd_model.Model(root)
     armature = rig.armature()
     mmd_root.show_armature = True
     utils.selectAObject(armature)
     morph = mmd_root.bone_morphs[mmd_root.active_morph]
     morph_data = morph.data[morph.active_bone_data]
     if morph_data.bone not in armature.pose.bones.keys():
         self.report({ 'ERROR' }, "Bone not found")
         return { 'CANCELLED' }                    
     armature.data.bones.active = armature.pose.bones[morph_data.bone].bone
     bpy.ops.object.mode_set(mode='POSE')
     armature.pose.bones[morph_data.bone].bone.select=True
     
     return { 'FINISHED' }
Example #16
0
    def execute(self, context):
        obj = context.active_object
        root = mmd_model.Model.findRoot(obj)
        mmd_root = root.mmd_root
        rig = mmd_model.Model(root)
        armature = rig.armature()
        mmd_root.show_armature = True
        utils.selectAObject(armature)
        bpy.ops.object.mode_set(mode='POSE')
        morph = mmd_root.bone_morphs[mmd_root.active_morph]
        morph_data = morph.data[morph.active_bone_data]
        p_bone = armature.pose.bones[morph_data.bone]
        p_bone.bone.select = True
        bpy.ops.pose.transforms_clear()
        p_bone.location = morph_data.location
        p_bone.rotation_quaternion = morph_data.rotation

        return {'FINISHED'}
Example #17
0
 def __importVertexMorphs(self):
     pmxModel = self.__model
     mmd_root = self.__rig.rootObject().mmd_root
     utils.selectAObject(self.__meshObj)
     bpy.ops.object.shape_key_add()
     categories = {
         0: 'SYSTEM',
         1: 'EYEBROW',
         2: 'EYE',
         3: 'MOUTH',
         }
     for morph in filter(lambda x: isinstance(x, pmx.VertexMorph), pmxModel.morphs):
         shapeKey = self.__meshObj.shape_key_add(morph.name)
         vtx_morph = mmd_root.vertex_morphs.add()
         vtx_morph.name = morph.name
         vtx_morph.name_e = morph.name_e
         vtx_morph.category = categories.get(morph.category, 'OTHER')
         for md in morph.offsets:
             shapeKeyPoint = shapeKey.data[md.index]
             offset = mathutils.Vector(md.offset) * self.TO_BLE_MATRIX
             shapeKeyPoint.co = shapeKeyPoint.co + offset * self.__scale
Example #18
0
 def __importVertexMorphs(self):
     pmxModel = self.__model
     mmd_root = self.__rig.rootObject().mmd_root
     utils.selectAObject(self.__meshObj)
     bpy.ops.object.shape_key_add()
     categories = {
         0: 'SYSTEM',
         1: 'EYEBROW',
         2: 'EYE',
         3: 'MOUTH',
         }
     for morph in filter(lambda x: isinstance(x, pmx.VertexMorph), pmxModel.morphs):
         shapeKey = self.__meshObj.shape_key_add(morph.name)
         vtx_morph = mmd_root.vertex_morphs.add()
         vtx_morph.name = morph.name
         vtx_morph.name_e = morph.name_e
         vtx_morph.category = categories.get(morph.category, 'OTHER')
         for md in morph.offsets:
             shapeKeyPoint = shapeKey.data[md.index]
             offset = mathutils.Vector(md.offset) @ self.TO_BLE_MATRIX
             shapeKeyPoint.co = shapeKeyPoint.co + offset * self.__scale
Example #19
0
    def execute(self, context):
        obj = context.active_object
        root = mmd_model.Model.findRoot(obj)
        rig = mmd_model.Model(root)
        arm = rig.armature()
        if obj != arm:
            utils.selectAObject(root)
            root.select = False
        elif arm.mode != 'POSE':
            bpy.ops.object.mode_set(mode='POSE')

        selected_pose_bones = []
        if context.selected_pose_bones:
            selected_pose_bones = context.selected_pose_bones

        arm.select = False
        if len(selected_pose_bones) > 0:
            for pose_bone in selected_pose_bones:
                rigid = self.__add_rigid_body(rig, arm, pose_bone)
                rigid.select = True
        else:
            rigid = self.__add_rigid_body(rig)
            rigid.select = True
        return {'FINISHED'}
Example #20
0
def _setActiveMeshObject(prop, v):
    obj = SceneOp(bpy.context).id_objects[v]
    if obj.type == 'MESH' and obj.mmd_type == 'NONE':
        obj.hide = False
        utils.selectAObject(obj)
    prop['active_mesh_index'] = v
Example #21
0
def _setActiveJointObject(prop, v):
    obj = SceneOp(bpy.context).id_objects[v]
    if mmd_model.isJointObject(obj):
        obj.hide = False
        utils.selectAObject(obj)
    prop['active_joint_object_index'] = v
Example #22
0
def _setActiveRigidbodyObject(prop, v):
    obj = SceneOp(bpy.context).id_objects[v]
    if mmd_model.isRigidBodyObject(obj):
        obj.hide = False
        utils.selectAObject(obj)
    prop['active_rigidbody_object_index'] = v
Example #23
0
    def __assignToArmature(self, armObj, action_name=None):
        if action_name is not None:
            act = bpy.data.actions.new(name=action_name)
            a = armObj.animation_data_create()
            a.action = act

        if self.__frame_margin > 1:
            utils.selectAObject(armObj)
            bpy.context.scene.frame_current = 1
            bpy.ops.object.mode_set(mode='POSE')
            hiddenBones = []
            for i in armObj.data.bones:
                if i.hide:
                    hiddenBones.append(i)
                    i.hide = False
                i.select = True
            bpy.ops.pose.transforms_clear()
            bpy.ops.anim.keyframe_insert_menu(type='LocRotScale', confirm_success=False, always_prompt=False)
            bpy.ops.object.mode_set(mode='OBJECT')
            for i in hiddenBones:
                i.hide = True

        boneAnim = self.__vmdFile.boneAnimation

        pose_bones = armObj.pose.bones
        if self.__use_pmx_bonename:
            pose_bones = utils.makePmxBoneMap(armObj)
        for name, keyFrames in boneAnim.items():
            if name not in pose_bones:
                print("WARNING: not found bone %s" % str(name))
                continue

            keyFrames.sort(key=lambda x: x.frame_number)
            bone = pose_bones[name]
            frameNumbers = map(lambda x: x.frame_number, keyFrames)
            mat = self.makeVMDBoneLocationToBlenderMatrix(bone)
            locations = map(lambda x: mat * mathutils.Vector(x.location) * self.__scale, keyFrames)
            rotations = map(lambda x: self.convertVMDBoneRotationToBlender(bone, x.rotation), keyFrames)
            rotations = self.__fixRotations(rotations)

            for frame, location, rotation in zip(frameNumbers, locations, rotations):
                bone.location = location
                bone.rotation_quaternion = rotation
                bone.keyframe_insert(data_path='location',
                                     group=name,
                                     frame=frame + self.__frame_margin)
                bone.keyframe_insert(data_path='rotation_quaternion',
                                     group=name,
                                     frame=frame + self.__frame_margin)

        rePath = re.compile(r'^pose\.bones\["(.+)"\]\.([a-z_]+)$')
        for fcurve in act.fcurves:
            m = rePath.match(fcurve.data_path)
            if m and m.group(2) in ['location', 'rotation_quaternion']:
                bone = armObj.pose.bones[m.group(1)]
                keyFrames = boneAnim[bone.get('name_j', bone.name)]
                if m.group(2) == 'location':
                    idx = [0, 2, 1][fcurve.array_index]
                else:
                    idx = 3
                frames = list(fcurve.keyframe_points)
                frames.sort(key=lambda kp: kp.co.x)
                if self.__frame_margin > 1:
                    del frames[0]
                for i in range(1, len(keyFrames)):
                    self.__setInterpolation(keyFrames[i].interp[idx:16:4], frames[i - 1], frames[i])
Example #24
0
    def __assignToArmature(self, armObj, action_name=None):
        if action_name is not None:
            act = bpy.data.actions.new(name=action_name)
            a = armObj.animation_data_create()
            a.action = act

        if self.__frame_margin > 1:
            utils.selectAObject(armObj)
            bpy.context.scene.frame_current = 1
            bpy.ops.object.mode_set(mode='POSE')
            hiddenBones = []
            for i in armObj.data.bones:
                if i.hide:
                    hiddenBones.append(i)
                    i.hide = False
                i.select = True
            bpy.ops.pose.transforms_clear()
            bpy.ops.anim.keyframe_insert_menu(type='LocRotScale',
                                              confirm_success=False,
                                              always_prompt=False)
            bpy.ops.object.mode_set(mode='OBJECT')
            for i in hiddenBones:
                i.hide = True

        boneAnim = self.__vmdFile.boneAnimation

        pose_bones = armObj.pose.bones
        if self.__use_pmx_bonename:
            pose_bones = utils.makePmxBoneMap(armObj)
        for name, keyFrames in boneAnim.items():
            if name not in pose_bones:
                print("WARNING: not found bone %s" % str(name))
                continue

            keyFrames.sort(key=lambda x: x.frame_number)
            bone = pose_bones[name]
            frameNumbers = map(lambda x: x.frame_number, keyFrames)
            mat = self.makeVMDBoneLocationToBlenderMatrix(bone)
            locations = map(
                lambda x: mat * mathutils.Vector(x.location) * self.__scale,
                keyFrames)
            rotations = map(
                lambda x: self.convertVMDBoneRotationToBlender(
                    bone, x.rotation), keyFrames)
            rotations = self.__fixRotations(rotations)

            for frame, location, rotation in zip(frameNumbers, locations,
                                                 rotations):
                bone.location = location
                bone.rotation_quaternion = rotation
                bone.keyframe_insert(data_path='location',
                                     group=name,
                                     frame=frame + self.__frame_margin)
                bone.keyframe_insert(data_path='rotation_quaternion',
                                     group=name,
                                     frame=frame + self.__frame_margin)

        rePath = re.compile(r'^pose\.bones\["(.+)"\]\.([a-z_]+)$')
        for fcurve in act.fcurves:
            m = rePath.match(fcurve.data_path)
            if m and m.group(2) in ['location', 'rotation_quaternion']:
                bone = armObj.pose.bones[m.group(1)]
                keyFrames = boneAnim[bone.get('name_j', bone.name)]
                if m.group(2) == 'location':
                    idx = [0, 2, 1][fcurve.array_index]
                else:
                    idx = 3
                frames = list(fcurve.keyframe_points)
                frames.sort(key=lambda kp: kp.co.x)
                if self.__frame_margin > 1:
                    del frames[0]
                for i in range(1, len(keyFrames)):
                    self.__setInterpolation(keyFrames[i].interp[idx:16:4],
                                            frames[i - 1], frames[i])