model/blend: drivers (object, object data, shape keys: variables, targets, keys, f-curve modifiers) and custom properties (objects, pose bones, bones) as data; f-curve modifiers on raw action curves; limit rotation use_legacy_behavior; 5.0 bone hide driver move for older files
This commit is contained in:
1 parent
b4e1ffebd4
commit
a1a3971207
16 files changed
+2056
-605
No files matched your search
@@ -13,7 +13,9 @@
|
||||
# rotation, child of, stretch to), lock and IK flags; shape keys with slider ranges, mute,
|
||||
# relative keys, a vertex group, and a shape-key action; an unassigned action driven by an
|
||||
# action constraint; transform / armature / floor / limit distance / track to / locked
|
||||
# track constraints; bone inheritance and b-bone settings; a saved pose basis
|
||||
# track constraints; bone inheritance and b-bone settings; a saved pose basis; drivers
|
||||
# (every variable type, keys, modifiers) on the rig, its data and the shape keys; custom
|
||||
# properties on pose bones, bones and objects
|
||||
import bpy, sys, os, math
|
||||
|
||||
out = sys.argv[sys.argv.index("--") + 1]
|
||||
@@ -726,6 +728,97 @@ def ctl_file():
|
||||
smile.value = v
|
||||
smile.keyframe_insert("value", frame=f)
|
||||
smile.value = 1.5
|
||||
# custom properties (ID properties)
|
||||
props = pose["root"]
|
||||
props["ik_arm"] = 1.0
|
||||
props["count"] = 3
|
||||
props["label"] = "left"
|
||||
props["weights"] = [0.25, 0.5, 0.75]
|
||||
props["flags"] = [1, 2, 3]
|
||||
props["nested"] = {"inner": 2.5, "name": "deep"}
|
||||
if V >= (3, 0):
|
||||
props["on"] = True
|
||||
bones["spine"]["bone_prop"] = 7
|
||||
rig["rig_prop"] = 0.5
|
||||
face["face_prop"] = "smile"
|
||||
if V >= (4, 2):
|
||||
pose["limit"].constraints["Limit Rotation"].use_legacy_behavior = True
|
||||
# drivers (data only for the reader: on constraint settings and a muted shape key, so the checked pose is unchanged)
|
||||
def drive(owner, path, kind, expression="", index=-1):
|
||||
fc = owner.driver_add(path) if index < 0 else owner.driver_add(path, index)
|
||||
fc.driver.type = kind
|
||||
if expression:
|
||||
fc.driver.expression = expression
|
||||
return fc
|
||||
fc = drive(rig, 'pose.bones["limit"].constraints["Stretch To"].bulge_smooth', "SCRIPTED", "max(0, (distance - 0.4 * s) / 2) + ik")
|
||||
setp(fc.driver, "use_self", True)
|
||||
v = fc.driver.variables.new()
|
||||
v.name, v.type = "distance", "LOC_DIFF"
|
||||
v.targets[0].id, v.targets[0].bone_target = rig, "hand_ik"
|
||||
v.targets[1].id, v.targets[1].bone_target = tgt, ""
|
||||
v.targets[1].transform_space = "LOCAL_SPACE"
|
||||
v = fc.driver.variables.new()
|
||||
v.name, v.type = "s", "TRANSFORMS"
|
||||
v.targets[0].id, v.targets[0].bone_target = rig, "upper"
|
||||
v.targets[0].transform_type, v.targets[0].transform_space = "SCALE_Y", "TRANSFORM_SPACE"
|
||||
setp(v.targets[0], "rotation_mode", "SWING_TWIST_Y")
|
||||
v = fc.driver.variables.new()
|
||||
v.name, v.type = "ik", "SINGLE_PROP"
|
||||
v.targets[0].id = rig
|
||||
v.targets[0].data_path = 'pose.bones["root"]["ik_arm"]'
|
||||
for m in list(fc.modifiers):
|
||||
fc.modifiers.remove(m)
|
||||
fc.keyframe_points.insert(0.0, 0.0)
|
||||
fc.keyframe_points.insert(1.0, 1.0)
|
||||
for k in fc.keyframe_points:
|
||||
k.interpolation = "LINEAR"
|
||||
fc.extrapolation = "LINEAR"
|
||||
fc = drive(rig, 'pose.bones["upper"].constraints["Copy Scale"].influence', "SUM")
|
||||
v = fc.driver.variables.new()
|
||||
v.name, v.type = "angle", "ROTATION_DIFF"
|
||||
v.targets[0].id, v.targets[0].bone_target = rig, "spine"
|
||||
v.targets[1].id, v.targets[1].bone_target = rig, "upper"
|
||||
gen = fc.modifiers[0] if len(fc.modifiers) else fc.modifiers.new("GENERATOR")
|
||||
gen.mode = "POLYNOMIAL"
|
||||
gen.poly_order = 2
|
||||
gen.coefficients = (0.5, 2.0, -1.0)
|
||||
gen.use_additive = True
|
||||
gen.influence = 0.8
|
||||
gen.use_influence = True
|
||||
lim = fc.modifiers.new("LIMITS")
|
||||
lim.use_max_y, lim.max_y = True, 2.0
|
||||
lim.mute = True
|
||||
st = fc.modifiers.new("STEPPED")
|
||||
st.frame_step = 2.0
|
||||
st.use_restricted_range = True
|
||||
st.frame_start, st.frame_end = 1.0, 10.0
|
||||
fc = drive(rig, 'pose.bones["pole"].constraints["Damped Track"].head_tail', "MIN")
|
||||
v = fc.driver.variables.new()
|
||||
v.name = "z"
|
||||
v.targets[0].id = tgt
|
||||
v.targets[0].data_path = "location.z"
|
||||
for m in list(fc.modifiers):
|
||||
fc.modifiers.remove(m)
|
||||
fc.modifiers.new("CYCLES")
|
||||
nz = fc.modifiers.new("NOISE")
|
||||
nz.scale, nz.strength = 2.0, 0.5
|
||||
if V >= (4, 0):
|
||||
v = fc.driver.variables.new()
|
||||
v.name, v.type = "frame", "CONTEXT_PROP"
|
||||
v.targets[0].context_property = "ACTIVE_SCENE"
|
||||
v.targets[0].data_path = "frame_current"
|
||||
fc = drive(arm_data, "bones[\"pole\"].bbone_x", "MAX")
|
||||
v = fc.driver.variables.new()
|
||||
v.name = "w"
|
||||
v.targets[0].id_type = "ARMATURE"
|
||||
v.targets[0].id = arm_data
|
||||
v.targets[0].data_path = "bones[\"upper\"].bbone_x"
|
||||
fc = drive(face.data.shape_keys, 'key_blocks["Blink"].value', "AVERAGE")
|
||||
v = fc.driver.variables.new()
|
||||
v.name, v.type = "rot", "TRANSFORMS"
|
||||
v.targets[0].id, v.targets[0].bone_target = rig, "lower"
|
||||
v.targets[0].transform_type, v.targets[0].transform_space = "ROT_X", "LOCAL_SPACE"
|
||||
setp(v.targets[0], "rotation_mode", "XZY")
|
||||
sc.frame_set(1)
|
||||
update()
|
||||
save(os.path.join(out, "ctl_%s.blend" % TAG))
|
||||
|
||||
@@ -177,6 +177,53 @@ def action_info(act):
|
||||
return {"frame_range": [r6(act.frame_range[0]), r6(act.frame_range[1])], "curves": curves}
|
||||
|
||||
|
||||
def props_info(owner):
|
||||
out = {}
|
||||
for k in owner.keys():
|
||||
if k == "_RNA_UI":
|
||||
continue
|
||||
v = owner[k]
|
||||
if hasattr(v, "to_dict"):
|
||||
v = v.to_dict()
|
||||
elif hasattr(v, "to_list"):
|
||||
v = v.to_list()
|
||||
out[k] = v
|
||||
return out
|
||||
|
||||
|
||||
MOD_KEYS = ("type", "mode", "use_additive", "coefficients", "poly_order", "mute", "influence", "use_influence",
|
||||
"use_restricted_range", "frame_start", "frame_end", "blend_in", "blend_out")
|
||||
|
||||
|
||||
def driver_info(fc):
|
||||
d = fc.driver
|
||||
variables = []
|
||||
for v in d.variables:
|
||||
targets = []
|
||||
for t in v.targets:
|
||||
targets.append({"id": t.id.name if t.id else "", "id_type": t.id_type, "data_path": t.data_path,
|
||||
"bone_target": t.bone_target, "transform_type": t.transform_type,
|
||||
"transform_space": t.transform_space, "rotation_mode": t.rotation_mode,
|
||||
"context_property": t.context_property})
|
||||
variables.append({"name": v.name, "type": v.type, "targets": targets})
|
||||
mods = []
|
||||
for m in fc.modifiers:
|
||||
e = {}
|
||||
for k in MOD_KEYS:
|
||||
if hasattr(m, k):
|
||||
e[k] = rna_value(getattr(m, k))
|
||||
mods.append(e)
|
||||
return {"data_path": fc.data_path, "array_index": fc.array_index, "extrapolation": fc.extrapolation,
|
||||
"keys": [{"co": [r6(k.co[0]), r6(k.co[1])], "interpolation": k.interpolation} for k in fc.keyframe_points],
|
||||
"driver": {"type": d.type, "expression": d.expression, "use_self": d.use_self, "variables": variables},
|
||||
"modifiers": mods}
|
||||
|
||||
|
||||
def drivers_of(idb):
|
||||
ad = getattr(idb, "animation_data", None)
|
||||
return [driver_info(fc) for fc in ad.drivers] if ad else []
|
||||
|
||||
|
||||
def constraint_info(c):
|
||||
out = {}
|
||||
if c.type == "ARMATURE":
|
||||
@@ -223,6 +270,8 @@ def rig_info(ob):
|
||||
pose[k + a] = rna_value(getattr(pb, k + a))
|
||||
for k in ("location", "rotation_quaternion", "rotation_euler", "rotation_axis_angle", "scale"):
|
||||
pose[k] = rna_value(getattr(pb, k))
|
||||
pose["props"] = props_info(pb)
|
||||
pose["bone_props"] = props_info(b)
|
||||
info = {}
|
||||
for k in BONE_KEYS:
|
||||
if hasattr(b, k):
|
||||
@@ -266,7 +315,9 @@ def dump(path):
|
||||
o = {"name": ob.name, "type": ob.type, "parent": ob.parent.name if ob.parent else "", "parent_type": ob.parent_type,
|
||||
"parent_bone": ob.parent_bone, "world": [r6(x) for x in mat(ob.matrix_world)],
|
||||
"collections": [c.name for c in ob.users_collection], "hide_viewport": ob.hide_viewport,
|
||||
"hide_render": ob.hide_render}
|
||||
"hide_render": ob.hide_render, "props": props_info(ob), "drivers": drivers_of(ob),
|
||||
"data_drivers": drivers_of(ob.data) if ob.data is not None and ob.type in ("ARMATURE", "MESH") else [],
|
||||
"shape_key_drivers": drivers_of(ob.data.shape_keys) if ob.type == "MESH" and ob.data.shape_keys else []}
|
||||
if ob.type == "MESH":
|
||||
o["mesh"] = mesh_info(ob)
|
||||
if ob.animation_data and ob.animation_data.action:
|
||||
|
||||
Reference in new issue
Block a user