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))
|
||||
|
||||
Reference in new issue
Block a user