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

+4 -16
View File
@@ -1,11 +1,6 @@
--!strict
-- model/3mf/Read: a 3MF package (an OPC zip) -> Scene. The root model part from _rels/.rels (fallback: the first
-- *.model under 3D/), other model parts referenced by the production extension's p:path (components and build items),
-- core resources (objects with mesh vertices / triangles, components with transforms), the materials extension
-- (basematerials, colorgroup, texture2d + texture2dgroup, compositematerials blended into one colour per entry,
-- multiproperties resolved through their first layer), build items with transforms -> root nodes, metadata, the unit.
-- Triangles are grouped into one primitive per property (a base material, a colour group, a texture group); colour and
-- texture groups give per-corner COLOR_0 / TEXCOORD_0, so vertices are split where corners of one vertex differ.
-- model/3mf/Read: a 3MF package -> Scene. The root model part comes from _rels/.rels (fallback: the first *.model under
-- 3D/); vertices are split where corners of one vertex carry different colours / texture coordinates.
local Err = require("@rosetta/core/Err")
local Types = require("@rosetta/Types")
local Xml = require("@rosetta/codecs/text/Xml")
@@ -21,7 +16,6 @@ local MAX_DEPTH = 64
local localName = Xml.localName
-- an attribute by local name (namespaced attributes such as p:path)
local function attr(node: any, name: string): string?
local a = node.attrs
local v = a[name]
@@ -44,7 +38,7 @@ local function int(s: string?): number?
return nil
end
-- "#RRGGBB" / "#RRGGBBAA" -> { r, g, b, a } sRGB 0..1
-- "#RRGGBB" / "#RRGGBBAA", sRGB
local function hexColor(s: string?): { number }?
if type(s) ~= "string" then
return nil
@@ -68,7 +62,7 @@ function Read.toLinear(c: number): number
end
local toLinear = Read.toLinear
-- "m00 m01 m02 m10 ... m32" (3MF row-vector convention) -> a column-major glTF matrix, nil for identity / invalid
-- "m00 m01 m02 m10 ... m32": 3MF's row-vector convention
local function transform(s: string?): ({ number }?, boolean)
if not s then
return nil, true
@@ -99,7 +93,6 @@ local function normPath(p: string): string
return p
end
-- one model part parsed into its resources and build
type Model = { path: string, unit: string?, metadata: { [string]: string }, res: { [number]: any }, items: { any }, required: string? }
local function parseModel(text: string, path: string, opts: any): (Model?, Err.Err?)
@@ -253,7 +246,6 @@ local function parseModel(text: string, path: string, opts: any): (Model?, Err.E
return model, nil
end
-- the root model part's path
local function rootPath(zip: any): string?
local rels = zip:readString("_rels/.rels")
if rels then
@@ -313,7 +305,6 @@ function Read.scene(zip: any, opts: any): (Types.Scene?, Err.Err?)
scene.meta.metadata = root.metadata
scene.meta.source = { format = "3mf", unit = unitName, part = rootP, requiredExtensions = root.required }
-- textures and materials (shared across model parts by part path + resource id)
local texCache: { [string]: number } = {}
local function texture(model: Model, id: number): number?
local key = model.path .. "#" .. id
@@ -359,7 +350,6 @@ function Read.scene(zip: any, opts: any): (Types.Scene?, Err.Err?)
return m
end
-- property of one corner -> (group key, material index?, kind, resource, index)
local function resolve(model: Model, pid: number, p: number, depth: number?): (string, number?, string, any, number)
local r = model.res[pid]
if not r or p < 0 then
@@ -429,7 +419,6 @@ function Read.scene(zip: any, opts: any): (Types.Scene?, Err.Err?)
return "none", nil, "none", nil, 0
end
-- one Scene mesh per (part, object) with a mesh
local meshCache: { [string]: number } = {}
local function buildMesh(model: Model, o: any): number?
local key = model.path .. "#" .. o.id
@@ -532,7 +521,6 @@ function Read.scene(zip: any, opts: any): (Types.Scene?, Err.Err?)
return #scene.meshes
end
-- nodes: one per object instance (build items and components)
local nodeCount = 0
local maxNodes = opts.maxNodes or 2 ^ 20
local instantiate: (model: Model, oid: number, matrix: { number }?, depth: number, extra: any) -> (number?, Err.Err?)