merge ws/blendrig2

This commit is contained in:
4DBug committed 2026-11-02 23:58:36 -06:00
commit b4e1ffebd4
15 files changed
+1683 -560

No files matched your search

+108 -1
View File
@@ -11,7 +11,9 @@
# collections and colours (4.x), custom shapes (a hidden widget in the scene, one outside it),
# pose-bone constraints (IK, copy rotation / location / transforms, damped track, limit
# 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
# 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
import bpy, sys, os, math
out = sys.argv[sys.argv.index("--") + 1]
@@ -461,6 +463,25 @@ def ctl_file():
b.parent = eb[parent]
b.use_connect = connect
b.use_deform = deform
up, lo = eb["hand_ik"], eb["lower"] # b-bone settings on a bone that deforms nothing (skinning stays linear)
setp(eb["upper"], "inherit_scale", "ALIGNED")
setp(eb["upper"], "use_inherit_scale", False)
setp(lo, "use_inherit_rotation", False)
setp(lo, "use_local_location", False)
setp(eb["limit"], "use_relative_parent", True)
up.bbone_segments = 4
up.bbone_x, up.bbone_z = 0.05, 0.08
setp(up, "bbone_easein", 0.5)
setp(up, "bbone_easeout", 1.5)
setp(up, "bbone_rollin", 0.2)
setp(up, "bbone_curveinx", 0.1)
setp(up, "bbone_curveinz", -0.1)
setp(up, "bbone_curveoutx", 0.3)
setp(up, "bbone_scalein", (1.0, 1.0, 1.2))
setp(up, "bbone_handle_type_start", "ABSOLUTE")
setp(up, "bbone_custom_handle_start", eb["spine"])
setp(up, "bbone_handle_type_end", "TANGENT")
setp(up, "bbone_custom_handle_end", eb["pole"])
bpy.ops.object.mode_set(mode="OBJECT")
bones = arm_data.bones
bones["root"].show_wire = True
@@ -587,6 +608,92 @@ def ctl_file():
c = pose["limit"].constraints.new("STRETCH_TO")
c.target = tgt
c.influence = 0.5
c.rest_length = 0.75
c.bulge = 1.5
c.volume = "VOLUME_X"
c.keep_axis = "PLANE_Z"
setp(c, "use_bulge_min", True)
setp(c, "bulge_min", 0.5)
setp(c, "use_bulge_max", True)
setp(c, "bulge_max", 2.0)
setp(c, "bulge_smooth", 0.3)
c = pose["limit"].constraints.new("TRANSFORM")
c.target = tgt
c.map_from, c.map_to = "ROTATION", "SCALE"
c.map_to_x_from, c.map_to_y_from, c.map_to_z_from = "Z", "X", "Y"
setp(c, "from_max_x_rot", 2.356194)
setp(c, "from_min_y_rot", -0.5)
setp(c, "to_max_y_scale", 0.65)
setp(c, "to_min_x_scale", 0.9)
setp(c, "mix_mode_scale", "MULTIPLY")
setp(c, "from_rotation_mode", "SWING_TWIST_Y")
setp(c, "to_euler_order", "ZXY")
c.use_motion_extrapolate = True
c = pose["limit"].constraints.new("FLOOR")
c.target = tgt
c.floor_location = "FLOOR_NEGATIVE_Y"
c.offset = 0.2
c.use_rotation = True
c = pose["pole"].constraints.new("TRACK_TO")
c.target, c.subtarget = rig, "upper"
c.track_axis, c.up_axis = "TRACK_NEGATIVE_Y", "UP_X"
c.use_target_z = True
c = pose["root"].constraints.new("LOCKED_TRACK")
c.target = tgt
c.track_axis, c.lock_axis = "TRACK_X", "LOCK_Z"
c = pose["root"].constraints.new("LIMIT_DISTANCE")
c.target = tgt
c.distance = 2.5
c.limit_mode = "LIMITDIST_OUTSIDE"
c = pose["upper"].constraints["Copy Scale"]
setp(c, "use_make_uniform", True)
setp(c, "use_add", True)
setp(c, "power", 0.5)
if V >= (2, 80):
c = pose["spine"].constraints.new("ARMATURE")
t = c.targets.new()
t.target, t.subtarget, t.weight = rig, "root", 0.75
c.use_deform_preserve_volume = True
c.use_bone_envelopes = True
c.use_current_location = True
# an action only the action constraint uses: keys on hand_ik / limit, then unassigned
for f, loc, eul in ((1, (0, 0, 0), (0, 0, 0)), (10, (0.5, 0.1, 0), (0.3, 0, -0.2)), (25, (0, 0.4, 0.2), (-0.4, 0.2, 0))):
pose["hand_ik"].location = loc
pose["hand_ik"].keyframe_insert("location", frame=f)
pose["limit"].rotation_euler = eul
pose["limit"].keyframe_insert("rotation_euler", frame=f)
act = rig.animation_data.action
act.name = "CtlAct"
act.use_fake_user = True
curves = act.fcurves if hasattr(act, "fcurves") and V < (5, 0) else [c for l in act.layers for st in l.strips for b in st.channelbags for c in b.fcurves]
for fc in curves:
if fc.data_path.endswith("location"):
for kp in fc.keyframe_points:
kp.interpolation = "LINEAR"
elif fc.array_index == 1:
fc.keyframe_points[1].interpolation = "QUAD"
fc.keyframe_points[1].easing = "EASE_OUT"
fc.extrapolation = "LINEAR"
rig.animation_data.action = None
pose["hand_ik"].location = (0, 0, 0)
pose["limit"].rotation_euler = (0, 0, 0)
c = pose["hand_ik"].constraints.new("ACTION")
c.target, c.subtarget = rig, "pole"
c.action = act
c.transform_channel = "LOCATION_Y"
c.target_space = "LOCAL"
c.frame_start, c.frame_end = 0, 40
c.min, c.max = -0.05, 0.05
setp(c, "mix_mode", "AFTER")
setp(c, "use_eval_time", False)
setp(c, "eval_time", 0.25)
c.influence = 0.5
# a saved pose basis
pose["spine"].location = (0.01, 0.02, 0.03) # no rotation above the hinge bone (not modelled by joint nodes)
pose["pole"].rotation_quaternion = (0.9, 0.1, 0.3, 0.2)
pose["lower"].rotation_euler = (0.1, -0.2, 0.3)
pose["hand_ik"].rotation_axis_angle = (0.4, 0, 0, 1)
pose["limit"].scale = (1, 1.25, 0.8)
# shape keys on a mesh parented to the rig
fv = [(x * 0.5, 0, z * 0.5) for z in range(3) for x in range(3)]
ff = [(0, 1, 4, 3), (1, 2, 5, 4), (3, 4, 7, 6), (4, 5, 8, 7)]
+41 -3
View File
@@ -131,7 +131,7 @@ def rna_value(v):
return ""
if isinstance(v, bpy.types.ID):
return v.name
if isinstance(v, bpy.types.PoseBone):
if isinstance(v, (bpy.types.PoseBone, bpy.types.Bone)):
return v.name
if isinstance(v, bool):
return v
@@ -151,8 +151,36 @@ SKIP = {"rna_type", "show_expanded", "active", "is_valid", "is_override_data_edi
"error_rotation", "targets", "space_object", "space_subtarget"}
BONE_KEYS = ("inherit_scale", "use_inherit_rotation", "use_local_location", "use_relative_parent", "bbone_segments",
"bbone_x", "bbone_z", "bbone_easein", "bbone_easeout", "bbone_rollin", "bbone_rollout", "bbone_curveinx",
"bbone_curveinz", "bbone_curveoutx", "bbone_curveoutz", "bbone_scalein", "bbone_scaleout",
"bbone_handle_type_start", "bbone_handle_type_end", "bbone_custom_handle_start", "bbone_custom_handle_end",
"use_endroll_as_inroll", "bbone_mapping_mode")
def action_fcurves(act):
if V >= (4, 4) and hasattr(act, "layers") and len(act.layers) > 0:
for strip in act.layers[0].strips:
for bag in strip.channelbags:
return list(bag.fcurves)
return []
return list(act.fcurves)
def action_info(act):
curves = []
for fc in action_fcurves(act):
keys = [{"co": [r6(k.co[0]), r6(k.co[1])], "interpolation": k.interpolation, "easing": k.easing,
"handle_left": [r6(k.handle_left[0]), r6(k.handle_left[1])],
"handle_right": [r6(k.handle_right[0]), r6(k.handle_right[1])]} for k in fc.keyframe_points]
curves.append({"data_path": fc.data_path, "array_index": fc.array_index, "extrapolation": fc.extrapolation, "keys": keys})
return {"frame_range": [r6(act.frame_range[0]), r6(act.frame_range[1])], "curves": curves}
def constraint_info(c):
out = {}
if c.type == "ARMATURE":
out["targets"] = [{"target": t.target.name if t.target else "", "subtarget": t.subtarget, "weight": r6(t.weight)} for t in c.targets]
for prop in c.bl_rna.properties:
k = prop.identifier
if k in SKIP or prop.type == "COLLECTION":
@@ -193,7 +221,13 @@ def rig_info(ob):
for a in "xyz":
for k in ("lock_ik_", "use_ik_limit_", "ik_min_", "ik_max_", "ik_stiffness_"):
pose[k + a] = rna_value(getattr(pb, k + a))
bones.append({"name": b.name, "head_local": [r6(x) for x in b.head_local], "tail_local": [r6(x) for x in b.tail_local],
for k in ("location", "rotation_quaternion", "rotation_euler", "rotation_axis_angle", "scale"):
pose[k] = rna_value(getattr(pb, k))
info = {}
for k in BONE_KEYS:
if hasattr(b, k):
info[k] = rna_value(getattr(b, k))
bones.append({"name": b.name, "head_local": [r6(x) for x in b.head_local], "tail_local": [r6(x) for x in b.tail_local], "bone": info,
"roll": r6(roll), "deform": b.use_deform, "use_connect": b.use_connect, "show_wire": b.show_wire,
"collections": [c.name for c in b.collections], "color": color_info(b.color), "pose": pose})
cols = [{"name": c.name, "visible": c.is_visible, "parent": c.parent.name if c.parent else ""} for c in arm.collections_all]
@@ -226,7 +260,8 @@ def dump(path):
ref = {"version": list(bpy.data.version), "fps": sc.render.fps / sc.render.fps_base, "frameStart": sc.frame_start,
"frameCurrent": sc.frame_current, "resolution": [sc.render.resolution_x, sc.render.resolution_y],
"objects": [], "materials": [], "images": [], "cameras": {}, "lights": {}, "armatures": {}, "actions": {},
"rigs": {}, "themeBoneColors": theme_colors()}
"rigs": {}, "themeBoneColors": theme_colors(),
"allActions": {a.name: action_info(a) for a in bpy.data.actions}}
for ob in obs:
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)],
@@ -272,6 +307,9 @@ def dump(path):
for pb in ob.pose.bones:
for c in pb.constraints:
c.mute = True
sc.frame_set(sc.frame_current)
ref["posedBones"] = {ob.name + "/" + pb.name: [r6(x) for x in mat(ob.matrix_world @ pb.matrix)]
for ob in obs if ob.type == "ARMATURE" for pb in ob.pose.bones}
poses = []
if ref["actions"]:
for f in FRAMES: