Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feet on ground #173

Open
wants to merge 1 commit into
base: blender4_measure
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/mpfb/services/humanservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions src/mpfb/ui/model/modelpanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 3 additions & 1 deletion src/mpfb/ui/model/operators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
33 changes: 33 additions & 0 deletions src/mpfb/ui/model/operators/feet_on_ground.py
Original file line number Diff line number Diff line change
@@ -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)