diff --git a/build/Rosetta.luau b/build/Rosetta.luau index ada131d..1142090 100644 --- a/build/Rosetta.luau +++ b/build/Rosetta.luau @@ -158566,9 +158566,10 @@ __FILES["model/blend"] = function() -- file's own SDNA). Supports: the scene's objects and collections, transforms with parent inverse and bone parents, -- meshes of every storage generation (MFace, MPoly / MLoop, attribute layers, AttributeStorage) with UV maps, colour -- attributes, custom normals, material slots; Principled BSDF materials; packed and external images; cameras; lights; --- armatures, skins (vertex groups, top 4 weights), shape keys; actions sampled into channels. +-- armatures, skins (vertex groups, top 4 weights), shape keys (relative keys, vertex groups); actions sampled into +-- channels; rig data (bone collections / layers, colours, custom shapes, pose settings, constraint stacks) as extras. -- Not supported: modifiers (listed in meta.source.modifiers), curves / text / metaballs / grease pencil / volumes, --- NLA strips, drivers, constraints, f-curve modifiers, linked libraries, collection instances. +-- NLA strips, drivers, constraint evaluation, f-curve modifiers, linked libraries, collection instances. -- ------------------------------------------------------------------------------------------------ requires local Err = __include("core/Err") @@ -158594,6 +158595,7 @@ local BlendFormat = { type DecodeOptions = { triangulate: boolean?, -- default true (false: "polygons" primitives) flipV: boolean?, -- default true (glTF's top-left UV origin) + looseEdges: boolean?, -- edges outside faces as "lines" primitives (default false; always for custom shape widgets) collections: boolean?, -- collections as nodes (default true) scene: string?, -- a scene by name (default: the file's current scene) sampleStep: number?, -- frames between animation samples (default 1) @@ -159001,6 +159003,413 @@ end return Anim end +__FILES["model/blend/Armature"] = function() + +-- model/blend/Armature: the rig data of an armature as Blender's Python API names it: bones (head / tail / roll in +-- armature space, deform, connect, wire), bone collections (4.x BoneCollection arrays and lists; before 4.0 the layers +-- and bone groups converted as Blender 4.0's versioning does), bone colours (BoneColor; bone group colours before 4.0), +-- pose bones (custom shapes, locks, rotation mode, IK settings) and constraint stacks (bConstraint and the data structs +-- of IK, copy rotation / location / scale / transforms, damped track, limit rotation / location / scale, child of; the +-- common fields for the rest). Flags from DNA_armature_types.h, DNA_action_types.h, DNA_constraint_types.h. +local Blend = __include("containers/Blend") + +local Armature = {} + +type Target = number | string -- a scene node index, or the object's name when it is not in the scene +type Resolve = (ob: Blend.View?) -> Target? +type Color = { palette: string, normal: { number }?, select: { number }?, active: { number }? } + +-- Blender's default theme (userdef_default_theme.c): bone colour sets THEME01..THEME20 as normal, select, active +local THEME = { + { 0x9a0000, 0xbd1111, 0xf70a0a }, { 0xf74018, 0xf66913, 0xfa9900 }, { 0x1e9109, 0x59b70b, 0x83ef1d }, + { 0x0a3694, 0x3667df, 0x5ec1ef }, { 0xa9294e, 0xc1416a, 0xf05d91 }, { 0x430c78, 0x543aa3, 0x8764d5 }, + { 0x24785a, 0x3c9579, 0x6fb6ab }, { 0x4b707c, 0x6a8691, 0x9bc2cd }, { 0xf4c90c, 0xeec236, 0xf3ff00 }, + { 0x1e2024, 0x484c56, 0xffffff }, { 0x6f2f6a, 0x9845be, 0xd330d6 }, { 0x6c8e22, 0x7fb022, 0xbbef5b }, + { 0x8d8d8d, 0xb0b0b0, 0xdedede }, { 0x834326, 0x8b5811, 0xbd6a11 }, { 0x08310e, 0x1c430b, 0x34622b }, + { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, +} + +local function rgb(hex: number): { number } + return { bit32.rshift(hex, 16) / 255, bit32.band(bit32.rshift(hex, 8), 255) / 255, bit32.band(hex, 255) / 255 } +end + +function Armature.colorSets(): { { normal: { number }, select: { number }, active: { number } } } + local out = {} + for i, s in THEME do + out[i] = { normal = rgb(s[1]), select = rgb(s[2]), active = rgb(s[3]) } + end + return out +end + +local ROTMODE: { [number]: string } = { [0] = "QUATERNION", [1] = "XYZ", [2] = "XZY", [3] = "YXZ", [4] = "YZX", [5] = "ZXY", [6] = "ZYX", [-1] = "AXIS_ANGLE" } +local SPACE: { [number]: string } = { [0] = "WORLD", [1] = "LOCAL", [2] = "POSE", [3] = "LOCAL_WITH_PARENT", [5] = "CUSTOM", [6] = "LOCAL_OWNER_ORIENT" } +local EULER_ORDER: { [number]: string } = { [0] = "AUTO", [1] = "XYZ", [2] = "XZY", [3] = "YXZ", [4] = "YZX", [5] = "ZXY", [6] = "ZYX" } +local TRACK: { [number]: string } = { [0] = "TRACK_X", [1] = "TRACK_Y", [2] = "TRACK_Z", [3] = "TRACK_NEGATIVE_X", [4] = "TRACK_NEGATIVE_Y", [5] = "TRACK_NEGATIVE_Z" } +local ROT_MIX: { [number]: string } = { [0] = "REPLACE", [1] = "OFFSET", [2] = "ADD", [3] = "BEFORE", [4] = "AFTER" } +local TRANS_MIX: { [number]: string } = { [0] = "REPLACE", [1] = "BEFORE", [2] = "AFTER", [3] = "BEFORE_FULL", [4] = "BEFORE_SPLIT", [5] = "AFTER_FULL", [6] = "AFTER_SPLIT" } +local TYPE: { [number]: string } = { + [1] = "CHILD_OF", [2] = "TRACK_TO", [3] = "IK", [4] = "FOLLOW_PATH", [5] = "LIMIT_ROTATION", [6] = "LIMIT_LOCATION", + [7] = "LIMIT_SCALE", [8] = "COPY_ROTATION", [9] = "COPY_LOCATION", [10] = "COPY_SCALE", [11] = "PYTHON", [12] = "ACTION", + [13] = "LOCKED_TRACK", [14] = "LIMIT_DISTANCE", [15] = "STRETCH_TO", [16] = "FLOOR", [17] = "RIGID_BODY_JOINT", + [18] = "CLAMP_TO", [19] = "TRANSFORM", [20] = "SHRINKWRAP", [21] = "DAMPED_TRACK", [22] = "SPLINE_IK", + [23] = "COPY_TRANSFORMS", [24] = "MAINTAIN_VOLUME", [25] = "PIVOT", [26] = "FOLLOW_TRACK", [27] = "CAMERA_SOLVER", + [28] = "OBJECT_SOLVER", [29] = "TRANSFORM_CACHE", [30] = "ARMATURE", [31] = "GEOMETRY_ATTRIBUTE", +} +-- constraint types with a head_tail (bConstraint.headtail) in Blender's API +local HEAD_TAIL: { [string]: boolean } = { + COPY_LOCATION = true, COPY_TRANSFORMS = true, DAMPED_TRACK = true, TRACK_TO = true, LOCKED_TRACK = true, + STRETCH_TO = true, LIMIT_DISTANCE = true, +} + +local CONSTRAINT_OFF, CONSTRAINT_BBONE_SHAPE = 0x200, 0x400 +local BONE_CONNECTED, BONE_HIDDEN_P, BONE_NO_DEFORM, BONE_DRAWWIRE = 0x10, 0x40, 0x1000, 0x20000 +local PCHAN_DRAW_NO_CUSTOM_BONE_SIZE = 1 +-- bPoseChannel.protectflag (OB_LOCK_*) and ikflag (BONE_IK_*) +local LOCK_LOC, LOCK_ROT, LOCK_SCALE, LOCK_ROTW, LOCK_ROT4D = { 1, 2, 4 }, { 8, 16, 32 }, { 64, 128, 256 }, 512, 1024 +local IK_NO_DOF, IK_LIMIT = { 1, 2, 4 }, { 8, 16, 32 } +local AXES = { "x", "y", "z" } + +local function bit(v: number?, mask: number): boolean + return bit32.band(v or 0, mask) ~= 0 +end + +local function bits(v: number?, masks: { number }): { boolean } + return { bit(v, masks[1]), bit(v, masks[2]), bit(v, masks[3]) } +end + +local function vec3(v: Blend.View, name: string, fallback: { number }?): { number }? + local x = v:vec(name) + if x and #x >= 3 then + return { x[1], x[2], x[3] } + end + return fallback and table.clone(fallback) +end + +local function text(v: Blend.View, name: string): string? + local s = v:str(name) + return if s and s ~= "" then s else nil +end + +-- ThemeWireColor: char solid[4], select[4], active[4] (sRGB bytes) +local function wire(v: Blend.View?): { [string]: { number } }? + if not v then + return nil + end + local out: { [string]: { number } } = {} + for _, pair in { { "normal", "solid" }, { "select", "select" }, { "active", "active" } } do + local key, field = pair[1], pair[2] + local fld = v.struct.byName[field] + local o = fld and v.offset + fld.offset + if not o or o + 3 > buffer.len(v.file.buf) then + return nil + end + local b = v.file.buf + out[key] = { buffer.readu8(b, o) / 255, buffer.readu8(b, o + 1) / 255, buffer.readu8(b, o + 2) / 255 } + end + return out +end + +-- palette: 0 default, 1..20 the theme sets, -1 custom (BoneColor.palette_index, bActionGroup.customCol); the colours +-- are the custom ones, or the default theme's set +local function color(index: number?, custom: Blend.View?): Color? + if not index or index == 0 then + return nil + end + local c: Color = { palette = if index < 0 then "CUSTOM" else string.format("THEME%02d", index) } + local w = if index < 0 then wire(custom) else nil + if w then + c.normal, c.select, c.active = w.normal, w.select, w.active + elseif index > 0 and THEME[index] then + local s = THEME[index] + c.normal, c.select, c.active = rgb(s[1]), rgb(s[2]), rgb(s[3]) + end + return c +end + +local function boneColor(v: Blend.View): Color? + local bc = v:sub("color") + if not bc then + return nil + end + return color(bc:num("palette_index"), bc:sub("custom")) +end + +-- ------------------------------------------------------------------------------------------------ bones +type Collections = { + list: { { name: string, visible: boolean, parent: string? } }, + byBone: { [string]: { string } }, -- bone name -> its collections, in collection order +} + +-- 4.1+: collection_array with child_index / child_count; 4.0: the collections list; before 4.0 the used layers +-- ("Layer N", hidden when the layer is off) and then the bone groups (hidden), as Blender's 4.0 versioning converts them +function Armature.collections(arm: Blend.View, bones: { Blend.View }, pose: Blend.View?): Collections + local out: Collections = { list = {}, byBone = {} } + local byAddr: { [any]: string } = {} + for _, b in bones do + if b.block then + byAddr[b.block.addr] = b:str("name") or "" + end + end + local function add(name: string, members: { string }) + for _, m in members do + local l = out.byBone[m] or {} + out.byBone[m] = l + table.insert(l, name) + end + end + local VISIBLE = 1 + local array = arm:has("collection_array") and arm:pointers("collection_array", arm:num("collection_array_num") or 0) or {} + local cols: { Blend.View } = {} + if #array > 0 then + for _, addr in array do + local blk = addr and Blend.resolve(arm.file, addr, arm.block) + local v = blk and Blend.struct(arm.file, blk, 0, "BoneCollection") + if v then + table.insert(cols, v) + end + end + elseif arm:has("collections") then + cols = arm:list("collections", "BoneCollection") + end + if #cols > 0 then + local parent: { [number]: string } = {} + for i, c in cols do + local first, n = c:num("child_index") or 0, c:num("child_count") or 0 + for k = first + 1, math.min(first + n, #cols) do + parent[k] = c:str("name") + end + local _ = i + end + for i, c in cols do + local name = c:str("name") or "" + table.insert(out.list, { name = name, visible = bit(c:num("flags"), VISIBLE), parent = parent[i] }) + local members = {} + for _, m in c:list("bones", "BoneCollectionMember") do + local n = byAddr[m:ptr("bone")] + if n then + table.insert(members, n) + end + end + add(name, members) + end + return out + end + local used, shown = arm:num("layer_used"), arm:num("layer") + if used then + for layer = 0, 31 do + local mask = bit32.lshift(1, layer) + if bit(used, mask) then + local name = "Layer " .. (layer + 1) + table.insert(out.list, { name = name, visible = bit(shown, mask) }) + local members = {} + for _, b in bones do + if bit(b:num("layer"), mask) then + table.insert(members, b:str("name") or "") + end + end + add(name, members) + end + end + end + if pose then + local groups = pose:list("agroups", "bActionGroup") + local members: { [number]: { string } } = {} + for _, pc in pose:list("chanbase", "bPoseChannel") do + local g = pc:num("agrp_index") or 0 + if g > 0 and groups[g] then + members[g] = members[g] or {} + table.insert(members[g], pc:str("name") or "") + end + end + for g, grp in groups do + local name = grp:str("name") or "" + table.insert(out.list, { name = name, visible = false }) + add(name, members[g] or {}) + end + end + return out +end + +-- a Bone's own fields: head_local / tail_local / roll in armature space (the roll is already in arm_mat, the rest +-- matrix); color from the Bone (4.x) or from the bone group of its pose channel (before 4.0) +function Armature.bone(bone: Blend.View, pc: Blend.View?, pose: Blend.View?): { [string]: any } + local flag = bone:num("flag") or 0 + local e: { [string]: any } = { + deform = not bit(flag, BONE_NO_DEFORM), + use_connect = bit(flag, BONE_CONNECTED), + show_wire = bit(flag, BONE_DRAWWIRE), + hide = bit(flag, BONE_HIDDEN_P), + head_local = vec3(bone, "arm_head"), + tail_local = vec3(bone, "arm_tail"), + roll = bone:num("arm_roll"), + } + if bone:has("color") then + e.color = boneColor(bone) + elseif pc and pose then + local g = pc:num("agrp_index") or 0 + local grp = if g > 0 then pose:list("agroups", "bActionGroup")[g] else nil + if grp then + e.color = color(grp:num("customCol"), grp:sub("cs")) + end + end + return e +end + +-- ------------------------------------------------------------------------------------------------ constraints +local function constraintData(e: { [string]: any }, kind: string, d: Blend.View, resolve: Resolve) + local flag = d:num("flag") or 0 + if kind == "IK" then + -- CONSTRAINT_IK_TIP / ROT / STRETCH / POS, NO_POS_X.. / NO_ROT_X..; type 0 copy pose, 1 distance + e.pole_target = resolve(d:deref("poletar", 0, "Object")) + e.pole_subtarget = text(d, "polesubtarget") + e.pole_angle = d:num("poleangle") + e.chain_count = d:num("rootbone") + e.iterations = d:num("iterations") + e.weight = d:num("weight") + e.orient_weight = d:num("orientweight") + e.use_tail = bit(flag, 1) + e.use_rotation = bit(flag, 2) + e.use_stretch = bit(flag, 16) + e.use_location = bit(flag, 32) + -- lock_* are the inverse of the NO_POS / NO_ROT bits, as Blender's API defines them + e.lock_location_x, e.lock_location_y, e.lock_location_z = not bit(flag, 256), not bit(flag, 512), not bit(flag, 1024) + e.lock_rotation_x, e.lock_rotation_y, e.lock_rotation_z = not bit(flag, 2048), not bit(flag, 4096), not bit(flag, 8192) + e.ik_type = if (d:num("type") or 0) == 1 then "DISTANCE" else "COPY_POSE" + e.distance = d:num("dist") + elseif kind == "COPY_ROTATION" then + -- ROTLIKE_X 1, Y 2, Z 4, X_INVERT 16, Y_INVERT 32, Z_INVERT 64, OFFSET 128 (mix_mode OFFSET before 2.82) + e.use_x, e.use_y, e.use_z = bit(flag, 1), bit(flag, 2), bit(flag, 4) + e.invert_x, e.invert_y, e.invert_z = bit(flag, 16), bit(flag, 32), bit(flag, 64) + e.euler_order = EULER_ORDER[d:num("euler_order") or 0] + local mix = d:num("mix_mode") + e.mix_mode = if mix then ROT_MIX[mix] else (if bit(flag, 128) then "OFFSET" else "REPLACE") + elseif kind == "COPY_LOCATION" then + -- LOCLIKE_X 1, Y 2, Z 4, X_INVERT 16, Y_INVERT 32, Z_INVERT 64, OFFSET 128 + e.use_x, e.use_y, e.use_z = bit(flag, 1), bit(flag, 2), bit(flag, 4) + e.invert_x, e.invert_y, e.invert_z = bit(flag, 16), bit(flag, 32), bit(flag, 64) + e.use_offset = bit(flag, 128) + elseif kind == "COPY_SCALE" then + -- SIZELIKE_X 1, Y 2, Z 4, OFFSET 8 + e.use_x, e.use_y, e.use_z = bit(flag, 1), bit(flag, 2), bit(flag, 4) + e.use_offset = bit(flag, 8) + e.power = d:num("power") or 1 + elseif kind == "COPY_TRANSFORMS" then + e.mix_mode = TRANS_MIX[d:num("mix_mode") or 0] + e.remove_target_shear = bit(flag, 1) + elseif kind == "DAMPED_TRACK" then + e.track_axis = TRACK[d:num("trackflag") or 1] + elseif kind == "LIMIT_ROTATION" then + -- LIMIT_XROT 1, YROT 2, ZROT 4; flag2 LIMIT_TRANSFORM 2 + for i, a in AXES do + e["use_limit_" .. a] = bit(flag, bit32.lshift(1, i - 1)) + e["min_" .. a] = d:num(a .. "min") + e["max_" .. a] = d:num(a .. "max") + end + e.use_transform_limit = bit(d:num("flag2"), 2) + e.euler_order = EULER_ORDER[d:num("euler_order") or 0] + elseif kind == "LIMIT_LOCATION" or kind == "LIMIT_SCALE" then + -- LIMIT_XMIN 1, XMAX 2, YMIN 4, YMAX 8, ZMIN 16, ZMAX 32; flag2 LIMIT_TRANSFORM 2 + for i, a in AXES do + e["use_min_" .. a] = bit(flag, bit32.lshift(1, (i - 1) * 2)) + e["use_max_" .. a] = bit(flag, bit32.lshift(2, (i - 1) * 2)) + e["min_" .. a] = d:num(a .. "min") + e["max_" .. a] = d:num(a .. "max") + end + e.use_transform_limit = bit(d:num("flag2"), 2) + elseif kind == "CHILD_OF" then + -- CHILDOF_LOCX 1 .. SIZEZ 256, SET_INVERSE 512 + for i, a in AXES do + e["use_location_" .. a] = bit(flag, bit32.lshift(1, i - 1)) + e["use_rotation_" .. a] = bit(flag, bit32.lshift(8, i - 1)) + e["use_scale_" .. a] = bit(flag, bit32.lshift(64, i - 1)) + end + e.set_inverse_pending = bit(flag, 512) + local m = d:vec("invmat") + e.inverse_matrix = if m and #m == 16 then m else nil -- column-major + end +end + +-- a constraint stack (ListBase of bConstraint) in evaluation order +function Armature.constraints(owner: Blend.View, resolve: Resolve): { { [string]: any } } + local out = {} + for _, c in owner:list("constraints", "bConstraint") do + local t = c:num("type") or 0 + local kind = TYPE[t] or tostring(t) + local flag = c:num("flag") or 0 + local e: { [string]: any } = { + type = kind, + name = c:str("name") or "", + influence = c:num("enforce") or 1, + mute = bit(flag, CONSTRAINT_OFF), + owner_space = SPACE[c:num("ownspace") or 0], + target_space = SPACE[c:num("tarspace") or 0], + } + if HEAD_TAIL[kind] then + e.head_tail = c:num("headtail") or 0 + e.use_bbone_shape = bit(flag, CONSTRAINT_BBONE_SHAPE) + end + if e.owner_space == "CUSTOM" or e.target_space == "CUSTOM" then + e.space_object = resolve(c:deref("space_object", 0, "Object")) + e.space_subtarget = text(c, "space_subtarget") + end + local d = c:deref("data", 0) + if d then + if d:has("tar") then + e.target = resolve(d:deref("tar", 0, "Object")) + end + e.subtarget = text(d, "subtarget") + if d:has("targets") then + local targets = {} + for _, ct in d:list("targets", "bConstraintTarget") do + table.insert(targets, { target = resolve(ct:deref("tar", 0, "Object")), subtarget = text(ct, "subtarget"), weight = ct:num("weight") }) + end + e.targets = targets + end + constraintData(e, kind, d, resolve) + end + table.insert(out, e) + end + return out +end + +-- ------------------------------------------------------------------------------------------------ pose bones +-- a bPoseChannel's settings into e: constraint targets through resolve, the custom shape object through shape +function Armature.pose(e: { [string]: any }, pc: Blend.View, resolve: Resolve, shape: Resolve) + local protect = pc:num("protectflag") or 0 + local ik = pc:num("ikflag") or 0 + e.rotation_mode = ROTMODE[pc:num("rotmode") or 0] or "QUATERNION" + e.lock_location = bits(protect, LOCK_LOC) + e.lock_rotation = bits(protect, LOCK_ROT) + e.lock_rotation_w = bit(protect, LOCK_ROTW) + e.lock_rotations_4d = bit(protect, LOCK_ROT4D) + e.lock_scale = bits(protect, LOCK_SCALE) + local custom = pc:deref("custom", 0, "Object") + if custom then + e.custom_shape = shape(custom) + end + local tx = pc:deref("custom_tx", 0, "bPoseChannel") + e.custom_shape_transform = if tx then text(tx, "name") else nil + e.custom_shape_translation = vec3(pc, "custom_translation", { 0, 0, 0 }) + e.custom_shape_rotation_euler = vec3(pc, "custom_rotation_euler", { 0, 0, 0 }) + local s = pc:num("custom_scale") or 1 -- before 3.0: one uniform scale + e.custom_shape_scale_xyz = vec3(pc, "custom_scale_xyz", { s, s, s }) + e.use_custom_shape_bone_size = not bit(pc:num("drawflag"), PCHAN_DRAW_NO_CUSTOM_BONE_SIZE) + e.custom_shape_wire_width = pc:num("custom_shape_wire_width") + e.ik_stretch = pc:num("ikstretch") or 0 + local lo, hi, stiff = pc:vec("limitmin"), pc:vec("limitmax"), pc:vec("stiffness") + for i, a in AXES do + e["lock_ik_" .. a] = bit(ik, IK_NO_DOF[i]) + e["use_ik_limit_" .. a] = bit(ik, IK_LIMIT[i]) + e["ik_min_" .. a] = lo and lo[i] or -math.pi + e["ik_max_" .. a] = hi and hi[i] or math.pi + e["ik_stiffness_" .. a] = stiff and stiff[i] or 0 + end + e.pose_color = if pc:has("color") then boneColor(pc) else nil + e.constraints = Armature.constraints(pc, resolve) +end + +return Armature +end __FILES["model/blend/Material"] = function() -- model/blend/Material: Blender materials to Scene PBR materials. With nodes: the Principled BSDF (the one feeding the @@ -159592,6 +160001,75 @@ end type Limits = { maxVertices: number? } +-- edge count and per-edge readers (vertex 1, vertex 2, sharp): ".edge_verts" / "sharp_edge" attributes or MEdge +local function edgeReaders(f: Blend.File, me: Blend.View, layers: { Layer }): (number, ((number) -> number)?, ((number) -> number)?, ((number) -> boolean)?) + local ne = count(me, "totedge", "edges_num") + local ev = find(layers, "edge", "int2", ".edge_verts") + local se = find(layers, "edge", "bool", "sharp_edge") + local medge = find(layers, "edge", "MEdge") or legacy(f, me, "medge", "MEdge", "edge") + if ne == 0 then + return 0, nil, nil, nil + end + if ev then + local er = reader(f, ev) + local sr = if se then reader(f, se) else nil + return ne, function(i: number): number + return er(i, 0) + end, function(i: number): number + return er(i, 1) + end, function(i: number): boolean + return sr ~= nil and sr(i, 0) ~= 0 + end + elseif medge then + local a, b, fl = fieldReader(f, medge, "v1"), fieldReader(f, medge, "v2"), fieldReader(f, medge, "flag") + if a and b then + local ser = if se then reader(f, se) else nil + return ne, function(i: number): number + return a(i, 0) + end, function(i: number): number + return b(i, 0) + end, function(i: number): boolean + if ser then + return ser(i, 0) ~= 0 + end + return fl ~= nil and bit32.band(fl(i, 0), ME_SHARP) ~= 0 + end + end + end + return ne, nil, nil, nil +end + +-- edges no face uses, as u32 vertex pairs (rig widgets are usually edges only) +function Mesh.looseEdges(f: Blend.File, me: Blend.View, poly: Poly): buffer + local ne, v1, v2 = edgeReaders(f, me, poly.layers) + if not v1 or not v2 then + return buffer.create(0) + end + local nv = poly.nv + local used: { [number]: boolean } = {} + local cv, fs = poly.cornerVert, poly.faceStart + for fi = 0, poly.nf - 1 do + local s0, s1 = buffer.readu32(fs, fi * 4), buffer.readu32(fs, fi * 4 + 4) + for c = s0, s1 - 1 do + local a, b = buffer.readu32(cv, c * 4), buffer.readu32(cv, (if c + 1 < s1 then c + 1 else s0) * 4) + used[math.min(a, b) * nv + math.max(a, b)] = true + end + end + local out = {} + for i = 0, ne - 1 do + local a, b = v1(i), v2(i) + if a ~= b and a >= 0 and b >= 0 and a < nv and b < nv and not used[math.min(a, b) * nv + math.max(a, b)] then + table.insert(out, a) + table.insert(out, b) + end + end + local buf = buffer.create(#out * 4) + for k, v in out do + buffer.writeu32(buf, (k - 1) * 4, v) + end + return buf +end + function Mesh.read(f: Blend.File, me: Blend.View, limits: Limits?): (Poly?, string?) local layers = Mesh.layers(f, me) local nv = count(me, "totvert", "verts_num") @@ -159871,10 +160349,6 @@ function Mesh.read(f: Blend.File, me: Blend.View, limits: Limits?): (Poly?, stri poly.customNormals = d end -- sharp edges - local ne = count(me, "totedge", "edges_num") - local ev = find(layers, "edge", "int2", ".edge_verts") - local se = find(layers, "edge", "bool", "sharp_edge") - local medge = find(layers, "edge", "MEdge") or legacy(f, me, "medge", "MEdge", "edge") local flags = me:num("flag") or 0 local smoothresh = me:num("smoothresh") local autoSmooth = f.version < 401 and bit32.band(flags, ME_AUTOSMOOTH) ~= 0 @@ -159882,27 +160356,8 @@ function Mesh.read(f: Blend.File, me: Blend.View, limits: Limits?): (Poly?, stri poly.autoSmooth = smoothresh or math.rad(30) end local useSharp = f.version >= 401 or autoSmooth - if useSharp and ne > 0 then - local v1, v2, sharp - if ev and se then - local er, sr = reader(f, ev), reader(f, se) - v1 = function(i: number): number return er(i, 0) end - v2 = function(i: number): number return er(i, 1) end - sharp = function(i: number): boolean return sr(i, 0) ~= 0 end - elseif medge then - local a, b, fl = fieldReader(f, medge, "v1"), fieldReader(f, medge, "v2"), fieldReader(f, medge, "flag") - if a and b and fl then - v1 = function(i: number): number return a(i, 0) end - v2 = function(i: number): number return b(i, 0) end - local ser = if se then reader(f, se) else nil - sharp = function(i: number): boolean - if ser then - return ser(i, 0) ~= 0 - end - return bit32.band(fl(i, 0), ME_SHARP) ~= 0 - end - end - end + if useSharp then + local ne, v1, v2, sharp = edgeReaders(f, me, layers) if v1 and v2 and sharp then for i = 0, ne - 1 do if sharp(i) then @@ -159947,7 +160402,7 @@ function Mesh.read(f: Blend.File, me: Blend.View, limits: Limits?): (Poly?, stri end -- shape keys: { name, value, relative (0-based), data: f32 x 3 per vertex } in file order, and the reference index -type Shape = { name: string, value: number, relative: number, data: buffer, mute: boolean, min: number, max: number } +type Shape = { name: string, value: number, relative: number, data: buffer, mute: boolean, min: number, max: number, vgroup: string? } function Mesh.shapes(f: Blend.File, me: Blend.View, nv: number): ({ Shape }, number?, Blend.View?) local key = me:deref("key", 0, "Key") if not key then @@ -159957,6 +160412,7 @@ function Mesh.shapes(f: Blend.File, me: Blend.View, nv: number): ({ Shape }, num local refAddr = key:ptr("refkey") local out: { Shape } = {} local ref: number? = nil + local index = 0 for i, kb in blocks do local blk = kb:target("data") local d = buffer.create(nv * 12) @@ -159969,15 +160425,21 @@ function Mesh.shapes(f: Blend.File, me: Blend.View, nv: number): ({ Shape }, num end end end - if kb.block and kb.block.addr == refAddr then + local isRef = kb.block ~= nil and kb.block.addr == refAddr + if isRef then ref = i + else + index += 1 end + local stored = kb:str("name") + -- unnamed in old files: named as Blender's 2.45 versioning does (Basis, Key 1, Key 2, ...) + local name: string = if stored and stored ~= "" then stored elseif isRef then "Basis" else "Key " .. index table.insert(out, { - -- unnamed in old files: Key 0 (the basis), Key 1, ... - name = kb:str("name") or ("Key " .. (i - 1)), value = kb:num("curval") or 0, relative = kb:num("relative") or 0, data = d, - mute = bit32.band(kb:num("flag") or 0, 2) ~= 0, + name = name, value = kb:num("curval") or 0, relative = kb:num("relative") or 0, data = d, + mute = bit32.band(kb:num("flag") or 0, 1) ~= 0, -- KEYBLOCK_MUTE min = kb:num("slidermin") or 0, max = kb:num("slidermax") or 1, + vgroup = if kb:str("vgroup") ~= "" then kb:str("vgroup") else nil, }) end if ref == nil and #out > 0 then @@ -160410,8 +160872,80 @@ end type Built = { mesh: Types.Mesh, slots: { number }, vertexSource: { { number } } } --- slots[k] = the scene material of slot k - 1 (or 0 for none); skin maps deform groups to joints -function Prim.build(poly: MeshT.Poly, slots: { number }, opts: Options?, skin: Skinning?, shapes: { MeshT.Shape }?, ref: number?): Built +-- morph targets of the output vertices (vsrc: their mesh vertices): each key minus its relative key, times the weight +-- of the key's vertex group, as Blender evaluates relative keys +local function targetDeltas(poly: MeshT.Poly, vsrc: { number }, shapes: { MeshT.Shape }, ref: number, groups: { string }?): { { [string]: Types.Accessor } } + local n = #vsrc + local targets: { { [string]: Types.Accessor } } = {} + for k, s in shapes do + if k ~= ref then + local rel = shapes[s.relative + 1] or shapes[ref] + local base = rel.data + local def: number? = nil + if s.vgroup and groups then + for gi, g in groups do + if g == s.vgroup then + def = gi - 1 + end + end + end + local t = table.create(n * 3) :: { number } + for i = 1, n do + local v = vsrc[i] + local w: number = 1 + if def then + w = 0 + local list = poly.weights and poly.weights[v + 1] or {} + for q = 1, #list - 1, 2 do + if list[q] == def then + w = list[q + 1] + end + end + end + for c = 0, 2 do + t[(i - 1) * 3 + c + 1] = (readf32(s.data, (v * 3 + c) * 4) - readf32(base, (v * 3 + c) * 4)) * w + end + end + table.insert(targets, { POSITION = accessor(t, 3) } :: { [string]: Types.Accessor }) + end + end + return targets +end + +-- a "lines" primitive of the given edges (u32 vertex pairs), with the morph targets the face primitives have +function Prim.lines(poly: MeshT.Poly, edges: buffer, shapes: { MeshT.Shape }?, ref: number?, groups: { string }?): Types.Primitive? + local ne = buffer.len(edges) // 8 + if ne == 0 then + return nil + end + local out: { [number]: number } = {} + local vsrc: { number } = {} + local I = buffer.create(ne * 8) + for k = 0, ne * 2 - 1 do + local v = readu32(edges, k * 4) + local o = out[v] + if not o then + o = #vsrc + out[v] = o + table.insert(vsrc, v) + end + writeu32(I, k * 4, o) + end + local n = #vsrc + local P = buffer.create(n * 12) + for i = 1, n do + buffer.copy(P, (i - 1) * 12, poly.pos, vsrc[i] * 12, 12) + end + local prim: Types.Primitive = { attributes = { POSITION = Scene.accessor(P, "f32", 3, n) }, indices = Scene.accessor(I, "u32", 1, ne * 2), mode = "lines" } + if shapes and ref and #shapes > 1 then + prim.targets = targetDeltas(poly, vsrc, shapes, ref, groups) + end + return prim +end + +-- slots[k] = the scene material of slot k - 1 (or 0 for none); skin maps deform groups to joints; vgroups names the +-- vertex groups (def_nr + 1) for shape keys limited to one +function Prim.build(poly: MeshT.Poly, slots: { number }, opts: Options?, skin: Skinning?, shapes: { MeshT.Shape }?, ref: number?, vgroups: { string }?): Built local triangulateOn = not (opts and opts.triangulate == false) local flipV = not (opts and opts.flipV == false) local withNormals = not (opts and opts.normals == false) @@ -160561,21 +161095,7 @@ function Prim.build(poly: MeshT.Poly, slots: { number }, opts: Options?, skin: S prim.material = mat end if shapes and ref and #shapes > 1 then - local base = shapes[ref].data - local targets: { { [string]: Types.Accessor } } = {} - for k, s in shapes do - if k ~= ref then - local t = table.create(n * 3) :: { number } - for i = 1, n do - local v = vsrc[i] - for c = 0, 2 do - t[(i - 1) * 3 + c + 1] = readf32(s.data, (v * 3 + c) * 4) - readf32(base, (v * 3 + c) * 4) - end - end - table.insert(targets, { POSITION = accessor(t, 3) } :: { [string]: Types.Accessor }) - end - end - prim.targets = targets + prim.targets = targetDeltas(poly, vsrc, shapes, ref, vgroups) end table.insert(mesh.primitives, prim) table.insert(sources, vsrc) @@ -160584,7 +161104,7 @@ function Prim.build(poly: MeshT.Poly, slots: { number }, opts: Options?, skin: S local w = {} for k, s in shapes do if k ~= ref then - table.insert(w, s.value) + table.insert(w, if s.mute then 0 else s.value) -- Blender skips muted keys end end mesh.weights = w @@ -160604,8 +161124,8 @@ __FILES["model/blend/Read"] = function() -- or Base list before 2.8) with their transforms (euler orders, quaternion, axis angle, delta transforms, parent -- inverse; bone parents), meshes (model/blend/Mesh, model/blend/Prim), materials (Principled BSDF node or the legacy -- colour), images (packed bytes or external uris), cameras, lights (watts to candela / lux as Blender's glTF exporter --- does: 683 lm/W, / 4 pi for point and spot), armatures (bones to joint nodes with the saved pose), skins, shape keys --- and actions sampled into channels. +-- does: 683 lm/W, / 4 pi for point and spot), armatures (bones to joint nodes with the saved pose, rig data through +-- model/blend/Armature), skins, shape keys and actions sampled into channels. local Blend = __include("containers/Blend") local Types = __include("Types") local Mat4 = __include("codecs/model/Mat4") @@ -160614,6 +161134,7 @@ local Mesh = __include("model/blend/Mesh") local Prim = __include("model/blend/Prim") local Anim = __include("model/blend/Anim") local Material = __include("model/blend/Material") +local Armature = __include("model/blend/Armature") local Read = {} @@ -160623,6 +161144,7 @@ type M4 = { number } type Options = { triangulate: boolean?, flipV: boolean?, + looseEdges: boolean?, -- edges outside faces as "lines" primitives (default false; always for custom shape widgets) collections: boolean?, -- collections as nodes (default true) scene: string?, -- the scene to read (default: the file's current scene) sampleStep: number?, -- frames between animation samples (default 1) @@ -160773,6 +161295,18 @@ local function mat4(v: Blend.View?, ...: string): M4? end -- ------------------------------------------------------------------------------------------------ scene +type ArmInfo = { + joints: { number }, + names: { [string]: number }, + rest: { M4 }, + restLocal: { M4 }, + bones: { Blend.View }, + deform: { boolean }, + node: number, + poseNames: { [string]: Blend.View }, + arm: Blend.View, + pose: Blend.View?, +} type Ctx = { f: Blend.File, scene: Types.Scene, @@ -160784,7 +161318,9 @@ type Ctx = { meshes: { [string]: number }, materials: { [any]: number }, textures: { [any]: number }, - armatures: { [any]: { joints: { number }, names: { [string]: number }, rest: { M4 }, restLocal: { M4 }, bones: { Blend.View }, deform: { boolean }, node: number, poseNames: { [string]: Blend.View } } }, + armatures: { [any]: ArmInfo }, + widgets: { [any]: Blend.View }, -- custom shape objects by address + widgetOrder: { any }, prefix: { [number]: M4 }, -- node -> the matrix before its basis (parent inverse, bone tail offset) props: { [number]: Props }, meta: { [string]: any }, @@ -160831,7 +161367,7 @@ local function armature(ctx: Ctx, ob: Blend.View, node: number) end end end - local info = { joints = {}, names = {}, rest = {}, restLocal = {}, bones = {}, deform = {}, node = node, poseNames = poseNames } + local info: ArmInfo = { joints = {}, names = {}, rest = {}, restLocal = {}, bones = {}, deform = {}, node = node, poseNames = poseNames, arm = arm, pose = pose } local function walk(list: { Blend.View }, parentJoint: number?, parentRest: M4?, depth: number) if depth > 256 then return @@ -161001,20 +161537,37 @@ local function groupNames(ob: Blend.View, me: Blend.View): { string } return out end -local function mesh(ctx: Ctx, ob: Blend.View, node: number) +local function shapeExtras(shapes: { Mesh.Shape }, ref: number?): ({ string }, { { [string]: any } }) + local names: { string }, list: { { [string]: any } } = {}, {} + for k, sh in shapes do + if k ~= ref then + table.insert(names, sh.name) + end + local rel = shapes[sh.relative + 1] + local e: { [string]: any } = { name = sh.name, value = sh.value, slider_min = sh.min, slider_max = sh.max, mute = sh.mute } + e.relative_key = if rel then rel.name else nil + e.vertex_group = sh.vgroup + table.insert(list, e) + end + return names, list +end + +-- the scene mesh of an object's mesh data (shared between objects with the same data, slots and armature) +local function meshOf(ctx: Ctx, ob: Blend.View, lines: boolean): (number?, ArmInfo?) local f = ctx.f local me = ob:deref("data", 0, "Mesh") if not me then - return + return nil, nil end local slots = slotMaterials(ctx, ob, me) local armOb = deformArmature(ctx, ob) local armInfo = armOb and armOb.block and ctx.armatures[armOb.block.addr] - local key = tostring(me.block and me.block.index) .. ":" .. table.concat(slots, ",") .. ":" .. tostring(armOb and armOb.block and armOb.block.index) + local key = tostring(me.block and me.block.index) .. ":" .. table.concat(slots, ",") .. ":" .. tostring(armOb and armOb.block and armOb.block.index) .. (if lines then ":lines" else "") local skin: Prim.Skinning? = nil + local groups = groupNames(ob, me) if armInfo then local joints = {} - for gi, name in groupNames(ob, me) do + for gi, name in groups do local j = armInfo.names[name] if j and armInfo.deform[j] then joints[gi - 1] = j - 1 @@ -161029,9 +161582,23 @@ local function mesh(ctx: Ctx, ob: Blend.View, node: number) error(err or "bad mesh", 0) end local shapes, ref = Mesh.shapes(f, me, poly.nv) - local built = Prim.build(poly, slots, { triangulate = ctx.opts.triangulate, flipV = ctx.opts.flipV }, skin, shapes, ref) + local built = Prim.build(poly, slots, { triangulate = ctx.opts.triangulate, flipV = ctx.opts.flipV }, skin, shapes, ref, groups) local m = built.mesh - m.extras = { blend = { vertices = poly.nv, faces = poly.nf, corners = poly.nc, generation = poly.generation, uvs = #poly.uvs, colors = #poly.colors, shapes = #shapes } } + local extras: { [string]: any } = { vertices = poly.nv, faces = poly.nf, corners = poly.nc, generation = poly.generation, uvs = #poly.uvs, colors = #poly.colors, shapes = #shapes } + m.extras = { blend = extras } + if lines then + local lp = Prim.lines(poly, Mesh.looseEdges(f, me, poly), shapes, ref, groups) + if lp then + table.insert(m.primitives, lp) + extras.looseEdges = (lp.indices :: Types.Accessor).count // 2 + end + end + if #shapes > 1 then + local names, list = shapeExtras(shapes, ref) + m.extras = { blend = extras, targetNames = names } + extras.shape_keys = list + extras.reference_key = if ref then shapes[ref].name else nil + end table.insert(ctx.scene.meshes, m) idx = #ctx.scene.meshes ctx.meshes[key] = idx @@ -161041,6 +161608,15 @@ local function mesh(ctx: Ctx, ob: Blend.View, node: number) ctx.meta.shapeKeys[idx] = { key = me:deref("key", 0, "Key"), mesh = me, shapes = shapes, ref = ref } end end + return idx, armInfo +end + +local function mesh(ctx: Ctx, ob: Blend.View, node: number) + local addr = ob.block and ob.block.addr + local idx, armInfo = meshOf(ctx, ob, ctx.opts.looseEdges == true or (addr ~= nil and ctx.widgets[addr] ~= nil)) + if not idx then + return + end local n = ctx.scene.nodes[node] n.mesh = idx if ctx.scene.meshes[idx].weights then @@ -161124,6 +161700,14 @@ local function object(ctx: Ctx, ob: Blend.View, under: number?, depth: number): if lay and ctx.f.version < 280 then extras.layers = lay end + -- Object.visibility_flag (2.8+): OB_HIDE_VIEWPORT 1, OB_HIDE_RENDER 4; restrictflag before: VIEW 1, RENDER 4 + local vis = ob:num("visibility_flag") or ob:num("restrictflag") or 0 + if bit32.band(vis, 1) ~= 0 then + extras.hide_viewport = true + end + if bit32.band(vis, 4) ~= 0 then + extras.hide_render = true + end local mods = {} for _, md in ob:list("modifiers") do table.insert(mods, { name = md:sub("modifier") and (md:sub("modifier") :: Blend.View):str("name") or md:str("name") or "", type = (string.gsub(md.struct.name, "ModifierData$", "")) }) @@ -161144,6 +161728,77 @@ local function object(ctx: Ctx, ob: Blend.View, under: number?, depth: number): return idx end +-- ------------------------------------------------------------------------------------------------ rigs +-- an object as a constraint target or custom shape: its node, else its name; widgets records custom shapes +local function resolver(ctx: Ctx, widgets: boolean): Armature.Resolve + return function(ob: Blend.View?): Armature.Target? + if not ob then + return nil + end + local addr = ob.block and ob.block.addr + if widgets and addr ~= nil and not ctx.widgets[addr] then + ctx.widgets[addr] = ob + table.insert(ctx.widgetOrder, addr) + end + local node = if addr ~= nil then ctx.objects[addr] else nil + if node then + return node + end + return ob:idName() + end +end + +local function rigs(ctx: Ctx) + local target, shape = resolver(ctx, false), resolver(ctx, true) + for node = 1, #ctx.scene.nodes do + local ob = ctx.objView[node] + local extras = ob and (ctx.scene.nodes[node].extras :: any).blend + if not ob or not extras then + continue + end + local list = Armature.constraints(ob, target) + if #list > 0 then + extras.constraints = list + end + local info = ob.block and ctx.armatures[ob.block.addr] + if info then + local cols = Armature.collections(info.arm, info.bones, info.pose) + extras.bone_collections = cols.list + for j, bone in info.bones do + local name = bone:str("name") or "" + local pc = info.poseNames[name] + local e = (ctx.scene.nodes[info.joints[j]].extras :: any).blend + for k, v in Armature.bone(bone, pc, info.pose) do + e[k] = v + end + e.collections = cols.byBone[name] or {} + if pc then + Armature.pose(e, pc, target, shape) + end + end + end + end +end + +-- every custom shape object: its node (and mesh) when it is in the scene, else its mesh only +local function widgetList(ctx: Ctx): { { [string]: any } } + local list = {} + for _, addr in ctx.widgetOrder do + local ob = ctx.widgets[addr] + local t = ob:num("type") or -1 + local w: { [string]: any } = { name = ob:idName() or "", type = TYPE_NAME[t] or tostring(t) } + local node = ctx.objects[addr] + if node then + w.node = node + w.mesh = ctx.scene.nodes[node].mesh + elseif t == OB_MESH then + w.mesh = (meshOf(ctx, ob, true)) + end + table.insert(list, w) + end + return list +end + -- ------------------------------------------------------------------------------------------------ animation local function apply(props: Props, curves: { Curve }, frame: number, prefix: string?, name: string?): Props local p: Props = {} @@ -161335,7 +161990,7 @@ local function animations(ctx: Ctx) v = math.clamp(Anim.evaluate(c, fr), math.min(s.min, s.max), math.max(s.min, s.max)) -- the slider range end end - buffer.writef32(out, ((i - 1) * count + k) * 4, v) + buffer.writef32(out, ((i - 1) * count + k) * 4, if s.mute then 0 else v) k += 1 end end @@ -161392,7 +162047,7 @@ function Read.scene(f: Blend.File, opts: Options?): (Types.Scene?, string?) } local ctx: Ctx = { f = f, scene = scene, opts = o, objects = {}, objView = {}, parentOf = {}, world = {}, meshes = {}, materials = {}, - textures = {}, armatures = {}, prefix = {}, props = {}, meta = meta, pending = {}, + textures = {}, armatures = {}, prefix = {}, props = {}, meta = meta, pending = {}, widgets = {}, widgetOrder = {}, } local order: { { ob: Blend.View, under: number? } } = {} if sc then @@ -161471,6 +162126,7 @@ function Read.scene(f: Blend.File, opts: Options?): (Types.Scene?, string?) local u = a ~= nil and firstUnder[a] or nil object(ctx, e.ob, if u and u > 0 then u else nil, 0) end + rigs(ctx) for node = 1, #scene.nodes do local ob = ctx.objView[node] if ob and (ob:num("type") or -1) == OB_MESH then @@ -161478,6 +162134,9 @@ function Read.scene(f: Blend.File, opts: Options?): (Types.Scene?, string?) end end skins(ctx) + if next(ctx.armatures) ~= nil then + scene.meta.blend = { widgets = widgetList(ctx), bone_color_sets = Armature.colorSets() } + end if o.animations ~= false then animations(ctx) end @@ -170401,6 +171060,16 @@ function Read.scene(doc: any, bin: buffer?, fetch: Fetch, opts: any?): (Types.Sc return nil, Err.new(Err.CORRUPT, "bad mesh " .. (i - 1)) end local mesh: Types.Mesh = { name = str(m.name), primitives = {}, weights = if type(m.weights) == "table" then table.clone(m.weights) else nil, extras = keep(m, nil) } + -- morph target names: the extras.targetNames convention (Blender's exporter, three.js, Babylon) + local tn = type(m.extras) == "table" and m.extras.targetNames + if type(tn) == "table" and #tn > 0 then + local names = {} + for k, v in tn do + names[k] = if type(v) == "string" then v else tostring(v) + end + mesh.extras = mesh.extras or {} + ;(mesh.extras :: any).targetNames = names + end for k, p in arr(m.primitives) do if type(p) ~= "table" or type(p.attributes) ~= "table" then return nil, Err.new(Err.CORRUPT, string.format("mesh %d primitive %d: no attributes", i - 1, k - 1)) @@ -171117,6 +171786,12 @@ function Write.build(scene: Types.Scene, opts: Options?): (Out?, Err.Err?) end g.weights = mesh.weights restore(g, mesh.extras) + local tn = mesh.extras and (mesh.extras :: any).targetNames + if type(tn) == "table" and #tn > 0 and g.extras == nil then + local ex = object() + ex.targetNames = table.clone(tn) + g.extras = ex + end table.insert(meshes, g) end local cameras: { any } = {} @@ -207102,7 +207777,10 @@ local function defaultFor(name: string, k: number): number return 0 end -function MeshOps.merge(input: any, opts: { byMaterial: boolean?, method: string? }?): (any, Err.Err?) +-- opts.targets: morph targets concatenated by name (mesh.extras.targetNames, else prim.extras.targetNames; unnamed +-- ones by index), zero where a primitive lacks one; the result's extras.targetNames / extras.weights name them and +-- give their default weights (node weights, else mesh weights) +function MeshOps.merge(input: any, opts: { byMaterial: boolean?, method: string?, targets: boolean? }?): (any, Err.Err?) local placed: { Types.Placed } = {} if type(input) ~= "table" then return nil, Err.new(Err.ARG, "merge: expected a Scene or a list of Primitives") @@ -207116,6 +207794,9 @@ function MeshOps.merge(input: any, opts: { byMaterial: boolean?, method: string? end local groups: { [number]: { Primitive } } = {} local order: { number } = {} + local withTargets = opts ~= nil and opts.targets == true + local keysOf: { [Primitive]: { any } } = {} -- per baked primitive: the key (name or index) of each target + local weightOf: { [any]: number } = {} local allPoints = #placed > 0 for _, pl in placed do if pl.primitive.mode ~= "points" then @@ -207135,6 +207816,27 @@ function MeshOps.merge(input: any, opts: { byMaterial: boolean?, method: string? for name, a in t.attributes do copy.attributes[name] = MeshOps.f32(a) end + if withTargets and t.targets and #t.targets > 0 then + local mesh = if input.kind == "scene" and pl.mesh > 0 then input.meshes[pl.mesh] else nil + local node = if input.kind == "scene" and pl.node > 0 then input.nodes[pl.node] else nil + local names = mesh and mesh.extras and mesh.extras.targetNames or (p.extras and (p.extras :: any).targetNames) + local weights = node and node.weights or (mesh and mesh.weights) + local keys, targets = {}, {} + for k, tg in t.targets do + local key = if type(names) == "table" and type(names[k]) == "string" then names[k] else k + keys[k] = key + if weightOf[key] == nil then + weightOf[key] = weights and weights[k] or 0 + end + local own = {} + for name, a in tg do + own[name] = MeshOps.f32(a) + end + targets[k] = own + end + copy.targets = targets + keysOf[copy] = keys + end if pl.matrix ~= Scene.IDENTITY then local ok, terr = MeshOps.transform(copy, pl.matrix) if not ok then @@ -207180,6 +207882,56 @@ function MeshOps.merge(input: any, opts: { byMaterial: boolean?, method: string? end attrs[name] = Scene.accessor(out, "f32", comps, nv) end + local targets: { { [string]: Accessor } }? = nil + local targetKeys: { any } = {} + if withTargets then + local index: { [any]: number } = {} + for _, p in list do + for _, key in keysOf[p] or {} do + if not index[key] then + table.insert(targetKeys, key) + index[key] = #targetKeys + end + end + end + if #targetKeys > 0 then + local out: { { [string]: Accessor } } = {} + for ti, key in targetKeys do + local comps: { [string]: number } = {} + for _, p in list do + for k, pk in keysOf[p] or {} do + if pk == key then + for name, a in (p.targets :: any)[k] do + comps[name] = math.max(comps[name] or 0, a.components) + end + end + end + end + local tgt: { [string]: Accessor } = {} + for name, nc in comps do + local buf = buffer.create(nv * nc * 4) -- zero where a primitive lacks the target + local base = 0 + for _, p in list do + local cnt = vertexCount(p) + for k, pk in keysOf[p] or {} do + local a = if pk == key then (p.targets :: any)[k][name] else nil + if a then + for v = 0, math.min(cnt, a.count) - 1 do + for c = 0, math.min(nc, a.components) - 1 do + writef32(buf, ((base + v) * nc + c) * 4, readf32(a.data, (v * a.components + c) * 4)) + end + end + end + end + base += cnt + end + tgt[name] = Scene.accessor(buf, "f32", nc, nv) + end + out[ti] = tgt + end + targets = out + end + end local idx = buffer.create(ni * 4) local base, at = 0, 0 for _, p in list do @@ -207190,11 +207942,22 @@ function MeshOps.merge(input: any, opts: { byMaterial: boolean?, method: string? at += n base += vertexCount(p) end + local extras: { [string]: any }? = nil + if targets then + local names, weights = {}, {} + for k, key in targetKeys do + names[k] = if type(key) == "string" then key else tostring(key) + weights[k] = weightOf[key] or 0 + end + extras = { targetNames = names, weights = weights } + end return { attributes = attrs, indices = if points then nil else Scene.accessor(idx, "u32", 1, ni), mode = if points then "points" else "triangles", material = material, + targets = targets, + extras = extras, } end if opts and opts.byMaterial then diff --git a/build/Rosetta.luau.linemap.json b/build/Rosetta.luau.linemap.json index c5b85e2..12987d8 100644 --- a/build/Rosetta.luau.linemap.json +++ b/build/Rosetta.luau.linemap.json @@ -433,186 +433,187 @@ [157937, "src/Rosetta/model/b3d/init.luau"], [157992, "src/Rosetta/model/b3d/Read.luau"], [158563, "src/Rosetta/model/blend/init.luau"], -[158659, "src/Rosetta/model/blend/Anim.luau"], -[159005, "src/Rosetta/model/blend/Material.luau"], -[159357, "src/Rosetta/model/blend/Mesh.luau"], -[159992, "src/Rosetta/model/blend/Normals.luau"], -[160153, "src/Rosetta/model/blend/Prim.luau"], -[160602, "src/Rosetta/model/blend/Read.luau"], -[161502, "src/Rosetta/model/bsp/init.luau"], -[161693, "src/Rosetta/model/bsp/Lightmap.luau"], -[161759, "src/Rosetta/model/bsp/Quake.luau"], -[162148, "src/Rosetta/model/bsp/Quake3.luau"], -[162377, "src/Rosetta/model/bsp/Tree.luau"], -[162765, "src/Rosetta/model/buildmap/init.luau"], -[163037, "src/Rosetta/model/buildmap/Geometry.luau"], -[163440, "src/Rosetta/model/d3map/init.luau"], -[163722, "src/Rosetta/model/d3map/Parse.luau"], -[163920, "src/Rosetta/model/dae/init.luau"], -[164109, "src/Rosetta/model/dae/Math.luau"], -[164156, "src/Rosetta/model/dae/Read.luau"], -[166006, "src/Rosetta/model/dae/Write.luau"], -[166375, "src/Rosetta/model/fbx/init.luau"], -[166523, "src/Rosetta/model/fbx/Ascii.luau"], -[166793, "src/Rosetta/model/fbx/Binary.luau"], -[167248, "src/Rosetta/model/fbx/Read.luau"], -[168610, "src/Rosetta/model/fbx/Write.luau"], -[169595, "src/Rosetta/model/fbx/Xform.luau"], -[169636, "src/Rosetta/model/gltf/init.luau"], -[169873, "src/Rosetta/model/gltf/Pack.luau"], -[169942, "src/Rosetta/model/gltf/Read.luau"], -[170673, "src/Rosetta/model/gltf/Write.luau"], -[171353, "src/Rosetta/model/godot/init.luau"], -[171444, "src/Rosetta/model/godot/Build.luau"], -[171986, "src/Rosetta/model/godot/Primitives.luau"], -[172261, "src/Rosetta/model/godot/Surface.luau"], -[172746, "src/Rosetta/model/godot/Write.luau"], -[173075, "src/Rosetta/model/iqm/init.luau"], -[173151, "src/Rosetta/model/iqm/Read.luau"], -[173506, "src/Rosetta/model/iqm/Write.luau"], -[174193, "src/Rosetta/model/ldraw/init.luau"], -[174271, "src/Rosetta/model/ldraw/Colors.luau"], -[174589, "src/Rosetta/model/ldraw/Read.luau"], -[175166, "src/Rosetta/model/lwo/init.luau"], -[175242, "src/Rosetta/model/lwo/Build.luau"], -[175704, "src/Rosetta/model/lwo/Parse.luau"], -[176247, "src/Rosetta/model/map/init.luau"], -[176564, "src/Rosetta/model/map/Build.luau"], -[176808, "src/Rosetta/model/map/Parse.luau"], -[177193, "src/Rosetta/model/map/Write.luau"], -[177339, "src/Rosetta/model/mca/init.luau"], -[177681, "src/Rosetta/model/mca/Chunk.luau"], -[177814, "src/Rosetta/model/mca/Lz4Block.luau"], -[177884, "src/Rosetta/model/md2/init.luau"], -[178083, "src/Rosetta/model/md3/init.luau"], -[178311, "src/Rosetta/model/md5/init.luau"], -[178392, "src/Rosetta/model/md5/Read.luau"], -[178825, "src/Rosetta/model/mdl/init.luau"], -[178907, "src/Rosetta/model/mdl/HalfLife.luau"], -[179211, "src/Rosetta/model/mdl/Quake.luau"], -[179429, "src/Rosetta/model/ms3d/init.luau"], -[179501, "src/Rosetta/model/ms3d/Read.luau"], -[179947, "src/Rosetta/model/ms3d/Write.luau"], -[180416, "src/Rosetta/model/obj/init.luau"], -[181234, "src/Rosetta/model/obj/Mtl.luau"], -[181522, "src/Rosetta/model/off/init.luau"], -[181984, "src/Rosetta/model/ply/init.luau"], -[183089, "src/Rosetta/model/ply/Binary.luau"], -[183290, "src/Rosetta/model/pmx/init.luau"], -[183359, "src/Rosetta/model/pmx/Build.luau"], -[183655, "src/Rosetta/model/pmx/Pmd.luau"], -[183990, "src/Rosetta/model/pmx/Read.luau"], -[184394, "src/Rosetta/model/proc/init.luau"], -[184776, "src/Rosetta/model/qb/init.luau"], -[185169, "src/Rosetta/model/rbxm/init.luau"], -[185762, "src/Rosetta/model/rbxmx/init.luau"], -[186438, "src/Rosetta/model/robloxmesh/init.luau"], -[187097, "src/Rosetta/model/robloxmesh/Parse.luau"], -[187554, "src/Rosetta/model/robloxmesh/Write.luau"], -[187663, "src/Rosetta/model/schematic/init.luau"], -[187984, "src/Rosetta/model/schematic/Common.luau"], -[188104, "src/Rosetta/model/schematic/Litematic.luau"], -[188315, "src/Rosetta/model/schematic/Mcedit.luau"], -[188559, "src/Rosetta/model/schematic/Sponge.luau"], -[188688, "src/Rosetta/model/smd/init.luau"], -[188755, "src/Rosetta/model/smd/Read.luau"], -[189024, "src/Rosetta/model/smd/Write.luau"], -[189267, "src/Rosetta/model/sourcemdl/init.luau"], -[189438, "src/Rosetta/model/sourcemdl/Build.luau"], -[189868, "src/Rosetta/model/sourcemdl/Material.luau"], -[190029, "src/Rosetta/model/sourcemdl/Mdl.luau"], -[190556, "src/Rosetta/model/sourcemdl/Phy.luau"], -[190679, "src/Rosetta/model/sourcemdl/Vtx.luau"], -[190861, "src/Rosetta/model/sourcemdl/Vvd.luau"], -[190955, "src/Rosetta/model/stl/init.luau"], -[191405, "src/Rosetta/model/stl/Decode.luau"], -[191479, "src/Rosetta/model/t3d/init.luau"], -[191573, "src/Rosetta/model/t3d/Build.luau"], -[191978, "src/Rosetta/model/t3d/Parse.luau"], -[192146, "src/Rosetta/model/udmf/init.luau"], -[192229, "src/Rosetta/model/usda/init.luau"], -[192438, "src/Rosetta/model/usda/Build.luau"], -[193716, "src/Rosetta/model/usda/Parse.luau"], -[194514, "src/Rosetta/model/usda/Write.luau"], -[195331, "src/Rosetta/model/vbsp/init.luau"], -[195777, "src/Rosetta/model/vbsp/Faces.luau"], -[196001, "src/Rosetta/model/vbsp/Props.luau"], -[196093, "src/Rosetta/model/vmf/init.luau"], -[196418, "src/Rosetta/model/vmf/Build.luau"], -[196842, "src/Rosetta/model/vox/init.luau"], -[197728, "src/Rosetta/model/vox/Grid.luau"], -[197785, "src/Rosetta/model/vrml/init.luau"], -[197851, "src/Rosetta/model/x/init.luau"], -[197981, "src/Rosetta/model/x/Build.luau"], -[198544, "src/Rosetta/model/x/Parse.luau"], -[198841, "src/Rosetta/model/x3d/init.luau"], -[198919, "src/Rosetta/music/669/init.luau"], -[199126, "src/Rosetta/music/ahx/init.luau"], -[199178, "src/Rosetta/music/far/init.luau"], -[199408, "src/Rosetta/music/hmp/init.luau"], -[199673, "src/Rosetta/music/hvl/init.luau"], -[199725, "src/Rosetta/music/it/init.luau"], -[200144, "src/Rosetta/music/it/Itsex.luau"], -[200261, "src/Rosetta/music/med/init.luau"], -[200909, "src/Rosetta/music/midi/init.luau"], -[201053, "src/Rosetta/music/midi/Smf.luau"], -[201465, "src/Rosetta/music/mod/init.luau"], -[201819, "src/Rosetta/music/mtm/init.luau"], -[202042, "src/Rosetta/music/mus/init.luau"], -[202200, "src/Rosetta/music/okt/init.luau"], -[202482, "src/Rosetta/music/ptm/init.luau"], -[202705, "src/Rosetta/music/s3m/init.luau"], -[202942, "src/Rosetta/music/sf2/init.luau"], -[202986, "src/Rosetta/music/stm/init.luau"], -[203218, "src/Rosetta/music/ult/init.luau"], -[203523, "src/Rosetta/music/umx/init.luau"], -[203740, "src/Rosetta/music/xm/init.luau"], -[204302, "src/Rosetta/music/xmi/init.luau"], -[204511, "src/Rosetta/ops/AudioOps.luau"], -[204990, "src/Rosetta/ops/ImageOps/init.luau"], -[205638, "src/Rosetta/ops/ImageOps/Kernels.luau"], -[206278, "src/Rosetta/ops/LayerOps.luau"], -[206371, "src/Rosetta/ops/MeshOps/init.luau"], -[207423, "src/Rosetta/ops/MeshOps/Greedy.luau"], -[207590, "src/Rosetta/ops/MusicOps.luau"], -[207939, "src/Rosetta/playlist/m3u/init.luau"], -[208292, "src/Rosetta/playlist/pls/init.luau"], -[208470, "src/Rosetta/playlist/xspf/init.luau"], -[208673, "src/Rosetta/subtitle/ass/init.luau"], -[209117, "src/Rosetta/subtitle/srt/init.luau"], -[209290, "src/Rosetta/subtitle/vtt/init.luau"], -[209493, "src/Rosetta/vector/gamemaps/init.luau"], -[209680, "src/Rosetta/vector/gamemaps/Expand.luau"], -[209777, "src/Rosetta/vector/ldtk/init.luau"], -[209869, "src/Rosetta/vector/ldtk/Read.luau"], -[210205, "src/Rosetta/vector/ldtk/Write.luau"], -[210853, "src/Rosetta/vector/ogmo/init.luau"], -[210972, "src/Rosetta/vector/ogmo/Read.luau"], -[211377, "src/Rosetta/vector/ogmo/Write.luau"], -[211731, "src/Rosetta/vector/svg/init.luau"], -[211817, "src/Rosetta/vector/svg/Parse.luau"], -[212563, "src/Rosetta/vector/svg/PathData.luau"], -[212931, "src/Rosetta/vector/svg/Render.luau"], -[213348, "src/Rosetta/vector/svg/Style.luau"], -[213720, "src/Rosetta/vector/svg/Write.luau"], -[213920, "src/Rosetta/vector/tiled/init.luau"], -[214100, "src/Rosetta/vector/tiled/Data.luau"], -[214251, "src/Rosetta/vector/tiled/Tmj.luau"], -[214882, "src/Rosetta/vector/tiled/Tmx.luau"], -[215494, "src/Rosetta/video/avi/init.luau"], -[215788, "src/Rosetta/video/fli/init.luau"], -[215939, "src/Rosetta/video/flv/init.luau"], -[216323, "src/Rosetta/video/flv/Amf.luau"], -[216481, "src/Rosetta/video/flv/Mux.luau"], -[216762, "src/Rosetta/video/h264/init.luau"], -[216901, "src/Rosetta/video/mkv/init.luau"], -[217057, "src/Rosetta/video/mkv/Mux.luau"], -[217336, "src/Rosetta/video/mkv/Parse.luau"], -[218057, "src/Rosetta/video/mp4/init.luau"], -[218385, "src/Rosetta/video/mpegps/init.luau"], -[218572, "src/Rosetta/video/mpegts/init.luau"], -[218818, "src/Rosetta/video/ogv/init.luau"], -[219213, "src/Rosetta/video/smk/init.luau"], -[219522, "src/Rosetta/video/smk/Audio.luau"], -[219642, "src/Rosetta/video/y4m/init.luau"] +[158661, "src/Rosetta/model/blend/Anim.luau"], +[159007, "src/Rosetta/model/blend/Armature.luau"], +[159414, "src/Rosetta/model/blend/Material.luau"], +[159766, "src/Rosetta/model/blend/Mesh.luau"], +[160454, "src/Rosetta/model/blend/Normals.luau"], +[160615, "src/Rosetta/model/blend/Prim.luau"], +[161122, "src/Rosetta/model/blend/Read.luau"], +[162161, "src/Rosetta/model/bsp/init.luau"], +[162352, "src/Rosetta/model/bsp/Lightmap.luau"], +[162418, "src/Rosetta/model/bsp/Quake.luau"], +[162807, "src/Rosetta/model/bsp/Quake3.luau"], +[163036, "src/Rosetta/model/bsp/Tree.luau"], +[163424, "src/Rosetta/model/buildmap/init.luau"], +[163696, "src/Rosetta/model/buildmap/Geometry.luau"], +[164099, "src/Rosetta/model/d3map/init.luau"], +[164381, "src/Rosetta/model/d3map/Parse.luau"], +[164579, "src/Rosetta/model/dae/init.luau"], +[164768, "src/Rosetta/model/dae/Math.luau"], +[164815, "src/Rosetta/model/dae/Read.luau"], +[166665, "src/Rosetta/model/dae/Write.luau"], +[167034, "src/Rosetta/model/fbx/init.luau"], +[167182, "src/Rosetta/model/fbx/Ascii.luau"], +[167452, "src/Rosetta/model/fbx/Binary.luau"], +[167907, "src/Rosetta/model/fbx/Read.luau"], +[169269, "src/Rosetta/model/fbx/Write.luau"], +[170254, "src/Rosetta/model/fbx/Xform.luau"], +[170295, "src/Rosetta/model/gltf/init.luau"], +[170532, "src/Rosetta/model/gltf/Pack.luau"], +[170601, "src/Rosetta/model/gltf/Read.luau"], +[171342, "src/Rosetta/model/gltf/Write.luau"], +[172028, "src/Rosetta/model/godot/init.luau"], +[172119, "src/Rosetta/model/godot/Build.luau"], +[172661, "src/Rosetta/model/godot/Primitives.luau"], +[172936, "src/Rosetta/model/godot/Surface.luau"], +[173421, "src/Rosetta/model/godot/Write.luau"], +[173750, "src/Rosetta/model/iqm/init.luau"], +[173826, "src/Rosetta/model/iqm/Read.luau"], +[174181, "src/Rosetta/model/iqm/Write.luau"], +[174868, "src/Rosetta/model/ldraw/init.luau"], +[174946, "src/Rosetta/model/ldraw/Colors.luau"], +[175264, "src/Rosetta/model/ldraw/Read.luau"], +[175841, "src/Rosetta/model/lwo/init.luau"], +[175917, "src/Rosetta/model/lwo/Build.luau"], +[176379, "src/Rosetta/model/lwo/Parse.luau"], +[176922, "src/Rosetta/model/map/init.luau"], +[177239, "src/Rosetta/model/map/Build.luau"], +[177483, "src/Rosetta/model/map/Parse.luau"], +[177868, "src/Rosetta/model/map/Write.luau"], +[178014, "src/Rosetta/model/mca/init.luau"], +[178356, "src/Rosetta/model/mca/Chunk.luau"], +[178489, "src/Rosetta/model/mca/Lz4Block.luau"], +[178559, "src/Rosetta/model/md2/init.luau"], +[178758, "src/Rosetta/model/md3/init.luau"], +[178986, "src/Rosetta/model/md5/init.luau"], +[179067, "src/Rosetta/model/md5/Read.luau"], +[179500, "src/Rosetta/model/mdl/init.luau"], +[179582, "src/Rosetta/model/mdl/HalfLife.luau"], +[179886, "src/Rosetta/model/mdl/Quake.luau"], +[180104, "src/Rosetta/model/ms3d/init.luau"], +[180176, "src/Rosetta/model/ms3d/Read.luau"], +[180622, "src/Rosetta/model/ms3d/Write.luau"], +[181091, "src/Rosetta/model/obj/init.luau"], +[181909, "src/Rosetta/model/obj/Mtl.luau"], +[182197, "src/Rosetta/model/off/init.luau"], +[182659, "src/Rosetta/model/ply/init.luau"], +[183764, "src/Rosetta/model/ply/Binary.luau"], +[183965, "src/Rosetta/model/pmx/init.luau"], +[184034, "src/Rosetta/model/pmx/Build.luau"], +[184330, "src/Rosetta/model/pmx/Pmd.luau"], +[184665, "src/Rosetta/model/pmx/Read.luau"], +[185069, "src/Rosetta/model/proc/init.luau"], +[185451, "src/Rosetta/model/qb/init.luau"], +[185844, "src/Rosetta/model/rbxm/init.luau"], +[186437, "src/Rosetta/model/rbxmx/init.luau"], +[187113, "src/Rosetta/model/robloxmesh/init.luau"], +[187772, "src/Rosetta/model/robloxmesh/Parse.luau"], +[188229, "src/Rosetta/model/robloxmesh/Write.luau"], +[188338, "src/Rosetta/model/schematic/init.luau"], +[188659, "src/Rosetta/model/schematic/Common.luau"], +[188779, "src/Rosetta/model/schematic/Litematic.luau"], +[188990, "src/Rosetta/model/schematic/Mcedit.luau"], +[189234, "src/Rosetta/model/schematic/Sponge.luau"], +[189363, "src/Rosetta/model/smd/init.luau"], +[189430, "src/Rosetta/model/smd/Read.luau"], +[189699, "src/Rosetta/model/smd/Write.luau"], +[189942, "src/Rosetta/model/sourcemdl/init.luau"], +[190113, "src/Rosetta/model/sourcemdl/Build.luau"], +[190543, "src/Rosetta/model/sourcemdl/Material.luau"], +[190704, "src/Rosetta/model/sourcemdl/Mdl.luau"], +[191231, "src/Rosetta/model/sourcemdl/Phy.luau"], +[191354, "src/Rosetta/model/sourcemdl/Vtx.luau"], +[191536, "src/Rosetta/model/sourcemdl/Vvd.luau"], +[191630, "src/Rosetta/model/stl/init.luau"], +[192080, "src/Rosetta/model/stl/Decode.luau"], +[192154, "src/Rosetta/model/t3d/init.luau"], +[192248, "src/Rosetta/model/t3d/Build.luau"], +[192653, "src/Rosetta/model/t3d/Parse.luau"], +[192821, "src/Rosetta/model/udmf/init.luau"], +[192904, "src/Rosetta/model/usda/init.luau"], +[193113, "src/Rosetta/model/usda/Build.luau"], +[194391, "src/Rosetta/model/usda/Parse.luau"], +[195189, "src/Rosetta/model/usda/Write.luau"], +[196006, "src/Rosetta/model/vbsp/init.luau"], +[196452, "src/Rosetta/model/vbsp/Faces.luau"], +[196676, "src/Rosetta/model/vbsp/Props.luau"], +[196768, "src/Rosetta/model/vmf/init.luau"], +[197093, "src/Rosetta/model/vmf/Build.luau"], +[197517, "src/Rosetta/model/vox/init.luau"], +[198403, "src/Rosetta/model/vox/Grid.luau"], +[198460, "src/Rosetta/model/vrml/init.luau"], +[198526, "src/Rosetta/model/x/init.luau"], +[198656, "src/Rosetta/model/x/Build.luau"], +[199219, "src/Rosetta/model/x/Parse.luau"], +[199516, "src/Rosetta/model/x3d/init.luau"], +[199594, "src/Rosetta/music/669/init.luau"], +[199801, "src/Rosetta/music/ahx/init.luau"], +[199853, "src/Rosetta/music/far/init.luau"], +[200083, "src/Rosetta/music/hmp/init.luau"], +[200348, "src/Rosetta/music/hvl/init.luau"], +[200400, "src/Rosetta/music/it/init.luau"], +[200819, "src/Rosetta/music/it/Itsex.luau"], +[200936, "src/Rosetta/music/med/init.luau"], +[201584, "src/Rosetta/music/midi/init.luau"], +[201728, "src/Rosetta/music/midi/Smf.luau"], +[202140, "src/Rosetta/music/mod/init.luau"], +[202494, "src/Rosetta/music/mtm/init.luau"], +[202717, "src/Rosetta/music/mus/init.luau"], +[202875, "src/Rosetta/music/okt/init.luau"], +[203157, "src/Rosetta/music/ptm/init.luau"], +[203380, "src/Rosetta/music/s3m/init.luau"], +[203617, "src/Rosetta/music/sf2/init.luau"], +[203661, "src/Rosetta/music/stm/init.luau"], +[203893, "src/Rosetta/music/ult/init.luau"], +[204198, "src/Rosetta/music/umx/init.luau"], +[204415, "src/Rosetta/music/xm/init.luau"], +[204977, "src/Rosetta/music/xmi/init.luau"], +[205186, "src/Rosetta/ops/AudioOps.luau"], +[205665, "src/Rosetta/ops/ImageOps/init.luau"], +[206313, "src/Rosetta/ops/ImageOps/Kernels.luau"], +[206953, "src/Rosetta/ops/LayerOps.luau"], +[207046, "src/Rosetta/ops/MeshOps/init.luau"], +[208186, "src/Rosetta/ops/MeshOps/Greedy.luau"], +[208353, "src/Rosetta/ops/MusicOps.luau"], +[208702, "src/Rosetta/playlist/m3u/init.luau"], +[209055, "src/Rosetta/playlist/pls/init.luau"], +[209233, "src/Rosetta/playlist/xspf/init.luau"], +[209436, "src/Rosetta/subtitle/ass/init.luau"], +[209880, "src/Rosetta/subtitle/srt/init.luau"], +[210053, "src/Rosetta/subtitle/vtt/init.luau"], +[210256, "src/Rosetta/vector/gamemaps/init.luau"], +[210443, "src/Rosetta/vector/gamemaps/Expand.luau"], +[210540, "src/Rosetta/vector/ldtk/init.luau"], +[210632, "src/Rosetta/vector/ldtk/Read.luau"], +[210968, "src/Rosetta/vector/ldtk/Write.luau"], +[211616, "src/Rosetta/vector/ogmo/init.luau"], +[211735, "src/Rosetta/vector/ogmo/Read.luau"], +[212140, "src/Rosetta/vector/ogmo/Write.luau"], +[212494, "src/Rosetta/vector/svg/init.luau"], +[212580, "src/Rosetta/vector/svg/Parse.luau"], +[213326, "src/Rosetta/vector/svg/PathData.luau"], +[213694, "src/Rosetta/vector/svg/Render.luau"], +[214111, "src/Rosetta/vector/svg/Style.luau"], +[214483, "src/Rosetta/vector/svg/Write.luau"], +[214683, "src/Rosetta/vector/tiled/init.luau"], +[214863, "src/Rosetta/vector/tiled/Data.luau"], +[215014, "src/Rosetta/vector/tiled/Tmj.luau"], +[215645, "src/Rosetta/vector/tiled/Tmx.luau"], +[216257, "src/Rosetta/video/avi/init.luau"], +[216551, "src/Rosetta/video/fli/init.luau"], +[216702, "src/Rosetta/video/flv/init.luau"], +[217086, "src/Rosetta/video/flv/Amf.luau"], +[217244, "src/Rosetta/video/flv/Mux.luau"], +[217525, "src/Rosetta/video/h264/init.luau"], +[217664, "src/Rosetta/video/mkv/init.luau"], +[217820, "src/Rosetta/video/mkv/Mux.luau"], +[218099, "src/Rosetta/video/mkv/Parse.luau"], +[218820, "src/Rosetta/video/mp4/init.luau"], +[219148, "src/Rosetta/video/mpegps/init.luau"], +[219335, "src/Rosetta/video/mpegts/init.luau"], +[219581, "src/Rosetta/video/ogv/init.luau"], +[219976, "src/Rosetta/video/smk/init.luau"], +[220285, "src/Rosetta/video/smk/Audio.luau"], +[220405, "src/Rosetta/video/y4m/init.luau"] ] diff --git a/build/Rosetta.rbxm b/build/Rosetta.rbxm index c1c44df..a222b0b 100644 Binary files a/build/Rosetta.rbxm and b/build/Rosetta.rbxm differ diff --git a/build/Rosetta.rbxm.linemap.json b/build/Rosetta.rbxm.linemap.json index 629bc05..7185eef 100644 --- a/build/Rosetta.rbxm.linemap.json +++ b/build/Rosetta.rbxm.linemap.json @@ -47,15 +47,15 @@ "image_1": [[8, "src/Rosetta/image/ani/init.luau"], [188, "src/Rosetta/image/art/init.luau"], [676, "src/Rosetta/image/blp/init.luau"], [934, "src/Rosetta/image/bmp/init.luau"], [1349, "src/Rosetta/image/dds/init.luau"], [1832, "src/Rosetta/image/exr/init.luau"], [2592, "src/Rosetta/image/exr/Codec.luau"], [2703, "src/Rosetta/image/exr/Piz.luau"], [3060, "src/Rosetta/image/gif/init.luau"], [3576, "src/Rosetta/image/gif/Decode.luau"], [3652, "src/Rosetta/image/hdr/init.luau"], [3881, "src/Rosetta/image/hdr/Codec.luau"], [4092, "src/Rosetta/image/icns/init.luau"], [4423, "src/Rosetta/image/ico/init.luau"], [4700, "src/Rosetta/image/ico/Dib.luau"], [4795, "src/Rosetta/image/ilbm/init.luau"], [5114, "src/Rosetta/image/jpeg/init.luau"], [5250, "src/Rosetta/image/ktx/init.luau"], [5910, "src/Rosetta/image/lmp/init.luau"], [6043, "src/Rosetta/image/pcx/init.luau"], [6307, "src/Rosetta/image/pnm/init.luau"], [6685, "src/Rosetta/image/pnm/Codec.luau"], [6962, "src/Rosetta/image/qoi/init.luau"], [7084, "src/Rosetta/image/qoi/Codec.luau"], [7241, "src/Rosetta/image/sgi/init.luau"], [7526, "src/Rosetta/image/spr/init.luau"]], "image_2": [[8, "src/Rosetta/image/sunras/init.luau"], [254, "src/Rosetta/image/tga/init.luau"], [524, "src/Rosetta/image/tga/Codec.luau"], [724, "src/Rosetta/image/tiff/init.luau"], [1551, "src/Rosetta/image/tiff/Pixels.luau"], [1941, "src/Rosetta/image/tim/init.luau"], [2183, "src/Rosetta/image/vtf/init.luau"], [2418, "src/Rosetta/image/webp/init.luau"], [3028, "src/Rosetta/image/webp/Alpha.luau"], [3104, "src/Rosetta/image/webp/Anim.luau"], [3259, "src/Rosetta/image/xbm/init.luau"], [3420, "src/Rosetta/image/xpm/init.luau"], [3688, "src/Rosetta/image/xpm/Names.luau"]], "layered": [[8, "src/Rosetta/layered/aseprite/init.luau"], [746, "src/Rosetta/layered/ora/init.luau"], [1033, "src/Rosetta/layered/psd/init.luau"], [1768, "src/Rosetta/layered/psd/Channels.luau"]], -"model_1": [[8, "src/Rosetta/model/3ds/init.luau"], [91, "src/Rosetta/model/3ds/Build.luau"], [738, "src/Rosetta/model/3ds/Read.luau"], [1234, "src/Rosetta/model/3ds/Write.luau"], [2039, "src/Rosetta/model/3mf/init.luau"], [2121, "src/Rosetta/model/3mf/Read.luau"], [2709, "src/Rosetta/model/3mf/Write.luau"], [3114, "src/Rosetta/model/ase/init.luau"], [3237, "src/Rosetta/model/ase/Build.luau"], [3811, "src/Rosetta/model/ase/Parse.luau"], [3880, "src/Rosetta/model/ase/Write.luau"], [4343, "src/Rosetta/model/b3d/init.luau"], [4398, "src/Rosetta/model/b3d/Read.luau"], [4969, "src/Rosetta/model/blend/init.luau"], [5065, "src/Rosetta/model/blend/Anim.luau"], [5411, "src/Rosetta/model/blend/Material.luau"], [5763, "src/Rosetta/model/blend/Mesh.luau"], [6398, "src/Rosetta/model/blend/Normals.luau"], [6559, "src/Rosetta/model/blend/Prim.luau"]], -"model_2": [[8, "src/Rosetta/model/blend/Read.luau"], [908, "src/Rosetta/model/bsp/init.luau"], [1099, "src/Rosetta/model/bsp/Lightmap.luau"], [1165, "src/Rosetta/model/bsp/Quake.luau"], [1554, "src/Rosetta/model/bsp/Quake3.luau"], [1783, "src/Rosetta/model/bsp/Tree.luau"], [2171, "src/Rosetta/model/buildmap/init.luau"], [2443, "src/Rosetta/model/buildmap/Geometry.luau"], [2846, "src/Rosetta/model/d3map/init.luau"], [3128, "src/Rosetta/model/d3map/Parse.luau"], [3326, "src/Rosetta/model/dae/init.luau"], [3515, "src/Rosetta/model/dae/Math.luau"], [3562, "src/Rosetta/model/dae/Read.luau"], [5412, "src/Rosetta/model/dae/Write.luau"], [5781, "src/Rosetta/model/fbx/init.luau"], [5929, "src/Rosetta/model/fbx/Ascii.luau"], [6199, "src/Rosetta/model/fbx/Binary.luau"]], -"model_3": [[8, "src/Rosetta/model/fbx/Read.luau"], [1370, "src/Rosetta/model/fbx/Write.luau"], [2355, "src/Rosetta/model/fbx/Xform.luau"], [2396, "src/Rosetta/model/gltf/init.luau"], [2633, "src/Rosetta/model/gltf/Pack.luau"], [2702, "src/Rosetta/model/gltf/Read.luau"], [3433, "src/Rosetta/model/gltf/Write.luau"], [4113, "src/Rosetta/model/godot/init.luau"], [4204, "src/Rosetta/model/godot/Build.luau"], [4746, "src/Rosetta/model/godot/Primitives.luau"], [5021, "src/Rosetta/model/godot/Surface.luau"], [5506, "src/Rosetta/model/godot/Write.luau"], [5835, "src/Rosetta/model/iqm/init.luau"], [5911, "src/Rosetta/model/iqm/Read.luau"], [6266, "src/Rosetta/model/iqm/Write.luau"], [6953, "src/Rosetta/model/ldraw/init.luau"], [7031, "src/Rosetta/model/ldraw/Colors.luau"]], +"model_1": [[8, "src/Rosetta/model/3ds/init.luau"], [91, "src/Rosetta/model/3ds/Build.luau"], [738, "src/Rosetta/model/3ds/Read.luau"], [1234, "src/Rosetta/model/3ds/Write.luau"], [2039, "src/Rosetta/model/3mf/init.luau"], [2121, "src/Rosetta/model/3mf/Read.luau"], [2709, "src/Rosetta/model/3mf/Write.luau"], [3114, "src/Rosetta/model/ase/init.luau"], [3237, "src/Rosetta/model/ase/Build.luau"], [3811, "src/Rosetta/model/ase/Parse.luau"], [3880, "src/Rosetta/model/ase/Write.luau"], [4343, "src/Rosetta/model/b3d/init.luau"], [4398, "src/Rosetta/model/b3d/Read.luau"], [4969, "src/Rosetta/model/blend/init.luau"], [5067, "src/Rosetta/model/blend/Anim.luau"], [5413, "src/Rosetta/model/blend/Armature.luau"], [5820, "src/Rosetta/model/blend/Material.luau"], [6172, "src/Rosetta/model/blend/Mesh.luau"], [6860, "src/Rosetta/model/blend/Normals.luau"], [7021, "src/Rosetta/model/blend/Prim.luau"]], +"model_2": [[8, "src/Rosetta/model/blend/Read.luau"], [1047, "src/Rosetta/model/bsp/init.luau"], [1238, "src/Rosetta/model/bsp/Lightmap.luau"], [1304, "src/Rosetta/model/bsp/Quake.luau"], [1693, "src/Rosetta/model/bsp/Quake3.luau"], [1922, "src/Rosetta/model/bsp/Tree.luau"], [2310, "src/Rosetta/model/buildmap/init.luau"], [2582, "src/Rosetta/model/buildmap/Geometry.luau"], [2985, "src/Rosetta/model/d3map/init.luau"], [3267, "src/Rosetta/model/d3map/Parse.luau"], [3465, "src/Rosetta/model/dae/init.luau"], [3654, "src/Rosetta/model/dae/Math.luau"], [3701, "src/Rosetta/model/dae/Read.luau"], [5551, "src/Rosetta/model/dae/Write.luau"], [5920, "src/Rosetta/model/fbx/init.luau"], [6068, "src/Rosetta/model/fbx/Ascii.luau"], [6338, "src/Rosetta/model/fbx/Binary.luau"]], +"model_3": [[8, "src/Rosetta/model/fbx/Read.luau"], [1370, "src/Rosetta/model/fbx/Write.luau"], [2355, "src/Rosetta/model/fbx/Xform.luau"], [2396, "src/Rosetta/model/gltf/init.luau"], [2633, "src/Rosetta/model/gltf/Pack.luau"], [2702, "src/Rosetta/model/gltf/Read.luau"], [3443, "src/Rosetta/model/gltf/Write.luau"], [4129, "src/Rosetta/model/godot/init.luau"], [4220, "src/Rosetta/model/godot/Build.luau"], [4762, "src/Rosetta/model/godot/Primitives.luau"], [5037, "src/Rosetta/model/godot/Surface.luau"], [5522, "src/Rosetta/model/godot/Write.luau"], [5851, "src/Rosetta/model/iqm/init.luau"], [5927, "src/Rosetta/model/iqm/Read.luau"], [6282, "src/Rosetta/model/iqm/Write.luau"], [6969, "src/Rosetta/model/ldraw/init.luau"], [7047, "src/Rosetta/model/ldraw/Colors.luau"]], "model_4": [[8, "src/Rosetta/model/ldraw/Read.luau"], [585, "src/Rosetta/model/lwo/init.luau"], [661, "src/Rosetta/model/lwo/Build.luau"], [1123, "src/Rosetta/model/lwo/Parse.luau"], [1666, "src/Rosetta/model/map/init.luau"], [1983, "src/Rosetta/model/map/Build.luau"], [2227, "src/Rosetta/model/map/Parse.luau"], [2612, "src/Rosetta/model/map/Write.luau"], [2758, "src/Rosetta/model/mca/init.luau"], [3100, "src/Rosetta/model/mca/Chunk.luau"], [3233, "src/Rosetta/model/mca/Lz4Block.luau"], [3303, "src/Rosetta/model/md2/init.luau"], [3502, "src/Rosetta/model/md3/init.luau"], [3730, "src/Rosetta/model/md5/init.luau"], [3811, "src/Rosetta/model/md5/Read.luau"], [4244, "src/Rosetta/model/mdl/init.luau"], [4326, "src/Rosetta/model/mdl/HalfLife.luau"], [4630, "src/Rosetta/model/mdl/Quake.luau"], [4848, "src/Rosetta/model/ms3d/init.luau"], [4920, "src/Rosetta/model/ms3d/Read.luau"], [5366, "src/Rosetta/model/ms3d/Write.luau"], [5835, "src/Rosetta/model/obj/init.luau"], [6653, "src/Rosetta/model/obj/Mtl.luau"], [6941, "src/Rosetta/model/off/init.luau"]], "model_5": [[8, "src/Rosetta/model/ply/init.luau"], [1113, "src/Rosetta/model/ply/Binary.luau"], [1314, "src/Rosetta/model/pmx/init.luau"], [1383, "src/Rosetta/model/pmx/Build.luau"], [1679, "src/Rosetta/model/pmx/Pmd.luau"], [2014, "src/Rosetta/model/pmx/Read.luau"], [2418, "src/Rosetta/model/proc/init.luau"], [2800, "src/Rosetta/model/qb/init.luau"], [3193, "src/Rosetta/model/rbxm/init.luau"], [3786, "src/Rosetta/model/rbxmx/init.luau"], [4462, "src/Rosetta/model/robloxmesh/init.luau"], [5121, "src/Rosetta/model/robloxmesh/Parse.luau"], [5578, "src/Rosetta/model/robloxmesh/Write.luau"], [5687, "src/Rosetta/model/schematic/init.luau"], [6008, "src/Rosetta/model/schematic/Common.luau"], [6128, "src/Rosetta/model/schematic/Litematic.luau"], [6339, "src/Rosetta/model/schematic/Mcedit.luau"], [6583, "src/Rosetta/model/schematic/Sponge.luau"], [6712, "src/Rosetta/model/smd/init.luau"], [6779, "src/Rosetta/model/smd/Read.luau"], [7048, "src/Rosetta/model/smd/Write.luau"], [7291, "src/Rosetta/model/sourcemdl/init.luau"], [7462, "src/Rosetta/model/sourcemdl/Build.luau"], [7892, "src/Rosetta/model/sourcemdl/Material.luau"]], "model_6": [[8, "src/Rosetta/model/sourcemdl/Mdl.luau"], [535, "src/Rosetta/model/sourcemdl/Phy.luau"], [658, "src/Rosetta/model/sourcemdl/Vtx.luau"], [840, "src/Rosetta/model/sourcemdl/Vvd.luau"], [934, "src/Rosetta/model/stl/init.luau"], [1384, "src/Rosetta/model/stl/Decode.luau"], [1458, "src/Rosetta/model/t3d/init.luau"], [1552, "src/Rosetta/model/t3d/Build.luau"], [1957, "src/Rosetta/model/t3d/Parse.luau"], [2125, "src/Rosetta/model/udmf/init.luau"], [2208, "src/Rosetta/model/usda/init.luau"], [2417, "src/Rosetta/model/usda/Build.luau"], [3695, "src/Rosetta/model/usda/Parse.luau"], [4493, "src/Rosetta/model/usda/Write.luau"], [5310, "src/Rosetta/model/vbsp/init.luau"], [5756, "src/Rosetta/model/vbsp/Faces.luau"], [5980, "src/Rosetta/model/vbsp/Props.luau"], [6072, "src/Rosetta/model/vmf/init.luau"], [6397, "src/Rosetta/model/vmf/Build.luau"], [6821, "src/Rosetta/model/vox/init.luau"], [7707, "src/Rosetta/model/vox/Grid.luau"], [7764, "src/Rosetta/model/vrml/init.luau"], [7830, "src/Rosetta/model/x/init.luau"]], "model_7": [[8, "src/Rosetta/model/x/Build.luau"], [571, "src/Rosetta/model/x/Parse.luau"], [868, "src/Rosetta/model/x3d/init.luau"]], "music": [[8, "src/Rosetta/music/669/init.luau"], [215, "src/Rosetta/music/ahx/init.luau"], [267, "src/Rosetta/music/far/init.luau"], [497, "src/Rosetta/music/hmp/init.luau"], [762, "src/Rosetta/music/hvl/init.luau"], [814, "src/Rosetta/music/it/init.luau"], [1233, "src/Rosetta/music/it/Itsex.luau"], [1350, "src/Rosetta/music/med/init.luau"], [1998, "src/Rosetta/music/midi/init.luau"], [2142, "src/Rosetta/music/midi/Smf.luau"], [2554, "src/Rosetta/music/mod/init.luau"], [2908, "src/Rosetta/music/mtm/init.luau"], [3131, "src/Rosetta/music/mus/init.luau"], [3289, "src/Rosetta/music/okt/init.luau"], [3571, "src/Rosetta/music/ptm/init.luau"], [3794, "src/Rosetta/music/s3m/init.luau"], [4031, "src/Rosetta/music/sf2/init.luau"], [4075, "src/Rosetta/music/stm/init.luau"], [4307, "src/Rosetta/music/ult/init.luau"], [4612, "src/Rosetta/music/umx/init.luau"], [4829, "src/Rosetta/music/xm/init.luau"], [5391, "src/Rosetta/music/xmi/init.luau"]], -"ops": [[8, "src/Rosetta/ops/AudioOps.luau"], [487, "src/Rosetta/ops/LayerOps.luau"], [580, "src/Rosetta/ops/MeshOps/init.luau"], [1632, "src/Rosetta/ops/MeshOps/Greedy.luau"], [1799, "src/Rosetta/ops/MusicOps.luau"]], +"ops": [[8, "src/Rosetta/ops/AudioOps.luau"], [487, "src/Rosetta/ops/LayerOps.luau"], [580, "src/Rosetta/ops/MeshOps/init.luau"], [1720, "src/Rosetta/ops/MeshOps/Greedy.luau"], [1887, "src/Rosetta/ops/MusicOps.luau"]], "playlist": [[8, "src/Rosetta/playlist/m3u/init.luau"], [361, "src/Rosetta/playlist/pls/init.luau"], [539, "src/Rosetta/playlist/xspf/init.luau"]], "subtitle": [[8, "src/Rosetta/subtitle/ass/init.luau"], [452, "src/Rosetta/subtitle/srt/init.luau"], [625, "src/Rosetta/subtitle/vtt/init.luau"]], "vector": [[8, "src/Rosetta/vector/gamemaps/init.luau"], [195, "src/Rosetta/vector/gamemaps/Expand.luau"], [292, "src/Rosetta/vector/ldtk/init.luau"], [384, "src/Rosetta/vector/ldtk/Read.luau"], [720, "src/Rosetta/vector/ldtk/Write.luau"], [1368, "src/Rosetta/vector/ogmo/init.luau"], [1487, "src/Rosetta/vector/ogmo/Read.luau"], [1892, "src/Rosetta/vector/ogmo/Write.luau"], [2246, "src/Rosetta/vector/svg/init.luau"], [2332, "src/Rosetta/vector/svg/Parse.luau"], [3078, "src/Rosetta/vector/svg/PathData.luau"], [3446, "src/Rosetta/vector/svg/Render.luau"], [3863, "src/Rosetta/vector/svg/Style.luau"], [4235, "src/Rosetta/vector/svg/Write.luau"], [4435, "src/Rosetta/vector/tiled/init.luau"], [4615, "src/Rosetta/vector/tiled/Data.luau"], [4766, "src/Rosetta/vector/tiled/Tmj.luau"], [5397, "src/Rosetta/vector/tiled/Tmx.luau"]], diff --git a/build/Rosetta.rbxmx b/build/Rosetta.rbxmx index f0ccab8..9707259 100644 --- a/build/Rosetta.rbxmx +++ b/build/Rosetta.rbxmx @@ -446,6 +446,7 @@ local __CHUNK = { ["model/b3d/Read"] = "model_1", ["model/blend"] = "model_1", ["model/blend/Anim"] = "model_1", + ["model/blend/Armature"] = "model_1", ["model/blend/Material"] = "model_1", ["model/blend/Mesh"] = "model_1", ["model/blend/Normals"] = "model_1", @@ -156165,7 +156166,7 @@ end --!optimize 2 --!nocheck -- rosetta chunk model_1 (build/Rosetta.rbxm): GENERATED by tools/bundle.py from src/Rosetta - do not edit. --- 19 modules (0 native: @native); the Rosetta root requires it when one of them is first included. +-- 20 modules (0 native: @native); the Rosetta root requires it when one of them is first included. -- Error lines map back to the sources through Rosetta.rbxm.linemap.json (tools/bundle.py --where). return function(__FILES, __include) __FILES["model/3ds"] = function() @@ -161136,9 +161137,10 @@ __FILES["model/blend"] = function() -- file's own SDNA). Supports: the scene's objects and collections, transforms with parent inverse and bone parents, -- meshes of every storage generation (MFace, MPoly / MLoop, attribute layers, AttributeStorage) with UV maps, colour -- attributes, custom normals, material slots; Principled BSDF materials; packed and external images; cameras; lights; --- armatures, skins (vertex groups, top 4 weights), shape keys; actions sampled into channels. +-- armatures, skins (vertex groups, top 4 weights), shape keys (relative keys, vertex groups); actions sampled into +-- channels; rig data (bone collections / layers, colours, custom shapes, pose settings, constraint stacks) as extras. -- Not supported: modifiers (listed in meta.source.modifiers), curves / text / metaballs / grease pencil / volumes, --- NLA strips, drivers, constraints, f-curve modifiers, linked libraries, collection instances. +-- NLA strips, drivers, constraint evaluation, f-curve modifiers, linked libraries, collection instances. -- ------------------------------------------------------------------------------------------------ requires local Err = __include("core/Err") @@ -161164,6 +161166,7 @@ local BlendFormat = { type DecodeOptions = { triangulate: boolean?, -- default true (false: "polygons" primitives) flipV: boolean?, -- default true (glTF's top-left UV origin) + looseEdges: boolean?, -- edges outside faces as "lines" primitives (default false; always for custom shape widgets) collections: boolean?, -- collections as nodes (default true) scene: string?, -- a scene by name (default: the file's current scene) sampleStep: number?, -- frames between animation samples (default 1) @@ -161571,6 +161574,413 @@ end return Anim end +__FILES["model/blend/Armature"] = function() + +-- model/blend/Armature: the rig data of an armature as Blender's Python API names it: bones (head / tail / roll in +-- armature space, deform, connect, wire), bone collections (4.x BoneCollection arrays and lists; before 4.0 the layers +-- and bone groups converted as Blender 4.0's versioning does), bone colours (BoneColor; bone group colours before 4.0), +-- pose bones (custom shapes, locks, rotation mode, IK settings) and constraint stacks (bConstraint and the data structs +-- of IK, copy rotation / location / scale / transforms, damped track, limit rotation / location / scale, child of; the +-- common fields for the rest). Flags from DNA_armature_types.h, DNA_action_types.h, DNA_constraint_types.h. +local Blend = __include("containers/Blend") + +local Armature = {} + +type Target = number | string -- a scene node index, or the object's name when it is not in the scene +type Resolve = (ob: Blend.View?) -> Target? +type Color = { palette: string, normal: { number }?, select: { number }?, active: { number }? } + +-- Blender's default theme (userdef_default_theme.c): bone colour sets THEME01..THEME20 as normal, select, active +local THEME = { + { 0x9a0000, 0xbd1111, 0xf70a0a }, { 0xf74018, 0xf66913, 0xfa9900 }, { 0x1e9109, 0x59b70b, 0x83ef1d }, + { 0x0a3694, 0x3667df, 0x5ec1ef }, { 0xa9294e, 0xc1416a, 0xf05d91 }, { 0x430c78, 0x543aa3, 0x8764d5 }, + { 0x24785a, 0x3c9579, 0x6fb6ab }, { 0x4b707c, 0x6a8691, 0x9bc2cd }, { 0xf4c90c, 0xeec236, 0xf3ff00 }, + { 0x1e2024, 0x484c56, 0xffffff }, { 0x6f2f6a, 0x9845be, 0xd330d6 }, { 0x6c8e22, 0x7fb022, 0xbbef5b }, + { 0x8d8d8d, 0xb0b0b0, 0xdedede }, { 0x834326, 0x8b5811, 0xbd6a11 }, { 0x08310e, 0x1c430b, 0x34622b }, + { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, +} + +local function rgb(hex: number): { number } + return { bit32.rshift(hex, 16) / 255, bit32.band(bit32.rshift(hex, 8), 255) / 255, bit32.band(hex, 255) / 255 } +end + +function Armature.colorSets(): { { normal: { number }, select: { number }, active: { number } } } + local out = {} + for i, s in THEME do + out[i] = { normal = rgb(s[1]), select = rgb(s[2]), active = rgb(s[3]) } + end + return out +end + +local ROTMODE: { [number]: string } = { [0] = "QUATERNION", [1] = "XYZ", [2] = "XZY", [3] = "YXZ", [4] = "YZX", [5] = "ZXY", [6] = "ZYX", [-1] = "AXIS_ANGLE" } +local SPACE: { [number]: string } = { [0] = "WORLD", [1] = "LOCAL", [2] = "POSE", [3] = "LOCAL_WITH_PARENT", [5] = "CUSTOM", [6] = "LOCAL_OWNER_ORIENT" } +local EULER_ORDER: { [number]: string } = { [0] = "AUTO", [1] = "XYZ", [2] = "XZY", [3] = "YXZ", [4] = "YZX", [5] = "ZXY", [6] = "ZYX" } +local TRACK: { [number]: string } = { [0] = "TRACK_X", [1] = "TRACK_Y", [2] = "TRACK_Z", [3] = "TRACK_NEGATIVE_X", [4] = "TRACK_NEGATIVE_Y", [5] = "TRACK_NEGATIVE_Z" } +local ROT_MIX: { [number]: string } = { [0] = "REPLACE", [1] = "OFFSET", [2] = "ADD", [3] = "BEFORE", [4] = "AFTER" } +local TRANS_MIX: { [number]: string } = { [0] = "REPLACE", [1] = "BEFORE", [2] = "AFTER", [3] = "BEFORE_FULL", [4] = "BEFORE_SPLIT", [5] = "AFTER_FULL", [6] = "AFTER_SPLIT" } +local TYPE: { [number]: string } = { + [1] = "CHILD_OF", [2] = "TRACK_TO", [3] = "IK", [4] = "FOLLOW_PATH", [5] = "LIMIT_ROTATION", [6] = "LIMIT_LOCATION", + [7] = "LIMIT_SCALE", [8] = "COPY_ROTATION", [9] = "COPY_LOCATION", [10] = "COPY_SCALE", [11] = "PYTHON", [12] = "ACTION", + [13] = "LOCKED_TRACK", [14] = "LIMIT_DISTANCE", [15] = "STRETCH_TO", [16] = "FLOOR", [17] = "RIGID_BODY_JOINT", + [18] = "CLAMP_TO", [19] = "TRANSFORM", [20] = "SHRINKWRAP", [21] = "DAMPED_TRACK", [22] = "SPLINE_IK", + [23] = "COPY_TRANSFORMS", [24] = "MAINTAIN_VOLUME", [25] = "PIVOT", [26] = "FOLLOW_TRACK", [27] = "CAMERA_SOLVER", + [28] = "OBJECT_SOLVER", [29] = "TRANSFORM_CACHE", [30] = "ARMATURE", [31] = "GEOMETRY_ATTRIBUTE", +} +-- constraint types with a head_tail (bConstraint.headtail) in Blender's API +local HEAD_TAIL: { [string]: boolean } = { + COPY_LOCATION = true, COPY_TRANSFORMS = true, DAMPED_TRACK = true, TRACK_TO = true, LOCKED_TRACK = true, + STRETCH_TO = true, LIMIT_DISTANCE = true, +} + +local CONSTRAINT_OFF, CONSTRAINT_BBONE_SHAPE = 0x200, 0x400 +local BONE_CONNECTED, BONE_HIDDEN_P, BONE_NO_DEFORM, BONE_DRAWWIRE = 0x10, 0x40, 0x1000, 0x20000 +local PCHAN_DRAW_NO_CUSTOM_BONE_SIZE = 1 +-- bPoseChannel.protectflag (OB_LOCK_*) and ikflag (BONE_IK_*) +local LOCK_LOC, LOCK_ROT, LOCK_SCALE, LOCK_ROTW, LOCK_ROT4D = { 1, 2, 4 }, { 8, 16, 32 }, { 64, 128, 256 }, 512, 1024 +local IK_NO_DOF, IK_LIMIT = { 1, 2, 4 }, { 8, 16, 32 } +local AXES = { "x", "y", "z" } + +local function bit(v: number?, mask: number): boolean + return bit32.band(v or 0, mask) ~= 0 +end + +local function bits(v: number?, masks: { number }): { boolean } + return { bit(v, masks[1]), bit(v, masks[2]), bit(v, masks[3]) } +end + +local function vec3(v: Blend.View, name: string, fallback: { number }?): { number }? + local x = v:vec(name) + if x and #x >= 3 then + return { x[1], x[2], x[3] } + end + return fallback and table.clone(fallback) +end + +local function text(v: Blend.View, name: string): string? + local s = v:str(name) + return if s and s ~= "" then s else nil +end + +-- ThemeWireColor: char solid[4], select[4], active[4] (sRGB bytes) +local function wire(v: Blend.View?): { [string]: { number } }? + if not v then + return nil + end + local out: { [string]: { number } } = {} + for _, pair in { { "normal", "solid" }, { "select", "select" }, { "active", "active" } } do + local key, field = pair[1], pair[2] + local fld = v.struct.byName[field] + local o = fld and v.offset + fld.offset + if not o or o + 3 > buffer.len(v.file.buf) then + return nil + end + local b = v.file.buf + out[key] = { buffer.readu8(b, o) / 255, buffer.readu8(b, o + 1) / 255, buffer.readu8(b, o + 2) / 255 } + end + return out +end + +-- palette: 0 default, 1..20 the theme sets, -1 custom (BoneColor.palette_index, bActionGroup.customCol); the colours +-- are the custom ones, or the default theme's set +local function color(index: number?, custom: Blend.View?): Color? + if not index or index == 0 then + return nil + end + local c: Color = { palette = if index < 0 then "CUSTOM" else string.format("THEME%02d", index) } + local w = if index < 0 then wire(custom) else nil + if w then + c.normal, c.select, c.active = w.normal, w.select, w.active + elseif index > 0 and THEME[index] then + local s = THEME[index] + c.normal, c.select, c.active = rgb(s[1]), rgb(s[2]), rgb(s[3]) + end + return c +end + +local function boneColor(v: Blend.View): Color? + local bc = v:sub("color") + if not bc then + return nil + end + return color(bc:num("palette_index"), bc:sub("custom")) +end + +-- ------------------------------------------------------------------------------------------------ bones +type Collections = { + list: { { name: string, visible: boolean, parent: string? } }, + byBone: { [string]: { string } }, -- bone name -> its collections, in collection order +} + +-- 4.1+: collection_array with child_index / child_count; 4.0: the collections list; before 4.0 the used layers +-- ("Layer N", hidden when the layer is off) and then the bone groups (hidden), as Blender's 4.0 versioning converts them +function Armature.collections(arm: Blend.View, bones: { Blend.View }, pose: Blend.View?): Collections + local out: Collections = { list = {}, byBone = {} } + local byAddr: { [any]: string } = {} + for _, b in bones do + if b.block then + byAddr[b.block.addr] = b:str("name") or "" + end + end + local function add(name: string, members: { string }) + for _, m in members do + local l = out.byBone[m] or {} + out.byBone[m] = l + table.insert(l, name) + end + end + local VISIBLE = 1 + local array = arm:has("collection_array") and arm:pointers("collection_array", arm:num("collection_array_num") or 0) or {} + local cols: { Blend.View } = {} + if #array > 0 then + for _, addr in array do + local blk = addr and Blend.resolve(arm.file, addr, arm.block) + local v = blk and Blend.struct(arm.file, blk, 0, "BoneCollection") + if v then + table.insert(cols, v) + end + end + elseif arm:has("collections") then + cols = arm:list("collections", "BoneCollection") + end + if #cols > 0 then + local parent: { [number]: string } = {} + for i, c in cols do + local first, n = c:num("child_index") or 0, c:num("child_count") or 0 + for k = first + 1, math.min(first + n, #cols) do + parent[k] = c:str("name") + end + local _ = i + end + for i, c in cols do + local name = c:str("name") or "" + table.insert(out.list, { name = name, visible = bit(c:num("flags"), VISIBLE), parent = parent[i] }) + local members = {} + for _, m in c:list("bones", "BoneCollectionMember") do + local n = byAddr[m:ptr("bone")] + if n then + table.insert(members, n) + end + end + add(name, members) + end + return out + end + local used, shown = arm:num("layer_used"), arm:num("layer") + if used then + for layer = 0, 31 do + local mask = bit32.lshift(1, layer) + if bit(used, mask) then + local name = "Layer " .. (layer + 1) + table.insert(out.list, { name = name, visible = bit(shown, mask) }) + local members = {} + for _, b in bones do + if bit(b:num("layer"), mask) then + table.insert(members, b:str("name") or "") + end + end + add(name, members) + end + end + end + if pose then + local groups = pose:list("agroups", "bActionGroup") + local members: { [number]: { string } } = {} + for _, pc in pose:list("chanbase", "bPoseChannel") do + local g = pc:num("agrp_index") or 0 + if g > 0 and groups[g] then + members[g] = members[g] or {} + table.insert(members[g], pc:str("name") or "") + end + end + for g, grp in groups do + local name = grp:str("name") or "" + table.insert(out.list, { name = name, visible = false }) + add(name, members[g] or {}) + end + end + return out +end + +-- a Bone's own fields: head_local / tail_local / roll in armature space (the roll is already in arm_mat, the rest +-- matrix); color from the Bone (4.x) or from the bone group of its pose channel (before 4.0) +function Armature.bone(bone: Blend.View, pc: Blend.View?, pose: Blend.View?): { [string]: any } + local flag = bone:num("flag") or 0 + local e: { [string]: any } = { + deform = not bit(flag, BONE_NO_DEFORM), + use_connect = bit(flag, BONE_CONNECTED), + show_wire = bit(flag, BONE_DRAWWIRE), + hide = bit(flag, BONE_HIDDEN_P), + head_local = vec3(bone, "arm_head"), + tail_local = vec3(bone, "arm_tail"), + roll = bone:num("arm_roll"), + } + if bone:has("color") then + e.color = boneColor(bone) + elseif pc and pose then + local g = pc:num("agrp_index") or 0 + local grp = if g > 0 then pose:list("agroups", "bActionGroup")[g] else nil + if grp then + e.color = color(grp:num("customCol"), grp:sub("cs")) + end + end + return e +end + +-- ------------------------------------------------------------------------------------------------ constraints +local function constraintData(e: { [string]: any }, kind: string, d: Blend.View, resolve: Resolve) + local flag = d:num("flag") or 0 + if kind == "IK" then + -- CONSTRAINT_IK_TIP / ROT / STRETCH / POS, NO_POS_X.. / NO_ROT_X..; type 0 copy pose, 1 distance + e.pole_target = resolve(d:deref("poletar", 0, "Object")) + e.pole_subtarget = text(d, "polesubtarget") + e.pole_angle = d:num("poleangle") + e.chain_count = d:num("rootbone") + e.iterations = d:num("iterations") + e.weight = d:num("weight") + e.orient_weight = d:num("orientweight") + e.use_tail = bit(flag, 1) + e.use_rotation = bit(flag, 2) + e.use_stretch = bit(flag, 16) + e.use_location = bit(flag, 32) + -- lock_* are the inverse of the NO_POS / NO_ROT bits, as Blender's API defines them + e.lock_location_x, e.lock_location_y, e.lock_location_z = not bit(flag, 256), not bit(flag, 512), not bit(flag, 1024) + e.lock_rotation_x, e.lock_rotation_y, e.lock_rotation_z = not bit(flag, 2048), not bit(flag, 4096), not bit(flag, 8192) + e.ik_type = if (d:num("type") or 0) == 1 then "DISTANCE" else "COPY_POSE" + e.distance = d:num("dist") + elseif kind == "COPY_ROTATION" then + -- ROTLIKE_X 1, Y 2, Z 4, X_INVERT 16, Y_INVERT 32, Z_INVERT 64, OFFSET 128 (mix_mode OFFSET before 2.82) + e.use_x, e.use_y, e.use_z = bit(flag, 1), bit(flag, 2), bit(flag, 4) + e.invert_x, e.invert_y, e.invert_z = bit(flag, 16), bit(flag, 32), bit(flag, 64) + e.euler_order = EULER_ORDER[d:num("euler_order") or 0] + local mix = d:num("mix_mode") + e.mix_mode = if mix then ROT_MIX[mix] else (if bit(flag, 128) then "OFFSET" else "REPLACE") + elseif kind == "COPY_LOCATION" then + -- LOCLIKE_X 1, Y 2, Z 4, X_INVERT 16, Y_INVERT 32, Z_INVERT 64, OFFSET 128 + e.use_x, e.use_y, e.use_z = bit(flag, 1), bit(flag, 2), bit(flag, 4) + e.invert_x, e.invert_y, e.invert_z = bit(flag, 16), bit(flag, 32), bit(flag, 64) + e.use_offset = bit(flag, 128) + elseif kind == "COPY_SCALE" then + -- SIZELIKE_X 1, Y 2, Z 4, OFFSET 8 + e.use_x, e.use_y, e.use_z = bit(flag, 1), bit(flag, 2), bit(flag, 4) + e.use_offset = bit(flag, 8) + e.power = d:num("power") or 1 + elseif kind == "COPY_TRANSFORMS" then + e.mix_mode = TRANS_MIX[d:num("mix_mode") or 0] + e.remove_target_shear = bit(flag, 1) + elseif kind == "DAMPED_TRACK" then + e.track_axis = TRACK[d:num("trackflag") or 1] + elseif kind == "LIMIT_ROTATION" then + -- LIMIT_XROT 1, YROT 2, ZROT 4; flag2 LIMIT_TRANSFORM 2 + for i, a in AXES do + e["use_limit_" .. a] = bit(flag, bit32.lshift(1, i - 1)) + e["min_" .. a] = d:num(a .. "min") + e["max_" .. a] = d:num(a .. "max") + end + e.use_transform_limit = bit(d:num("flag2"), 2) + e.euler_order = EULER_ORDER[d:num("euler_order") or 0] + elseif kind == "LIMIT_LOCATION" or kind == "LIMIT_SCALE" then + -- LIMIT_XMIN 1, XMAX 2, YMIN 4, YMAX 8, ZMIN 16, ZMAX 32; flag2 LIMIT_TRANSFORM 2 + for i, a in AXES do + e["use_min_" .. a] = bit(flag, bit32.lshift(1, (i - 1) * 2)) + e["use_max_" .. a] = bit(flag, bit32.lshift(2, (i - 1) * 2)) + e["min_" .. a] = d:num(a .. "min") + e["max_" .. a] = d:num(a .. "max") + end + e.use_transform_limit = bit(d:num("flag2"), 2) + elseif kind == "CHILD_OF" then + -- CHILDOF_LOCX 1 .. SIZEZ 256, SET_INVERSE 512 + for i, a in AXES do + e["use_location_" .. a] = bit(flag, bit32.lshift(1, i - 1)) + e["use_rotation_" .. a] = bit(flag, bit32.lshift(8, i - 1)) + e["use_scale_" .. a] = bit(flag, bit32.lshift(64, i - 1)) + end + e.set_inverse_pending = bit(flag, 512) + local m = d:vec("invmat") + e.inverse_matrix = if m and #m == 16 then m else nil -- column-major + end +end + +-- a constraint stack (ListBase of bConstraint) in evaluation order +function Armature.constraints(owner: Blend.View, resolve: Resolve): { { [string]: any } } + local out = {} + for _, c in owner:list("constraints", "bConstraint") do + local t = c:num("type") or 0 + local kind = TYPE[t] or tostring(t) + local flag = c:num("flag") or 0 + local e: { [string]: any } = { + type = kind, + name = c:str("name") or "", + influence = c:num("enforce") or 1, + mute = bit(flag, CONSTRAINT_OFF), + owner_space = SPACE[c:num("ownspace") or 0], + target_space = SPACE[c:num("tarspace") or 0], + } + if HEAD_TAIL[kind] then + e.head_tail = c:num("headtail") or 0 + e.use_bbone_shape = bit(flag, CONSTRAINT_BBONE_SHAPE) + end + if e.owner_space == "CUSTOM" or e.target_space == "CUSTOM" then + e.space_object = resolve(c:deref("space_object", 0, "Object")) + e.space_subtarget = text(c, "space_subtarget") + end + local d = c:deref("data", 0) + if d then + if d:has("tar") then + e.target = resolve(d:deref("tar", 0, "Object")) + end + e.subtarget = text(d, "subtarget") + if d:has("targets") then + local targets = {} + for _, ct in d:list("targets", "bConstraintTarget") do + table.insert(targets, { target = resolve(ct:deref("tar", 0, "Object")), subtarget = text(ct, "subtarget"), weight = ct:num("weight") }) + end + e.targets = targets + end + constraintData(e, kind, d, resolve) + end + table.insert(out, e) + end + return out +end + +-- ------------------------------------------------------------------------------------------------ pose bones +-- a bPoseChannel's settings into e: constraint targets through resolve, the custom shape object through shape +function Armature.pose(e: { [string]: any }, pc: Blend.View, resolve: Resolve, shape: Resolve) + local protect = pc:num("protectflag") or 0 + local ik = pc:num("ikflag") or 0 + e.rotation_mode = ROTMODE[pc:num("rotmode") or 0] or "QUATERNION" + e.lock_location = bits(protect, LOCK_LOC) + e.lock_rotation = bits(protect, LOCK_ROT) + e.lock_rotation_w = bit(protect, LOCK_ROTW) + e.lock_rotations_4d = bit(protect, LOCK_ROT4D) + e.lock_scale = bits(protect, LOCK_SCALE) + local custom = pc:deref("custom", 0, "Object") + if custom then + e.custom_shape = shape(custom) + end + local tx = pc:deref("custom_tx", 0, "bPoseChannel") + e.custom_shape_transform = if tx then text(tx, "name") else nil + e.custom_shape_translation = vec3(pc, "custom_translation", { 0, 0, 0 }) + e.custom_shape_rotation_euler = vec3(pc, "custom_rotation_euler", { 0, 0, 0 }) + local s = pc:num("custom_scale") or 1 -- before 3.0: one uniform scale + e.custom_shape_scale_xyz = vec3(pc, "custom_scale_xyz", { s, s, s }) + e.use_custom_shape_bone_size = not bit(pc:num("drawflag"), PCHAN_DRAW_NO_CUSTOM_BONE_SIZE) + e.custom_shape_wire_width = pc:num("custom_shape_wire_width") + e.ik_stretch = pc:num("ikstretch") or 0 + local lo, hi, stiff = pc:vec("limitmin"), pc:vec("limitmax"), pc:vec("stiffness") + for i, a in AXES do + e["lock_ik_" .. a] = bit(ik, IK_NO_DOF[i]) + e["use_ik_limit_" .. a] = bit(ik, IK_LIMIT[i]) + e["ik_min_" .. a] = lo and lo[i] or -math.pi + e["ik_max_" .. a] = hi and hi[i] or math.pi + e["ik_stiffness_" .. a] = stiff and stiff[i] or 0 + end + e.pose_color = if pc:has("color") then boneColor(pc) else nil + e.constraints = Armature.constraints(pc, resolve) +end + +return Armature +end __FILES["model/blend/Material"] = function() -- model/blend/Material: Blender materials to Scene PBR materials. With nodes: the Principled BSDF (the one feeding the @@ -162162,6 +162572,75 @@ end type Limits = { maxVertices: number? } +-- edge count and per-edge readers (vertex 1, vertex 2, sharp): ".edge_verts" / "sharp_edge" attributes or MEdge +local function edgeReaders(f: Blend.File, me: Blend.View, layers: { Layer }): (number, ((number) -> number)?, ((number) -> number)?, ((number) -> boolean)?) + local ne = count(me, "totedge", "edges_num") + local ev = find(layers, "edge", "int2", ".edge_verts") + local se = find(layers, "edge", "bool", "sharp_edge") + local medge = find(layers, "edge", "MEdge") or legacy(f, me, "medge", "MEdge", "edge") + if ne == 0 then + return 0, nil, nil, nil + end + if ev then + local er = reader(f, ev) + local sr = if se then reader(f, se) else nil + return ne, function(i: number): number + return er(i, 0) + end, function(i: number): number + return er(i, 1) + end, function(i: number): boolean + return sr ~= nil and sr(i, 0) ~= 0 + end + elseif medge then + local a, b, fl = fieldReader(f, medge, "v1"), fieldReader(f, medge, "v2"), fieldReader(f, medge, "flag") + if a and b then + local ser = if se then reader(f, se) else nil + return ne, function(i: number): number + return a(i, 0) + end, function(i: number): number + return b(i, 0) + end, function(i: number): boolean + if ser then + return ser(i, 0) ~= 0 + end + return fl ~= nil and bit32.band(fl(i, 0), ME_SHARP) ~= 0 + end + end + end + return ne, nil, nil, nil +end + +-- edges no face uses, as u32 vertex pairs (rig widgets are usually edges only) +function Mesh.looseEdges(f: Blend.File, me: Blend.View, poly: Poly): buffer + local ne, v1, v2 = edgeReaders(f, me, poly.layers) + if not v1 or not v2 then + return buffer.create(0) + end + local nv = poly.nv + local used: { [number]: boolean } = {} + local cv, fs = poly.cornerVert, poly.faceStart + for fi = 0, poly.nf - 1 do + local s0, s1 = buffer.readu32(fs, fi * 4), buffer.readu32(fs, fi * 4 + 4) + for c = s0, s1 - 1 do + local a, b = buffer.readu32(cv, c * 4), buffer.readu32(cv, (if c + 1 < s1 then c + 1 else s0) * 4) + used[math.min(a, b) * nv + math.max(a, b)] = true + end + end + local out = {} + for i = 0, ne - 1 do + local a, b = v1(i), v2(i) + if a ~= b and a >= 0 and b >= 0 and a < nv and b < nv and not used[math.min(a, b) * nv + math.max(a, b)] then + table.insert(out, a) + table.insert(out, b) + end + end + local buf = buffer.create(#out * 4) + for k, v in out do + buffer.writeu32(buf, (k - 1) * 4, v) + end + return buf +end + function Mesh.read(f: Blend.File, me: Blend.View, limits: Limits?): (Poly?, string?) local layers = Mesh.layers(f, me) local nv = count(me, "totvert", "verts_num") @@ -162441,10 +162920,6 @@ function Mesh.read(f: Blend.File, me: Blend.View, limits: Limits?): (Poly?, stri poly.customNormals = d end -- sharp edges - local ne = count(me, "totedge", "edges_num") - local ev = find(layers, "edge", "int2", ".edge_verts") - local se = find(layers, "edge", "bool", "sharp_edge") - local medge = find(layers, "edge", "MEdge") or legacy(f, me, "medge", "MEdge", "edge") local flags = me:num("flag") or 0 local smoothresh = me:num("smoothresh") local autoSmooth = f.version < 401 and bit32.band(flags, ME_AUTOSMOOTH) ~= 0 @@ -162452,27 +162927,8 @@ function Mesh.read(f: Blend.File, me: Blend.View, limits: Limits?): (Poly?, stri poly.autoSmooth = smoothresh or math.rad(30) end local useSharp = f.version >= 401 or autoSmooth - if useSharp and ne > 0 then - local v1, v2, sharp - if ev and se then - local er, sr = reader(f, ev), reader(f, se) - v1 = function(i: number): number return er(i, 0) end - v2 = function(i: number): number return er(i, 1) end - sharp = function(i: number): boolean return sr(i, 0) ~= 0 end - elseif medge then - local a, b, fl = fieldReader(f, medge, "v1"), fieldReader(f, medge, "v2"), fieldReader(f, medge, "flag") - if a and b and fl then - v1 = function(i: number): number return a(i, 0) end - v2 = function(i: number): number return b(i, 0) end - local ser = if se then reader(f, se) else nil - sharp = function(i: number): boolean - if ser then - return ser(i, 0) ~= 0 - end - return bit32.band(fl(i, 0), ME_SHARP) ~= 0 - end - end - end + if useSharp then + local ne, v1, v2, sharp = edgeReaders(f, me, layers) if v1 and v2 and sharp then for i = 0, ne - 1 do if sharp(i) then @@ -162517,7 +162973,7 @@ function Mesh.read(f: Blend.File, me: Blend.View, limits: Limits?): (Poly?, stri end -- shape keys: { name, value, relative (0-based), data: f32 x 3 per vertex } in file order, and the reference index -type Shape = { name: string, value: number, relative: number, data: buffer, mute: boolean, min: number, max: number } +type Shape = { name: string, value: number, relative: number, data: buffer, mute: boolean, min: number, max: number, vgroup: string? } function Mesh.shapes(f: Blend.File, me: Blend.View, nv: number): ({ Shape }, number?, Blend.View?) local key = me:deref("key", 0, "Key") if not key then @@ -162527,6 +162983,7 @@ function Mesh.shapes(f: Blend.File, me: Blend.View, nv: number): ({ Shape }, num local refAddr = key:ptr("refkey") local out: { Shape } = {} local ref: number? = nil + local index = 0 for i, kb in blocks do local blk = kb:target("data") local d = buffer.create(nv * 12) @@ -162539,15 +162996,21 @@ function Mesh.shapes(f: Blend.File, me: Blend.View, nv: number): ({ Shape }, num end end end - if kb.block and kb.block.addr == refAddr then + local isRef = kb.block ~= nil and kb.block.addr == refAddr + if isRef then ref = i + else + index += 1 end + local stored = kb:str("name") + -- unnamed in old files: named as Blender's 2.45 versioning does (Basis, Key 1, Key 2, ...) + local name: string = if stored and stored ~= "" then stored elseif isRef then "Basis" else "Key " .. index table.insert(out, { - -- unnamed in old files: Key 0 (the basis), Key 1, ... - name = kb:str("name") or ("Key " .. (i - 1)), value = kb:num("curval") or 0, relative = kb:num("relative") or 0, data = d, - mute = bit32.band(kb:num("flag") or 0, 2) ~= 0, + name = name, value = kb:num("curval") or 0, relative = kb:num("relative") or 0, data = d, + mute = bit32.band(kb:num("flag") or 0, 1) ~= 0, -- KEYBLOCK_MUTE min = kb:num("slidermin") or 0, max = kb:num("slidermax") or 1, + vgroup = if kb:str("vgroup") ~= "" then kb:str("vgroup") else nil, }) end if ref == nil and #out > 0 then @@ -162980,8 +163443,80 @@ end type Built = { mesh: Types.Mesh, slots: { number }, vertexSource: { { number } } } --- slots[k] = the scene material of slot k - 1 (or 0 for none); skin maps deform groups to joints -function Prim.build(poly: MeshT.Poly, slots: { number }, opts: Options?, skin: Skinning?, shapes: { MeshT.Shape }?, ref: number?): Built +-- morph targets of the output vertices (vsrc: their mesh vertices): each key minus its relative key, times the weight +-- of the key's vertex group, as Blender evaluates relative keys +local function targetDeltas(poly: MeshT.Poly, vsrc: { number }, shapes: { MeshT.Shape }, ref: number, groups: { string }?): { { [string]: Types.Accessor } } + local n = #vsrc + local targets: { { [string]: Types.Accessor } } = {} + for k, s in shapes do + if k ~= ref then + local rel = shapes[s.relative + 1] or shapes[ref] + local base = rel.data + local def: number? = nil + if s.vgroup and groups then + for gi, g in groups do + if g == s.vgroup then + def = gi - 1 + end + end + end + local t = table.create(n * 3) :: { number } + for i = 1, n do + local v = vsrc[i] + local w: number = 1 + if def then + w = 0 + local list = poly.weights and poly.weights[v + 1] or {} + for q = 1, #list - 1, 2 do + if list[q] == def then + w = list[q + 1] + end + end + end + for c = 0, 2 do + t[(i - 1) * 3 + c + 1] = (readf32(s.data, (v * 3 + c) * 4) - readf32(base, (v * 3 + c) * 4)) * w + end + end + table.insert(targets, { POSITION = accessor(t, 3) } :: { [string]: Types.Accessor }) + end + end + return targets +end + +-- a "lines" primitive of the given edges (u32 vertex pairs), with the morph targets the face primitives have +function Prim.lines(poly: MeshT.Poly, edges: buffer, shapes: { MeshT.Shape }?, ref: number?, groups: { string }?): Types.Primitive? + local ne = buffer.len(edges) // 8 + if ne == 0 then + return nil + end + local out: { [number]: number } = {} + local vsrc: { number } = {} + local I = buffer.create(ne * 8) + for k = 0, ne * 2 - 1 do + local v = readu32(edges, k * 4) + local o = out[v] + if not o then + o = #vsrc + out[v] = o + table.insert(vsrc, v) + end + writeu32(I, k * 4, o) + end + local n = #vsrc + local P = buffer.create(n * 12) + for i = 1, n do + buffer.copy(P, (i - 1) * 12, poly.pos, vsrc[i] * 12, 12) + end + local prim: Types.Primitive = { attributes = { POSITION = Scene.accessor(P, "f32", 3, n) }, indices = Scene.accessor(I, "u32", 1, ne * 2), mode = "lines" } + if shapes and ref and #shapes > 1 then + prim.targets = targetDeltas(poly, vsrc, shapes, ref, groups) + end + return prim +end + +-- slots[k] = the scene material of slot k - 1 (or 0 for none); skin maps deform groups to joints; vgroups names the +-- vertex groups (def_nr + 1) for shape keys limited to one +function Prim.build(poly: MeshT.Poly, slots: { number }, opts: Options?, skin: Skinning?, shapes: { MeshT.Shape }?, ref: number?, vgroups: { string }?): Built local triangulateOn = not (opts and opts.triangulate == false) local flipV = not (opts and opts.flipV == false) local withNormals = not (opts and opts.normals == false) @@ -163131,21 +163666,7 @@ function Prim.build(poly: MeshT.Poly, slots: { number }, opts: Options?, skin: S prim.material = mat end if shapes and ref and #shapes > 1 then - local base = shapes[ref].data - local targets: { { [string]: Types.Accessor } } = {} - for k, s in shapes do - if k ~= ref then - local t = table.create(n * 3) :: { number } - for i = 1, n do - local v = vsrc[i] - for c = 0, 2 do - t[(i - 1) * 3 + c + 1] = readf32(s.data, (v * 3 + c) * 4) - readf32(base, (v * 3 + c) * 4) - end - end - table.insert(targets, { POSITION = accessor(t, 3) } :: { [string]: Types.Accessor }) - end - end - prim.targets = targets + prim.targets = targetDeltas(poly, vsrc, shapes, ref, vgroups) end table.insert(mesh.primitives, prim) table.insert(sources, vsrc) @@ -163154,7 +163675,7 @@ function Prim.build(poly: MeshT.Poly, slots: { number }, opts: Options?, skin: S local w = {} for k, s in shapes do if k ~= ref then - table.insert(w, s.value) + table.insert(w, if s.mute then 0 else s.value) -- Blender skips muted keys end end mesh.weights = w @@ -163187,8 +163708,8 @@ __FILES["model/blend/Read"] = function() -- or Base list before 2.8) with their transforms (euler orders, quaternion, axis angle, delta transforms, parent -- inverse; bone parents), meshes (model/blend/Mesh, model/blend/Prim), materials (Principled BSDF node or the legacy -- colour), images (packed bytes or external uris), cameras, lights (watts to candela / lux as Blender's glTF exporter --- does: 683 lm/W, / 4 pi for point and spot), armatures (bones to joint nodes with the saved pose), skins, shape keys --- and actions sampled into channels. +-- does: 683 lm/W, / 4 pi for point and spot), armatures (bones to joint nodes with the saved pose, rig data through +-- model/blend/Armature), skins, shape keys and actions sampled into channels. local Blend = __include("containers/Blend") local Types = __include("Types") local Mat4 = __include("codecs/model/Mat4") @@ -163197,6 +163718,7 @@ local Mesh = __include("model/blend/Mesh") local Prim = __include("model/blend/Prim") local Anim = __include("model/blend/Anim") local Material = __include("model/blend/Material") +local Armature = __include("model/blend/Armature") local Read = {} @@ -163206,6 +163728,7 @@ type M4 = { number } type Options = { triangulate: boolean?, flipV: boolean?, + looseEdges: boolean?, -- edges outside faces as "lines" primitives (default false; always for custom shape widgets) collections: boolean?, -- collections as nodes (default true) scene: string?, -- the scene to read (default: the file's current scene) sampleStep: number?, -- frames between animation samples (default 1) @@ -163356,6 +163879,18 @@ local function mat4(v: Blend.View?, ...: string): M4? end -- ------------------------------------------------------------------------------------------------ scene +type ArmInfo = { + joints: { number }, + names: { [string]: number }, + rest: { M4 }, + restLocal: { M4 }, + bones: { Blend.View }, + deform: { boolean }, + node: number, + poseNames: { [string]: Blend.View }, + arm: Blend.View, + pose: Blend.View?, +} type Ctx = { f: Blend.File, scene: Types.Scene, @@ -163367,7 +163902,9 @@ type Ctx = { meshes: { [string]: number }, materials: { [any]: number }, textures: { [any]: number }, - armatures: { [any]: { joints: { number }, names: { [string]: number }, rest: { M4 }, restLocal: { M4 }, bones: { Blend.View }, deform: { boolean }, node: number, poseNames: { [string]: Blend.View } } }, + armatures: { [any]: ArmInfo }, + widgets: { [any]: Blend.View }, -- custom shape objects by address + widgetOrder: { any }, prefix: { [number]: M4 }, -- node -> the matrix before its basis (parent inverse, bone tail offset) props: { [number]: Props }, meta: { [string]: any }, @@ -163414,7 +163951,7 @@ local function armature(ctx: Ctx, ob: Blend.View, node: number) end end end - local info = { joints = {}, names = {}, rest = {}, restLocal = {}, bones = {}, deform = {}, node = node, poseNames = poseNames } + local info: ArmInfo = { joints = {}, names = {}, rest = {}, restLocal = {}, bones = {}, deform = {}, node = node, poseNames = poseNames, arm = arm, pose = pose } local function walk(list: { Blend.View }, parentJoint: number?, parentRest: M4?, depth: number) if depth > 256 then return @@ -163584,20 +164121,37 @@ local function groupNames(ob: Blend.View, me: Blend.View): { string } return out end -local function mesh(ctx: Ctx, ob: Blend.View, node: number) +local function shapeExtras(shapes: { Mesh.Shape }, ref: number?): ({ string }, { { [string]: any } }) + local names: { string }, list: { { [string]: any } } = {}, {} + for k, sh in shapes do + if k ~= ref then + table.insert(names, sh.name) + end + local rel = shapes[sh.relative + 1] + local e: { [string]: any } = { name = sh.name, value = sh.value, slider_min = sh.min, slider_max = sh.max, mute = sh.mute } + e.relative_key = if rel then rel.name else nil + e.vertex_group = sh.vgroup + table.insert(list, e) + end + return names, list +end + +-- the scene mesh of an object's mesh data (shared between objects with the same data, slots and armature) +local function meshOf(ctx: Ctx, ob: Blend.View, lines: boolean): (number?, ArmInfo?) local f = ctx.f local me = ob:deref("data", 0, "Mesh") if not me then - return + return nil, nil end local slots = slotMaterials(ctx, ob, me) local armOb = deformArmature(ctx, ob) local armInfo = armOb and armOb.block and ctx.armatures[armOb.block.addr] - local key = tostring(me.block and me.block.index) .. ":" .. table.concat(slots, ",") .. ":" .. tostring(armOb and armOb.block and armOb.block.index) + local key = tostring(me.block and me.block.index) .. ":" .. table.concat(slots, ",") .. ":" .. tostring(armOb and armOb.block and armOb.block.index) .. (if lines then ":lines" else "") local skin: Prim.Skinning? = nil + local groups = groupNames(ob, me) if armInfo then local joints = {} - for gi, name in groupNames(ob, me) do + for gi, name in groups do local j = armInfo.names[name] if j and armInfo.deform[j] then joints[gi - 1] = j - 1 @@ -163612,9 +164166,23 @@ local function mesh(ctx: Ctx, ob: Blend.View, node: number) error(err or "bad mesh", 0) end local shapes, ref = Mesh.shapes(f, me, poly.nv) - local built = Prim.build(poly, slots, { triangulate = ctx.opts.triangulate, flipV = ctx.opts.flipV }, skin, shapes, ref) + local built = Prim.build(poly, slots, { triangulate = ctx.opts.triangulate, flipV = ctx.opts.flipV }, skin, shapes, ref, groups) local m = built.mesh - m.extras = { blend = { vertices = poly.nv, faces = poly.nf, corners = poly.nc, generation = poly.generation, uvs = #poly.uvs, colors = #poly.colors, shapes = #shapes } } + local extras: { [string]: any } = { vertices = poly.nv, faces = poly.nf, corners = poly.nc, generation = poly.generation, uvs = #poly.uvs, colors = #poly.colors, shapes = #shapes } + m.extras = { blend = extras } + if lines then + local lp = Prim.lines(poly, Mesh.looseEdges(f, me, poly), shapes, ref, groups) + if lp then + table.insert(m.primitives, lp) + extras.looseEdges = (lp.indices :: Types.Accessor).count // 2 + end + end + if #shapes > 1 then + local names, list = shapeExtras(shapes, ref) + m.extras = { blend = extras, targetNames = names } + extras.shape_keys = list + extras.reference_key = if ref then shapes[ref].name else nil + end table.insert(ctx.scene.meshes, m) idx = #ctx.scene.meshes ctx.meshes[key] = idx @@ -163624,6 +164192,15 @@ local function mesh(ctx: Ctx, ob: Blend.View, node: number) ctx.meta.shapeKeys[idx] = { key = me:deref("key", 0, "Key"), mesh = me, shapes = shapes, ref = ref } end end + return idx, armInfo +end + +local function mesh(ctx: Ctx, ob: Blend.View, node: number) + local addr = ob.block and ob.block.addr + local idx, armInfo = meshOf(ctx, ob, ctx.opts.looseEdges == true or (addr ~= nil and ctx.widgets[addr] ~= nil)) + if not idx then + return + end local n = ctx.scene.nodes[node] n.mesh = idx if ctx.scene.meshes[idx].weights then @@ -163707,6 +164284,14 @@ local function object(ctx: Ctx, ob: Blend.View, under: number?, depth: number): if lay and ctx.f.version < 280 then extras.layers = lay end + -- Object.visibility_flag (2.8+): OB_HIDE_VIEWPORT 1, OB_HIDE_RENDER 4; restrictflag before: VIEW 1, RENDER 4 + local vis = ob:num("visibility_flag") or ob:num("restrictflag") or 0 + if bit32.band(vis, 1) ~= 0 then + extras.hide_viewport = true + end + if bit32.band(vis, 4) ~= 0 then + extras.hide_render = true + end local mods = {} for _, md in ob:list("modifiers") do table.insert(mods, { name = md:sub("modifier") and (md:sub("modifier") :: Blend.View):str("name") or md:str("name") or "", type = (string.gsub(md.struct.name, "ModifierData$", "")) }) @@ -163727,6 +164312,77 @@ local function object(ctx: Ctx, ob: Blend.View, under: number?, depth: number): return idx end +-- ------------------------------------------------------------------------------------------------ rigs +-- an object as a constraint target or custom shape: its node, else its name; widgets records custom shapes +local function resolver(ctx: Ctx, widgets: boolean): Armature.Resolve + return function(ob: Blend.View?): Armature.Target? + if not ob then + return nil + end + local addr = ob.block and ob.block.addr + if widgets and addr ~= nil and not ctx.widgets[addr] then + ctx.widgets[addr] = ob + table.insert(ctx.widgetOrder, addr) + end + local node = if addr ~= nil then ctx.objects[addr] else nil + if node then + return node + end + return ob:idName() + end +end + +local function rigs(ctx: Ctx) + local target, shape = resolver(ctx, false), resolver(ctx, true) + for node = 1, #ctx.scene.nodes do + local ob = ctx.objView[node] + local extras = ob and (ctx.scene.nodes[node].extras :: any).blend + if not ob or not extras then + continue + end + local list = Armature.constraints(ob, target) + if #list > 0 then + extras.constraints = list + end + local info = ob.block and ctx.armatures[ob.block.addr] + if info then + local cols = Armature.collections(info.arm, info.bones, info.pose) + extras.bone_collections = cols.list + for j, bone in info.bones do + local name = bone:str("name") or "" + local pc = info.poseNames[name] + local e = (ctx.scene.nodes[info.joints[j]].extras :: any).blend + for k, v in Armature.bone(bone, pc, info.pose) do + e[k] = v + end + e.collections = cols.byBone[name] or {} + if pc then + Armature.pose(e, pc, target, shape) + end + end + end + end +end + +-- every custom shape object: its node (and mesh) when it is in the scene, else its mesh only +local function widgetList(ctx: Ctx): { { [string]: any } } + local list = {} + for _, addr in ctx.widgetOrder do + local ob = ctx.widgets[addr] + local t = ob:num("type") or -1 + local w: { [string]: any } = { name = ob:idName() or "", type = TYPE_NAME[t] or tostring(t) } + local node = ctx.objects[addr] + if node then + w.node = node + w.mesh = ctx.scene.nodes[node].mesh + elseif t == OB_MESH then + w.mesh = (meshOf(ctx, ob, true)) + end + table.insert(list, w) + end + return list +end + -- ------------------------------------------------------------------------------------------------ animation local function apply(props: Props, curves: { Curve }, frame: number, prefix: string?, name: string?): Props local p: Props = {} @@ -163918,7 +164574,7 @@ local function animations(ctx: Ctx) v = math.clamp(Anim.evaluate(c, fr), math.min(s.min, s.max), math.max(s.min, s.max)) -- the slider range end end - buffer.writef32(out, ((i - 1) * count + k) * 4, v) + buffer.writef32(out, ((i - 1) * count + k) * 4, if s.mute then 0 else v) k += 1 end end @@ -163975,7 +164631,7 @@ function Read.scene(f: Blend.File, opts: Options?): (Types.Scene?, string?) } local ctx: Ctx = { f = f, scene = scene, opts = o, objects = {}, objView = {}, parentOf = {}, world = {}, meshes = {}, materials = {}, - textures = {}, armatures = {}, prefix = {}, props = {}, meta = meta, pending = {}, + textures = {}, armatures = {}, prefix = {}, props = {}, meta = meta, pending = {}, widgets = {}, widgetOrder = {}, } local order: { { ob: Blend.View, under: number? } } = {} if sc then @@ -164054,6 +164710,7 @@ function Read.scene(f: Blend.File, opts: Options?): (Types.Scene?, string?) local u = a ~= nil and firstUnder[a] or nil object(ctx, e.ob, if u and u > 0 then u else nil, 0) end + rigs(ctx) for node = 1, #scene.nodes do local ob = ctx.objView[node] if ob and (ob:num("type") or -1) == OB_MESH then @@ -164061,6 +164718,9 @@ function Read.scene(f: Blend.File, opts: Options?): (Types.Scene?, string?) end end skins(ctx) + if next(ctx.armatures) ~= nil then + scene.meta.blend = { widgets = widgetList(ctx), bone_color_sets = Armature.colorSets() } + end if o.animations ~= false then animations(ctx) end @@ -172997,6 +173657,16 @@ function Read.scene(doc: any, bin: buffer?, fetch: Fetch, opts: any?): (Types.Sc return nil, Err.new(Err.CORRUPT, "bad mesh " .. (i - 1)) end local mesh: Types.Mesh = { name = str(m.name), primitives = {}, weights = if type(m.weights) == "table" then table.clone(m.weights) else nil, extras = keep(m, nil) } + -- morph target names: the extras.targetNames convention (Blender's exporter, three.js, Babylon) + local tn = type(m.extras) == "table" and m.extras.targetNames + if type(tn) == "table" and #tn > 0 then + local names = {} + for k, v in tn do + names[k] = if type(v) == "string" then v else tostring(v) + end + mesh.extras = mesh.extras or {} + ;(mesh.extras :: any).targetNames = names + end for k, p in arr(m.primitives) do if type(p) ~= "table" or type(p.attributes) ~= "table" then return nil, Err.new(Err.CORRUPT, string.format("mesh %d primitive %d: no attributes", i - 1, k - 1)) @@ -173713,6 +174383,12 @@ function Write.build(scene: Types.Scene, opts: Options?): (Out?, Err.Err?) end g.weights = mesh.weights restore(g, mesh.extras) + local tn = mesh.extras and (mesh.extras :: any).targetNames + if type(tn) == "table" and #tn > 0 and g.extras == nil then + local ex = object() + ex.targetNames = table.clone(tn) + g.extras = ex + end table.insert(meshes, g) end local cameras: { any } = {} @@ -208488,7 +209164,10 @@ local function defaultFor(name: string, k: number): number return 0 end -function MeshOps.merge(input: any, opts: { byMaterial: boolean?, method: string? }?): (any, Err.Err?) +-- opts.targets: morph targets concatenated by name (mesh.extras.targetNames, else prim.extras.targetNames; unnamed +-- ones by index), zero where a primitive lacks one; the result's extras.targetNames / extras.weights name them and +-- give their default weights (node weights, else mesh weights) +function MeshOps.merge(input: any, opts: { byMaterial: boolean?, method: string?, targets: boolean? }?): (any, Err.Err?) local placed: { Types.Placed } = {} if type(input) ~= "table" then return nil, Err.new(Err.ARG, "merge: expected a Scene or a list of Primitives") @@ -208502,6 +209181,9 @@ function MeshOps.merge(input: any, opts: { byMaterial: boolean?, method: string? end local groups: { [number]: { Primitive } } = {} local order: { number } = {} + local withTargets = opts ~= nil and opts.targets == true + local keysOf: { [Primitive]: { any } } = {} -- per baked primitive: the key (name or index) of each target + local weightOf: { [any]: number } = {} local allPoints = #placed > 0 for _, pl in placed do if pl.primitive.mode ~= "points" then @@ -208521,6 +209203,27 @@ function MeshOps.merge(input: any, opts: { byMaterial: boolean?, method: string? for name, a in t.attributes do copy.attributes[name] = MeshOps.f32(a) end + if withTargets and t.targets and #t.targets > 0 then + local mesh = if input.kind == "scene" and pl.mesh > 0 then input.meshes[pl.mesh] else nil + local node = if input.kind == "scene" and pl.node > 0 then input.nodes[pl.node] else nil + local names = mesh and mesh.extras and mesh.extras.targetNames or (p.extras and (p.extras :: any).targetNames) + local weights = node and node.weights or (mesh and mesh.weights) + local keys, targets = {}, {} + for k, tg in t.targets do + local key = if type(names) == "table" and type(names[k]) == "string" then names[k] else k + keys[k] = key + if weightOf[key] == nil then + weightOf[key] = weights and weights[k] or 0 + end + local own = {} + for name, a in tg do + own[name] = MeshOps.f32(a) + end + targets[k] = own + end + copy.targets = targets + keysOf[copy] = keys + end if pl.matrix ~= Scene.IDENTITY then local ok, terr = MeshOps.transform(copy, pl.matrix) if not ok then @@ -208566,6 +209269,56 @@ function MeshOps.merge(input: any, opts: { byMaterial: boolean?, method: string? end attrs[name] = Scene.accessor(out, "f32", comps, nv) end + local targets: { { [string]: Accessor } }? = nil + local targetKeys: { any } = {} + if withTargets then + local index: { [any]: number } = {} + for _, p in list do + for _, key in keysOf[p] or {} do + if not index[key] then + table.insert(targetKeys, key) + index[key] = #targetKeys + end + end + end + if #targetKeys > 0 then + local out: { { [string]: Accessor } } = {} + for ti, key in targetKeys do + local comps: { [string]: number } = {} + for _, p in list do + for k, pk in keysOf[p] or {} do + if pk == key then + for name, a in (p.targets :: any)[k] do + comps[name] = math.max(comps[name] or 0, a.components) + end + end + end + end + local tgt: { [string]: Accessor } = {} + for name, nc in comps do + local buf = buffer.create(nv * nc * 4) -- zero where a primitive lacks the target + local base = 0 + for _, p in list do + local cnt = vertexCount(p) + for k, pk in keysOf[p] or {} do + local a = if pk == key then (p.targets :: any)[k][name] else nil + if a then + for v = 0, math.min(cnt, a.count) - 1 do + for c = 0, math.min(nc, a.components) - 1 do + writef32(buf, ((base + v) * nc + c) * 4, readf32(a.data, (v * a.components + c) * 4)) + end + end + end + end + base += cnt + end + tgt[name] = Scene.accessor(buf, "f32", nc, nv) + end + out[ti] = tgt + end + targets = out + end + end local idx = buffer.create(ni * 4) local base, at = 0, 0 for _, p in list do @@ -208576,11 +209329,22 @@ function MeshOps.merge(input: any, opts: { byMaterial: boolean?, method: string? at += n base += vertexCount(p) end + local extras: { [string]: any }? = nil + if targets then + local names, weights = {}, {} + for k, key in targetKeys do + names[k] = if type(key) == "string" then key else tostring(key) + weights[k] = weightOf[key] or 0 + end + extras = { targetNames = names, weights = weights } + end return { attributes = attrs, indices = if points then nil else Scene.accessor(idx, "u32", 1, ni), mode = if points then "points" else "triangles", material = material, + targets = targets, + extras = extras, } end if opts and opts.byMaterial then diff --git a/build/rosetta.lua b/build/rosetta.lua index bfee08d..1a4d2b6 100644 --- a/build/rosetta.lua +++ b/build/rosetta.lua @@ -159208,9 +159208,10 @@ local __compat = __compat local buffer = __compat.buffer --!strict -- file's own SDNA). Supports: the scene's objects and collections, transforms with parent inverse and bone parents, -- meshes of every storage generation (MFace, MPoly / MLoop, attribute layers, AttributeStorage) with UV maps, colour -- attributes, custom normals, material slots; Principled BSDF materials; packed and external images; cameras; lights; --- armatures, skins (vertex groups, top 4 weights), shape keys; actions sampled into channels. +-- armatures, skins (vertex groups, top 4 weights), shape keys (relative keys, vertex groups); actions sampled into +-- channels; rig data (bone collections / layers, colours, custom shapes, pose settings, constraint stacks) as extras. -- Not supported: modifiers (listed in meta.source.modifiers), curves / text / metaballs / grease pencil / volumes, --- NLA strips, drivers, constraints, f-curve modifiers, linked libraries, collection instances. +-- NLA strips, drivers, constraint evaluation, f-curve modifiers, linked libraries, collection instances. -- ------------------------------------------------------------------------------------------------ requires local Err = __include("core/Err") @@ -159249,6 +159250,7 @@ local BlendFormat = { + function BlendFormat.sniff(r) local head = r:peek(7) if head == "BLENDER" then @@ -159643,6 +159645,413 @@ end return Anim end +__FILES["model/blend/Armature"] = function() +local __compat = __compat local buffer, bit32, type, __iter = __compat.buffer, __compat.bit32, __compat.type, __compat.__iter --!strict +-- model/blend/Armature: the rig data of an armature as Blender's Python API names it: bones (head / tail / roll in +-- armature space, deform, connect, wire), bone collections (4.x BoneCollection arrays and lists; before 4.0 the layers +-- and bone groups converted as Blender 4.0's versioning does), bone colours (BoneColor; bone group colours before 4.0), +-- pose bones (custom shapes, locks, rotation mode, IK settings) and constraint stacks (bConstraint and the data structs +-- of IK, copy rotation / location / scale / transforms, damped track, limit rotation / location / scale, child of; the +-- common fields for the rest). Flags from DNA_armature_types.h, DNA_action_types.h, DNA_constraint_types.h. +local Blend = __include("containers/Blend") + +local Armature = {} + +-- Blender's default theme (userdef_default_theme.c): bone colour sets THEME01..THEME20 as normal, select, active + + + + +local THEME = { + { 0x9a0000, 0xbd1111, 0xf70a0a }, { 0xf74018, 0xf66913, 0xfa9900 }, { 0x1e9109, 0x59b70b, 0x83ef1d }, + { 0x0a3694, 0x3667df, 0x5ec1ef }, { 0xa9294e, 0xc1416a, 0xf05d91 }, { 0x430c78, 0x543aa3, 0x8764d5 }, + { 0x24785a, 0x3c9579, 0x6fb6ab }, { 0x4b707c, 0x6a8691, 0x9bc2cd }, { 0xf4c90c, 0xeec236, 0xf3ff00 }, + { 0x1e2024, 0x484c56, 0xffffff }, { 0x6f2f6a, 0x9845be, 0xd330d6 }, { 0x6c8e22, 0x7fb022, 0xbbef5b }, + { 0x8d8d8d, 0xb0b0b0, 0xdedede }, { 0x834326, 0x8b5811, 0xbd6a11 }, { 0x08310e, 0x1c430b, 0x34622b }, + { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, +} + +local function rgb(hex) +return { bit32.rshift(hex, 16) / 255, bit32.band(bit32.rshift(hex, 8), 255) / 255, bit32.band(hex, 255) / 255 } +end + +function Armature.colorSets() +local out = {} + for i, s in __iter(THEME) do + out[i] = { normal = rgb(s[1]), select = rgb(s[2]), active = rgb(s[3]) } + end + return out +end + +local ROTMODE= { [0] = "QUATERNION", [1] = "XYZ", [2] = "XZY", [3] = "YXZ", [4] = "YZX", [5] = "ZXY", [6] = "ZYX", [-1] = "AXIS_ANGLE" } +local SPACE= { [0] = "WORLD", [1] = "LOCAL", [2] = "POSE", [3] = "LOCAL_WITH_PARENT", [5] = "CUSTOM", [6] = "LOCAL_OWNER_ORIENT" } +local EULER_ORDER= { [0] = "AUTO", [1] = "XYZ", [2] = "XZY", [3] = "YXZ", [4] = "YZX", [5] = "ZXY", [6] = "ZYX" } +local TRACK= { [0] = "TRACK_X", [1] = "TRACK_Y", [2] = "TRACK_Z", [3] = "TRACK_NEGATIVE_X", [4] = "TRACK_NEGATIVE_Y", [5] = "TRACK_NEGATIVE_Z" } +local ROT_MIX= { [0] = "REPLACE", [1] = "OFFSET", [2] = "ADD", [3] = "BEFORE", [4] = "AFTER" } +local TRANS_MIX= { [0] = "REPLACE", [1] = "BEFORE", [2] = "AFTER", [3] = "BEFORE_FULL", [4] = "BEFORE_SPLIT", [5] = "AFTER_FULL", [6] = "AFTER_SPLIT" } +local TYPE= { + [1] = "CHILD_OF", [2] = "TRACK_TO", [3] = "IK", [4] = "FOLLOW_PATH", [5] = "LIMIT_ROTATION", [6] = "LIMIT_LOCATION", + [7] = "LIMIT_SCALE", [8] = "COPY_ROTATION", [9] = "COPY_LOCATION", [10] = "COPY_SCALE", [11] = "PYTHON", [12] = "ACTION", + [13] = "LOCKED_TRACK", [14] = "LIMIT_DISTANCE", [15] = "STRETCH_TO", [16] = "FLOOR", [17] = "RIGID_BODY_JOINT", + [18] = "CLAMP_TO", [19] = "TRANSFORM", [20] = "SHRINKWRAP", [21] = "DAMPED_TRACK", [22] = "SPLINE_IK", + [23] = "COPY_TRANSFORMS", [24] = "MAINTAIN_VOLUME", [25] = "PIVOT", [26] = "FOLLOW_TRACK", [27] = "CAMERA_SOLVER", + [28] = "OBJECT_SOLVER", [29] = "TRANSFORM_CACHE", [30] = "ARMATURE", [31] = "GEOMETRY_ATTRIBUTE", +} +-- constraint types with a head_tail (bConstraint.headtail) in Blender's API +local HEAD_TAIL= { + COPY_LOCATION = true, COPY_TRANSFORMS = true, DAMPED_TRACK = true, TRACK_TO = true, LOCKED_TRACK = true, + STRETCH_TO = true, LIMIT_DISTANCE = true, +} + +local CONSTRAINT_OFF, CONSTRAINT_BBONE_SHAPE = 0x200, 0x400 +local BONE_CONNECTED, BONE_HIDDEN_P, BONE_NO_DEFORM, BONE_DRAWWIRE = 0x10, 0x40, 0x1000, 0x20000 +local PCHAN_DRAW_NO_CUSTOM_BONE_SIZE = 1 +-- bPoseChannel.protectflag (OB_LOCK_*) and ikflag (BONE_IK_*) +local LOCK_LOC, LOCK_ROT, LOCK_SCALE, LOCK_ROTW, LOCK_ROT4D = { 1, 2, 4 }, { 8, 16, 32 }, { 64, 128, 256 }, 512, 1024 +local IK_NO_DOF, IK_LIMIT = { 1, 2, 4 }, { 8, 16, 32 } +local AXES = { "x", "y", "z" } + +local function bit(v, mask) +return bit32.band(v or 0, mask) ~= 0 +end + +local function bits(v, masks) +return { bit(v, masks[1]), bit(v, masks[2]), bit(v, masks[3]) } +end + +local function vec3(v, name, fallback) +local x = v:vec(name) + if x and #x >= 3 then + return { x[1], x[2], x[3] } + end + return fallback and table.clone(fallback) +end + +local function text(v, name) +local s = v:str(name) + return (s and s ~= "" and{s }or{nil +})[1]end + +-- ThemeWireColor: char solid[4], select[4], active[4] (sRGB bytes) +local function wire(v) +if not v then + return nil + end + local out= {} + for _, pair in __iter({ { "normal", "solid" }, { "select", "select" }, { "active", "active" } }) do + local key, field = pair[1], pair[2] + local fld = v.struct.byName[field] + local o = fld and v.offset + fld.offset + if not o or o + 3 > buffer.len(v.file.buf) then + return nil + end + local b = v.file.buf + out[key] = { buffer.readu8(b, o) / 255, buffer.readu8(b, o + 1) / 255, buffer.readu8(b, o + 2) / 255 } + end + return out +end + +-- palette: 0 default, 1..20 the theme sets, -1 custom (BoneColor.palette_index, bActionGroup.customCol); the colours +-- are the custom ones, or the default theme's set +local function color(index, custom) +if not index or index == 0 then + return nil + end + local c= { palette = index < 0 and"CUSTOM" or string.format("THEME%02d", index) } + local w = (index < 0 and{(wire(custom) )}or{nil +})[1] if w then + c.normal, c.select, c.active = w.normal, w.select, w.active + elseif index > 0 and THEME[index] then + local s = THEME[index] + c.normal, c.select, c.active = rgb(s[1]), rgb(s[2]), rgb(s[3]) + end + return c +end + +local function boneColor(v) +local bc = v:sub("color") + if not bc then + return nil + end + return color(bc:num("palette_index"), bc:sub("custom")) +end +-- ------------------------------------------------------------------------------------------------ bones +-- 4.1+: collection_array with child_index / child_count; 4.0: the collections list; before 4.0 the used layers +-- ("Layer N", hidden when the layer is off) and then the bone groups (hidden), as Blender's 4.0 versioning converts them + + + + + + +function Armature.collections(arm, bones, pose) +local out= { list = {}, byBone = {} } + local byAddr= {} + for _, b in __iter(bones) do + if b.block then + byAddr[b.block.addr] = b:str("name") or "" + end + end + local function add(name, members) + for _, m in __iter(members) do + local l = out.byBone[m] or {} + out.byBone[m] = l + table.insert(l, name) + end + end + local VISIBLE = 1 + local array = arm:has("collection_array") and arm:pointers("collection_array", arm:num("collection_array_num") or 0) or {} + local cols= {} + if #array > 0 then + for _, addr in __iter(array) do + local blk = addr and Blend.resolve(arm.file, addr, arm.block) + local v = blk and Blend.struct(arm.file, blk, 0, "BoneCollection") + if v then + table.insert(cols, v) + end + end + elseif arm:has("collections") then + cols = arm:list("collections", "BoneCollection") + end + if #cols > 0 then + local parent= {} + for i, c in __iter(cols) do + local first, n = c:num("child_index") or 0, c:num("child_count") or 0 + for k = first + 1, math.min(first + n, #cols) do + parent[k] = c:str("name") + end + local _ = i + end + for i, c in __iter(cols) do + local name = c:str("name") or "" + table.insert(out.list, { name = name, visible = bit(c:num("flags"), VISIBLE), parent = parent[i] }) + local members = {} + for _, m in __iter(c:list("bones", "BoneCollectionMember")) do + local n = byAddr[m:ptr("bone")] + if n then + table.insert(members, n) + end + end + add(name, members) + end + return out + end + local used, shown = arm:num("layer_used"), arm:num("layer") + if used then + for layer = 0, 31 do + local mask = bit32.lshift(1, layer) + if bit(used, mask) then + local name = "Layer " .. (layer + 1) + table.insert(out.list, { name = name, visible = bit(shown, mask) }) + local members = {} + for _, b in __iter(bones) do + if bit(b:num("layer"), mask) then + table.insert(members, b:str("name") or "") + end + end + add(name, members) + end + end + end + if pose then + local groups = pose:list("agroups", "bActionGroup") + local members= {} + for _, pc in __iter(pose:list("chanbase", "bPoseChannel")) do + local g = pc:num("agrp_index") or 0 + if g > 0 and groups[g] then + members[g] = members[g] or {} + table.insert(members[g], pc:str("name") or "") + end + end + for g, grp in __iter(groups) do + local name = grp:str("name") or "" + table.insert(out.list, { name = name, visible = false }) + add(name, members[g] or {}) + end + end + return out +end + +-- a Bone's own fields: head_local / tail_local / roll in armature space (the roll is already in arm_mat, the rest +-- matrix); color from the Bone (4.x) or from the bone group of its pose channel (before 4.0) +function Armature.bone(bone, pc, pose) +local flag = bone:num("flag") or 0 + local e= { + deform = not bit(flag, BONE_NO_DEFORM), + use_connect = bit(flag, BONE_CONNECTED), + show_wire = bit(flag, BONE_DRAWWIRE), + hide = bit(flag, BONE_HIDDEN_P), + head_local = vec3(bone, "arm_head"), + tail_local = vec3(bone, "arm_tail"), + roll = bone:num("arm_roll"), + } + if bone:has("color") then + e.color = boneColor(bone) + elseif pc and pose then + local g = pc:num("agrp_index") or 0 + local grp = (g > 0 and{pose:list("agroups", "bActionGroup")[g] }or{nil +})[1] if grp then + e.color = color(grp:num("customCol"), grp:sub("cs")) + end + end + return e +end + +-- ------------------------------------------------------------------------------------------------ constraints +local function constraintData(e, kind, d, resolve) + local flag = d:num("flag") or 0 + if kind == "IK" then + -- CONSTRAINT_IK_TIP / ROT / STRETCH / POS, NO_POS_X.. / NO_ROT_X..; type 0 copy pose, 1 distance + e.pole_target = resolve(d:deref("poletar", 0, "Object")) + e.pole_subtarget = text(d, "polesubtarget") + e.pole_angle = d:num("poleangle") + e.chain_count = d:num("rootbone") + e.iterations = d:num("iterations") + e.weight = d:num("weight") + e.orient_weight = d:num("orientweight") + e.use_tail = bit(flag, 1) + e.use_rotation = bit(flag, 2) + e.use_stretch = bit(flag, 16) + e.use_location = bit(flag, 32) + -- lock_* are the inverse of the NO_POS / NO_ROT bits, as Blender's API defines them + e.lock_location_x, e.lock_location_y, e.lock_location_z = not bit(flag, 256), not bit(flag, 512), not bit(flag, 1024) + e.lock_rotation_x, e.lock_rotation_y, e.lock_rotation_z = not bit(flag, 2048), not bit(flag, 4096), not bit(flag, 8192) + e.ik_type = (d:num("type") or 0) == 1 and"DISTANCE" or"COPY_POSE" + e.distance = d:num("dist") + elseif kind == "COPY_ROTATION" then + -- ROTLIKE_X 1, Y 2, Z 4, X_INVERT 16, Y_INVERT 32, Z_INVERT 64, OFFSET 128 (mix_mode OFFSET before 2.82) + e.use_x, e.use_y, e.use_z = bit(flag, 1), bit(flag, 2), bit(flag, 4) + e.invert_x, e.invert_y, e.invert_z = bit(flag, 16), bit(flag, 32), bit(flag, 64) + e.euler_order = EULER_ORDER[d:num("euler_order") or 0] + local mix = d:num("mix_mode") + e.mix_mode = (mix and{ROT_MIX[mix] }or{(bit(flag, 128) and"OFFSET" or"REPLACE") +})[1] elseif kind == "COPY_LOCATION" then + -- LOCLIKE_X 1, Y 2, Z 4, X_INVERT 16, Y_INVERT 32, Z_INVERT 64, OFFSET 128 + e.use_x, e.use_y, e.use_z = bit(flag, 1), bit(flag, 2), bit(flag, 4) + e.invert_x, e.invert_y, e.invert_z = bit(flag, 16), bit(flag, 32), bit(flag, 64) + e.use_offset = bit(flag, 128) + elseif kind == "COPY_SCALE" then + -- SIZELIKE_X 1, Y 2, Z 4, OFFSET 8 + e.use_x, e.use_y, e.use_z = bit(flag, 1), bit(flag, 2), bit(flag, 4) + e.use_offset = bit(flag, 8) + e.power = d:num("power") or 1 + elseif kind == "COPY_TRANSFORMS" then + e.mix_mode = TRANS_MIX[d:num("mix_mode") or 0] + e.remove_target_shear = bit(flag, 1) + elseif kind == "DAMPED_TRACK" then + e.track_axis = TRACK[d:num("trackflag") or 1] + elseif kind == "LIMIT_ROTATION" then + -- LIMIT_XROT 1, YROT 2, ZROT 4; flag2 LIMIT_TRANSFORM 2 + for i, a in __iter(AXES) do + e["use_limit_" .. a] = bit(flag, bit32.lshift(1, i - 1)) + e["min_" .. a] = d:num(a .. "min") + e["max_" .. a] = d:num(a .. "max") + end + e.use_transform_limit = bit(d:num("flag2"), 2) + e.euler_order = EULER_ORDER[d:num("euler_order") or 0] + elseif kind == "LIMIT_LOCATION" or kind == "LIMIT_SCALE" then + -- LIMIT_XMIN 1, XMAX 2, YMIN 4, YMAX 8, ZMIN 16, ZMAX 32; flag2 LIMIT_TRANSFORM 2 + for i, a in __iter(AXES) do + e["use_min_" .. a] = bit(flag, bit32.lshift(1, (i - 1) * 2)) + e["use_max_" .. a] = bit(flag, bit32.lshift(2, (i - 1) * 2)) + e["min_" .. a] = d:num(a .. "min") + e["max_" .. a] = d:num(a .. "max") + end + e.use_transform_limit = bit(d:num("flag2"), 2) + elseif kind == "CHILD_OF" then + -- CHILDOF_LOCX 1 .. SIZEZ 256, SET_INVERSE 512 + for i, a in __iter(AXES) do + e["use_location_" .. a] = bit(flag, bit32.lshift(1, i - 1)) + e["use_rotation_" .. a] = bit(flag, bit32.lshift(8, i - 1)) + e["use_scale_" .. a] = bit(flag, bit32.lshift(64, i - 1)) + end + e.set_inverse_pending = bit(flag, 512) + local m = d:vec("invmat") + e.inverse_matrix = (m and #m == 16 and{m }or{nil -- column-major +})[1] end +end + +-- a constraint stack (ListBase of bConstraint) in evaluation order +function Armature.constraints(owner, resolve) +local out = {} + for _, c in __iter(owner:list("constraints", "bConstraint")) do + local t = c:num("type") or 0 + local kind = TYPE[t] or tostring(t) + local flag = c:num("flag") or 0 + local e= { + type = kind, + name = c:str("name") or "", + influence = c:num("enforce") or 1, + mute = bit(flag, CONSTRAINT_OFF), + owner_space = SPACE[c:num("ownspace") or 0], + target_space = SPACE[c:num("tarspace") or 0], + } + if HEAD_TAIL[kind] then + e.head_tail = c:num("headtail") or 0 + e.use_bbone_shape = bit(flag, CONSTRAINT_BBONE_SHAPE) + end + if e.owner_space == "CUSTOM" or e.target_space == "CUSTOM" then + e.space_object = resolve(c:deref("space_object", 0, "Object")) + e.space_subtarget = text(c, "space_subtarget") + end + local d = c:deref("data", 0) + if d then + if d:has("tar") then + e.target = resolve(d:deref("tar", 0, "Object")) + end + e.subtarget = text(d, "subtarget") + if d:has("targets") then + local targets = {} + for _, ct in __iter(d:list("targets", "bConstraintTarget")) do + table.insert(targets, { target = resolve(ct:deref("tar", 0, "Object")), subtarget = text(ct, "subtarget"), weight = ct:num("weight") }) + end + e.targets = targets + end + constraintData(e, kind, d, resolve) + end + table.insert(out, e) + end + return out +end + +-- ------------------------------------------------------------------------------------------------ pose bones +-- a bPoseChannel's settings into e: constraint targets through resolve, the custom shape object through shape +function Armature.pose(e, pc, resolve, shape) + local protect = pc:num("protectflag") or 0 + local ik = pc:num("ikflag") or 0 + e.rotation_mode = ROTMODE[pc:num("rotmode") or 0] or "QUATERNION" + e.lock_location = bits(protect, LOCK_LOC) + e.lock_rotation = bits(protect, LOCK_ROT) + e.lock_rotation_w = bit(protect, LOCK_ROTW) + e.lock_rotations_4d = bit(protect, LOCK_ROT4D) + e.lock_scale = bits(protect, LOCK_SCALE) + local custom = pc:deref("custom", 0, "Object") + if custom then + e.custom_shape = shape(custom) + end + local tx = pc:deref("custom_tx", 0, "bPoseChannel") + e.custom_shape_transform = (tx and{(text(tx, "name") )}or{nil +})[1] e.custom_shape_translation = vec3(pc, "custom_translation", { 0, 0, 0 }) + e.custom_shape_rotation_euler = vec3(pc, "custom_rotation_euler", { 0, 0, 0 }) + local s = pc:num("custom_scale") or 1 -- before 3.0: one uniform scale + e.custom_shape_scale_xyz = vec3(pc, "custom_scale_xyz", { s, s, s }) + e.use_custom_shape_bone_size = not bit(pc:num("drawflag"), PCHAN_DRAW_NO_CUSTOM_BONE_SIZE) + e.custom_shape_wire_width = pc:num("custom_shape_wire_width") + e.ik_stretch = pc:num("ikstretch") or 0 + local lo, hi, stiff = pc:vec("limitmin"), pc:vec("limitmax"), pc:vec("stiffness") + for i, a in __iter(AXES) do + e["lock_ik_" .. a] = bit(ik, IK_NO_DOF[i]) + e["use_ik_limit_" .. a] = bit(ik, IK_LIMIT[i]) + e["ik_min_" .. a] = lo and lo[i] or -math.pi + e["ik_max_" .. a] = hi and hi[i] or math.pi + e["ik_stiffness_" .. a] = stiff and stiff[i] or 0 + end + e.pose_color = (pc:has("color") and{(boneColor(pc) )}or{nil +})[1] e.constraints = Armature.constraints(pc, resolve) +end + +return Armature +end __FILES["model/blend/Material"] = function() local __compat = __compat local buffer, bit32, type, __iter = __compat.buffer, __compat.bit32, __compat.type, __compat.__iter --!strict -- model/blend/Material: Blender materials to Scene PBR materials. With nodes: the Principled BSDF (the one feeding the @@ -160232,8 +160641,77 @@ local v = me:num(...) return (v and v > 0 and{v }or{0 })[1]end +-- edge count and per-edge readers (vertex 1, vertex 2, sharp): ".edge_verts" / "sharp_edge" attributes or MEdge +local function edgeReaders(f, me, layers) +local ne = count(me, "totedge", "edges_num") + local ev = find(layers, "edge", "int2", ".edge_verts") + local se = find(layers, "edge", "bool", "sharp_edge") + local medge = find(layers, "edge", "MEdge") or legacy(f, me, "medge", "MEdge", "edge") + if ne == 0 then + return 0, nil, nil, nil + end + if ev then + local er = reader(f, ev) + local sr = (se and{(reader(f, se) )}or{nil +})[1] return ne, function(i) +return er(i, 0) + end, function(i) +return er(i, 1) + end, function(i) +return sr ~= nil and sr(i, 0) ~= 0 + end + elseif medge then + local a, b, fl = fieldReader(f, medge, "v1"), fieldReader(f, medge, "v2"), fieldReader(f, medge, "flag") + if a and b then + local ser = (se and{(reader(f, se) )}or{nil +})[1] return ne, function(i) +return a(i, 0) + end, function(i) +return b(i, 0) + end, function(i) +if ser then + return ser(i, 0) ~= 0 + end + return fl ~= nil and bit32.band(fl(i, 0), ME_SHARP) ~= 0 + end + end + end + return ne, nil, nil, nil +end + +-- edges no face uses, as u32 vertex pairs (rig widgets are usually edges only) +function Mesh.looseEdges(f, me, poly) +local ne, v1, v2 = edgeReaders(f, me, poly.layers) + if not v1 or not v2 then + return buffer.create(0) + end + local nv = poly.nv + local used= {} + local cv, fs = poly.cornerVert, poly.faceStart + for fi = 0, poly.nf - 1 do + local s0, s1 = buffer.readu32(fs, fi * 4), buffer.readu32(fs, fi * 4 + 4) + for c = s0, s1 - 1 do + local a, b = buffer.readu32(cv, c * 4), buffer.readu32(cv, ((c + 1 < s1 and((c + 1 ))or(s0))) * 4) + used[math.min(a, b) * nv + math.max(a, b)] = true + end + end + local out = {} + for i = 0, ne - 1 do + local a, b = v1(i), v2(i) + if a ~= b and a >= 0 and b >= 0 and a < nv and b < nv and not used[math.min(a, b) * nv + math.max(a, b)] then + table.insert(out, a) + table.insert(out, b) + end + end + local buf = buffer.create(#out * 4) + for k, v in __iter(out) do + buffer.writeu32(buf, (k - 1) * 4, v) + end + return buf +end + function Mesh.read(f, me, limits) local layers = Mesh.layers(f, me) local nv = count(me, "totvert", "verts_num") @@ -160513,10 +160991,6 @@ local d = buffer.create(nc * 8) poly.customNormals = d end -- sharp edges - local ne = count(me, "totedge", "edges_num") - local ev = find(layers, "edge", "int2", ".edge_verts") - local se = find(layers, "edge", "bool", "sharp_edge") - local medge = find(layers, "edge", "MEdge") or legacy(f, me, "medge", "MEdge", "edge") local flags = me:num("flag") or 0 local smoothresh = me:num("smoothresh") local autoSmooth = f.version < 401 and bit32.band(flags, ME_AUTOSMOOTH) ~= 0 @@ -160524,27 +160998,8 @@ local d = buffer.create(nc * 8) poly.autoSmooth = smoothresh or math.rad(30) end local useSharp = f.version >= 401 or autoSmooth - if useSharp and ne > 0 then - local v1, v2, sharp - if ev and se then - local er, sr = reader(f, ev), reader(f, se) - v1 = function(i)return er(i, 0) end - v2 = function(i)return er(i, 1) end - sharp = function(i)return sr(i, 0) ~= 0 end - elseif medge then - local a, b, fl = fieldReader(f, medge, "v1"), fieldReader(f, medge, "v2"), fieldReader(f, medge, "flag") - if a and b and fl then - v1 = function(i)return a(i, 0) end - v2 = function(i)return b(i, 0) end - local ser = (se and{(reader(f, se) )}or{nil -})[1] sharp = function(i) -if ser then - return ser(i, 0) ~= 0 - end - return bit32.band(fl(i, 0), ME_SHARP) ~= 0 - end - end - end + if useSharp then + local ne, v1, v2, sharp = edgeReaders(f, me, layers) if v1 and v2 and sharp then for i = 0, ne - 1 do if sharp(i) then @@ -160599,6 +161054,7 @@ local key = me:deref("key", 0, "Key") local refAddr = key:ptr("refkey") local out= {} local ref= nil + local index = 0 for i, kb in __iter(blocks) do local blk = kb:target("data") local d = buffer.create(nv * 12) @@ -160611,15 +161067,21 @@ local key = me:deref("key", 0, "Key") end end end - if kb.block and kb.block.addr == refAddr then + local isRef = kb.block ~= nil and kb.block.addr == refAddr + if isRef then ref = i + else + index =index+ 1 end - table.insert(out, { - -- unnamed in old files: Key 0 (the basis), Key 1, ... - name = kb:str("name") or ("Key " .. (i - 1)), value = kb:num("curval") or 0, relative = kb:num("relative") or 0, data = d, - mute = bit32.band(kb:num("flag") or 0, 2) ~= 0, + local stored = kb:str("name") + -- unnamed in old files: named as Blender's 2.45 versioning does (Basis, Key 1, Key 2, ...) + local name= (stored and stored ~= "" and{stored }or{isRef and"Basis" or"Key " .. index +})[1] table.insert(out, { + name = name, value = kb:num("curval") or 0, relative = kb:num("relative") or 0, data = d, + mute = bit32.band(kb:num("flag") or 0, 1) ~= 0, -- KEYBLOCK_MUTE min = kb:num("slidermin") or 0, max = kb:num("slidermax") or 1, + vgroup = (kb:str("vgroup") ~= "" and{(kb:str("vgroup") )}or{nil})[1], }) end if ref == nil and #out > 0 then @@ -161050,10 +161512,82 @@ local n = math.floor(#t / comps return Scene.accessor(b, "f32", comps, n) end --- slots[k] = the scene material of slot k - 1 (or 0 for none); skin maps deform groups to joints +-- morph targets of the output vertices (vsrc: their mesh vertices): each key minus its relative key, times the weight +-- of the key's vertex group, as Blender evaluates relative keys -function Prim.build(poly, slots, opts, skin, shapes, ref) +local function targetDeltas(poly, vsrc, shapes, ref, groups) +local n = #vsrc + local targets= {} + for k, s in __iter(shapes) do + if k ~= ref then + local rel = shapes[s.relative + 1] or shapes[ref] + local base = rel.data + local def= nil + if s.vgroup and groups then + for gi, g in __iter(groups) do + if g == s.vgroup then + def = gi - 1 + end + end + end + local t = (table.create(n * 3) ) +for i = 1, n do + local v = vsrc[i] + local w= 1 + if def then + w = 0 + local list = poly.weights and poly.weights[v + 1] or {} + for q = 1, #list - 1, 2 do + if list[q] == def then + w = list[q + 1] + end + end + end + for c = 0, 2 do + t[(i - 1) * 3 + c + 1] = (readf32(s.data, (v * 3 + c) * 4) - readf32(base, (v * 3 + c) * 4)) * w + end + end + table.insert(targets, { POSITION = accessor(t, 3) } ) + end + end + return targets +end + +-- a "lines" primitive of the given edges (u32 vertex pairs), with the morph targets the face primitives have +function Prim.lines(poly, edges, shapes, ref, groups) +local ne = math.floor(buffer.len(edges) / 8 +) if ne == 0 then + return nil + end + local out= {} + local vsrc= {} + local I = buffer.create(ne * 8) + for k = 0, ne * 2 - 1 do + local v = readu32(edges, k * 4) + local o = out[v] + if not o then + o = #vsrc + out[v] = o + table.insert(vsrc, v) + end + writeu32(I, k * 4, o) + end + local n = #vsrc + local P = buffer.create(n * 12) + for i = 1, n do + buffer.copy(P, (i - 1) * 12, poly.pos, vsrc[i] * 12, 12) + end + local prim= { attributes = { POSITION = Scene.accessor(P, "f32", 3, n) }, indices = Scene.accessor(I, "u32", 1, ne * 2), mode = "lines" } + if shapes and ref and #shapes > 1 then + prim.targets = targetDeltas(poly, vsrc, shapes, ref, groups) + end + return prim +end + +-- slots[k] = the scene material of slot k - 1 (or 0 for none); skin maps deform groups to joints; vgroups names the +-- vertex groups (def_nr + 1) for shape keys limited to one +function Prim.build(poly, slots, opts, skin, shapes, ref, vgroups) local triangulateOn = not (opts and opts.triangulate == false) local flipV = not (opts and opts.flipV == false) local withNormals = not (opts and opts.normals == false) @@ -161203,21 +161737,7 @@ for i = 1, n do prim.material = mat end if shapes and ref and #shapes > 1 then - local base = shapes[ref].data - local targets= {} - for k, s in __iter(shapes) do - if k ~= ref then - local t = (table.create(n * 3) ) -for i = 1, n do - local v = vsrc[i] - for c = 0, 2 do - t[(i - 1) * 3 + c + 1] = readf32(s.data, (v * 3 + c) * 4) - readf32(base, (v * 3 + c) * 4) - end - end - table.insert(targets, { POSITION = accessor(t, 3) } ) - end - end - prim.targets = targets + prim.targets = targetDeltas(poly, vsrc, shapes, ref, vgroups) end table.insert(mesh.primitives, prim) table.insert(sources, vsrc) @@ -161226,7 +161746,7 @@ for i = 1, n do local w = {} for k, s in __iter(shapes) do if k ~= ref then - table.insert(w, s.value) + table.insert(w, s.mute and 0 or s.value) -- Blender skips muted keys end end mesh.weights = w @@ -161246,8 +161766,8 @@ local __compat = __compat local buffer, bit32, type, __iter = __compat.buffer, _ -- or Base list before 2.8) with their transforms (euler orders, quaternion, axis angle, delta transforms, parent -- inverse; bone parents), meshes (model/blend/Mesh, model/blend/Prim), materials (Principled BSDF node or the legacy -- colour), images (packed bytes or external uris), cameras, lights (watts to candela / lux as Blender's glTF exporter --- does: 683 lm/W, / 4 pi for point and spot), armatures (bones to joint nodes with the saved pose), skins, shape keys --- and actions sampled into channels. +-- does: 683 lm/W, / 4 pi for point and spot), armatures (bones to joint nodes with the saved pose, rig data through +-- model/blend/Armature), skins, shape keys and actions sampled into channels. local Blend = __include("containers/Blend") local Types = __include("Types") local Mat4 = __include("codecs/model/Mat4") @@ -161256,6 +161776,7 @@ local Mesh = __include("model/blend/Mesh") local Prim = __include("model/blend/Prim") local Anim = __include("model/blend/Anim") local Material = __include("model/blend/Material") +local Armature = __include("model/blend/Armature") local Read = {} @@ -161274,6 +161795,7 @@ local Scene = Types.Scene + local OB_EMPTY, OB_MESH, OB_LAMP, OB_CAMERA, OB_ARMATURE = 0, 1, 10, 11, 25 local PARSKEL, PARBONE = 4, 7 local LA_LOCAL, LA_SUN, LA_SPOT, LA_HEMI, LA_AREA = 0, 1, 2, 3, 4 @@ -161426,6 +161948,20 @@ end + + + + + + + + + + + + + + @@ -161473,7 +162009,7 @@ local function armature(ctx, ob, node) end end end - local info = { joints = {}, names = {}, rest = {}, restLocal = {}, bones = {}, deform = {}, node = node, poseNames = poseNames } + local info= { joints = {}, names = {}, rest = {}, restLocal = {}, bones = {}, deform = {}, node = node, poseNames = poseNames, arm = arm, pose = pose } local function walk(list, parentJoint, parentRest, depth) if depth > 256 then return @@ -161643,20 +162179,37 @@ local list = me:list("vertex_group_names", "bDeformGroup") return out end -local function mesh(ctx, ob, node) - local f = ctx.f +local function shapeExtras(shapes, ref) +local names, list= {}, {} + for k, sh in __iter(shapes) do + if k ~= ref then + table.insert(names, sh.name) + end + local rel = shapes[sh.relative + 1] + local e= { name = sh.name, value = sh.value, slider_min = sh.min, slider_max = sh.max, mute = sh.mute } + e.relative_key = (rel and{rel.name }or{nil +})[1] e.vertex_group = sh.vgroup + table.insert(list, e) + end + return names, list +end + +-- the scene mesh of an object's mesh data (shared between objects with the same data, slots and armature) +local function meshOf(ctx, ob, lines) +local f = ctx.f local me = ob:deref("data", 0, "Mesh") if not me then - return + return nil, nil end local slots = slotMaterials(ctx, ob, me) local armOb = deformArmature(ctx, ob) local armInfo = armOb and armOb.block and ctx.armatures[armOb.block.addr] - local key = tostring(me.block and me.block.index) .. ":" .. table.concat(slots, ",") .. ":" .. tostring(armOb and armOb.block and armOb.block.index) + local key = tostring(me.block and me.block.index) .. ":" .. table.concat(slots, ",") .. ":" .. tostring(armOb and armOb.block and armOb.block.index) .. (lines and":lines" or"") local skin= nil + local groups = groupNames(ob, me) if armInfo then local joints = {} - for gi, name in __iter(groupNames(ob, me)) do + for gi, name in __iter(groups) do local j = armInfo.names[name] if j and armInfo.deform[j] then joints[gi - 1] = j - 1 @@ -161671,9 +162224,23 @@ local function mesh(ctx, ob, node) error(err or "bad mesh", 0) end local shapes, ref = Mesh.shapes(f, me, poly.nv) - local built = Prim.build(poly, slots, { triangulate = ctx.opts.triangulate, flipV = ctx.opts.flipV }, skin, shapes, ref) + local built = Prim.build(poly, slots, { triangulate = ctx.opts.triangulate, flipV = ctx.opts.flipV }, skin, shapes, ref, groups) local m = built.mesh - m.extras = { blend = { vertices = poly.nv, faces = poly.nf, corners = poly.nc, generation = poly.generation, uvs = #poly.uvs, colors = #poly.colors, shapes = #shapes } } + local extras= { vertices = poly.nv, faces = poly.nf, corners = poly.nc, generation = poly.generation, uvs = #poly.uvs, colors = #poly.colors, shapes = #shapes } + m.extras = { blend = extras } + if lines then + local lp = Prim.lines(poly, Mesh.looseEdges(f, me, poly), shapes, ref, groups) + if lp then + table.insert(m.primitives, lp) + extras.looseEdges = math.floor((lp.indices ).count / 2 +) end + end + if #shapes > 1 then + local names, list = shapeExtras(shapes, ref) + m.extras = { blend = extras, targetNames = names } + extras.shape_keys = list + extras.reference_key = (ref and{shapes[ref].name }or{nil +})[1] end table.insert(ctx.scene.meshes, m) idx = #ctx.scene.meshes ctx.meshes[key] = idx @@ -161683,6 +162250,15 @@ local function mesh(ctx, ob, node) ctx.meta.shapeKeys[idx] = { key = me:deref("key", 0, "Key"), mesh = me, shapes = shapes, ref = ref } end end + return idx, armInfo +end + +local function mesh(ctx, ob, node) + local addr = ob.block and ob.block.addr + local idx, armInfo = meshOf(ctx, ob, ctx.opts.looseEdges == true or (addr ~= nil and ctx.widgets[addr] ~= nil)) + if not idx then + return + end local n = ctx.scene.nodes[node] n.mesh = idx if ctx.scene.meshes[idx].weights then @@ -161766,6 +162342,14 @@ local addr = ob.block and ob.block.addr if lay and ctx.f.version < 280 then extras.layers = lay end + -- Object.visibility_flag (2.8+): OB_HIDE_VIEWPORT 1, OB_HIDE_RENDER 4; restrictflag before: VIEW 1, RENDER 4 + local vis = ob:num("visibility_flag") or ob:num("restrictflag") or 0 + if bit32.band(vis, 1) ~= 0 then + extras.hide_viewport = true + end + if bit32.band(vis, 4) ~= 0 then + extras.hide_render = true + end local mods = {} for _, md in __iter(ob:list("modifiers")) do table.insert(mods, { name = md:sub("modifier") and ((md:sub("modifier") )):str("name") or md:str("name") or "", type = (string.gsub(md.struct.name, "ModifierData$", "")) }) @@ -161786,6 +162370,77 @@ local addr = ob.block and ob.block.addr return idx end +-- ------------------------------------------------------------------------------------------------ rigs +-- an object as a constraint target or custom shape: its node, else its name; widgets records custom shapes +local function resolver(ctx, widgets) +return function(ob) +if not ob then + return nil + end + local addr = ob.block and ob.block.addr + if widgets and addr ~= nil and not ctx.widgets[addr] then + ctx.widgets[addr] = ob + table.insert(ctx.widgetOrder, addr) + end + local node = (addr ~= nil and{ctx.objects[addr] }or{nil +})[1] if node then + return node + end + return ob:idName() + end +end + +local function rigs(ctx) + local target, shape = resolver(ctx, false), resolver(ctx, true) + for node = 1, #ctx.scene.nodes do +local __DARKLUA_CONTINUE_16=false repeat local ob = ctx.objView[node] + local extras = ob and (ctx.scene.nodes[node].extras ).blend + if not ob or not extras then +__DARKLUA_CONTINUE_16=true break + end + local list = Armature.constraints(ob, target) + if #list > 0 then + extras.constraints = list + end + local info = ob.block and ctx.armatures[ob.block.addr] + if info then + local cols = Armature.collections(info.arm, info.bones, info.pose) + extras.bone_collections = cols.list + for j, bone in __iter(info.bones) do + local name = bone:str("name") or "" + local pc = info.poseNames[name] + local e = (ctx.scene.nodes[info.joints[j] ].extras ).blend + for k, v in __iter(Armature.bone(bone, pc, info.pose)) do + e[k] = v + end + e.collections = cols.byBone[name] or {} + if pc then + Armature.pose(e, pc, target, shape) + end + end + end +__DARKLUA_CONTINUE_16=true until true if not __DARKLUA_CONTINUE_16 then break end end +end + +-- every custom shape object: its node (and mesh) when it is in the scene, else its mesh only +local function widgetList(ctx) +local list = {} + for _, addr in __iter(ctx.widgetOrder) do + local ob = ctx.widgets[addr] + local t = ob:num("type") or -1 + local w= { name = ob:idName() or "", type = TYPE_NAME[t] or tostring(t) } + local node = ctx.objects[addr] + if node then + w.node = node + w.mesh = ctx.scene.nodes[node].mesh + elseif t == OB_MESH then + w.mesh = (meshOf(ctx, ob, true)) + end + table.insert(list, w) + end + return list +end + -- ------------------------------------------------------------------------------------------------ animation local function apply(props, curves, frame, prefix, name) local p= {} @@ -161977,7 +162632,7 @@ local track = { translation = {}, rotation = {}, scale = {} } v = math.clamp(Anim.evaluate(c, fr), math.min(s.min, s.max), math.max(s.min, s.max)) -- the slider range end end - buffer.writef32(out, ((i - 1) * count + k) * 4, v) + buffer.writef32(out, ((i - 1) * count + k) * 4, s.mute and 0 or v) k =k+ 1 end end @@ -162034,7 +162689,7 @@ local o= opts or {} } local ctx= { f = f, scene = scene, opts = o, objects = {}, objView = {}, parentOf = {}, world = {}, meshes = {}, materials = {}, - textures = {}, armatures = {}, prefix = {}, props = {}, meta = meta, pending = {}, + textures = {}, armatures = {}, prefix = {}, props = {}, meta = meta, pending = {}, widgets = {}, widgetOrder = {}, } local order= {} if sc then @@ -162113,6 +162768,7 @@ local o= opts or {} local u = a ~= nil and firstUnder[a] or nil object(ctx, e.ob, (u and u > 0 and{u }or{nil})[1], 0) end + rigs(ctx) for node = 1, #scene.nodes do local ob = ctx.objView[node] if ob and (ob:num("type") or -1) == OB_MESH then @@ -162120,6 +162776,9 @@ local o= opts or {} end end skins(ctx) + if next(ctx.armatures) ~= nil then + scene.meta.blend = { widgets = widgetList(ctx), bone_color_sets = Armature.colorSets() } + end if o.animations ~= false then animations(ctx) end @@ -171043,6 +171702,16 @@ if type(v) ~= "table" then return nil, Err.new(Err.CORRUPT, "bad mesh " .. (i - 1)) end local mesh= { name = str(m.name), primitives = {}, weights = (type(m.weights) == "table" and{(table.clone(m.weights) )}or{nil})[1], extras = keep(m, nil) } + -- morph target names: the extras.targetNames convention (Blender's exporter, three.js, Babylon) + local tn = type(m.extras) == "table" and m.extras.targetNames + if type(tn) == "table" and #tn > 0 then + local names = {} + for k, v in __iter(tn) do + names[k] = (type(v) == "string" and{v }or{(tostring(v) +)})[1] end + mesh.extras = mesh.extras or {} + ;(mesh.extras ).targetNames = names + end for k, p in __iter(arr(m.primitives)) do if type(p) ~= "table" or type(p.attributes) ~= "table" then return nil, Err.new(Err.CORRUPT, string.format("mesh %d primitive %d: no attributes", i - 1, k - 1)) @@ -171759,6 +172428,12 @@ if type(v) ~= "table" then end g.weights = mesh.weights restore(g, mesh.extras) + local tn = mesh.extras and (mesh.extras ).targetNames + if type(tn) == "table" and #tn > 0 and g.extras == nil then + local ex = object() + ex.targetNames = table.clone(tn) + g.extras = ex + end table.insert(meshes, g) end local cameras= {} @@ -207744,6 +208419,9 @@ if string.sub(name, 1, 6) == "COLOR_" then return 0 end +-- opts.targets: morph targets concatenated by name (mesh.extras.targetNames, else prim.extras.targetNames; unnamed +-- ones by index), zero where a primitive lacks one; the result's extras.targetNames / extras.weights name them and +-- give their default weights (node weights, else mesh weights) function MeshOps.merge(input, opts) local placed= {} if type(input) ~= "table" then @@ -207758,6 +208436,9 @@ local placed= {} end local groups= {} local order= {} + local withTargets = opts ~= nil and opts.targets == true + local keysOf= {} -- per baked primitive: the key (name or index) of each target + local weightOf= {} local allPoints = #placed > 0 for _, pl in __iter(placed) do if pl.primitive.mode ~= "points" then @@ -207777,6 +208458,27 @@ local placed= {} for name, a in __iter(t.attributes) do copy.attributes[name] = MeshOps.f32(a) end + if withTargets and t.targets and #t.targets > 0 then + local mesh = (input.kind == "scene" and pl.mesh > 0 and{input.meshes[pl.mesh] }or{nil +})[1] local node = (input.kind == "scene" and pl.node > 0 and{input.nodes[pl.node] }or{nil +})[1] local names = mesh and mesh.extras and mesh.extras.targetNames or (p.extras and (p.extras ).targetNames) + local weights = node and node.weights or (mesh and mesh.weights) + local keys, targets = {}, {} + for k, tg in __iter(t.targets) do + local key = (type(names) == "table" and type(names[k]) == "string" and{names[k] }or{k +})[1] keys[k] = key + if weightOf[key] == nil then + weightOf[key] = weights and weights[k] or 0 + end + local own = {} + for name, a in __iter(tg) do + own[name] = MeshOps.f32(a) + end + targets[k] = own + end + copy.targets = targets + keysOf[copy] = keys + end if pl.matrix ~= Scene.IDENTITY then local ok, terr = MeshOps.transform(copy, pl.matrix) if not ok then @@ -207822,6 +208524,56 @@ local names= {} end attrs[name] = Scene.accessor(out, "f32", comps, nv) end + local targets= nil + local targetKeys= {} + if withTargets then + local index= {} + for _, p in __iter(list) do + for _, key in __iter(keysOf[p] or {}) do + if not index[key] then + table.insert(targetKeys, key) + index[key] = #targetKeys + end + end + end + if #targetKeys > 0 then + local out= {} + for ti, key in __iter(targetKeys) do + local comps= {} + for _, p in __iter(list) do + for k, pk in __iter(keysOf[p] or {}) do + if pk == key then + for name, a in __iter((p.targets )[k]) do + comps[name] = math.max(comps[name] or 0, a.components) + end + end + end + end + local tgt= {} + for name, nc in __iter(comps) do + local buf = buffer.create(nv * nc * 4) -- zero where a primitive lacks the target + local base = 0 + for _, p in __iter(list) do + local cnt = vertexCount(p) + for k, pk in __iter(keysOf[p] or {}) do + local a = (pk == key and{(p.targets )[k][name] }or{nil +})[1] if a then + for v = 0, math.min(cnt, a.count) - 1 do + for c = 0, math.min(nc, a.components) - 1 do + writef32(buf, ((base + v) * nc + c) * 4, readf32(a.data, (v * a.components + c) * 4)) + end + end + end + end + base =base+ cnt + end + tgt[name] = Scene.accessor(buf, "f32", nc, nv) + end + out[ti] = tgt + end + targets = out + end + end local idx = buffer.create(ni * 4) local base, at = 0, 0 for _, p in __iter(list) do @@ -207832,11 +208584,22 @@ local names= {} at =at+ n base =base+ vertexCount(p) end + local extras= nil + if targets then + local names, weights = {}, {} + for k, key in __iter(targetKeys) do + names[k] = (type(key) == "string" and{key }or{(tostring(key) +)})[1] weights[k] = weightOf[key] or 0 + end + extras = { targetNames = names, weights = weights } + end return { attributes = attrs, indices = (points and{nil }or{(Scene.accessor(idx, "u32", 1, ni))})[1], mode = points and"points" or"triangles", material = material, + targets = targets, + extras = extras, } end if opts and opts.byMaterial then diff --git a/build/rosetta.lua.linemap.json b/build/rosetta.lua.linemap.json index 9de4308..b0a0b9a 100644 --- a/build/rosetta.lua.linemap.json +++ b/build/rosetta.lua.linemap.json @@ -433,186 +433,187 @@ [158579, "src/Rosetta/model/b3d/init.luau"], [158634, "src/Rosetta/model/b3d/Read.luau"], [159205, "src/Rosetta/model/blend/init.luau"], -[159301, "src/Rosetta/model/blend/Anim.luau"], -[159647, "src/Rosetta/model/blend/Material.luau"], -[159999, "src/Rosetta/model/blend/Mesh.luau"], -[160634, "src/Rosetta/model/blend/Normals.luau"], -[160795, "src/Rosetta/model/blend/Prim.luau"], -[161244, "src/Rosetta/model/blend/Read.luau"], -[162144, "src/Rosetta/model/bsp/init.luau"], -[162335, "src/Rosetta/model/bsp/Lightmap.luau"], -[162401, "src/Rosetta/model/bsp/Quake.luau"], -[162790, "src/Rosetta/model/bsp/Quake3.luau"], -[163019, "src/Rosetta/model/bsp/Tree.luau"], -[163407, "src/Rosetta/model/buildmap/init.luau"], -[163679, "src/Rosetta/model/buildmap/Geometry.luau"], -[164082, "src/Rosetta/model/d3map/init.luau"], -[164364, "src/Rosetta/model/d3map/Parse.luau"], -[164562, "src/Rosetta/model/dae/init.luau"], -[164751, "src/Rosetta/model/dae/Math.luau"], -[164798, "src/Rosetta/model/dae/Read.luau"], -[166648, "src/Rosetta/model/dae/Write.luau"], -[167017, "src/Rosetta/model/fbx/init.luau"], -[167165, "src/Rosetta/model/fbx/Ascii.luau"], -[167435, "src/Rosetta/model/fbx/Binary.luau"], -[167890, "src/Rosetta/model/fbx/Read.luau"], -[169252, "src/Rosetta/model/fbx/Write.luau"], -[170237, "src/Rosetta/model/fbx/Xform.luau"], -[170278, "src/Rosetta/model/gltf/init.luau"], -[170515, "src/Rosetta/model/gltf/Pack.luau"], -[170584, "src/Rosetta/model/gltf/Read.luau"], -[171315, "src/Rosetta/model/gltf/Write.luau"], -[171995, "src/Rosetta/model/godot/init.luau"], -[172086, "src/Rosetta/model/godot/Build.luau"], -[172628, "src/Rosetta/model/godot/Primitives.luau"], -[172903, "src/Rosetta/model/godot/Surface.luau"], -[173388, "src/Rosetta/model/godot/Write.luau"], -[173717, "src/Rosetta/model/iqm/init.luau"], -[173793, "src/Rosetta/model/iqm/Read.luau"], -[174148, "src/Rosetta/model/iqm/Write.luau"], -[174835, "src/Rosetta/model/ldraw/init.luau"], -[174913, "src/Rosetta/model/ldraw/Colors.luau"], -[175231, "src/Rosetta/model/ldraw/Read.luau"], -[175808, "src/Rosetta/model/lwo/init.luau"], -[175884, "src/Rosetta/model/lwo/Build.luau"], -[176346, "src/Rosetta/model/lwo/Parse.luau"], -[176889, "src/Rosetta/model/map/init.luau"], -[177206, "src/Rosetta/model/map/Build.luau"], -[177450, "src/Rosetta/model/map/Parse.luau"], -[177835, "src/Rosetta/model/map/Write.luau"], -[177981, "src/Rosetta/model/mca/init.luau"], -[178323, "src/Rosetta/model/mca/Chunk.luau"], -[178456, "src/Rosetta/model/mca/Lz4Block.luau"], -[178526, "src/Rosetta/model/md2/init.luau"], -[178725, "src/Rosetta/model/md3/init.luau"], -[178953, "src/Rosetta/model/md5/init.luau"], -[179034, "src/Rosetta/model/md5/Read.luau"], -[179467, "src/Rosetta/model/mdl/init.luau"], -[179549, "src/Rosetta/model/mdl/HalfLife.luau"], -[179853, "src/Rosetta/model/mdl/Quake.luau"], -[180071, "src/Rosetta/model/ms3d/init.luau"], -[180143, "src/Rosetta/model/ms3d/Read.luau"], -[180589, "src/Rosetta/model/ms3d/Write.luau"], -[181058, "src/Rosetta/model/obj/init.luau"], -[181876, "src/Rosetta/model/obj/Mtl.luau"], -[182164, "src/Rosetta/model/off/init.luau"], -[182626, "src/Rosetta/model/ply/init.luau"], -[183731, "src/Rosetta/model/ply/Binary.luau"], -[183932, "src/Rosetta/model/pmx/init.luau"], -[184001, "src/Rosetta/model/pmx/Build.luau"], -[184297, "src/Rosetta/model/pmx/Pmd.luau"], -[184632, "src/Rosetta/model/pmx/Read.luau"], -[185036, "src/Rosetta/model/proc/init.luau"], -[185418, "src/Rosetta/model/qb/init.luau"], -[185811, "src/Rosetta/model/rbxm/init.luau"], -[186404, "src/Rosetta/model/rbxmx/init.luau"], -[187080, "src/Rosetta/model/robloxmesh/init.luau"], -[187739, "src/Rosetta/model/robloxmesh/Parse.luau"], -[188196, "src/Rosetta/model/robloxmesh/Write.luau"], -[188305, "src/Rosetta/model/schematic/init.luau"], -[188626, "src/Rosetta/model/schematic/Common.luau"], -[188746, "src/Rosetta/model/schematic/Litematic.luau"], -[188957, "src/Rosetta/model/schematic/Mcedit.luau"], -[189201, "src/Rosetta/model/schematic/Sponge.luau"], -[189330, "src/Rosetta/model/smd/init.luau"], -[189397, "src/Rosetta/model/smd/Read.luau"], -[189666, "src/Rosetta/model/smd/Write.luau"], -[189909, "src/Rosetta/model/sourcemdl/init.luau"], -[190080, "src/Rosetta/model/sourcemdl/Build.luau"], -[190510, "src/Rosetta/model/sourcemdl/Material.luau"], -[190671, "src/Rosetta/model/sourcemdl/Mdl.luau"], -[191198, "src/Rosetta/model/sourcemdl/Phy.luau"], -[191321, "src/Rosetta/model/sourcemdl/Vtx.luau"], -[191503, "src/Rosetta/model/sourcemdl/Vvd.luau"], -[191597, "src/Rosetta/model/stl/init.luau"], -[192047, "src/Rosetta/model/stl/Decode.luau"], -[192121, "src/Rosetta/model/t3d/init.luau"], -[192215, "src/Rosetta/model/t3d/Build.luau"], -[192620, "src/Rosetta/model/t3d/Parse.luau"], -[192788, "src/Rosetta/model/udmf/init.luau"], -[192871, "src/Rosetta/model/usda/init.luau"], -[193080, "src/Rosetta/model/usda/Build.luau"], -[194358, "src/Rosetta/model/usda/Parse.luau"], -[195156, "src/Rosetta/model/usda/Write.luau"], -[195973, "src/Rosetta/model/vbsp/init.luau"], -[196419, "src/Rosetta/model/vbsp/Faces.luau"], -[196643, "src/Rosetta/model/vbsp/Props.luau"], -[196735, "src/Rosetta/model/vmf/init.luau"], -[197060, "src/Rosetta/model/vmf/Build.luau"], -[197484, "src/Rosetta/model/vox/init.luau"], -[198370, "src/Rosetta/model/vox/Grid.luau"], -[198427, "src/Rosetta/model/vrml/init.luau"], -[198493, "src/Rosetta/model/x/init.luau"], -[198623, "src/Rosetta/model/x/Build.luau"], -[199186, "src/Rosetta/model/x/Parse.luau"], -[199483, "src/Rosetta/model/x3d/init.luau"], -[199561, "src/Rosetta/music/669/init.luau"], -[199768, "src/Rosetta/music/ahx/init.luau"], -[199820, "src/Rosetta/music/far/init.luau"], -[200050, "src/Rosetta/music/hmp/init.luau"], -[200315, "src/Rosetta/music/hvl/init.luau"], -[200367, "src/Rosetta/music/it/init.luau"], -[200786, "src/Rosetta/music/it/Itsex.luau"], -[200903, "src/Rosetta/music/med/init.luau"], -[201551, "src/Rosetta/music/midi/init.luau"], -[201695, "src/Rosetta/music/midi/Smf.luau"], -[202107, "src/Rosetta/music/mod/init.luau"], -[202461, "src/Rosetta/music/mtm/init.luau"], -[202684, "src/Rosetta/music/mus/init.luau"], -[202842, "src/Rosetta/music/okt/init.luau"], -[203124, "src/Rosetta/music/ptm/init.luau"], -[203347, "src/Rosetta/music/s3m/init.luau"], -[203584, "src/Rosetta/music/sf2/init.luau"], -[203628, "src/Rosetta/music/stm/init.luau"], -[203860, "src/Rosetta/music/ult/init.luau"], -[204165, "src/Rosetta/music/umx/init.luau"], -[204382, "src/Rosetta/music/xm/init.luau"], -[204944, "src/Rosetta/music/xmi/init.luau"], -[205153, "src/Rosetta/ops/AudioOps.luau"], -[205632, "src/Rosetta/ops/ImageOps/init.luau"], -[206280, "src/Rosetta/ops/ImageOps/Kernels.luau"], -[206920, "src/Rosetta/ops/LayerOps.luau"], -[207013, "src/Rosetta/ops/MeshOps/init.luau"], -[208065, "src/Rosetta/ops/MeshOps/Greedy.luau"], -[208232, "src/Rosetta/ops/MusicOps.luau"], -[208581, "src/Rosetta/playlist/m3u/init.luau"], -[208934, "src/Rosetta/playlist/pls/init.luau"], -[209112, "src/Rosetta/playlist/xspf/init.luau"], -[209315, "src/Rosetta/subtitle/ass/init.luau"], -[209759, "src/Rosetta/subtitle/srt/init.luau"], -[209932, "src/Rosetta/subtitle/vtt/init.luau"], -[210135, "src/Rosetta/vector/gamemaps/init.luau"], -[210322, "src/Rosetta/vector/gamemaps/Expand.luau"], -[210419, "src/Rosetta/vector/ldtk/init.luau"], -[210511, "src/Rosetta/vector/ldtk/Read.luau"], -[210847, "src/Rosetta/vector/ldtk/Write.luau"], -[211495, "src/Rosetta/vector/ogmo/init.luau"], -[211614, "src/Rosetta/vector/ogmo/Read.luau"], -[212019, "src/Rosetta/vector/ogmo/Write.luau"], -[212373, "src/Rosetta/vector/svg/init.luau"], -[212459, "src/Rosetta/vector/svg/Parse.luau"], -[213205, "src/Rosetta/vector/svg/PathData.luau"], -[213573, "src/Rosetta/vector/svg/Render.luau"], -[213990, "src/Rosetta/vector/svg/Style.luau"], -[214362, "src/Rosetta/vector/svg/Write.luau"], -[214562, "src/Rosetta/vector/tiled/init.luau"], -[214742, "src/Rosetta/vector/tiled/Data.luau"], -[214893, "src/Rosetta/vector/tiled/Tmj.luau"], -[215524, "src/Rosetta/vector/tiled/Tmx.luau"], -[216136, "src/Rosetta/video/avi/init.luau"], -[216430, "src/Rosetta/video/fli/init.luau"], -[216581, "src/Rosetta/video/flv/init.luau"], -[216965, "src/Rosetta/video/flv/Amf.luau"], -[217123, "src/Rosetta/video/flv/Mux.luau"], -[217404, "src/Rosetta/video/h264/init.luau"], -[217543, "src/Rosetta/video/mkv/init.luau"], -[217699, "src/Rosetta/video/mkv/Mux.luau"], -[217978, "src/Rosetta/video/mkv/Parse.luau"], -[218699, "src/Rosetta/video/mp4/init.luau"], -[219027, "src/Rosetta/video/mpegps/init.luau"], -[219214, "src/Rosetta/video/mpegts/init.luau"], -[219460, "src/Rosetta/video/ogv/init.luau"], -[219855, "src/Rosetta/video/smk/init.luau"], -[220164, "src/Rosetta/video/smk/Audio.luau"], -[220284, "src/Rosetta/video/y4m/init.luau"] +[159303, "src/Rosetta/model/blend/Anim.luau"], +[159649, "src/Rosetta/model/blend/Armature.luau"], +[160056, "src/Rosetta/model/blend/Material.luau"], +[160408, "src/Rosetta/model/blend/Mesh.luau"], +[161096, "src/Rosetta/model/blend/Normals.luau"], +[161257, "src/Rosetta/model/blend/Prim.luau"], +[161764, "src/Rosetta/model/blend/Read.luau"], +[162803, "src/Rosetta/model/bsp/init.luau"], +[162994, "src/Rosetta/model/bsp/Lightmap.luau"], +[163060, "src/Rosetta/model/bsp/Quake.luau"], +[163449, "src/Rosetta/model/bsp/Quake3.luau"], +[163678, "src/Rosetta/model/bsp/Tree.luau"], +[164066, "src/Rosetta/model/buildmap/init.luau"], +[164338, "src/Rosetta/model/buildmap/Geometry.luau"], +[164741, "src/Rosetta/model/d3map/init.luau"], +[165023, "src/Rosetta/model/d3map/Parse.luau"], +[165221, "src/Rosetta/model/dae/init.luau"], +[165410, "src/Rosetta/model/dae/Math.luau"], +[165457, "src/Rosetta/model/dae/Read.luau"], +[167307, "src/Rosetta/model/dae/Write.luau"], +[167676, "src/Rosetta/model/fbx/init.luau"], +[167824, "src/Rosetta/model/fbx/Ascii.luau"], +[168094, "src/Rosetta/model/fbx/Binary.luau"], +[168549, "src/Rosetta/model/fbx/Read.luau"], +[169911, "src/Rosetta/model/fbx/Write.luau"], +[170896, "src/Rosetta/model/fbx/Xform.luau"], +[170937, "src/Rosetta/model/gltf/init.luau"], +[171174, "src/Rosetta/model/gltf/Pack.luau"], +[171243, "src/Rosetta/model/gltf/Read.luau"], +[171984, "src/Rosetta/model/gltf/Write.luau"], +[172670, "src/Rosetta/model/godot/init.luau"], +[172761, "src/Rosetta/model/godot/Build.luau"], +[173303, "src/Rosetta/model/godot/Primitives.luau"], +[173578, "src/Rosetta/model/godot/Surface.luau"], +[174063, "src/Rosetta/model/godot/Write.luau"], +[174392, "src/Rosetta/model/iqm/init.luau"], +[174468, "src/Rosetta/model/iqm/Read.luau"], +[174823, "src/Rosetta/model/iqm/Write.luau"], +[175510, "src/Rosetta/model/ldraw/init.luau"], +[175588, "src/Rosetta/model/ldraw/Colors.luau"], +[175906, "src/Rosetta/model/ldraw/Read.luau"], +[176483, "src/Rosetta/model/lwo/init.luau"], +[176559, "src/Rosetta/model/lwo/Build.luau"], +[177021, "src/Rosetta/model/lwo/Parse.luau"], +[177564, "src/Rosetta/model/map/init.luau"], +[177881, "src/Rosetta/model/map/Build.luau"], +[178125, "src/Rosetta/model/map/Parse.luau"], +[178510, "src/Rosetta/model/map/Write.luau"], +[178656, "src/Rosetta/model/mca/init.luau"], +[178998, "src/Rosetta/model/mca/Chunk.luau"], +[179131, "src/Rosetta/model/mca/Lz4Block.luau"], +[179201, "src/Rosetta/model/md2/init.luau"], +[179400, "src/Rosetta/model/md3/init.luau"], +[179628, "src/Rosetta/model/md5/init.luau"], +[179709, "src/Rosetta/model/md5/Read.luau"], +[180142, "src/Rosetta/model/mdl/init.luau"], +[180224, "src/Rosetta/model/mdl/HalfLife.luau"], +[180528, "src/Rosetta/model/mdl/Quake.luau"], +[180746, "src/Rosetta/model/ms3d/init.luau"], +[180818, "src/Rosetta/model/ms3d/Read.luau"], +[181264, "src/Rosetta/model/ms3d/Write.luau"], +[181733, "src/Rosetta/model/obj/init.luau"], +[182551, "src/Rosetta/model/obj/Mtl.luau"], +[182839, "src/Rosetta/model/off/init.luau"], +[183301, "src/Rosetta/model/ply/init.luau"], +[184406, "src/Rosetta/model/ply/Binary.luau"], +[184607, "src/Rosetta/model/pmx/init.luau"], +[184676, "src/Rosetta/model/pmx/Build.luau"], +[184972, "src/Rosetta/model/pmx/Pmd.luau"], +[185307, "src/Rosetta/model/pmx/Read.luau"], +[185711, "src/Rosetta/model/proc/init.luau"], +[186093, "src/Rosetta/model/qb/init.luau"], +[186486, "src/Rosetta/model/rbxm/init.luau"], +[187079, "src/Rosetta/model/rbxmx/init.luau"], +[187755, "src/Rosetta/model/robloxmesh/init.luau"], +[188414, "src/Rosetta/model/robloxmesh/Parse.luau"], +[188871, "src/Rosetta/model/robloxmesh/Write.luau"], +[188980, "src/Rosetta/model/schematic/init.luau"], +[189301, "src/Rosetta/model/schematic/Common.luau"], +[189421, "src/Rosetta/model/schematic/Litematic.luau"], +[189632, "src/Rosetta/model/schematic/Mcedit.luau"], +[189876, "src/Rosetta/model/schematic/Sponge.luau"], +[190005, "src/Rosetta/model/smd/init.luau"], +[190072, "src/Rosetta/model/smd/Read.luau"], +[190341, "src/Rosetta/model/smd/Write.luau"], +[190584, "src/Rosetta/model/sourcemdl/init.luau"], +[190755, "src/Rosetta/model/sourcemdl/Build.luau"], +[191185, "src/Rosetta/model/sourcemdl/Material.luau"], +[191346, "src/Rosetta/model/sourcemdl/Mdl.luau"], +[191873, "src/Rosetta/model/sourcemdl/Phy.luau"], +[191996, "src/Rosetta/model/sourcemdl/Vtx.luau"], +[192178, "src/Rosetta/model/sourcemdl/Vvd.luau"], +[192272, "src/Rosetta/model/stl/init.luau"], +[192722, "src/Rosetta/model/stl/Decode.luau"], +[192796, "src/Rosetta/model/t3d/init.luau"], +[192890, "src/Rosetta/model/t3d/Build.luau"], +[193295, "src/Rosetta/model/t3d/Parse.luau"], +[193463, "src/Rosetta/model/udmf/init.luau"], +[193546, "src/Rosetta/model/usda/init.luau"], +[193755, "src/Rosetta/model/usda/Build.luau"], +[195033, "src/Rosetta/model/usda/Parse.luau"], +[195831, "src/Rosetta/model/usda/Write.luau"], +[196648, "src/Rosetta/model/vbsp/init.luau"], +[197094, "src/Rosetta/model/vbsp/Faces.luau"], +[197318, "src/Rosetta/model/vbsp/Props.luau"], +[197410, "src/Rosetta/model/vmf/init.luau"], +[197735, "src/Rosetta/model/vmf/Build.luau"], +[198159, "src/Rosetta/model/vox/init.luau"], +[199045, "src/Rosetta/model/vox/Grid.luau"], +[199102, "src/Rosetta/model/vrml/init.luau"], +[199168, "src/Rosetta/model/x/init.luau"], +[199298, "src/Rosetta/model/x/Build.luau"], +[199861, "src/Rosetta/model/x/Parse.luau"], +[200158, "src/Rosetta/model/x3d/init.luau"], +[200236, "src/Rosetta/music/669/init.luau"], +[200443, "src/Rosetta/music/ahx/init.luau"], +[200495, "src/Rosetta/music/far/init.luau"], +[200725, "src/Rosetta/music/hmp/init.luau"], +[200990, "src/Rosetta/music/hvl/init.luau"], +[201042, "src/Rosetta/music/it/init.luau"], +[201461, "src/Rosetta/music/it/Itsex.luau"], +[201578, "src/Rosetta/music/med/init.luau"], +[202226, "src/Rosetta/music/midi/init.luau"], +[202370, "src/Rosetta/music/midi/Smf.luau"], +[202782, "src/Rosetta/music/mod/init.luau"], +[203136, "src/Rosetta/music/mtm/init.luau"], +[203359, "src/Rosetta/music/mus/init.luau"], +[203517, "src/Rosetta/music/okt/init.luau"], +[203799, "src/Rosetta/music/ptm/init.luau"], +[204022, "src/Rosetta/music/s3m/init.luau"], +[204259, "src/Rosetta/music/sf2/init.luau"], +[204303, "src/Rosetta/music/stm/init.luau"], +[204535, "src/Rosetta/music/ult/init.luau"], +[204840, "src/Rosetta/music/umx/init.luau"], +[205057, "src/Rosetta/music/xm/init.luau"], +[205619, "src/Rosetta/music/xmi/init.luau"], +[205828, "src/Rosetta/ops/AudioOps.luau"], +[206307, "src/Rosetta/ops/ImageOps/init.luau"], +[206955, "src/Rosetta/ops/ImageOps/Kernels.luau"], +[207595, "src/Rosetta/ops/LayerOps.luau"], +[207688, "src/Rosetta/ops/MeshOps/init.luau"], +[208828, "src/Rosetta/ops/MeshOps/Greedy.luau"], +[208995, "src/Rosetta/ops/MusicOps.luau"], +[209344, "src/Rosetta/playlist/m3u/init.luau"], +[209697, "src/Rosetta/playlist/pls/init.luau"], +[209875, "src/Rosetta/playlist/xspf/init.luau"], +[210078, "src/Rosetta/subtitle/ass/init.luau"], +[210522, "src/Rosetta/subtitle/srt/init.luau"], +[210695, "src/Rosetta/subtitle/vtt/init.luau"], +[210898, "src/Rosetta/vector/gamemaps/init.luau"], +[211085, "src/Rosetta/vector/gamemaps/Expand.luau"], +[211182, "src/Rosetta/vector/ldtk/init.luau"], +[211274, "src/Rosetta/vector/ldtk/Read.luau"], +[211610, "src/Rosetta/vector/ldtk/Write.luau"], +[212258, "src/Rosetta/vector/ogmo/init.luau"], +[212377, "src/Rosetta/vector/ogmo/Read.luau"], +[212782, "src/Rosetta/vector/ogmo/Write.luau"], +[213136, "src/Rosetta/vector/svg/init.luau"], +[213222, "src/Rosetta/vector/svg/Parse.luau"], +[213968, "src/Rosetta/vector/svg/PathData.luau"], +[214336, "src/Rosetta/vector/svg/Render.luau"], +[214753, "src/Rosetta/vector/svg/Style.luau"], +[215125, "src/Rosetta/vector/svg/Write.luau"], +[215325, "src/Rosetta/vector/tiled/init.luau"], +[215505, "src/Rosetta/vector/tiled/Data.luau"], +[215656, "src/Rosetta/vector/tiled/Tmj.luau"], +[216287, "src/Rosetta/vector/tiled/Tmx.luau"], +[216899, "src/Rosetta/video/avi/init.luau"], +[217193, "src/Rosetta/video/fli/init.luau"], +[217344, "src/Rosetta/video/flv/init.luau"], +[217728, "src/Rosetta/video/flv/Amf.luau"], +[217886, "src/Rosetta/video/flv/Mux.luau"], +[218167, "src/Rosetta/video/h264/init.luau"], +[218306, "src/Rosetta/video/mkv/init.luau"], +[218462, "src/Rosetta/video/mkv/Mux.luau"], +[218741, "src/Rosetta/video/mkv/Parse.luau"], +[219462, "src/Rosetta/video/mp4/init.luau"], +[219790, "src/Rosetta/video/mpegps/init.luau"], +[219977, "src/Rosetta/video/mpegts/init.luau"], +[220223, "src/Rosetta/video/ogv/init.luau"], +[220618, "src/Rosetta/video/smk/init.luau"], +[220927, "src/Rosetta/video/smk/Audio.luau"], +[221047, "src/Rosetta/video/y4m/init.luau"] ] diff --git a/docs/guide/scene.md b/docs/guide/scene.md index 5ba7868..53c1857 100644 --- a/docs/guide/scene.md +++ b/docs/guide/scene.md @@ -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). diff --git a/src/Rosetta/model/blend/Armature.luau b/src/Rosetta/model/blend/Armature.luau index 01e7438..bc4b32e 100644 --- a/src/Rosetta/model/blend/Armature.luau +++ b/src/Rosetta/model/blend/Armature.luau @@ -89,8 +89,9 @@ local function wire(v: Blend.View?): { [string]: { number } }? if not v then return nil end - local out = {} - for key, field in { normal = "solid", select = "select", active = "active" } do + local out: { [string]: { number } } = {} + for _, pair in { { "normal", "solid" }, { "select", "select" }, { "active", "active" } } do + local key, field = pair[1], pair[2] local fld = v.struct.byName[field] local o = fld and v.offset + fld.offset if not o or o + 3 > buffer.len(v.file.buf) then diff --git a/src/Rosetta/model/blend/Mesh.luau b/src/Rosetta/model/blend/Mesh.luau index f890508..a972b34 100644 --- a/src/Rosetta/model/blend/Mesh.luau +++ b/src/Rosetta/model/blend/Mesh.luau @@ -666,11 +666,9 @@ function Mesh.shapes(f: Blend.File, me: Blend.View, nv: number): ({ Shape }, num else index += 1 end - local name = kb:str("name") - if not name or name == "" then - -- unnamed in old files: named as Blender's 2.45 versioning does (Basis, Key 1, Key 2, ...) - name = if isRef then "Basis" else "Key " .. index - end + local stored = kb:str("name") + -- unnamed in old files: named as Blender's 2.45 versioning does (Basis, Key 1, Key 2, ...) + local name: string = if stored and stored ~= "" then stored elseif isRef then "Basis" else "Key " .. index table.insert(out, { name = name, value = kb:num("curval") or 0, relative = kb:num("relative") or 0, data = d, mute = bit32.band(kb:num("flag") or 0, 1) ~= 0, -- KEYBLOCK_MUTE diff --git a/src/Rosetta/model/blend/Prim.luau b/src/Rosetta/model/blend/Prim.luau index 3b30531..570a290 100644 --- a/src/Rosetta/model/blend/Prim.luau +++ b/src/Rosetta/model/blend/Prim.luau @@ -278,7 +278,7 @@ local function targetDeltas(poly: MeshT.Poly, vsrc: { number }, shapes: { MeshT. local t = table.create(n * 3) :: { number } for i = 1, n do local v = vsrc[i] - local w = 1 + local w: number = 1 if def then w = 0 local list = poly.weights and poly.weights[v + 1] or {} diff --git a/src/Rosetta/model/blend/Read.luau b/src/Rosetta/model/blend/Read.luau index 73dc758..e6fb1e0 100644 --- a/src/Rosetta/model/blend/Read.luau +++ b/src/Rosetta/model/blend/Read.luau @@ -3,8 +3,8 @@ -- or Base list before 2.8) with their transforms (euler orders, quaternion, axis angle, delta transforms, parent -- inverse; bone parents), meshes (model/blend/Mesh, model/blend/Prim), materials (Principled BSDF node or the legacy -- colour), images (packed bytes or external uris), cameras, lights (watts to candela / lux as Blender's glTF exporter --- does: 683 lm/W, / 4 pi for point and spot), armatures (bones to joint nodes with the saved pose), skins, shape keys --- and actions sampled into channels. +-- does: 683 lm/W, / 4 pi for point and spot), armatures (bones to joint nodes with the saved pose, rig data through +-- model/blend/Armature), skins, shape keys and actions sampled into channels. local Blend = require("@rosetta/containers/Blend") local Types = require("@rosetta/Types") local Mat4 = require("@rosetta/codecs/model/Mat4") @@ -417,16 +417,16 @@ local function groupNames(ob: Blend.View, me: Blend.View): { string } end local function shapeExtras(shapes: { Mesh.Shape }, ref: number?): ({ string }, { { [string]: any } }) - local names, list = {}, {} + local names: { string }, list: { { [string]: any } } = {}, {} for k, sh in shapes do if k ~= ref then table.insert(names, sh.name) end local rel = shapes[sh.relative + 1] - table.insert(list, { - name = sh.name, value = sh.value, slider_min = sh.min, slider_max = sh.max, mute = sh.mute, - relative_key = if rel then rel.name else nil, vertex_group = sh.vgroup, - }) + local e: { [string]: any } = { name = sh.name, value = sh.value, slider_min = sh.min, slider_max = sh.max, mute = sh.mute } + e.relative_key = if rel then rel.name else nil + e.vertex_group = sh.vgroup + table.insert(list, e) end return names, list end @@ -474,7 +474,7 @@ local function meshOf(ctx: Ctx, ob: Blend.View, lines: boolean): (number?, ArmIn end if #shapes > 1 then local names, list = shapeExtras(shapes, ref) - m.extras.targetNames = names + m.extras = { blend = extras, targetNames = names } extras.shape_keys = list extras.reference_key = if ref then shapes[ref].name else nil end diff --git a/src/Rosetta/model/blend/init.luau b/src/Rosetta/model/blend/init.luau index 0f14405..e62f158 100644 --- a/src/Rosetta/model/blend/init.luau +++ b/src/Rosetta/model/blend/init.luau @@ -4,9 +4,10 @@ -- file's own SDNA). Supports: the scene's objects and collections, transforms with parent inverse and bone parents, -- meshes of every storage generation (MFace, MPoly / MLoop, attribute layers, AttributeStorage) with UV maps, colour -- attributes, custom normals, material slots; Principled BSDF materials; packed and external images; cameras; lights; --- armatures, skins (vertex groups, top 4 weights), shape keys; actions sampled into channels. +-- armatures, skins (vertex groups, top 4 weights), shape keys (relative keys, vertex groups); actions sampled into +-- channels; rig data (bone collections / layers, colours, custom shapes, pose settings, constraint stacks) as extras. -- Not supported: modifiers (listed in meta.source.modifiers), curves / text / metaballs / grease pencil / volumes, --- NLA strips, drivers, constraints, f-curve modifiers, linked libraries, collection instances. +-- NLA strips, drivers, constraint evaluation, f-curve modifiers, linked libraries, collection instances. -- ------------------------------------------------------------------------------------------------ requires local Err = require("@rosetta/core/Err") @@ -32,6 +33,7 @@ local BlendFormat = { export type DecodeOptions = { triangulate: boolean?, -- default true (false: "polygons" primitives) flipV: boolean?, -- default true (glTF's top-left UV origin) + looseEdges: boolean?, -- edges outside faces as "lines" primitives (default false; always for custom shape widgets) collections: boolean?, -- collections as nodes (default true) scene: string?, -- a scene by name (default: the file's current scene) sampleStep: number?, -- frames between animation samples (default 1) diff --git a/src/Rosetta/model/gltf/Write.luau b/src/Rosetta/model/gltf/Write.luau index f4027ce..a94ecd0 100644 --- a/src/Rosetta/model/gltf/Write.luau +++ b/src/Rosetta/model/gltf/Write.luau @@ -447,8 +447,9 @@ function Write.build(scene: Types.Scene, opts: Options?): (Out?, Err.Err?) restore(g, mesh.extras) local tn = mesh.extras and (mesh.extras :: any).targetNames if type(tn) == "table" and #tn > 0 and g.extras == nil then - g.extras = object() - g.extras.targetNames = table.clone(tn) + local ex = object() + ex.targetNames = table.clone(tn) + g.extras = ex end table.insert(meshes, g) end diff --git a/tools/fixtures/docs_blend.py b/tools/fixtures/docs_blend.py index e8f59f1..dc843a7 100644 --- a/tools/fixtures/docs_blend.py +++ b/tools/fixtures/docs_blend.py @@ -1,5 +1,6 @@ # Docs inputs for the .blend section of docs/guide/scene.md (tools/fixtures.py; tools/docs_check.py explains the -# inputs): a small rig saved zstd-compressed by the nixpkgs Blender (a two-bone armature, a skinned cylinder with a +# inputs): a small rig saved zstd-compressed by the nixpkgs Blender (a two-bone armature with a control bone in a bone +# collection, a damped track constraint and an edge-only custom shape outside the scene, a skinned cylinder with a # shape key, a bone action and a Principled material). # tests/gen/docs_blend.luau { files = { ["rig.blend"] = bytes }, vars = { riggedBlendBytes = "rig.blend" } } import importlib.util, os, shutil, subprocess, tempfile @@ -19,7 +20,16 @@ a = arm.edit_bones.new("lower") a.head, a.tail = (0, 0, 0), (0, 0, 1) b = arm.edit_bones.new("upper") b.head, b.tail, b.parent, b.use_connect = (0, 0, 1), (0, 0, 2), a, True +c = arm.edit_bones.new("ctrl") +c.head, c.tail, c.use_deform = (0.5, 0, 2), (0.5, 0, 2.5), False bpy.ops.object.mode_set(mode="OBJECT") +arm.collections.new("Controls").assign(arm.bones["ctrl"]) +ring = bpy.data.meshes.new("WGT_ring") +ring.from_pydata([(math.cos(k * math.pi / 4), math.sin(k * math.pi / 4), 0) for k in range(8)], [(k, (k + 1) % 8) for k in range(8)], []) +bpy.data.collections.new("Widgets").objects.link(bpy.data.objects.new("WGT_ring", ring)) +rig.pose.bones["ctrl"].custom_shape = bpy.data.objects["WGT_ring"] +track = rig.pose.bones["upper"].constraints.new("DAMPED_TRACK") +track.target, track.subtarget = rig, "ctrl" ring = [(math.cos(k * math.pi / 3) * 0.3, math.sin(k * math.pi / 3) * 0.3) for k in range(6)] verts = [(x, y, z) for z in (0, 1, 2) for x, y in ring] faces = [(r * 6 + k, r * 6 + (k + 1) % 6, (r + 1) * 6 + (k + 1) % 6, (r + 1) * 6 + k) for r in range(2) for k in range(6)] @@ -41,6 +51,7 @@ for i in range(18): up.add([i], (i // 6) * 0.5, "REPLACE") tube.shape_key_add(name="Basis") bulge = tube.shape_key_add(name="Bulge") +bulge.slider_max = 2.0 for p in bulge.data: p.co = (p.co[0] * 1.4, p.co[1] * 1.4, p.co[2]) pb = rig.pose.bones["upper"]