model/blend: rig data (bone head / tail / roll, deform, collections and layers, colours, custom shapes and widgets, pose locks and IK settings, constraint stacks), shape key fields and targetNames, relative keys and vertex groups in morph targets, muted keys, loose edges as lines

This commit is contained in:
4DBug committed 2026-11-02 21:49:19 -06:00
1 parent 03e7b21eca
commit 835ddde65b
7 files changed
+1241 -68

No files matched your search

+100 -3
View File
@@ -2,7 +2,9 @@
# <this> -- <json list of .blend paths> <out dir>): opens each file (old ones through Blender's versioning) and writes
# <out dir>/<file>.json with the reference values (object world matrices, mesh counts / bounds / attribute sums / corner normals,
# vertex groups, shape keys, materials, images, cameras, lights, bones, f-curve values, posed world matrices per frame),
# and exports a .glb of each file (Z up, no modifiers) whose JSON part is returned as "gltf".
# the rig data of each armature (bone head / tail / roll, collections, colours, custom shapes, locks, IK settings,
# constraints with every RNA property of their type) and the default theme's bone colour sets; posed matrices are
# taken with every constraint muted (the reader does not evaluate constraints). It exports a .glb of each file (Z up, no modifiers) whose JSON part is returned as "gltf".
import bpy, sys, os, json, struct, math
args = sys.argv[sys.argv.index("--") + 1:]
@@ -62,6 +64,8 @@ def mesh_info(ob):
if me.shape_keys:
k = me.shape_keys
info["shapes"] = [{"name": b.name, "value": r6(b.value), "relative": b.relative_key.name,
"slider_min": r6(b.slider_min), "slider_max": r6(b.slider_max), "mute": bool(b.mute),
"vertex_group": b.vertex_group,
"co": [r6(p.co[c]) for p in b.data for c in range(3)]} for b in k.key_blocks]
info["reference"] = k.reference_key.name
info["modifiers"] = [m.type for m in ob.modifiers]
@@ -122,6 +126,87 @@ def fcurves(act):
return out
def rna_value(v):
if v is None:
return ""
if isinstance(v, bpy.types.ID):
return v.name
if isinstance(v, bpy.types.PoseBone):
return v.name
if isinstance(v, bool):
return v
if isinstance(v, (int, float)):
return r6(v)
if isinstance(v, str):
return v
if hasattr(v, "col"): # a Matrix
return [r6(x) for x in mat(v)]
try:
return [rna_value(x) for x in v]
except TypeError:
return None
SKIP = {"rna_type", "show_expanded", "active", "is_valid", "is_override_data_editable", "error_location",
"error_rotation", "targets", "space_object", "space_subtarget"}
def constraint_info(c):
out = {}
for prop in c.bl_rna.properties:
k = prop.identifier
if k in SKIP or prop.type == "COLLECTION":
continue
try:
v = rna_value(getattr(c, k))
except Exception: # noqa: BLE001
continue
if v is not None:
out[k] = v
return out
def color_info(c):
return {"palette": c.palette, "normal": [r6(x) for x in c.custom.normal], "select": [r6(x) for x in c.custom.select],
"active": [r6(x) for x in c.custom.active]}
def rig_info(ob):
arm = ob.data
bones = []
for b in arm.bones:
_, roll = bpy.types.Bone.AxisRollFromMatrix(b.matrix_local.to_3x3())
pb = ob.pose.bones[b.name]
pose = {
"custom_shape": pb.custom_shape.name if pb.custom_shape else "",
"custom_shape_transform": pb.custom_shape_transform.name if pb.custom_shape_transform else "",
"custom_shape_translation": [r6(x) for x in pb.custom_shape_translation],
"custom_shape_rotation_euler": [r6(x) for x in pb.custom_shape_rotation_euler],
"custom_shape_scale_xyz": [r6(x) for x in pb.custom_shape_scale_xyz],
"use_custom_shape_bone_size": pb.use_custom_shape_bone_size,
"lock_location": list(pb.lock_location), "lock_rotation": list(pb.lock_rotation),
"lock_rotation_w": pb.lock_rotation_w, "lock_rotations_4d": pb.lock_rotations_4d,
"lock_scale": list(pb.lock_scale), "rotation_mode": pb.rotation_mode, "ik_stretch": r6(pb.ik_stretch),
"color": color_info(pb.color),
"constraints": [constraint_info(c) for c in pb.constraints],
}
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],
"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]
return {"bones": bones, "collections": cols}
def theme_colors():
out = []
for cs in bpy.context.preferences.themes[0].bone_color_sets:
out.append({"normal": [r6(x) for x in cs.normal], "select": [r6(x) for x in cs.select], "active": [r6(x) for x in cs.active]})
return out
FRAMES = [1 + 0.5 * i for i in range(43)] # 1 .. 22 (past the last key: extrapolation)
@@ -140,11 +225,13 @@ def dump(path):
obs = list(sc.objects)
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": {}}
"objects": [], "materials": [], "images": [], "cameras": {}, "lights": {}, "armatures": {}, "actions": {},
"rigs": {}, "themeBoneColors": theme_colors()}
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)],
"collections": [c.name for c in ob.users_collection]}
"collections": [c.name for c in ob.users_collection], "hide_viewport": ob.hide_viewport,
"hide_render": ob.hide_render}
if ob.type == "MESH":
o["mesh"] = mesh_info(ob)
if ob.animation_data and ob.animation_data.action:
@@ -168,6 +255,9 @@ def dump(path):
if ob.type == "ARMATURE":
ref["armatures"][ob.name] = [{"name": b.name, "parent": b.parent.name if b.parent else "", "deform": b.use_deform,
"local": [r6(x) for x in mat(b.matrix_local)], "length": r6(b.length)} for b in ob.data.bones]
ref["rigs"][ob.name] = rig_info(ob)
if ob.constraints:
o["constraints"] = [constraint_info(c) for c in ob.constraints]
for m in bpy.data.materials:
ref["materials"].append(material_info(m))
for im in bpy.data.images:
@@ -175,6 +265,13 @@ def dump(path):
ref["images"].append({"name": im.name, "filepath": im.filepath, "packed": im.packed_file.size if im.packed_file else 0,
"source": im.source})
# posed world matrices: objects, pose bones (world), shape key values
for ob in obs:
for c in ob.constraints:
c.mute = True
if ob.type == "ARMATURE":
for pb in ob.pose.bones:
for c in pb.constraints:
c.mute = True
poses = []
if ref["actions"]:
for f in FRAMES: