Skip to content

Commit

Permalink
Also select a corresponding material slot, for issue #186
Browse files Browse the repository at this point in the history
  • Loading branch information
joepal1976 committed May 24, 2024
1 parent b7a2abc commit 7a52cb0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
13 changes: 12 additions & 1 deletion src/mpfb/ui/assetlibrary/operators/loadlibraryskin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

_LOG = LogService.get_logger("assetlibrary.loadlibraryskin")


class MPFB_OT_Load_Library_Skin_Operator(bpy.types.Operator):
"""Load skin MHMAT from asset library"""
bl_idname = "mpfb.load_library_skin"
Expand All @@ -21,7 +22,7 @@ def execute(self, context):

_LOG.debug("filepath", self.filepath)

from mpfb.ui.assetlibrary.assetsettingspanel import ASSET_SETTINGS_PROPERTIES # pylint: disable=C0415
from mpfb.ui.assetlibrary.assetsettingspanel import ASSET_SETTINGS_PROPERTIES # pylint: disable=C0415

scene = context.scene

Expand All @@ -37,7 +38,17 @@ def execute(self, context):

HumanService.set_character_skin(self.filepath, basemesh, bodyproxy=bodyproxy, skin_type=skin_type, material_instances=material_instances)

for slot in basemesh.material_slots:
if str(slot.material.name).lower().endswith("body"):
basemesh.active_material_index = slot.slot_index

if bodyproxy:
for slot in bodyproxy.material_slots:
if str(slot.material.name).lower().endswith("body"):
bodyproxy.active_material_index = slot.slot_index

self.report({'INFO'}, "Skin was loaded")
return {'FINISHED'}


ClassManager.add_class(MPFB_OT_Load_Library_Skin_Operator)
7 changes: 7 additions & 0 deletions src/mpfb/ui/newhuman/operators/humanfrompresets.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ def hardened_execute(self, context):
bpy.ops.object.mode_set(mode='EDIT', toggle=False)
MeshService.select_all_vertices_in_vertex_group_for_active_object(preselect_group, deselect_other=True)
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
for slot in proxy.material_slots:
if str(slot.material.name).lower().endswith(str(preselect_group).lower()):
proxy.active_material_index = slot.slot_index

bpy.ops.object.select_all(action='DESELECT')
bpy.context.view_layer.objects.active = basemesh
Expand All @@ -84,6 +87,10 @@ def hardened_execute(self, context):
MeshService.select_all_vertices_in_vertex_group_for_active_object(preselect_group, deselect_other=True)
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)

for slot in basemesh.material_slots:
if str(slot.material.name).lower().endswith(str(preselect_group).lower()):
basemesh.active_material_index = slot.slot_index

rig = ObjectService.find_object_of_type_amongst_nearest_relatives(basemesh, mpfb_type_name="Skeleton")
if rig:
bpy.context.view_layer.objects.active = rig
Expand Down
4 changes: 2 additions & 2 deletions src/mpfb/ui/newhuman/properties/preselect_group.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"type": "string",
"name": "preselect_group",
"description": "The name of a a vertex group that should be selected per default in edit mode. This will come into effect for both base mesh and proxy",
"description": "The name of a a vertex group that should be selected per default in edit mode. This will come into effect for both base mesh and proxy. If material slots are used, the material slot with the group in its name will be marked as active",
"label": "Preselect group",
"default": ""
"default": "body"
}

0 comments on commit 7a52cb0

Please sign in to comment.