model formats (3ds..lwo): comments are specs only
This commit is contained in:
1 parent
0bd7b87d2b
commit
3bddd582bc
35 files changed
+233
-697
No files matched your search
@@ -1,22 +1,7 @@
|
||||
--!strict
|
||||
-- model/gltf: glTF 2.0 (Khronos specification 2.0.1), JSON (.gltf with embedded data: URIs or external files) and
|
||||
-- binary (.glb). New code.
|
||||
-- Reads: scenes, the node tree (TRS / matrix), meshes (every primitive mode, morph targets), accessors of every
|
||||
-- component type (normalized -> unorm / snorm, sparse, byte strides, padded matrix columns, no bufferView), PBR
|
||||
-- materials + the KHR_materials_* extensions (emissive_strength, unlit, clearcoat, transmission, volume, ior,
|
||||
-- specular, sheen, iridescence, anisotropy, dispersion, diffuse_transmission, pbrSpecularGlossiness: their fields kept,
|
||||
-- textureInfo objects as TextureRefs), KHR_texture_transform, textures + samplers + images (kept encoded: bytes + mime,
|
||||
-- or the uri; KHR_texture_basisu / EXT_texture_webp / EXT_texture_avif sources), cameras, KHR_lights_punctual, skins,
|
||||
-- animations, KHR_mesh_quantization, extras and unknown extensions (written back). Images are never decoded here (a
|
||||
-- format does not require another format): F.model.loadTextures(scene) decodes them at the api layer.
|
||||
-- External .bin / image files come from opts.resolve(uri) or opts.files[uri] (the api sets resolve for paths).
|
||||
-- Writes .gltf (buffers and images embedded as data: URIs by default; opts.external = true writes <name>.bin and the
|
||||
-- images into opts.files) or .glb (opts.binary, or opts.format == "glb": the api passes the destination's extension).
|
||||
-- Draco compressed primitives (KHR_draco_mesh_compression) decode through codecs/model/Draco: the attributes the
|
||||
-- extension lists and the indices come from the Draco data, as the types their accessors declare. Written back
|
||||
-- uncompressed (the extension is dropped).
|
||||
-- Not supported: meshopt (EXT_meshopt_compression) compressed primitives (UNSUPPORTED), KHR_animation_pointer channels
|
||||
-- (skipped and counted in the animation's extras).
|
||||
-- model/gltf: glTF 2.0 (Khronos specification 2.0.1), .gltf JSON and .glb. Supports: the core spec, KHR_materials_*,
|
||||
-- KHR_texture_transform, KHR_lights_punctual, KHR_mesh_quantization, KHR_draco_mesh_compression (written uncompressed).
|
||||
-- Not supported: EXT_meshopt_compression (UNSUPPORTED), KHR_animation_pointer channels (skipped).
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ requires
|
||||
local Err = require("@rosetta/core/Err")
|
||||
@@ -40,16 +25,16 @@ local Gltf = {
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ types
|
||||
export type DecodeOptions = {
|
||||
resolve: ((uri: string) -> any)?, -- external .bin / image files (buffer or string); the api sets it for paths
|
||||
files: { [string]: any }?, -- or: the files by uri
|
||||
maxBytes: number?, -- refuse buffers / accessors over this many bytes in total (default 2^30)
|
||||
resolve: ((uri: string) -> any)?, -- external .bin / image files (buffer or string)
|
||||
files: { [string]: any }?,
|
||||
maxBytes: number?, -- default 2^30 bytes of buffers / accessors
|
||||
}
|
||||
export type EncodeOptions = {
|
||||
binary: boolean?, -- write GLB (default: when opts.format is "glb")
|
||||
format: string?, -- "glb" -> binary (set by the api from the destination's extension)
|
||||
external: boolean?, -- .gltf: write the buffer and images as files into opts.files (default false: data: URIs)
|
||||
binary: boolean?, -- default: when opts.format is "glb"
|
||||
format: string?,
|
||||
external: boolean?, -- default false: data: URIs
|
||||
files: { [string]: any }?, -- receives <name>.bin and images with external = true
|
||||
name: string?, -- the destination's file name (names the external files)
|
||||
name: string?,
|
||||
embedImages: boolean?, -- default true (false with external = true)
|
||||
}
|
||||
|
||||
@@ -98,7 +83,6 @@ local function fetcher(opts: DecodeOptions?): Read.Fetch
|
||||
end
|
||||
end
|
||||
|
||||
-- the JSON text and BIN chunk of a GLB
|
||||
local function glb(r: Bytes.Reader): (string?, buffer?, Err.Err?)
|
||||
local magic, version, length = r:u32le(), r:u32le(), r:u32le()
|
||||
if r.err then
|
||||
@@ -178,7 +162,6 @@ function Gltf.encode(scene: Types.Scene, opts: EncodeOptions?): (buffer?, Err.Er
|
||||
local doc = out.doc
|
||||
local base = opts and opts.name and string.gsub(string.match(opts.name, "([^/\\]+)$") or opts.name, "%.[^.]*$", "") or "model"
|
||||
local files = opts and opts.files
|
||||
-- images: data: URIs, or files
|
||||
if doc.images then
|
||||
local n = 0
|
||||
for _, im in doc.images do
|
||||
|
||||
Reference in new issue
Block a user