model formats (3ds..lwo): comments are specs only

This commit is contained in:
4DBug committed 2026-11-01 01:53:16 -05:00
1 parent 0bd7b87d2b
commit 3bddd582bc
35 files changed
+233 -697

No files matched your search

+6 -19
View File
@@ -1,11 +1,6 @@
--!strict
-- model/fbx/Write: Scene -> an FBX 7.4 node tree (model/fbx/Binary.write / Ascii.write serialize it). Property types
-- follow what Blender's and the FBX SDK's readers check (ids L, ints I, doubles D, KTime L, arrays d / i / l / f).
-- Nodes -> Model (Mesh / Null / LimbNode / Camera / Light) with Lcl T / R (Euler XYZ degrees) / S; meshes -> one
-- Geometry (primitives merged; triangles, polygons, strips and fans; control points = the Scene vertices; normals
-- ByVertice, uvs and colours ByPolygonVertex IndexToDirect, materials ByPolygon); materials -> Phong Material;
-- textures -> Texture + Video (Content embedded); skins -> Skin + Cluster deformers + BindPose; morph targets ->
-- BlendShape / BlendShapeChannel / Shape; animations -> AnimationStack / Layer / CurveNode / Curve.
-- model/fbx/Write: Scene -> an FBX 7.4 node tree. Property types follow what Blender's and the FBX SDK's readers check
-- (ids L, ints I, doubles D, KTime L, arrays d / i / l / f); rotations as Euler XYZ degrees.
local Err = require("@rosetta/core/Err")
local Types = require("@rosetta/Types")
local Mat4 = require("@rosetta/codecs/model/Mat4")
@@ -28,7 +23,7 @@ local function arr(t: string, list: { number }): any
end
return { array = true, type = t, count = n, data = d }
end
-- P: name, type, label, flags, values (vt: one type character per value)
-- P: name, type, label, flags, values
local function P(name: string, ptype: string, label: string, flags: string, vt: string, ...: any): WNode
return { name = "P", types = "SSSS" .. vt, props = { name, ptype, label, flags, ... } }
end
@@ -64,7 +59,6 @@ local function accessorReader(acc: Types.Accessor?): ((i: number, c: number) ->
return Types.Scene.reader(acc)
end
-- primitive -> triangles / polygons as a list of corner lists (vertex indices, 0-based)
local function faces(prim: Types.Primitive): { { number } }?
local pos = prim.attributes.POSITION
if not pos then
@@ -235,7 +229,6 @@ function Write.tree(scene: Types.Scene, opts: any?): (WNode?, Err.Err?)
link(m.baseColorTexture, "DiffuseColor")
link(m.normalTexture, "NormalMap")
link(m.emissiveTexture, "EmissiveColor")
-- the other textures the FBX material had (specular, metalness, ... maps), under their property names
local linked = {
[m.baseColorTexture and m.baseColorTexture.texture or -1] = true,
[m.normalTexture and m.normalTexture.texture or -1] = true,
@@ -260,7 +253,7 @@ function Write.tree(scene: Types.Scene, opts: any?): (WNode?, Err.Err?)
-- ------------------------------------------------------------------------------------------ models
local modelIds: { [number]: number } = {}
local skip: { [number]: boolean } = {}
local attrHost: { [number]: number } = {} -- orientation node -> its parent node (the attribute moves there)
local attrHost: { [number]: number } = {}
local parentOf: { [number]: number } = {}
for i, nd in nodes do
for _, c in nd.children or {} do
@@ -283,7 +276,6 @@ function Write.tree(scene: Types.Scene, opts: any?): (WNode?, Err.Err?)
attrHost[i] = p
end
end
-- world matrices (rest pose) for clusters and the bind pose
local worldM: { [number]: Mat4.M4 } = {}
local visiting: { [number]: boolean } = {}
local function world(i: number): Mat4.M4
@@ -390,7 +382,6 @@ function Write.tree(scene: Types.Scene, opts: any?): (WNode?, Err.Err?)
local euler = Mat4.eulerXYZ(r)
local ftype = nd.extras and (nd.extras :: any).fbx and (nd.extras :: any).fbx.type
local sub = if nd.mesh then "Mesh" elseif jointSet[i] or ftype == "LimbNode" then "LimbNode" else "Null"
-- an orientation child folded into this node gives it its attribute
local folded: number? = nil
for c, host in pairs(attrHost) do -- pairs: a sparse integer map (compat __iter takes it for an array)
if host == i then
@@ -430,9 +421,9 @@ function Write.tree(scene: Types.Scene, opts: any?): (WNode?, Err.Err?)
-- ------------------------------------------------------------------------------------------ geometry
local geoIds: { [number]: number } = {}
local geoSlots: { [number]: { number } } = {} -- mesh -> material indices by slot
local geoSlots: { [number]: { number } } = {}
local geoVerts: { [number]: { { prim: Types.Primitive, offset: number } } } = {}
local geoChannels: any = {} -- mesh index -> blend shape channel ids (for weights animation)
local geoChannels: any = {}
local geoCount: { [number]: number } = {}
local function geometry(mi: number): number?
if geoIds[mi] then
@@ -625,7 +616,6 @@ function Write.tree(scene: Types.Scene, opts: any?): (WNode?, Err.Err?)
geoSlots[mi] = if anyMat then slots else {}
geoVerts[mi] = layout
geoCount[mi] = offset
-- morph targets
local prims = mesh.primitives
local ntargets = 0
for _, l in layout do
@@ -717,7 +707,6 @@ function Write.tree(scene: Types.Scene, opts: any?): (WNode?, Err.Err?)
OO(pm, mid)
end
end
-- skin: one Skin per (geometry, skin)
local skin = nd.skin and scene.skins[nd.skin]
local key = tostring(gid) .. ":" .. tostring(nd.skin)
if skin and not skinned[key] then
@@ -728,7 +717,6 @@ function Write.tree(scene: Types.Scene, opts: any?): (WNode?, Err.Err?)
local meshWorld = world(i)
pose(mid, meshWorld)
local ibm = accessorReader(skin.inverseBindMatrices)
-- per joint: control points and weights
local perJoint: { { idx: { number }, w: { number } } } = {}
for j in skin.joints do
perJoint[j] = { idx = {}, w = {} }
@@ -878,7 +866,6 @@ function Write.tree(scene: Types.Scene, opts: any?): (WNode?, Err.Err?)
end
table.insert(layerNodes, { spec[1], lid, mid, spec[2], { X, Y, Z }, times, { "X", "Y", "Z" }, step })
else
-- weights: one DeformPercent curve per blend shape channel of the node's mesh
local nd = nodes[ch.node]
local gc: any = geoChannels
local chans = nd.mesh and gc[nd.mesh]