Exemple #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
Exemple #2
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')
Exemple #3
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
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()])
        else:
            prop_value = utils.uniqueName(value, [mat.mmd_material.name_j for mat in bpy.data.materials])

    prop['name_j'] = prop_value
Exemple #5
0
    def execute(self, context):
        from mmd_tools_local.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'}
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
    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)))

        armature = Model(Model.findRoot(context.active_object)).armature()
        __is_child_of_armature = lambda x: x.parent and (
            x.parent == armature or __is_child_of_armature(x.parent))

        name_dict = {}
        for i, obj in enumerate(objects):
            if obj.type == 'MESH' and obj.mmd_type == 'NONE' and __is_child_of_armature(
                    obj):
                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
Exemple #8
0
    def draw(self, context):
        layout = self.layout
        active_obj = context.active_object
        root = Model.findRoot(active_obj)
        if root is None:
            layout.label("Select a MMD Model")
            return

        col = layout.column(align=True)
        row = col.row()
        row.template_list("UL_ModelMeshes", "", context.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'
 def poll(cls, context):
     return Model.findRoot(context.active_object)