model formats (mca..x3d): comments are specs only

This commit is contained in:
4DBug committed 2026-11-01 01:54:32 -05:00
1 parent 0bd7b87d2b
commit b952c10222
49 files changed
+310 -936

No files matched your search

+15 -29
View File
@@ -1,20 +1,8 @@
--!strict
-- model/usda: USD ASCII layers (.usda, .usd in text form) and USDZ packages holding them. New code, from the Sdf text
-- format and the UsdGeom / UsdShade / UsdLux schema documentation (OpenUSD 26.x); checked against OpenUSD's own
-- reader / writer (pxr) and Blender's USD exporter.
-- Reads: stage metadata (upAxis -> meta.up, metersPerUnit -> meta.unit, defaultPrim, timeCodesPerSecond, start /
-- endTimeCode), the prim tree (def / over; class skipped; selected variants merged), xform op stacks (translate, scale,
-- rotateX/Y/Z, rotateXYZ ... rotateZYX, orient, transform, !invert!, !resetXformStack!) with time samples -> one
-- animation of TRS channels, Mesh (faceVertexCounts / Indices, holes, leftHanded orientation, normals, every
-- texCoord2f primvar -> TEXCOORD_n with st first, displayColor / displayOpacity, all interpolations, :indices,
-- GeomSubsets -> one primitive each), UsdPreviewSurface materials with UsdUVTexture / UsdPrimvarReader_float2 /
-- UsdTransform2d, material:binding (inherited, per subset), Camera, DistantLight / SphereLight (+ ShapingAPI cone ->
-- spot) / RectLight / DiskLight (-> spot lights over a hemisphere). Textures stay encoded: bytes from opts.files /
-- opts.resolve (or the USDZ package) + mime, else just the uri (F.model.loadTextures decodes them).
-- Writes .usda (see model/usda/Write): Xform / Mesh / GeomSubset / Material / Shader / Camera / lights, time samples.
-- Not supported: USDC binary crate files (.usdc, and .usd / USDZ holding one: UNSUPPORTED), composition arcs
-- (references, payloads, inherits, specializes, subLayers: ignored and listed in meta.source.unsupported), UsdSkel
-- skinning, blend shapes, curves / points / NURBS prims, point instancers, MaterialX shading networks, writing USDZ.
-- model/usda: USD ASCII layers (.usda, text .usd) and USDZ packages of them, from the Sdf text format and the UsdGeom /
-- UsdShade / UsdLux docs (OpenUSD 26.x), checked against pxr and Blender's exporter. Not supported: USDC crate files,
-- composition arcs (listed in meta.source.unsupported), UsdSkel, blend shapes, curves / points / NURBS, instancers,
-- MaterialX, writing USDZ.
-- ------------------------------------------------------------------------------------------------ requires
local Err = require("@rosetta/core/Err")
@@ -37,18 +25,18 @@ local Usda = {
-- ------------------------------------------------------------------------------------------------ types
export type DecodeOptions = {
triangulate: boolean?, -- fan-triangulate faces (default true); false keeps "polygons" primitives
flipV: boolean?, -- TEXCOORD_n.v = 1 - v (default true: glTF's top-left origin)
resolve: ((uri: string) -> any)?, -- texture files next to the layer (the api sets it for paths)
files: { [string]: any }?, -- or: the files by asset path
maxVertices: number?, -- refuse meshes with more points / face corners (default 2^25)
maxBytes: number?, -- refuse numeric arrays over this many bytes (default 2^30)
triangulate: boolean?, -- default true
flipV: boolean?, -- default true
resolve: ((uri: string) -> any)?,
files: { [string]: any }?,
maxVertices: number?, -- default 2^25
maxBytes: number?, -- default 2^30
}
export type EncodeOptions = {
files: { [string]: any }?, -- receives embedded texture bytes as <name>_<n>.<ext>
name: string?, -- the destination's file name (names the texture files)
format: string?, -- "usdz" -> UNSUPPORTED (set by the api from the destination's extension)
upAxis: string?, -- "Y" / "Z" (default: from scene.meta.up)
files: { [string]: any }?, -- as <name>_<n>.<ext>
name: string?,
format: string?, -- "usdz" -> UNSUPPORTED
upAxis: string?, -- default: from scene.meta.up
metersPerUnit: number?, -- default scene.meta.unit or 1
}
@@ -57,7 +45,6 @@ local function isUsdz(r: Bytes.Reader): boolean
if r:peek(4) ~= "PK\3\4" then
return false
end
-- the first entry is the root layer
local lo, hi = r:peekU8(26), r:peekU8(27)
if lo < 0 or hi < 0 then
return false
@@ -74,7 +61,7 @@ function Usda.sniff(r: Bytes.Reader): number
return 1
end
if head == "PXR-USDC" then
return 0.9 -- recognised so the error says USDC is not supported
return 0.9 -- USDC magic, so the error says it is unsupported
end
if isUsdz(r) then
return 0.95
@@ -209,7 +196,6 @@ function Usda.encode(scene: Types.Scene, opts: EncodeOptions?): (buffer?, Err.Er
end
-- ------------------------------------------------------------------------------------------------ extras
-- parse(text) -> the raw layer (prim specs, properties, metadata) | nil, Err: for prims the Scene does not cover
function Usda.parse(text: string): (Parse.Layer?, Err.Err?)
local layer, msg, at = Parse.layer(text)
if not layer then