Need an easy way to mass add shape keys
In order to make shape keys available to, for example, game devs, it'd be beneficial to have the ability to add many shape keys at once. Possibly an entire category, or some other similar mass add functionality.
The functionality itself is not particularly tricky, it's more a question of figuring out a usable workflow with an understandable UI.
For now, running this in blender's script tab with a basemesh selected will load all the targets listed in "targets_to_load". Note that this is a heavy operation which might take some time. It is probably a bad idea to mass load macro targets this way.
import bpy, os, json
from mpfb.services.targetservice import TargetService
from mpfb.services.locationservice import LocationService
_TARGETS_DIR = LocationService.get_mpfb_data("targets")
_TARGETS_JSON = os.path.join(_TARGETS_DIR, "target.json")
targets_to_load = ["head", "nose"]
obj = bpy.context.object
with open(_TARGETS_JSON, "r") as json_file:
ALL_TARGETS = json.load(json_file)
for section_name in ALL_TARGETS.keys():
if section_name in targets_to_load:
section = ALL_TARGETS[section_name]
for category in section["categories"]:
for target in category["targets"]:
full_path = os.path.abspath(os.path.join(_TARGETS_DIR, section_name, target + ".target.gz"))
TargetService.load_target(obj, full_path)
I think there should be a built-in button to run this script. It is very useful for creating shape keys by applying the Armature modifier as a shape key. Example application:
- In Pose mode, a certain position of the face is created.
- Bake the shape keys so Armature can be applied.
- The Armture modifier is applied as a shape key.
- Restore the original shape keys using the script.
- A new Armature modifier is created.
- Using MakeTarget we create a new key form - PrimaryTarget. We rename it or delete it. We rename our key shape to PrimaryTarget so that it can be exported to Makehuman. This avoids creating key shapes in Edit mode.
I don't have enough practice with Blender and mpfb2 yet, but I just tried this and it seems to work. Exported shape key in MakeHuman works. However, that is not reflected in the MakeHuman exported model, hoverer import custom target /shape key exists.