diff --git a/src/mpfb/services/humanservice.py b/src/mpfb/services/humanservice.py index d35bfa17..4a0acbfb 100644 --- a/src/mpfb/services/humanservice.py +++ b/src/mpfb/services/humanservice.py @@ -1322,3 +1322,10 @@ def unload_mhclo_asset(basemesh, asset): bpy.data.objects.remove(subrig) bpy.data.objects.remove(asset) + + @staticmethod + def feet_on_ground(basemesh): + """ Make feet touch the ground """ + lowest_point = ObjectService.get_lowest_point(basemesh) + basemesh.location = (0.0, 0.0, -lowest_point) + bpy.ops.object.transform_apply(location=True, rotation=True, scale=True) diff --git a/src/mpfb/ui/model/modelpanel.py b/src/mpfb/ui/model/modelpanel.py index 8ae03aaf..eaa0411d 100644 --- a/src/mpfb/ui/model/modelpanel.py +++ b/src/mpfb/ui/model/modelpanel.py @@ -44,6 +44,7 @@ def _general(self, scene, layout): box = self._create_box(layout, "Actions") box.operator('mpfb.refit_human') box.operator('mpfb.prune_human') + box.operator('mpfb.feet_on_ground') def draw(self, context): _LOG.enter() diff --git a/src/mpfb/ui/model/operators/__init__.py b/src/mpfb/ui/model/operators/__init__.py index 371708ac..28de2f9c 100644 --- a/src/mpfb/ui/model/operators/__init__.py +++ b/src/mpfb/ui/model/operators/__init__.py @@ -6,8 +6,10 @@ from .refithuman import MPFB_OT_RefitHumanOperator from .prunehuman import MPFB_OT_PruneHumanOperator +from .feet_on_ground import MPFB_OT_TranslateHumanOperator __all__ = [ "MPFB_OT_RefitHumanOperator", - "MPFB_OT_PruneHumanOperator" + "MPFB_OT_PruneHumanOperator", + "MPFB_OT_TranslateHumanOperator", ] diff --git a/src/mpfb/ui/model/operators/feet_on_ground.py b/src/mpfb/ui/model/operators/feet_on_ground.py new file mode 100644 index 00000000..ecadc0e1 --- /dev/null +++ b/src/mpfb/ui/model/operators/feet_on_ground.py @@ -0,0 +1,33 @@ +"""Operator for a human with feet on ground.""" + +import bpy +from mpfb.services.logservice import LogService +from mpfb.services.humanservice import HumanService +from mpfb.services.objectservice import ObjectService +from mpfb import ClassManager + +_LOG = LogService.get_logger("model.feet_on_ground") + +class MPFB_OT_TranslateHumanOperator(bpy.types.Operator): + """ Translate the basemesh for feet to touch the ground. This is needed if you have changed modeling sliders for leg length""" + bl_idname = "mpfb.feet_on_ground" + bl_label = "Make feet touch the ground" + bl_options = {'REGISTER', 'UNDO'} + + def execute(self, context): + + basemesh = ObjectService.find_object_of_type_amongst_nearest_relatives(context.active_object, "Basemesh") + ObjectService.activate_blender_object(basemesh, deselect_all=True) + HumanService.feet_on_ground(basemesh) + + self.report({'INFO'}, "Assets have been translated") + return {'FINISHED'} + + @classmethod + def poll(cls, context): + if not context.active_object: + return False + basemesh = ObjectService.find_object_of_type_amongst_nearest_relatives(context.active_object, "Basemesh") + return basemesh is not None + +ClassManager.add_class(MPFB_OT_TranslateHumanOperator)