model formats (mca..x3d): comments are specs only
This commit is contained in:
1 parent
0bd7b87d2b
commit
b952c10222
49 files changed
+310
-936
No files matched your search
@@ -1,15 +1,7 @@
|
||||
--!strict
|
||||
-- model/md2: Quake II MD2 models ("IDP2" version 8), read into a Scene. Written from the MD2 format description in the
|
||||
-- Quake II source release (qfiles.h: dmdl_t) and the "MD2 file format" notes (David Henry); no code taken.
|
||||
-- Decode: one primitive: the triangles (welded on (vertex, texture coordinate) pairs; MD2 front faces are clockwise,
|
||||
-- the indices are reversed to counter-clockwise as glTF wants), POSITION of frame opts.frame (default 1),
|
||||
-- TEXCOORD_0 = s / skinwidth, t / skinheight (top-left origin), NORMAL computed from the geometry (the stored
|
||||
-- indexes into Quake's normal table are kept as meta.source.normalIndexes = false: that table is not
|
||||
-- redistributable here); every frame as a morph target (codecs/model/Rig: weight k = 1 shows frame k) and one
|
||||
-- animation per frame-name group ("run1".."run6" -> "run", 10 frames per second, LINEAR); the skins as texture
|
||||
-- URIs (the first is the material's base colour texture; mesh.extras.skins lists all). Units are Quake units, z up.
|
||||
-- meta.source = { format, frames, frameNames, skinWidth, skinHeight }.
|
||||
-- Not supported: the GL command list (the triangles carry the same geometry), writing.
|
||||
-- model/md2: Quake II MD2 ("IDP2" v8), from qfiles.h dmdl_t and David Henry's "MD2 file format"; no code taken.
|
||||
-- Supports: clockwise faces reversed, frames as morph targets, animations per frame-name group (10 fps), skin URIs.
|
||||
-- Not supported: the GL command list, writing; Quake's normal table (not redistributable: normals are computed).
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ requires
|
||||
local Err = require("@rosetta/core/Err")
|
||||
@@ -30,10 +22,10 @@ local Md2 = {
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ types
|
||||
export type DecodeOptions = {
|
||||
frame: number?, -- the frame used as the base POSITION (1-based, default 1)
|
||||
morph: boolean?, -- every frame as a morph target + the animations (default true)
|
||||
fps: number?, -- animation frame rate (default 10)
|
||||
maxVertices: number?, -- frames x vertices (default 2^24)
|
||||
frame: number?, -- 1-based, default 1
|
||||
morph: boolean?, -- default true
|
||||
fps: number?, -- default 10
|
||||
maxVertices: number?, -- default 2^24
|
||||
}
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ constants
|
||||
@@ -49,7 +41,6 @@ function Md2.sniff(r: Bytes.Reader): number
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ decode
|
||||
-- group frame names by their name without trailing digits, in file order
|
||||
local function groups(names: { string }, fps: number): { Rig.Range }
|
||||
local out: { Rig.Range } = {}
|
||||
for i, n in names do
|
||||
@@ -99,13 +90,11 @@ function Md2.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Scene?, Err.E
|
||||
return nil, Err.new(Err.CORRUPT, "frame size too small", 16)
|
||||
end
|
||||
local b, base = r.buf, r.base
|
||||
-- skins
|
||||
local skins: { string } = {}
|
||||
for i = 0, nSkins - 1 do
|
||||
local s = buffer.readstring(b, base + oSkins + i * 64, 64)
|
||||
table.insert(skins, (string.match(s, "^[^%z]*")) :: string)
|
||||
end
|
||||
-- weld (xyz, st) pairs
|
||||
local key: { [number]: number } = {}
|
||||
local vx: { number }, vst: { number } = {}, {}
|
||||
local indices: { number } = {}
|
||||
@@ -140,7 +129,6 @@ function Md2.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Scene?, Err.E
|
||||
writef32(uv, (i - 1) * 8 + 4, readi16(b, o + 2) / math.max(sh, 1))
|
||||
end
|
||||
end
|
||||
-- frames
|
||||
local frames: { buffer } = {}
|
||||
local normals: { buffer } = {}
|
||||
local names: { string } = {}
|
||||
|
||||
Reference in new issue
Block a user