model/blend: rig data docs section and snippet (docs_blend: control bone, collection, damped track, widget), header; type fixes; rebuild
This commit is contained in:
1 parent
4231149f3e
commit
9a15a71b4a
15 files changed
+2950
-580
No files matched your search
+67
-2
@@ -959,9 +959,10 @@ cameras, lights, armatures, skins, shape keys and actions. Blender is z-up (`met
|
||||
| Materials | the Principled BSDF (base colour, metallic, roughness, alpha, emission and its strength, image textures on Base Color / Emission, Normal through a Normal Map node, Roughness / Metallic through Separate RGB), else the legacy `r, g, b` colour |
|
||||
| Images | packed images as encoded bytes (`texture.data`), external ones as `uri` (relative to the `.blend`, bytes through `files` / `resolve`) |
|
||||
| Cameras, lights | perspective (`yfov` from the lens, sensor fit and render aspect) / orthographic; point, sun, spot (watts to candela / lux as Blender's glTF exporter does); area lights are skipped (`meta.source.skippedLights`) |
|
||||
| Armatures | a joint node per bone (rest pose times the saved pose), one skin per deformed mesh |
|
||||
| Armatures | a joint node per bone (rest pose times the saved pose), one skin per deformed mesh; the rig data (bones, collections, colours, custom shapes, constraints) in `extras.blend`, see [Rig data](#rig-data) |
|
||||
| Shape keys | morph targets (each key minus its relative key, times its vertex group's weights, as Blender evaluates them), named in `mesh.extras.targetNames`; muted keys have weight 0; every key's fields in `mesh.extras.blend.shape_keys` |
|
||||
| Animation | the active action of each object, armature (pose bones) and shape key set, f-curves evaluated (constant, linear, bezier, easing; extrapolation) and sampled once per frame (`sampleStep`) into channels; time 0 is `meta.source.frameZero` at `meta.source.fps` |
|
||||
| Not loaded | modifiers (listed per object in `meta.source.modifiers`, never applied), curves, text, metaballs, grease pencil, volumes, NLA strips, drivers, constraints, linked libraries |
|
||||
| Not loaded | modifiers (listed per object in `meta.source.modifiers`, never applied), curves, text, metaballs, grease pencil, volumes, NLA strips, drivers, linked libraries; constraints are data only (never evaluated) |
|
||||
|
||||
```luau
|
||||
local scene = assert(F.model.load(riggedBlendBytes))
|
||||
@@ -974,6 +975,70 @@ assert(scene.materials[1].name == "Skin" and scene.materials[1].roughness > 0.69
|
||||
print(src.modifiers.Tube[1].type) -- Armature (not applied)
|
||||
```
|
||||
|
||||
### Rig data
|
||||
|
||||
Field names are Blender's Python API names. Spaces: the armature node carries the armature object's transform; each
|
||||
joint node's rest matrix is relative to its parent bone (root bones: to the armature object), so a joint's world rest
|
||||
matrix is armature world x `Bone.matrix_local`, and the skins' inverse bind matrices map mesh space to that joint space
|
||||
(glTF's convention). Roll is already part of the rest matrices. Constraints are read, never evaluated: joint nodes
|
||||
hold the saved pose.
|
||||
|
||||
| Where | Fields |
|
||||
|---|---|
|
||||
| joint node `extras.blend` (Bone) | `bone = true`, `length`, `deform`, `use_connect`, `show_wire`, `hide`, `head_local` / `tail_local` (armature space), `roll` (radians, armature space), `collections` (names, in collection order), `color` |
|
||||
| joint node `extras.blend` (pose bone) | `rotation_mode` (`"QUATERNION"`, `"XYZ"` .. `"ZYX"`, `"AXIS_ANGLE"`), `lock_location` / `lock_rotation` / `lock_scale` (3 booleans), `lock_rotation_w`, `lock_rotations_4d`, `custom_shape` (node index, or the object's name when it is not in the scene), `custom_shape_transform` (bone name), `custom_shape_translation` / `custom_shape_rotation_euler` / `custom_shape_scale_xyz`, `use_custom_shape_bone_size`, `custom_shape_wire_width` (4.2+), `ik_stretch`, `lock_ik_x/y/z`, `use_ik_limit_x/y/z`, `ik_min_x/y/z`, `ik_max_x/y/z`, `ik_stiffness_x/y/z`, `pose_color`, `constraints` |
|
||||
| armature node `extras.blend` | `bone_collections`: `{ name, visible, parent? }` (parent by name; files before 4.0 get Blender 4.0's conversion: a `Layer N` collection per used layer, then one hidden collection per bone group) |
|
||||
| any object node `extras.blend` | `constraints` (object constraints), `hide_viewport`, `hide_render` (when set) |
|
||||
| `scene.meta.blend` | `widgets`: every custom shape object `{ name, type, node?, mesh? }` (objects outside the scene's collections get a mesh without a node; edge-only meshes as `"lines"` primitives); `bone_color_sets`: the default theme's `THEME01` .. `THEME20` |
|
||||
|
||||
A colour is `{ palette, normal, select, active }`: `palette` is `"THEME01"` .. `"THEME20"` or `"CUSTOM"` (nil: the
|
||||
default colour), the three colours are 0..1 sRGB (the custom colours, or the theme set's). Before 4.0 the bone group
|
||||
colour is the bone's `color`, as Blender's conversion does.
|
||||
|
||||
A constraint (in stack order) is `{ type, name, influence, mute, target, subtarget, owner_space, target_space }` with
|
||||
`target` a node index or an object name; `space_object` / `space_subtarget` for `"CUSTOM"` spaces, `head_tail` /
|
||||
`use_bbone_shape` where Blender has them, `targets` (`{ target, subtarget, weight }`) for multi-target constraints.
|
||||
Type fields:
|
||||
|
||||
| Type | Fields |
|
||||
|---|---|
|
||||
| `IK` | `pole_target`, `pole_subtarget`, `pole_angle`, `chain_count`, `iterations`, `use_tail`, `use_stretch`, `use_location`, `use_rotation`, `weight`, `orient_weight`, `lock_location_x/y/z`, `lock_rotation_x/y/z`, `ik_type`, `distance` |
|
||||
| `COPY_ROTATION` | `use_x/y/z`, `invert_x/y/z`, `euler_order`, `mix_mode` |
|
||||
| `COPY_LOCATION` | `use_x/y/z`, `invert_x/y/z`, `use_offset` |
|
||||
| `COPY_SCALE` | `use_x/y/z`, `use_offset`, `power` |
|
||||
| `COPY_TRANSFORMS` | `mix_mode`, `remove_target_shear` |
|
||||
| `DAMPED_TRACK` | `track_axis` |
|
||||
| `LIMIT_ROTATION` | `use_limit_x/y/z`, `min_x/y/z`, `max_x/y/z`, `euler_order`, `use_transform_limit` |
|
||||
| `LIMIT_LOCATION`, `LIMIT_SCALE` | `use_min_x/y/z`, `use_max_x/y/z`, `min_x/y/z`, `max_x/y/z`, `use_transform_limit` |
|
||||
| `CHILD_OF` | `use_location_x/y/z`, `use_rotation_x/y/z`, `use_scale_x/y/z`, `set_inverse_pending`, `inverse_matrix` (column-major) |
|
||||
|
||||
Shape keys: `mesh.extras.blend.shape_keys` lists every key in file order (the basis too) as `{ name, value, slider_min,
|
||||
slider_max, mute, relative_key, vertex_group? }`, and `reference_key` names the basis. Actions on shape key values
|
||||
become `weights` channels (clamped to the slider range).
|
||||
|
||||
```luau
|
||||
local rig = assert(F.model.load(riggedBlendBytes))
|
||||
local joint = {}
|
||||
for _, node in rig.nodes do
|
||||
local e = node.extras and node.extras.blend
|
||||
if e and e.bone then
|
||||
joint[node.name] = e
|
||||
end
|
||||
end
|
||||
local upper, ctrl = joint.upper, joint.ctrl
|
||||
assert(upper.deform and not ctrl.deform)
|
||||
assert(upper.head_local[3] == 1 and upper.tail_local[3] == 2 and upper.roll == 0)
|
||||
assert(ctrl.collections[1] == "Controls" and ctrl.custom_shape == "WGT_ring") -- a widget outside the scene
|
||||
local track = upper.constraints[1]
|
||||
assert(track.type == "DAMPED_TRACK" and rig.nodes[track.target].name == "Rig" and track.subtarget == "ctrl")
|
||||
print(track.track_axis, track.influence) -- TRACK_Y 1
|
||||
local widget = rig.meta.blend.widgets[1]
|
||||
assert(widget.name == "WGT_ring" and widget.node == nil)
|
||||
assert(rig.meshes[widget.mesh].primitives[1].mode == "lines")
|
||||
local tube = rig.meshes[1]
|
||||
assert(tube.extras.targetNames[1] == "Bulge" and tube.extras.blend.shape_keys[2].slider_max == 2)
|
||||
```
|
||||
|
||||
Anything else in the file is reachable through the container: `F.format("blend").open` parses the blocks and the
|
||||
SDNA, and every struct reads by field name (`get`, `num`, `str`, `vec`, `sub`, `deref`, `list` for ListBase, `array`
|
||||
and `pointers` behind pointers).
|
||||
|
||||
Reference in new issue
Block a user