Shape keys problem

Discussions about MakeHuman, Blender and MPFB. It is ok to ask for general Blender support here, even if it isn't directly related to MakeHuman

Shape keys problem

Postby kerem » Wed Feb 26, 2025 9:25 pm

Hello, I am new to using blender. I am working on a web-based project using the three.js library. I want to observe the changes in the avatar by entering body measurements, just like in blender and makehuman application. I can manipulate specific areas such as shoulder width, hip size, arm length, but I cannot manipulate age, gender, weight etc. I made the necessary codes and python connections for this,I roughly know which areas to change in the phenotype parameters and how, but many morph targets cannot be found in the relevant changes. but I think the error is related to shape keys. When I try to export the avatar in (.glb) format, I cannot access all morph targets. How can I export from blender with all shape keys or do you have any suggestions for this project? Thanks!
kerem
 
Posts: 1
Joined: Wed Feb 26, 2025 8:56 pm

Re: Shape keys problem

Postby joepal » Fri Feb 28, 2025 1:47 pm

There is no way to export a character with all available shape keys. Many shape keys are mutually exclusive. Besides there are 1.2k of them, and my guess is both blender and the external system would have problems keeping all these loaded at the same time.

If you are trying to build a character editor with the ability to manipulate the character, it would probably be better to take the raw target files from here: https://github.com/makehumancommunity/m ... ta/targets and then try to implement the loading and morphing dynamically. I know other people have successfully built character editors with makehuman assets in javascript before, for example https://github.com/makehuman-js/makehuman-js and https://github.com/markandre13/makehuman.js. Maybe you could find some inspiration there?

The target file format is pretty simple. First number of each line is vertex number. The following three are how much the vertex should shift in XZY direction.
Joel Palmius (LinkedIn)
MakeHuman Infrastructure Manager
http://www.palmius.com/joel
joepal
 
Posts: 4621
Joined: Wed Jun 04, 2008 11:20 am

Re: Shape keys problem

Postby tomcat » Sat Mar 01, 2025 11:41 am

kerem wrote:When I try to export the avatar in (.glb) format, I cannot access all morph targets.

To make the shape keys appear in glTF you need to put them there manually (in Blender).

A significant part of such work is done in this project.
Foreigners' reactions to Russian "Bird's Milk" candies
— Are your birds being milked?
— In Russia everyone is milked. Here even the zucchini is used to make caviar.
User avatar
tomcat
 
Posts: 476
Joined: Sun Sep 27, 2015 7:53 pm
Location: Moscow (Orcish Stun), The Aggressive Evil Empire

Re: Shape keys problem

Postby electricmachine » Tue Mar 04, 2025 5:35 pm

hi, i was able to export a model with 758 shape keys from blender in glb format. it is 125 mb, and takes around 25 seconds to load into the browser (i have no idea whether these numbers are good or bad btw lol). i think joepal's suggestion of loading them dynamically is the best approach, but the way i did it was similar to tomcat's.

when you adjust the macrodetails in blender, it adds relevant shape keys automatically, which can be seen on object data properties. it is important that you should uncheck the "prune" option in mpfb settings, because it removes shape keys with no effect on the model. then, just set one category to 0 (gender for example), and move all other sliders between 0 and 1. this will add all possible female shape keys like "female-young", "female-old" etc. then you move gender slider to 1 for male, and repeat. then move to next category and repeat. it's time consuming but i guess it can be done through a python script in blender.

shape keys and their influences are located at your model's morphTargetDictionary and morphTargetInfluences properties.
Capture01.PNG

Capture02.PNG
electricmachine
 
Posts: 6
Joined: Wed Jan 08, 2025 9:48 am

Re: Shape keys problem

Postby joepal » Wed Mar 05, 2025 8:29 am

electricmachine wrote: it's time consuming but i guess it can be done through a python script in blender.


You can import MPFB logic and use that from the script tab. The trick is you need a workaround for importing via the relative packages that the extension platform forces on addons these days. Here's a method which can be copy-pasted to use as a replacement for imports:

Code: Select all
import sys, importlib

def dynamic_import(absolute_package_str, key):
    for amod in sys.modules:
        if amod.endswith(absolute_package_str):
            mpfb_mod = importlib.import_module(amod)

            if not hasattr(mpfb_mod, key):
                raise AttributeError(f"Module {amod} does not have attribute {key}")

            return getattr(mpfb_mod, key)
    raise ValueError(f"No module found with name ending in {absolute_package_str}")


With this in place, you can access MPFB global services and data.

For example, here's how to list all available target categories:

Code: Select all
import bpy, sys, importlib, json, os

LocationService = dynamic_import("mpfb.services.locationservice", "LocationService") # equivalent of "from mpfb.services.locationservice import LocationService"

_TARGETS_DIR = LocationService.get_mpfb_data("targets")
_TARGETS_JSON = os.path.join(_TARGETS_DIR, "target.json")
with open(_TARGETS_JSON, "r") as json_file:
    TARGETS = json.load(json_file)

for section in TARGETS.keys():
    for category in TARGETS[section]["categories"]:
        print(section + " " + category["name"])


And here's how to create a muscular caucasian woman:

Code: Select all
import bpy, sys, importlib, json, os

HumanService = dynamic_import("mpfb.services.humanservice", "HumanService")
TargetService = dynamic_import("mpfb.services.targetservice", "TargetService")

macros = TargetService.get_default_macro_info_dict()
macros["gender"] = 0.0 # female
macros["weight"] = 0.4
macros["muscle"] = 0.7
macros["cupsize"] = 0.65
macros["firmness"] = 0.45
macros["race"]["asian"] = 0.0
macros["race"]["african"] = 0.0
macros["race"]["caucasian"] = 1.0

basemesh = HumanService.create_human(macro_detail_dict=macros)


If you look at TargetService, particularly bulk_load_targets(), I'm sure you could figure out ways to add all the desired target to your basemesh: https://github.com/makehumancommunity/m ... ce.py#L695
Joel Palmius (LinkedIn)
MakeHuman Infrastructure Manager
http://www.palmius.com/joel
joepal
 
Posts: 4621
Joined: Wed Jun 04, 2008 11:20 am


Return to Blender and MPFB

Who is online

Users browsing this forum: No registered users and 1 guest