Esempio n. 1
0
    def filter_items(self, context, data, propname):
        # We will use the filtering to sort the mesh objects to match the rig order
        objects = getattr(data, propname)
        flt_flags = [~self.bitflag_filter_item] * len(objects)
        flt_neworder = list(range(len(objects)))
        active_root = Model.findRoot(context.active_object)
        #rig = Model(active_root)
        #for i, obj in enumerate(objects):
        #    if (obj.type == 'MESH' and obj.mmd_type == 'NONE'
        #            and Model.findRoot(obj) == active_root):
        #        flt_flags[i] = self.bitflag_filter_item
        #        new_index = rig.getMeshIndex(obj.name)
        #        flt_neworder[i] = new_index
        name_dict = {}
        for i, obj in enumerate(objects):
            if (obj.type == 'MESH' and obj.mmd_type == 'NONE'
                    and Model.findRoot(obj) == active_root):
                flt_flags[i] = self.bitflag_filter_item
                name_dict[obj.name] = i

        for new_index, name in enumerate(sorted(name_dict.keys())):
            i = name_dict[name]
            flt_neworder[i] = new_index

        return flt_flags, flt_neworder
Esempio n. 2
0
def _get_selected_objects(context):
    selected_objects = set(i for i in context.selected_objects
                           if i.type == 'MESH')
    for i in context.selected_objects:
        root = Model.findRoot(i)
        if root == i:
            selected_objects |= set(Model(root).meshes())
    return selected_objects
Esempio n. 3
0
def _set_bone(prop, value):
    root = prop.id_data
    fnModel = FnModel(root)
    arm = fnModel.armature()
    if value not in arm.pose.bones.keys():
        prop['bone_id'] = -1
        return
    pose_bone = arm.pose.bones[value]
    fnBone = FnBone(pose_bone)
    prop['bone_id'] = fnBone.bone_id
Esempio n. 4
0
def _set_bone(prop, value):
    root = prop.id_data
    fnModel = FnModel(root)
    arm = fnModel.armature()
    if value not in arm.pose.bones.keys():
        prop['bone_id'] = -1
        return
    pose_bone = arm.pose.bones[value]
    fnBone = FnBone(pose_bone)
    prop['bone_id'] = fnBone.bone_id
Esempio n. 5
0
def _get_bone(prop):
    bone_id = prop.get('bone_id', -1)
    if bone_id < 0:
        return ''
    root = prop.id_data
    fnModel = FnModel(root)
    arm = fnModel.armature()
    fnBone = FnBone.from_bone_id(arm, bone_id)
    if not fnBone:
        return ''
    return fnBone.pose_bone.name
Esempio n. 6
0
def _get_bone(prop):
    bone_id = prop.get('bone_id', -1)
    if bone_id < 0:
        return ''
    root = prop.id_data
    fnModel = FnModel(root)
    arm = fnModel.armature()
    fnBone = FnBone.from_bone_id(arm, bone_id)
    if not fnBone:
        return ''
    return fnBone.pose_bone.name
Esempio n. 7
0
def _setNameJ(prop, value):
    old_value = prop.get('name_j')
    prop_value = value
    if prop_value and prop_value != old_value:
        root = Model.findRoot(bpy.context.active_object)
        if root:
            rig = Model(root)
            prop_value = utils.uniqueName(
                value,
                [mat.mmd_material.name_j for mat in rig.materials() if mat])
        else:
            prop_value = utils.uniqueName(
                value, [mat.mmd_material.name_j for mat in bpy.data.materials])

    prop['name_j'] = prop_value
Esempio n. 8
0
    def draw(self, context):
        layout = self.layout
        obj = context.active_object

        root = Model.findRoot(obj)

        row = layout.row(align=True)
        c = row.column(align=True)
        c.prop(root.mmd_root, 'show_meshes', text='Mesh')
        c.prop(root.mmd_root, 'show_armature', text='Armature')
        c.prop(root.mmd_root, 'show_rigid_bodies', text='Rigid Body')
        c.prop(root.mmd_root, 'show_joints', text='Joint')
        c = row.column(align=True)
        c.prop(root.mmd_root, 'show_temporary_objects', text='Temporary Object')
        c.label() # for alignment only
        c.prop(root.mmd_root, 'show_names_of_rigid_bodies', text='Rigid Body Name')
        c.prop(root.mmd_root, 'show_names_of_joints', text='Joint Name')

        row = layout.row(align=True)
        row.active = context.scene.render.engine in {'BLENDER_RENDER', 'BLENDER_GAME'}
        row.prop(root.mmd_root, 'use_toon_texture', text='Toon Texture')
        row.prop(root.mmd_root, 'use_sphere_texture', text='Sphere Texture')

        row = layout.row(align=True)
        row.prop(root.mmd_root, 'use_sdef', text='SDEF')
Esempio n. 9
0
def _set_bone(prop, value):
    bone_name = value
    obj = prop.id_data
    relation = obj.constraints.get('mmd_tools_rigid_parent', None)
    if relation is None:
        relation = obj.constraints.new('CHILD_OF')
        relation.name = 'mmd_tools_rigid_parent'
        relation.mute = True

    arm = relation.target
    if arm is None:
        root = Model.findRoot(obj)
        if root:
            arm = relation.target = Model(root).armature()

    if arm is not None and bone_name in arm.data.bones:
        relation.subtarget = bone_name
    else:
        relation.subtarget = bone_name = ''

    prop['bone'] = bone_name
Esempio n. 10
0
    def execute(self, context):
        from mmd_tools.core.model import Model
        root = Model.findRoot(context.active_object)
        if root is None:
            self.report({'ERROR'}, 'Select a MMD model')
            return {'CANCELLED'}

        rig = Model(root)
        if self.action == 'CLEAN':
            for obj in rig.meshes():
                self.__clean_toon_edge(obj)
        else:
            scale = rig.rootObject().empty_draw_size * 0.2
            counts = sum(
                self.__create_toon_edge(obj, scale) for obj in rig.meshes())
            self.report({'INFO'}, 'Created %d toon edge(s)' % counts)
        return {'FINISHED'}
Esempio n. 11
0
    def draw(self, context):
        layout = self.layout
        active_obj = context.active_object
        root = Model.findRoot(active_obj)
        if root is None:
            layout.label(text='Select a MMD Model')
            return

        col = layout.column(align=True)
        row = col.row()
        row.template_list("MMD_TOOLS_UL_ModelMeshes", "",
                          SceneOp(context).id_scene, 'objects', root.mmd_root,
                          "active_mesh_index")
        tb = row.column()
        tb1 = tb.column(align=True)
        tb1.enabled = active_obj.type == 'MESH' and active_obj.mmd_type == 'NONE'
        tb1.operator('mmd_tools.object_move', text='',
                     icon=TRIA_UP_BAR).type = 'TOP'
        tb1.operator('mmd_tools.object_move', text='',
                     icon='TRIA_UP').type = 'UP'
        tb1.operator('mmd_tools.object_move', text='',
                     icon='TRIA_DOWN').type = 'DOWN'
        tb1.operator('mmd_tools.object_move', text='',
                     icon=TRIA_DOWN_BAR).type = 'BOTTOM'
Esempio n. 12
0
def _set_related_mesh(prop, value):
    rig = FnModel(prop.id_data)
    if rig.findMesh(value):
        prop['related_mesh'] = value
    else:
        prop['related_mesh'] = ''
Esempio n. 13
0
 def poll(cls, context):
     return Model.findRoot(context.active_object)