ws-cleanup-types: image/pnm, model/*: type lookup tables, table.create results and literals; casts for known values
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
98b3957d51
commit
5ee6736c6e
23 files changed
+139
-137
No files matched your search
@@ -14,7 +14,7 @@ local Types = require("@formats/Types")
|
||||
|
||||
local Write = {}
|
||||
|
||||
local EXT = { ["image/png"] = "png", ["image/jpeg"] = "jpg", ["image/webp"] = "webp", ["image/ktx2"] = "ktx2", ["image/avif"] = "avif", ["image/bmp"] = "bmp", ["image/x-tga"] = "tga", ["image/gif"] = "gif", ["image/tiff"] = "tiff" }
|
||||
local EXT: { [string]: string } = { ["image/png"] = "png", ["image/jpeg"] = "jpg", ["image/webp"] = "webp", ["image/ktx2"] = "ktx2", ["image/avif"] = "avif", ["image/bmp"] = "bmp", ["image/x-tga"] = "tga", ["image/gif"] = "gif", ["image/tiff"] = "tiff" }
|
||||
local RAD = 180 / math.pi
|
||||
|
||||
export type Options = { files: { [string]: any }?, name: string?, upAxis: string?, metersPerUnit: number? }
|
||||
@@ -79,7 +79,7 @@ local function values(acc: Types.Accessor?): ({ number }?, number)
|
||||
return nil, 0
|
||||
end
|
||||
local n, c = acc.count, acc.components
|
||||
local out = table.create(n * c)
|
||||
local out = table.create(n * c) :: { number }
|
||||
for i = 0, n - 1 do
|
||||
for k = 0, c - 1 do
|
||||
out[i * c + k + 1] = get(i, k)
|
||||
@@ -123,14 +123,14 @@ type Merged = {
|
||||
local function faces(p: Types.Primitive, nverts: number): ({ number }?, { number }?)
|
||||
local idx: { number }
|
||||
if p.indices then
|
||||
idx = (values(p.indices)) or {}
|
||||
idx = (values(p.indices)) or {} :: { number }
|
||||
else
|
||||
idx = table.create(nverts)
|
||||
idx = table.create(nverts) :: { number }
|
||||
for i = 1, nverts do
|
||||
idx[i] = i - 1
|
||||
end
|
||||
end
|
||||
local counts, out = {}, {}
|
||||
local counts: { number }, out: { number } = {}, {}
|
||||
local mode = p.mode
|
||||
if mode == "triangles" or mode == nil then
|
||||
for k = 1, #idx - 2, 3 do
|
||||
@@ -180,7 +180,7 @@ end
|
||||
local function merge(mesh: Types.Mesh, notes: { [string]: number }): Merged?
|
||||
local prims: { Types.Primitive } = {}
|
||||
for _, p in mesh.primitives do
|
||||
if p.attributes and p.attributes.POSITION and p.attributes.POSITION.components == 3 and p.mode ~= "lines" and p.mode ~= "line_strip" and p.mode ~= "line_loop" and p.mode ~= "points" then
|
||||
if p.attributes and p.attributes.POSITION and (p.attributes.POSITION :: Types.Accessor).components == 3 and p.mode ~= "lines" and p.mode ~= "line_strip" and p.mode ~= "line_loop" and p.mode ~= "points" then
|
||||
table.insert(prims, p)
|
||||
else
|
||||
notes["lines / points primitives"] = (notes["lines / points primitives"] or 0) + 1
|
||||
@@ -318,7 +318,7 @@ function Write.text(scene: Types.Scene, opts: Options?): (string, { [string]: nu
|
||||
local rootName = if wrap then "root" else rootNames(nodes[roots[1]].name, "root")
|
||||
|
||||
-- texture files
|
||||
local base = o.name and string.gsub(string.match(o.name, "([^/\\]+)$") or o.name, "%.[^.]*$", "") or "model"
|
||||
local base: string = o.name and string.gsub(string.match(o.name, "([^/\\]+)$") or o.name, "%.[^.]*$", "") or "model"
|
||||
local texFile: { [number]: string } = {}
|
||||
for i, tex in scene.textures or {} do
|
||||
local uri: string? = if tex.uri then (string.gsub(tex.uri, "\\", "/")) else nil
|
||||
@@ -340,7 +340,7 @@ function Write.text(scene: Types.Scene, opts: Options?): (string, { [string]: nu
|
||||
|
||||
-- animation: per node, per path -> { times, values (components) }
|
||||
type Track = { times: { number }, vals: { number }, comps: number }
|
||||
local tracks: { [number]: { [string]: Track } } = {}
|
||||
local tracks: { [number]: { [string]: Track? } } = {}
|
||||
local tcps = 24
|
||||
local tMin, tMax = math.huge, -math.huge
|
||||
for _, anim in scene.animations or {} do
|
||||
@@ -399,7 +399,7 @@ function Write.text(scene: Types.Scene, opts: Options?): (string, { [string]: nu
|
||||
|
||||
-- xform ops of a node (+ its animation)
|
||||
local function xform(depth: number, ni: number, n: Types.Node)
|
||||
local tr = tracks[ni]
|
||||
local tr: { [string]: Track? }? = tracks[ni]
|
||||
local order: { string } = {}
|
||||
local function samples(track: Track, f: (vals: { number }, at: number) -> string): string
|
||||
local parts = {}
|
||||
@@ -438,7 +438,7 @@ function Write.text(scene: Types.Scene, opts: Options?): (string, { [string]: nu
|
||||
line(depth, "double3 xformOp:translate = " .. tuple({ t[1] or 0, t[2] or 0, t[3] or 0 }))
|
||||
end
|
||||
if tr and tr.translation then
|
||||
line(depth, "double3 xformOp:translate.timeSamples = " .. samples(tr.translation, vec3))
|
||||
line(depth, "double3 xformOp:translate.timeSamples = " .. samples(tr.translation :: Track, vec3))
|
||||
end
|
||||
table.insert(order, '"xformOp:translate"')
|
||||
end
|
||||
@@ -447,7 +447,7 @@ function Write.text(scene: Types.Scene, opts: Options?): (string, { [string]: nu
|
||||
line(depth, "quatf xformOp:orient = " .. quat(r, 0))
|
||||
end
|
||||
if tr and tr.rotation then
|
||||
line(depth, "quatf xformOp:orient.timeSamples = " .. samples(tr.rotation, quat))
|
||||
line(depth, "quatf xformOp:orient.timeSamples = " .. samples(tr.rotation :: Track, quat))
|
||||
end
|
||||
table.insert(order, '"xformOp:orient"')
|
||||
end
|
||||
@@ -456,7 +456,7 @@ function Write.text(scene: Types.Scene, opts: Options?): (string, { [string]: nu
|
||||
line(depth, "float3 xformOp:scale = " .. tuple({ s[1] or 1, s[2] or 1, s[3] or 1 }))
|
||||
end
|
||||
if tr and tr.scale then
|
||||
line(depth, "float3 xformOp:scale.timeSamples = " .. samples(tr.scale, vec3))
|
||||
line(depth, "float3 xformOp:scale.timeSamples = " .. samples(tr.scale :: Track, vec3))
|
||||
end
|
||||
table.insert(order, '"xformOp:scale"')
|
||||
end
|
||||
@@ -570,7 +570,7 @@ function Write.text(scene: Types.Scene, opts: Options?): (string, { [string]: nu
|
||||
line(depth, "float verticalAperture = " .. fmt(vap))
|
||||
end
|
||||
|
||||
local LIGHT_TYPE = { directional = "DistantLight", point = "SphereLight", spot = "SphereLight" }
|
||||
local LIGHT_TYPE: { [string]: string } = { directional = "DistantLight", point = "SphereLight", spot = "SphereLight" }
|
||||
local function lightBody(depth: number, l: Types.Light)
|
||||
local c = l.color or { 1, 1, 1 }
|
||||
line(depth, "color3f inputs:color = " .. tuple({ c[1] or 1, c[2] or 1, c[3] or 1 }))
|
||||
@@ -808,7 +808,7 @@ function Write._looks(out: { string }, depth: number, scene: Types.Scene, matPat
|
||||
stSource = path .. "/" .. tn.name .. "_Transform.outputs:result"
|
||||
end
|
||||
local tex = scene.textures[ref.texture]
|
||||
local sampler = tex and tex.sampler or {}
|
||||
local sampler: Types.Sampler = tex and tex.sampler or {}
|
||||
table.insert(out, "")
|
||||
line(d, 'def Shader "' .. tn.name .. '"')
|
||||
line(d, "{")
|
||||
|
||||
Reference in new issue
Block a user