diff --git a/licenses/NOTICE.md b/licenses/NOTICE.md index 383183a..23a8c74 100644 --- a/licenses/NOTICE.md +++ b/licenses/NOTICE.md @@ -7,6 +7,7 @@ | `tests/fixtures/pngsuite/` | PngSuite by Willem van Schaik | [PngSuite-LICENSE.txt](PngSuite-LICENSE.txt) | | `tests/fixtures/vox/{chr_knight,chr_sword,deer,maze}.vox`, `tests/fixtures/vox/MagicaVoxel-file-format-vox*.txt` (the format spec) | ephtracy/voxel-model (MagicaVoxel sample models) | MIT: [voxel-model-LICENSE.txt](voxel-model-LICENSE.txt) | | `tests/fixtures/vox/ogt_*.vox` | jpaver/opengametools `demo/vox/` (files saved by MagicaVoxel 0.99.x) | MIT: [opengametools-LICENSE.txt](opengametools-LICENSE.txt) | +| `tests/fixtures/gltf/` | KhronosGroup/glTF-Sample-Assets `Models/` (one LICENSE.md per model folder; `UnicodeTest` is `Unicode❤♻Test` renamed) | CC-BY-4.0 or CC0-1.0 per model, see each folder's LICENSE.md | Ports of third-party code (minimp3, stb_vorbis, libopus, ...) add a row here and their upstream licence text in this folder (see docs/STYLE.md, "Absorbing an existing repo"). diff --git a/src/Formats/model/gltf/Pack.luau b/src/Formats/model/gltf/Pack.luau new file mode 100644 index 0000000..470d384 --- /dev/null +++ b/src/Formats/model/gltf/Pack.luau @@ -0,0 +1,74 @@ +--!strict +--!native +-- model/gltf/Pack: the byte loops of glTF accessors: strided / column-padded elements into tightly packed Scene +-- accessor data (gather), the reverse for writing (scatter), and sparse substitution. Callers check every range +-- first (offsets, strides and counts against the buffer lengths); nothing here throws. +local Pack = {} + +local bcopy, readu8, readu16, readu32 = buffer.copy, buffer.readu8, buffer.readu16, buffer.readu32 + +-- gather(dst, src, off, count, elem, stride, cols, colBytes, colStride): element i starts at off + i * stride; an element is +-- cols columns of colBytes bytes, colStride apart (glTF pads matrix columns to 4 bytes); dst gets them packed (elem = +-- cols * colBytes bytes each) +function Pack.gather(dst: buffer, src: buffer, off: number, count: number, elem: number, stride: number, cols: number, colBytes: number, colStride: number) + if cols == 1 or colBytes == colStride then + if stride == elem then + bcopy(dst, 0, src, off, count * elem) + return + end + for i = 0, count - 1 do + bcopy(dst, i * elem, src, off + i * stride, elem) + end + return + end + for i = 0, count - 1 do + local s = off + i * stride + local d = i * elem + for c = 0, cols - 1 do + bcopy(dst, d + c * colBytes, src, s + c * colStride, colBytes) + end + end +end + +-- scatter(dst, at, src, count, elem, stride, cols, colBytes, colStride): the reverse of gather (dst zero-filled) +function Pack.scatter(dst: buffer, at: number, src: buffer, count: number, elem: number, stride: number, cols: number, colBytes: number, colStride: number) + if cols == 1 or colBytes == colStride then + if stride == elem then + bcopy(dst, at, src, 0, count * elem) + return + end + for i = 0, count - 1 do + bcopy(dst, at + i * stride, src, i * elem, elem) + end + return + end + for i = 0, count - 1 do + local d = at + i * stride + local s = i * elem + for c = 0, cols - 1 do + bcopy(dst, d + c * colStride, src, s + c * colBytes, colBytes) + end + end +end + +-- sparse(dst, count, elem, idx, idxOff, idxSize, values, valOff, n) -> false when an index is out of range: element +-- idx[k] of dst becomes value k (values packed, elem bytes each) +function Pack.sparse(dst: buffer, count: number, elem: number, idx: buffer, idxOff: number, idxSize: number, values: buffer, valOff: number, n: number): boolean + for k = 0, n - 1 do + local i + if idxSize == 1 then + i = readu8(idx, idxOff + k) + elseif idxSize == 2 then + i = readu16(idx, idxOff + k * 2) + else + i = readu32(idx, idxOff + k * 4) + end + if i >= count then + return false + end + bcopy(dst, i * elem, values, valOff + k * elem, elem) + end + return true +end + +return Pack diff --git a/src/Formats/model/gltf/Read.luau b/src/Formats/model/gltf/Read.luau new file mode 100644 index 0000000..ab59fe6 --- /dev/null +++ b/src/Formats/model/gltf/Read.luau @@ -0,0 +1,661 @@ +--!strict +-- model/gltf/Read: a parsed glTF 2.0 JSON document (+ its buffers) -> Scene. Accessors of every component type +-- (normalized ones as unorm / snorm, matrices with their column padding removed, byte strides, sparse substitution, +-- accessors without a bufferView as zeros), images kept encoded (bufferView / data: URI / external file through the +-- fetch callback), samplers, PBR materials with every material extension (textureInfo objects -> TextureRefs), the +-- KHR_texture_transform of every texture reference, cameras, KHR_lights_punctual, skins, animations, morph targets, +-- scenes. glTF extras and unhandled extensions are kept in .extras.gltf = { extras, extensions }. +local Err = require("@formats/core/Err") +local Types = require("@formats/Types") +local Base64 = require("@formats/codecs/Base64") +local Pack = require("@formats/model/gltf/Pack") + +local Read = {} + +local COMPONENT: { [number]: { string } } = { + [5120] = { "i8", "snorm8" }, + [5121] = { "u8", "unorm8" }, + [5122] = { "i16", "snorm16" }, + [5123] = { "u16", "unorm16" }, + [5125] = { "u32", "" }, + [5126] = { "f32", "" }, +} +local SIZE = { [5120] = 1, [5121] = 1, [5122] = 2, [5123] = 2, [5125] = 4, [5126] = 4 } +local TYPE_COMPONENTS = { SCALAR = 1, VEC2 = 2, VEC3 = 3, VEC4 = 4, MAT2 = 4, MAT3 = 9, MAT4 = 16 } +local TYPE_COLUMNS = { MAT2 = 2, MAT3 = 3, MAT4 = 4 } +local MODES = { [0] = "points", [1] = "lines", [2] = "line_loop", [3] = "line_strip", [4] = "triangles", [5] = "triangle_strip", [6] = "triangle_fan" } +local WRAP = { [33071] = "clamp", [33648] = "mirror", [10497] = "repeat" } +local MIN_FILTER = { [9728] = "nearest", [9729] = "linear", [9984] = "nearest_mipmap_nearest", [9985] = "linear_mipmap_nearest", [9986] = "nearest_mipmap_linear", [9987] = "linear_mipmap_linear" } +-- the extensions this reader understands (everything else that is required -> UNSUPPORTED) +local KNOWN = { + KHR_lights_punctual = true, + KHR_mesh_quantization = true, + KHR_texture_transform = true, + KHR_materials_emissive_strength = true, + KHR_materials_unlit = true, + KHR_materials_clearcoat = true, + KHR_materials_transmission = true, + KHR_materials_volume = true, + KHR_materials_ior = true, + KHR_materials_specular = true, + KHR_materials_sheen = true, + KHR_materials_iridescence = true, + KHR_materials_anisotropy = true, + KHR_materials_dispersion = true, + KHR_materials_diffuse_transmission = true, + KHR_materials_variants = true, + KHR_materials_pbrSpecularGlossiness = true, + KHR_texture_basisu = true, -- the image stays encoded (image/ktx2) + EXT_texture_webp = true, + EXT_texture_avif = true, + KHR_node_visibility = true, + KHR_xmp_json_ld = true, +} +Read.KNOWN = KNOWN + +export type Fetch = (uri: string) -> buffer? +type View = { buf: buffer, offset: number, length: number, stride: number? } +type Img = { data: buffer?, mime: string?, uri: string?, name: string? } + +local function num(v: any, default: number): number + return if type(v) == "number" then v else default +end +local function int(v: any): number? + return if type(v) == "number" and v == math.floor(v) and v >= 0 then v else nil +end +local function arr(v: any): { any } + return if type(v) == "table" then v else {} +end +local function str(v: any): string? + return if type(v) == "string" then v else nil +end +local function numbers(v: any, n: number): { number }? + if type(v) ~= "table" or #v ~= n then + return nil + end + for i = 1, n do + if type(v[i]) ~= "number" then + return nil + end + end + return table.move(v, 1, n, 1, {}) +end + +-- extras.gltf: the JSON extras and the extensions not turned into Scene fields +local function keep(obj: any, handled: { [string]: boolean }?): { [string]: any }? + local extras = obj.extras + local ext: { [string]: any }? = nil + if type(obj.extensions) == "table" then + for k, v in obj.extensions do + if not (handled and handled[k]) then + ext = ext or {} + local e: any = ext + e[k] = v + end + end + end + if extras == nil and ext == nil then + return nil + end + return { gltf = { extras = extras, extensions = ext } } +end + +function Read.scene(doc: any, bin: buffer?, fetch: Fetch, opts: any?): (Types.Scene?, Err.Err?) + local maxBytes = opts and opts.maxBytes or 2 ^ 30 + if type(doc) ~= "table" then + return nil, Err.new(Err.CORRUPT, "the JSON is not an object") + end + local asset = doc.asset + if type(asset) ~= "table" or type(asset.version) ~= "string" then + return nil, Err.new(Err.CORRUPT, "no asset.version") + end + if string.sub(asset.version, 1, 1) ~= "2" then + return nil, Err.new(Err.UNSUPPORTED, "glTF version " .. asset.version .. " (only 2.x)") + end + for _, e in arr(doc.extensionsRequired) do + if type(e) == "string" and not KNOWN[e] then + return nil, Err.new(Err.UNSUPPORTED, "required extension " .. e) + end + end + local scene = Types.Scene.new() + -- buffers + local buffers: { buffer } = {} + local total = 0 + for i, b in arr(doc.buffers) do + if type(b) ~= "table" then + return nil, Err.new(Err.CORRUPT, "bad buffer " .. (i - 1)) + end + local len = int(b.byteLength) + if not len then + return nil, Err.new(Err.CORRUPT, "buffer " .. (i - 1) .. " without byteLength") + end + total += len + if total > maxBytes then + return nil, Err.new(Err.LIMIT, "buffers over " .. maxBytes .. " bytes") + end + local data: buffer? = nil + local uri = str(b.uri) + if uri == nil then + if i == 1 and bin then + data = bin + else + return nil, Err.new(Err.CORRUPT, "buffer " .. (i - 1) .. " has no uri and no GLB BIN chunk") + end + elseif string.sub(uri, 1, 5) == "data:" then + local d, derr = Base64.decodeDataUri(uri) + if not d then + return nil, Err.new(Err.CORRUPT, "buffer " .. (i - 1) .. ": " .. tostring(derr)) + end + data = d + else + data = fetch(uri) + if not data then + return nil, Err.new(Err.IO, "buffer file " .. uri .. " not found (pass opts.resolve or opts.files)") + end + end + if buffer.len(data :: buffer) < len then + return nil, Err.new(Err.TRUNCATED, "buffer " .. (i - 1) .. " is shorter than its byteLength") + end + buffers[i] = data :: buffer + end + -- buffer views -> { buf, offset, length, stride } + local views: { View } = {} + for i, v in arr(doc.bufferViews) do + if type(v) ~= "table" then + return nil, Err.new(Err.CORRUPT, "bad bufferView " .. (i - 1)) + end + local bi, off, len = int(v.buffer), int(v.byteOffset or 0), int(v.byteLength) + local b = bi and buffers[bi + 1] + if not b or not off or not len or off + len > buffer.len(b) then + return nil, Err.new(Err.CORRUPT, "bufferView " .. (i - 1) .. " out of range") + end + local stride = v.byteStride + if stride ~= nil and (not int(stride) or stride < 4 or stride > 252) then + return nil, Err.new(Err.CORRUPT, "bufferView " .. (i - 1) .. ": bad byteStride") + end + views[i] = { buf = b, offset = off, length = len, stride = stride } + end + -- accessors + local accessors: { Types.Accessor } = {} + for i, a in arr(doc.accessors) do + local label = "accessor " .. (i - 1) + if type(a) ~= "table" then + return nil, Err.new(Err.CORRUPT, "bad " .. label) + end + local ct, count, typ = a.componentType, int(a.count), a.type + local names = COMPONENT[ct] + local comps = TYPE_COMPONENTS[typ] + if not names or not count or not comps then + return nil, Err.new(Err.CORRUPT, label .. ": bad componentType, count or type") + end + local normalized = a.normalized == true + local tname = if normalized then names[2] else names[1] + if tname == "" then + return nil, Err.new(Err.CORRUPT, label .. ": normalized " .. names[1]) + end + local size = SIZE[ct] + local cols = TYPE_COLUMNS[typ] or 1 + local rows = comps // cols + local colBytes = rows * size + local colStride = if cols > 1 then (colBytes + 3) // 4 * 4 else colBytes + local elem = comps * size + local padded = cols * colStride + if count * elem > maxBytes then + return nil, Err.new(Err.LIMIT, label .. " is over " .. maxBytes .. " bytes") + end + local data = buffer.create(count * elem) + local vi = a.bufferView + if vi ~= nil then + local view = int(vi) and views[vi + 1] + if not view then + return nil, Err.new(Err.CORRUPT, label .. ": bad bufferView") + end + local off = int(a.byteOffset or 0) + if not off then + return nil, Err.new(Err.CORRUPT, label .. ": bad byteOffset") + end + local stride = view.stride or padded + if stride < padded and count > 1 then + return nil, Err.new(Err.CORRUPT, label .. ": byteStride smaller than an element") + end + if count > 0 and off + (count - 1) * stride + padded > view.length then + return nil, Err.new(Err.CORRUPT, label .. " runs past its bufferView") + end + if count > 0 then + Pack.gather(data, view.buf, view.offset + off, count, elem, stride, cols, colBytes, colStride) + end + end + local sp = a.sparse + if type(sp) == "table" then + local n = int(sp.count) + local si, sv = sp.indices, sp.values + if not n or type(si) ~= "table" or type(sv) ~= "table" then + return nil, Err.new(Err.CORRUPT, label .. ": bad sparse") + end + local isz = SIZE[si.componentType] + local iv, vv = int(si.bufferView) and views[si.bufferView + 1], int(sv.bufferView) and views[sv.bufferView + 1] + local io, vo = int(si.byteOffset or 0), int(sv.byteOffset or 0) + local okType = si.componentType == 5121 or si.componentType == 5123 or si.componentType == 5125 + if not okType or not isz or not iv or not vv or not io or not vo then + return nil, Err.new(Err.CORRUPT, label .. ": bad sparse indices / values") + end + if io + n * isz > iv.length or vo + n * elem > vv.length then + return nil, Err.new(Err.CORRUPT, label .. ": sparse data runs past its bufferView") + end + -- sparse values are tightly packed (matrices: padded columns, rare enough to repack first) + local vals, valOff = vv.buf, vv.offset + vo + if cols > 1 and colBytes ~= colStride then + vals = buffer.create(n * elem) + Pack.gather(vals, vv.buf, vv.offset + vo, n, elem, padded, cols, colBytes, colStride) + valOff = 0 + end + if not Pack.sparse(data, count, elem, iv.buf, iv.offset + io, isz, vals, valOff, n) then + return nil, Err.new(Err.CORRUPT, label .. ": sparse index out of range") + end + end + local acc = Types.Scene.accessor(data, tname, comps, count) + if cols > 1 then + acc.matrix = true + end + acc.name = str(a.name) + accessors[i] = acc + end + local function accessor(v: any): Types.Accessor? + local k = int(v) + return if k then accessors[k + 1] else nil + end + -- images (kept encoded), samplers, textures + local images: { Img } = {} + for i, im in arr(doc.images) do + if type(im) ~= "table" then + return nil, Err.new(Err.CORRUPT, "bad image " .. (i - 1)) + end + local img: Img = { mime = str(im.mimeType), name = str(im.name) } + if im.bufferView ~= nil then + local view = int(im.bufferView) and views[im.bufferView + 1] + if not view then + return nil, Err.new(Err.CORRUPT, "image " .. (i - 1) .. ": bad bufferView") + end + local d = buffer.create(view.length) + buffer.copy(d, 0, view.buf, view.offset, view.length) + img.data = d + elseif type(im.uri) == "string" then + if string.sub(im.uri, 1, 5) == "data:" then + local d, mime = Base64.decodeDataUri(im.uri) + if d then + img.data = d + img.mime = img.mime or mime + end + else + img.uri = im.uri + img.data = fetch(im.uri) + if not img.mime then + local ext = string.lower(string.match(im.uri, "%.(%w+)$") or "") + img.mime = if ext == "png" then "image/png" elseif ext == "jpg" or ext == "jpeg" then "image/jpeg" elseif ext == "webp" then "image/webp" elseif ext == "ktx2" then "image/ktx2" else nil + end + end + end + images[i] = img + end + local samplers: { Types.Sampler } = {} + for i, s in arr(doc.samplers) do + if type(s) == "table" then + samplers[i] = { + wrapS = WRAP[s.wrapS] or (if s.wrapS == nil then nil else "repeat") :: any, + wrapT = WRAP[s.wrapT] or (if s.wrapT == nil then nil else "repeat") :: any, + filter = if s.magFilter == 9728 then "nearest" elseif s.magFilter == 9729 then "linear" else nil, + minFilter = MIN_FILTER[s.minFilter], + } + else + samplers[i] = {} + end + end + local TEX_SOURCE_EXT = { "KHR_texture_basisu", "EXT_texture_webp", "EXT_texture_avif" } + for i, t in arr(doc.textures) do + if type(t) ~= "table" then + return nil, Err.new(Err.CORRUPT, "bad texture " .. (i - 1)) + end + local src = t.source + local handled = {} + if type(t.extensions) == "table" then + for _, e in TEX_SOURCE_EXT do + local x = t.extensions[e] + if type(x) == "table" and int(x.source) then + src = x.source + handled[e] = true + break + end + end + end + local img = int(src) and images[src + 1] + local tex: Types.Texture = { name = str(t.name) } + if img then + tex.data, tex.mime, tex.uri = img.data, img.mime, img.uri + tex.name = tex.name or img.name + end + local si = int(t.sampler) + if si and samplers[si + 1] then + tex.sampler = table.clone(samplers[si + 1]) + end + tex.extras = keep(t, handled) + if next(handled) then + -- the fallback image (t.source) and the extension name, for writing the texture back the same way + tex.extras = tex.extras or { gltf = {} } + local g = (tex.extras :: any).gltf + g.sourceExtension = next(handled) + local fb = int(t.source) and images[t.source + 1] + if fb then + g.fallback = { data = fb.data, mime = fb.mime, uri = fb.uri } + end + end + table.insert(scene.textures, tex) + end + -- materials + local function texRef(info: any): Types.TextureRef? + if type(info) ~= "table" or not int(info.index) or info.index >= #scene.textures then + return nil + end + local r: Types.TextureRef = { texture = info.index + 1, texCoord = int(info.texCoord), scale = if type(info.scale) == "number" then info.scale else nil, strength = if type(info.strength) == "number" then info.strength else nil } + local tt = type(info.extensions) == "table" and info.extensions.KHR_texture_transform + if type(tt) == "table" then + r.transform = { offset = numbers(tt.offset, 2), scale = numbers(tt.scale, 2), rotation = if type(tt.rotation) == "number" then tt.rotation else nil, texCoord = int(tt.texCoord) } + end + return r + end + -- an extension object with every textureInfo (a table with an index, under a key ending in Texture) -> TextureRef + local function convertExt(v: any): any + if type(v) ~= "table" then + return v + end + local out = if Types.isObject(v) or next(v) == nil then Types.object() else {} + for k, x in v do + if type(k) == "string" and string.sub(k, -7) == "Texture" and type(x) == "table" and int(x.index) then + out[k] = texRef(x) + else + out[k] = convertExt(x) + end + end + return out + end + for i, m in arr(doc.materials) do + if type(m) ~= "table" then + return nil, Err.new(Err.CORRUPT, "bad material " .. (i - 1)) + end + local mat = Types.Scene.material(str(m.name)) + local pbr = if type(m.pbrMetallicRoughness) == "table" then m.pbrMetallicRoughness else {} + mat.baseColor = numbers(pbr.baseColorFactor, 4) or { 1, 1, 1, 1 } + mat.baseColorTexture = texRef(pbr.baseColorTexture) + mat.metallic = num(pbr.metallicFactor, 1) + mat.roughness = num(pbr.roughnessFactor, 1) + mat.metallicRoughnessTexture = texRef(pbr.metallicRoughnessTexture) + mat.normalTexture = texRef(m.normalTexture) + mat.occlusionTexture = texRef(m.occlusionTexture) + mat.emissive = numbers(m.emissiveFactor, 3) or { 0, 0, 0 } + mat.emissiveTexture = texRef(m.emissiveTexture) + mat.alphaMode = if m.alphaMode == "MASK" then "mask" elseif m.alphaMode == "BLEND" then "blend" else "opaque" + mat.alphaCutoff = num(m.alphaCutoff, 0.5) + mat.doubleSided = m.doubleSided == true + if type(m.extensions) == "table" then + local ext = {} + for k, v in m.extensions do + ext[k] = convertExt(v) + end + mat.extensions = ext + end + local kept = keep(m, mat.extensions and (mat.extensions :: any) or {}) + local pk = keep(pbr, nil) + if pk then + kept = kept or { gltf = {} } + local kk: any = kept + kk.gltf.pbr = pk.gltf + end + mat.extras = kept + table.insert(scene.materials, mat) + end + -- meshes + for i, m in arr(doc.meshes) do + if type(m) ~= "table" then + return nil, Err.new(Err.CORRUPT, "bad mesh " .. (i - 1)) + end + local mesh: Types.Mesh = { name = str(m.name), primitives = {}, weights = if type(m.weights) == "table" then table.clone(m.weights) else nil, extras = keep(m, nil) } + for k, p in arr(m.primitives) do + if type(p) ~= "table" or type(p.attributes) ~= "table" then + return nil, Err.new(Err.CORRUPT, string.format("mesh %d primitive %d: no attributes", i - 1, k - 1)) + end + if type(p.extensions) == "table" and (p.extensions.KHR_draco_mesh_compression or p.extensions.EXT_meshopt_compression) then + return nil, Err.new(Err.UNSUPPORTED, "compressed primitives (Draco / meshopt)") + end + local attrs: { [string]: Types.Accessor } = {} + local count = -1 + for name, ai in p.attributes do + local a = accessor(ai) + if not a then + return nil, Err.new(Err.CORRUPT, string.format("mesh %d: attribute %s: bad accessor", i - 1, tostring(name))) + end + if count >= 0 and a.count ~= count then + return nil, Err.new(Err.CORRUPT, string.format("mesh %d: attributes with different counts", i - 1)) + end + count = a.count + attrs[name] = a + end + local mode = MODES[if p.mode == nil then 4 else p.mode] + if not mode then + return nil, Err.new(Err.CORRUPT, "bad primitive mode") + end + local prim: Types.Primitive = { attributes = attrs, mode = mode :: any, material = if int(p.material) and p.material < #scene.materials then p.material + 1 else nil } + if p.indices ~= nil then + local ind = accessor(p.indices) + if not ind or ind.components ~= 1 or (ind.type ~= "u8" and ind.type ~= "u16" and ind.type ~= "u32") then + return nil, Err.new(Err.CORRUPT, "bad indices accessor") + end + -- indices must reference existing vertices + local get = Types.Scene.reader(ind) :: any + for q = 0, ind.count - 1 do + if get(q, 0) >= count then + return nil, Err.new(Err.CORRUPT, "index out of range") + end + end + prim.indices = ind + end + if type(p.targets) == "table" then + local targets = {} + for ti, t in p.targets do + local tt = {} + for name, ai in (if type(t) == "table" then t else {}) do + local a = accessor(ai) + if not a or a.count ~= count then + return nil, Err.new(Err.CORRUPT, "bad morph target accessor") + end + tt[name] = a + end + targets[ti] = tt + end + prim.targets = targets + end + prim.extras = keep(p, nil) + table.insert(mesh.primitives, prim) + end + table.insert(scene.meshes, mesh) + end + -- cameras, lights + for _, c in arr(doc.cameras) do + if type(c) ~= "table" then + return nil, Err.new(Err.CORRUPT, "bad camera") + end + if c.type == "orthographic" and type(c.orthographic) == "table" then + local o = c.orthographic + table.insert(scene.cameras, { name = str(c.name), type = "orthographic", xmag = num(o.xmag, 1), ymag = num(o.ymag, 1), znear = num(o.znear, 0), zfar = num(o.zfar, 100) }) + else + local p = if type(c.perspective) == "table" then c.perspective else {} + table.insert(scene.cameras, { name = str(c.name), type = "perspective", yfov = num(p.yfov, 0.8), aspect = if type(p.aspectRatio) == "number" then p.aspectRatio else nil, znear = num(p.znear, 0.01), zfar = if type(p.zfar) == "number" then p.zfar else nil }) + end + end + local lp = type(doc.extensions) == "table" and doc.extensions.KHR_lights_punctual + for _, l in arr(lp and lp.lights) do + if type(l) == "table" then + local spot = if type(l.spot) == "table" then l.spot else {} + table.insert(scene.lights, { + name = str(l.name), + type = if l.type == "spot" or l.type == "point" then l.type else "directional", + color = numbers(l.color, 3) or { 1, 1, 1 }, + intensity = num(l.intensity, 1), + range = if type(l.range) == "number" then l.range else nil, + innerCone = if l.type == "spot" then num(spot.innerConeAngle, 0) else nil, + outerCone = if l.type == "spot" then num(spot.outerConeAngle, math.pi / 4) else nil, + }) + end + end + -- nodes + local nodes = arr(doc.nodes) + for i, n in nodes do + if type(n) ~= "table" then + return nil, Err.new(Err.CORRUPT, "bad node " .. (i - 1)) + end + local node: Types.Node = { name = str(n.name), children = {} } + for _, c in arr(n.children) do + if not int(c) or c >= #nodes then + return nil, Err.new(Err.CORRUPT, "node " .. (i - 1) .. ": bad child") + end + table.insert(node.children, c + 1) + end + if int(n.mesh) and n.mesh < #scene.meshes then + node.mesh = n.mesh + 1 + end + if int(n.camera) and n.camera < #scene.cameras then + node.camera = n.camera + 1 + end + if int(n.skin) and n.skin < #arr(doc.skins) then + node.skin = n.skin + 1 + end + node.matrix = numbers(n.matrix, 16) + node.translation = numbers(n.translation, 3) + node.rotation = numbers(n.rotation, 4) + node.scale = numbers(n.scale, 3) + node.weights = if type(n.weights) == "table" then table.clone(n.weights) else nil + local handled = {} + local le = type(n.extensions) == "table" and n.extensions.KHR_lights_punctual + if type(le) == "table" and int(le.light) and le.light < #scene.lights then + node.light = le.light + 1 + handled.KHR_lights_punctual = true + end + node.extras = keep(n, handled) + scene.nodes[i] = node + end + -- a node may have one parent only, and no cycles + local parent: { [number]: number } = {} + for i, node in scene.nodes do + for _, c in node.children do + if parent[c] or c == i then + return nil, Err.new(Err.CORRUPT, "node " .. (c - 1) .. " has two parents or is its own child") + end + parent[c] = i + end + end + for i in scene.nodes do + local seen, p = 0, parent[i] + while p do + seen += 1 + if seen > #scene.nodes then + return nil, Err.new(Err.CORRUPT, "the node hierarchy has a cycle") + end + p = parent[p] + end + end + -- skins + for _, s in arr(doc.skins) do + if type(s) ~= "table" then + return nil, Err.new(Err.CORRUPT, "bad skin") + end + local joints = {} + for _, j in arr(s.joints) do + if not int(j) or j >= #scene.nodes then + return nil, Err.new(Err.CORRUPT, "skin: bad joint") + end + table.insert(joints, j + 1) + end + table.insert(scene.skins, { name = str(s.name), joints = joints, inverseBindMatrices = accessor(s.inverseBindMatrices), skeleton = if int(s.skeleton) and s.skeleton < #scene.nodes then s.skeleton + 1 else nil }) + end + -- animations + for _, a in arr(doc.animations) do + if type(a) ~= "table" then + return nil, Err.new(Err.CORRUPT, "bad animation") + end + local anim: Types.Animation = { name = str(a.name), channels = {} } + local samplersA = arr(a.samplers) + local skipped = {} + for _, c in arr(a.channels) do + local s = type(c) == "table" and int(c.sampler) and samplersA[c.sampler + 1] + local target = type(c) == "table" and c.target + if not s or type(target) ~= "table" then + return nil, Err.new(Err.CORRUPT, "animation: bad channel") + end + local input, output = accessor(s.input), accessor(s.output) + if not input or not output then + return nil, Err.new(Err.CORRUPT, "animation: bad sampler accessors") + end + local path = target.path + if int(target.node) and target.node < #scene.nodes and (path == "translation" or path == "rotation" or path == "scale" or path == "weights") then + table.insert(anim.channels, { + node = target.node + 1, + path = path, + input = input, + output = output, + interpolation = if s.interpolation == "STEP" or s.interpolation == "CUBICSPLINE" then s.interpolation else "LINEAR", + }) + else + table.insert(skipped, c) -- KHR_animation_pointer and friends + end + end + if #skipped > 0 then + local aa: any = anim + aa.extras = { gltf = { skippedChannels = #skipped } } + end + table.insert(scene.animations, anim) + end + -- scenes + local scenes = arr(doc.scenes) + local list = {} + for _, s in scenes do + local roots = {} + for _, n in arr(type(s) == "table" and s.nodes) do + if int(n) and n < #scene.nodes and not parent[n + 1] then + table.insert(roots, n + 1) + end + end + table.insert(list, { name = type(s) == "table" and str(s.name) or nil, nodes = roots, extras = if type(s) == "table" then keep(s, nil) else nil }) + end + local which = int(doc.scene) or 0 + if list[which + 1] then + scene.roots = list[which + 1].nodes + elseif #list == 0 then + for i in scene.nodes do + if not parent[i] then + table.insert(scene.roots, i) + end + end + end + -- root extensions other than the lights, asset info + local rootExt = nil + if type(doc.extensions) == "table" then + for k, v in doc.extensions do + if k ~= "KHR_lights_punctual" then + rootExt = rootExt or {} + rootExt[k] = v + end + end + end + scene.meta.up = "y" + scene.meta.unit = 1 + scene.meta.gltf = { + asset = asset, + scenes = list, + scene = if doc.scene ~= nil then which + 1 else nil, + extensionsUsed = doc.extensionsUsed, + extensionsRequired = doc.extensionsRequired, + extensions = rootExt, + extras = doc.extras, + } + return scene, nil +end + +return Read diff --git a/src/Formats/model/gltf/Write.luau b/src/Formats/model/gltf/Write.luau new file mode 100644 index 0000000..473f293 --- /dev/null +++ b/src/Formats/model/gltf/Write.luau @@ -0,0 +1,696 @@ +--!strict +-- model/gltf/Write: Scene -> a glTF 2.0 JSON document + one binary buffer. One bufferView per accessor (vertex +-- attributes 4-byte aligned per element with a byteStride when needed, matrix columns padded as glTF requires), +-- accessors shared between primitives / animations written once, f64 / i32 data converted (glTF has neither), +-- POSITION and animation input min / max, KHR_mesh_quantization declared when attributes are not floats, +-- KHR_texture_transform / KHR_lights_punctual / material extensions declared when used, images deduplicated by their +-- bytes (or uri), samplers by their settings. "polygons" primitives are fan-triangulated (MeshOps.triangulate first +-- for concave faces). +local Err = require("@formats/core/Err") +local Bytes = require("@formats/core/Bytes") +local Types = require("@formats/Types") +local Pack = require("@formats/model/gltf/Pack") + +local Write = {} + +local object = Types.object +local CT = { i8 = 5120, u8 = 5121, i16 = 5122, u16 = 5123, u32 = 5125, f32 = 5126, unorm8 = 5121, unorm16 = 5123, snorm8 = 5120, snorm16 = 5122 } +local SIZE = Types.COMPONENT_SIZE +local NORMALIZED = { unorm8 = true, unorm16 = true, snorm8 = true, snorm16 = true } +local MODES = { points = 0, lines = 1, line_loop = 2, line_strip = 3, triangles = 4, triangle_strip = 5, triangle_fan = 6 } +local WRAP = { clamp = 33071, mirror = 33648, ["repeat"] = 10497 } +local MIN_FILTER = { nearest = 9728, linear = 9729, nearest_mipmap_nearest = 9984, linear_mipmap_nearest = 9985, nearest_mipmap_linear = 9986, linear_mipmap_linear = 9987 } +-- attribute types the core spec allows (others need KHR_mesh_quantization) +local CORE = { + POSITION = { f32 = true }, + NORMAL = { f32 = true }, + TANGENT = { f32 = true }, + TEXCOORD = { f32 = true, unorm8 = true, unorm16 = true }, + COLOR = { f32 = true, unorm8 = true, unorm16 = true }, + JOINTS = { u8 = true, u16 = true }, + WEIGHTS = { f32 = true, unorm8 = true, unorm16 = true }, +} + +export type Options = { embedImages: boolean?, binary: boolean? } +export type Out = { doc: any, bin: buffer, images: { { data: buffer, mime: string?, name: string } } } + +local function convert(acc: Types.Accessor, to: string): Types.Accessor + local get = Types.Scene.reader(acc) :: (number, number) -> number + local out = Types.Scene.accessor(nil, to, acc.components, acc.count) + local w = if to == "f32" then buffer.writef32 else buffer.writeu32 + local size = SIZE[to] + for i = 0, acc.count - 1 do + for c = 0, acc.components - 1 do + local v = get(i, c) + if to == "u32" then + v = math.clamp(math.floor(v), 0, 4294967295) + end + w(out.data, (i * acc.components + c) * size, v) + end + end + out.matrix = acc.matrix + out.name = acc.name + return out +end + +local function checkAcc(acc: any, label: string): Err.Err? + if type(acc) ~= "table" or type(acc.data) ~= "buffer" or not SIZE[acc.type] or type(acc.count) ~= "number" or type(acc.components) ~= "number" then + return Err.new(Err.ARG, label .. ": not an accessor") + end + if acc.components < 1 or acc.components > 16 or buffer.len(acc.data) < acc.count * acc.components * SIZE[acc.type] then + return Err.new(Err.ARG, label .. ": data is smaller than count x components") + end + return nil +end + +function Write.build(scene: Types.Scene, opts: Options?): (Out?, Err.Err?) + local binary = opts and opts.binary or false + local embedImages = not (opts and opts.embedImages == false) + local doc: { [string]: any } = object() + local used: { [string]: boolean } = {} + local required: { [string]: boolean } = {} + local bin = Bytes.writer(65536) + local views: { any } = {} + local accessors: { any } = {} + local accIndex: { [any]: number } = {} + local failure: Err.Err? = nil + + local function view(data: buffer, length: number, target: number?, stride: number?): number + local pad = (4 - bin:tell() % 4) % 4 + bin:fill(0, pad) + local v = object() + v.buffer = 0 + v.byteOffset = bin:tell() + v.byteLength = length + v.target = target + v.byteStride = stride + bin:bytes(data, 0, length) + table.insert(views, v) + return #views - 1 + end + + -- accessor(acc, usage, attribute?) -> the glTF index (0-based) + local function accessor(acc: Types.Accessor, usage: string, attribute: string?): number + local known = accIndex[acc] + if known then + return known + end + local err = checkAcc(acc, attribute or usage) + if err then + failure = failure or err + return 0 + end + local a = acc + if usage == "index" then + if a.type ~= "u8" and a.type ~= "u16" and a.type ~= "u32" then + a = convert(a, "u32") + end + elseif a.type == "f64" or a.type == "i32" or a.type == "u32" and usage ~= "index" and attribute ~= nil then + a = convert(a, "f32") + end + if attribute then + local kind = string.match(attribute, "^([A-Z]+)_%d+$") or attribute + local core = CORE[kind] + if core and not core[a.type] then + used.KHR_mesh_quantization = true + required.KHR_mesh_quantization = true + end + end + local size = SIZE[a.type] + local comps = a.components + local isMat = a.matrix == true and (comps == 4 or comps == 9 or comps == 16) + local cols = if isMat then math.sqrt(comps) else 1 + local colBytes = (comps // cols) * size + local colStride = if cols > 1 then (colBytes + 3) // 4 * 4 else colBytes + local elem = comps * size + local padded = cols * colStride + local stride = padded + local byteStride: number? = nil + if usage == "vertex" and padded % 4 ~= 0 then + stride = (padded + 3) // 4 * 4 + byteStride = stride + end + local data = a.data + local length = a.count * stride + if stride ~= elem then + data = buffer.create(length) + Pack.scatter(data, 0, a.data, a.count, elem, stride, cols, colBytes, colStride) + end + local g = object() + g.bufferView = view(data, length, if usage == "vertex" then 34962 elseif usage == "index" then 34963 else nil, byteStride) + g.componentType = CT[a.type] + g.normalized = if NORMALIZED[a.type] then true else nil + g.count = a.count + g.type = if isMat then ({ [4] = "MAT2", [9] = "MAT3", [16] = "MAT4" })[comps] else ({ "SCALAR", "VEC2", "VEC3", "VEC4" })[comps] + g.name = acc.name + if not g.type then + failure = failure or Err.new(Err.ARG, (attribute or usage) .. ": " .. comps .. " components is not a glTF type") + return 0 + end + if attribute == "POSITION" or usage == "input" then + -- min / max of the raw component values + local raw = Types.Scene.accessor(a.data, if a.type == "unorm8" then "u8" elseif a.type == "unorm16" then "u16" elseif a.type == "snorm8" then "i8" elseif a.type == "snorm16" then "i16" else a.type, comps, a.count) + local get = Types.Scene.reader(raw) :: (number, number) -> number + local lo, hi = table.create(comps, math.huge), table.create(comps, -math.huge) + for i = 0, a.count - 1 do + for c = 1, comps do + local v = get(i, c - 1) + if v < lo[c] then + lo[c] = v + end + if v > hi[c] then + hi[c] = v + end + end + end + if a.count > 0 then + g.min, g.max = lo, hi + end + end + table.insert(accessors, g) + local index = #accessors - 1 + accIndex[acc] = index + return index + end + + -- extras.gltf -> extras / extensions fields of a glTF object + local function restore(g: any, extras: any) + local saved = type(extras) == "table" and extras.gltf + if type(saved) ~= "table" then + return + end + if saved.extras ~= nil then + g.extras = saved.extras + end + if type(saved.extensions) == "table" then + g.extensions = g.extensions or object() + for k, v in saved.extensions do + if g.extensions[k] == nil then + g.extensions[k] = v + used[k] = true + end + end + end + end + + -- images, samplers, textures + local images: { any } = {} + local imageOut: { { data: buffer, mime: string?, name: string } } = {} + local imageIndex: { [any]: number } = {} + local function image(data: buffer?, mime: string?, uri: string?, name: string?): number? + local key: any = data or uri + if key == nil then + return nil + end + if imageIndex[key] then + return imageIndex[key] + end + local im = object() + im.name = name + if data then + if binary then + im.bufferView = view(data, buffer.len(data), nil, nil) + im.mimeType = mime or "image/png" + elseif embedImages then + im.uri = "\0image" .. (#images + 1) -- replaced by a data: URI by the caller (init) / a file name + im.mimeType = mime + table.insert(imageOut, { data = data, mime = mime, name = im.uri }) + else + im.uri = uri or ("\0file" .. (#images + 1)) + im.mimeType = mime + table.insert(imageOut, { data = data, mime = mime, name = im.uri }) + end + else + im.uri = uri + im.mimeType = mime + end + table.insert(images, im) + imageIndex[key] = #images - 1 + return #images - 1 + end + local samplers: { any } = {} + local samplerIndex: { [string]: number } = {} + local function sampler(s: Types.Sampler?): number? + if type(s) ~= "table" then + return nil + end + local g = object() + g.wrapS = if s.wrapS then WRAP[s.wrapS] else nil + g.wrapT = if s.wrapT then WRAP[s.wrapT] else nil + g.magFilter = if s.filter == "nearest" then 9728 elseif s.filter == "linear" then 9729 else nil + g.minFilter = if s.minFilter then MIN_FILTER[s.minFilter] else nil + local key = string.format("%s/%s/%s/%s", tostring(g.wrapS), tostring(g.wrapT), tostring(g.magFilter), tostring(g.minFilter)) + if samplerIndex[key] == nil then + table.insert(samplers, g) + samplerIndex[key] = #samplers - 1 + end + return samplerIndex[key] + end + local textures: { any } = {} + for i, t in scene.textures or {} do + if type(t) ~= "table" then + return nil, Err.new(Err.ARG, "texture " .. i .. ": not a table") + end + local g = object() + g.name = t.name + g.sampler = sampler(t.sampler) + local saved = type(t.extras) == "table" and type(t.extras.gltf) == "table" and t.extras.gltf or nil + local srcExt = saved and saved.sourceExtension + local img = image(t.data, t.mime, t.uri, t.name) + if srcExt and img then + g.extensions = object() + local e = object() + e.source = img + g.extensions[srcExt] = e + used[srcExt] = true + local fb = saved.fallback + if type(fb) == "table" then + g.source = image(fb.data, fb.mime, fb.uri, nil) + end + if g.source == nil then + required[srcExt] = true + end + else + g.source = img + end + restore(g, t.extras) + table.insert(textures, g) + end + local function texInfo(r: any, kind: string?): any + if type(r) ~= "table" or type(r.texture) ~= "number" or not textures[r.texture] then + return nil + end + local g = object() + g.index = r.texture - 1 + if r.texCoord and r.texCoord ~= 0 then + g.texCoord = r.texCoord + end + if kind == "normal" and r.scale ~= nil and r.scale ~= 1 then + g.scale = r.scale + end + if kind == "occlusion" and r.strength ~= nil and r.strength ~= 1 then + g.strength = r.strength + end + if type(r.transform) == "table" then + local tt = object() + tt.offset = r.transform.offset + tt.scale = r.transform.scale + tt.rotation = r.transform.rotation + tt.texCoord = r.transform.texCoord + g.extensions = object() + g.extensions.KHR_texture_transform = tt + used.KHR_texture_transform = true + end + return g + end + local function extValue(v: any, key: string?): any + if type(v) ~= "table" then + return v + end + if key and string.sub(key, -7) == "Texture" and type(v.texture) == "number" then + return texInfo(v, if key == "normalTexture" or key == "clearcoatNormalTexture" then "normal" else nil) + end + local out = if Types.isObject(v) or next(v) == nil then object() else {} + for k, x in v do + out[k] = extValue(x, if type(k) == "string" then k else nil) + end + return out + end + -- materials + local materials: { any } = {} + for i, m in scene.materials or {} do + if type(m) ~= "table" then + return nil, Err.new(Err.ARG, "material " .. i .. ": not a table") + end + local g = object() + g.name = m.name + local pbr = object() + local bc = m.baseColor or { 1, 1, 1, 1 } + if bc[1] ~= 1 or bc[2] ~= 1 or bc[3] ~= 1 or (bc[4] or 1) ~= 1 then + pbr.baseColorFactor = { bc[1], bc[2], bc[3], bc[4] or 1 } + end + pbr.baseColorTexture = texInfo(m.baseColorTexture) + if m.metallic ~= nil and m.metallic ~= 1 then + pbr.metallicFactor = m.metallic + end + if m.roughness ~= nil and m.roughness ~= 1 then + pbr.roughnessFactor = m.roughness + end + pbr.metallicRoughnessTexture = texInfo(m.metallicRoughnessTexture) + local saved = type(m.extras) == "table" and type(m.extras.gltf) == "table" and m.extras.gltf or nil + if saved and saved.pbr then + restore(pbr, { gltf = saved.pbr }) + end + g.pbrMetallicRoughness = pbr + g.normalTexture = texInfo(m.normalTexture, "normal") + g.occlusionTexture = texInfo(m.occlusionTexture, "occlusion") + g.emissiveTexture = texInfo(m.emissiveTexture) + local em = m.emissive or { 0, 0, 0 } + if em[1] ~= 0 or em[2] ~= 0 or em[3] ~= 0 then + g.emissiveFactor = { em[1], em[2], em[3] } + end + if m.alphaMode == "mask" then + g.alphaMode = "MASK" + if m.alphaCutoff ~= nil and m.alphaCutoff ~= 0.5 then + g.alphaCutoff = m.alphaCutoff + end + elseif m.alphaMode == "blend" then + g.alphaMode = "BLEND" + end + if m.doubleSided then + g.doubleSided = true + end + if type(m.extensions) == "table" then + g.extensions = object() + for k, v in m.extensions do + g.extensions[k] = extValue(v, nil) + used[k] = true + end + end + restore(g, m.extras) + table.insert(materials, g) + end + -- meshes + local meshes: { any } = {} + for i, mesh in scene.meshes or {} do + if type(mesh) ~= "table" or type(mesh.primitives) ~= "table" then + return nil, Err.new(Err.ARG, "mesh " .. i .. ": no primitives") + end + local g = object() + g.name = mesh.name + g.primitives = {} + for k, p in mesh.primitives do + if type(p) ~= "table" or type(p.attributes) ~= "table" or not p.attributes.POSITION then + return nil, Err.new(Err.ARG, string.format("mesh %d primitive %d: no POSITION", i, k)) + end + local gp = object() + gp.attributes = object() + local names = {} + for name in p.attributes do + table.insert(names, name) + end + table.sort(names) + for _, name in names do + gp.attributes[name] = accessor(p.attributes[name], "vertex", name) + end + local mode = p.mode or "triangles" + local indices = p.indices + if mode == "polygons" then + -- fan-triangulate + local faces = p.faces + local getf = faces and Types.Scene.reader(faces) + local n = if indices then indices.count else p.attributes.POSITION.count + local geti = if indices then Types.Scene.reader(indices) else nil + if not faces or not getf or (indices and not geti) then + return nil, Err.new(Err.ARG, "polygons without faces") + end + local list = {} + local at = 0 + for f = 0, faces.count - 1 do + local c = getf(f, 0) + if at + c > n then + return nil, Err.new(Err.ARG, "faces run past the indices") + end + for a = 1, c - 2 do + for _, j in { at, at + a, at + a + 1 } do + table.insert(list, if geti then geti(j, 0) else j) + end + end + at += c + end + local ib = buffer.create(#list * 4) + for q, v in list do + buffer.writeu32(ib, (q - 1) * 4, v) + end + indices = Types.Scene.accessor(ib, "u32", 1, #list) + mode = "triangles" + end + if MODES[mode] == nil then + return nil, Err.new(Err.ARG, "unknown primitive mode " .. tostring(mode)) + end + if indices then + gp.indices = accessor(indices, "index", nil) + end + if mode ~= "triangles" then + gp.mode = MODES[mode] + end + if type(p.material) == "number" and materials[p.material] then + gp.material = p.material - 1 + end + if type(p.targets) == "table" and #p.targets > 0 then + gp.targets = {} + for _, t in p.targets do + local gt = object() + local tn = {} + for name in t do + table.insert(tn, name) + end + table.sort(tn) + for _, name in tn do + gt[name] = accessor(t[name], "vertex", nil) + end + table.insert(gp.targets, gt) + end + end + restore(gp, p.extras) + table.insert(g.primitives, gp) + end + g.weights = mesh.weights + restore(g, mesh.extras) + table.insert(meshes, g) + end + -- cameras, lights + local cameras: { any } = {} + for _, c in scene.cameras or {} do + local g = object() + g.name = c.name + g.type = c.type + local p = object() + if c.type == "orthographic" then + p.xmag, p.ymag, p.znear, p.zfar = c.xmag or 1, c.ymag or 1, c.znear or 0, c.zfar or 100 + g.orthographic = p + else + g.type = "perspective" + p.yfov, p.aspectRatio, p.znear, p.zfar = c.yfov or 0.8, c.aspect, c.znear or 0.01, c.zfar + g.perspective = p + end + table.insert(cameras, g) + end + local lights: { any } = {} + for _, l in scene.lights or {} do + local g = object() + g.name = l.name + g.type = l.type + if l.color and (l.color[1] ~= 1 or l.color[2] ~= 1 or l.color[3] ~= 1) then + g.color = { l.color[1], l.color[2], l.color[3] } + end + if l.intensity ~= nil and l.intensity ~= 1 then + g.intensity = l.intensity + end + if l.type ~= "directional" then + g.range = l.range + end + if l.type == "spot" then + local s = object() + s.innerConeAngle = if l.innerCone and l.innerCone ~= 0 then l.innerCone else nil + s.outerConeAngle = if l.outerCone and math.abs(l.outerCone - math.pi / 4) > 1e-12 then l.outerCone else nil + g.spot = s + end + table.insert(lights, g) + end + -- nodes + local nodes: { any } = {} + local nodeCount = #(scene.nodes or {}) + for i, n in scene.nodes or {} do + if type(n) ~= "table" then + return nil, Err.new(Err.ARG, "node " .. i .. ": not a table") + end + local g = object() + g.name = n.name + if n.children and #n.children > 0 then + g.children = {} + for _, c in n.children do + if type(c) ~= "number" or c < 1 or c > nodeCount then + return nil, Err.new(Err.ARG, "node " .. i .. ": bad child") + end + table.insert(g.children, c - 1) + end + end + if n.mesh and meshes[n.mesh] then + g.mesh = n.mesh - 1 + end + if n.camera and cameras[n.camera] then + g.camera = n.camera - 1 + end + if n.skin and scene.skins[n.skin] then + g.skin = n.skin - 1 + end + if n.matrix then + local ident = true + for k = 1, 16 do + if n.matrix[k] ~= Types.Scene.IDENTITY[k] then + ident = false + end + end + if not ident then + g.matrix = n.matrix + end + else + g.translation, g.rotation, g.scale = n.translation, n.rotation, n.scale + end + g.weights = n.weights + if n.light and lights[n.light] then + g.extensions = object() + local le = object() + le.light = n.light - 1 + g.extensions.KHR_lights_punctual = le + used.KHR_lights_punctual = true + end + restore(g, n.extras) + table.insert(nodes, g) + end + -- skins + local skins: { any } = {} + for _, s in scene.skins or {} do + local g = object() + g.name = s.name + g.joints = {} + for _, j in s.joints or {} do + table.insert(g.joints, j - 1) + end + if s.inverseBindMatrices then + local ibm = s.inverseBindMatrices + if ibm.matrix == nil and ibm.components == 16 then + ibm.matrix = true + end + g.inverseBindMatrices = accessor(ibm, "other", nil) + end + if s.skeleton then + g.skeleton = s.skeleton - 1 + end + table.insert(skins, g) + end + -- animations + local animations: { any } = {} + for _, a in scene.animations or {} do + local g = object() + g.name = a.name + g.channels, g.samplers = {}, {} + local samplerOf: { [string]: number } = {} + for _, c in a.channels or {} do + local input = accessor(c.input, "input", nil) + local output = accessor(c.output, "other", nil) + local key = input .. "/" .. output .. "/" .. tostring(c.interpolation) + if samplerOf[key] == nil then + local s = object() + s.input, s.output = input, output + if c.interpolation and c.interpolation ~= "LINEAR" then + s.interpolation = c.interpolation + end + table.insert(g.samplers, s) + samplerOf[key] = #g.samplers - 1 + end + local ch = object() + ch.sampler = samplerOf[key] + ch.target = object() + ch.target.node = c.node - 1 + ch.target.path = c.path + table.insert(g.channels, ch) + end + table.insert(animations, g) + end + if failure then + return nil, failure + end + -- scenes: the original list (meta.gltf.scenes) when it is there, else the roots + local meta = if type(scene.meta) == "table" then scene.meta else {} + local mg = type(meta.gltf) == "table" and meta.gltf or {} + local scenes = {} + if type(mg.scenes) == "table" and #mg.scenes > 0 then + for _, s in mg.scenes do + local g = object() + g.name = s.name + g.nodes = {} + for _, n in s.nodes or {} do + if nodes[n] then + table.insert(g.nodes, n - 1) + end + end + restore(g, s.extras) + table.insert(scenes, g) + end + -- the current roots replace the default scene's list + local which = mg.scene or 1 + if scenes[which] then + scenes[which].nodes = {} + for _, r in scene.roots or {} do + table.insert(scenes[which].nodes, r - 1) + end + end + doc.scene = (mg.scene or 1) - 1 + else + local g = object() + g.nodes = {} + for _, r in scene.roots or {} do + table.insert(g.nodes, r - 1) + end + table.insert(scenes, g) + doc.scene = 0 + end + local asset = object() + asset.version = "2.0" + asset.generator = "formats-luau" + if type(mg.asset) == "table" then + asset.copyright = mg.asset.copyright + asset.minVersion = mg.asset.minVersion + asset.extras = mg.asset.extras + end + doc.asset = asset + -- root extensions kept from the source (variants, ...), the lights + if type(mg.extensions) == "table" then + doc.extensions = object() + for k, v in mg.extensions do + doc.extensions[k] = v + used[k] = true + end + end + if #lights > 0 then + doc.extensions = doc.extensions or object() + local lp = object() + lp.lights = lights + doc.extensions.KHR_lights_punctual = lp + used.KHR_lights_punctual = true + end + doc.extras = mg.extras + local function list(t: { [string]: boolean }): { string }? + local out = {} + for k in t do + table.insert(out, k) + end + table.sort(out) + return if #out > 0 then out else nil + end + -- the source's required extensions that are still used stay required + for _, e in (if type(mg.extensionsRequired) == "table" then mg.extensionsRequired else {}) do + if used[e] then + required[e] = true + end + end + doc.extensionsUsed = list(used) + doc.extensionsRequired = list(required) + doc.scenes = scenes + doc.nodes = if #nodes > 0 then nodes else nil + doc.meshes = if #meshes > 0 then meshes else nil + doc.materials = if #materials > 0 then materials else nil + doc.textures = if #textures > 0 then textures else nil + doc.images = if #images > 0 then images else nil + doc.samplers = if #samplers > 0 then samplers else nil + doc.cameras = if #cameras > 0 then cameras else nil + doc.skins = if #skins > 0 then skins else nil + doc.animations = if #animations > 0 then animations else nil + doc.accessors = if #accessors > 0 then accessors else nil + doc.bufferViews = if #views > 0 then views else nil + return { doc = doc, bin = bin:finish(), images = imageOut }, nil +end + +return Write diff --git a/src/Formats/model/gltf/init.luau b/src/Formats/model/gltf/init.luau new file mode 100644 index 0000000..3f533a0 --- /dev/null +++ b/src/Formats/model/gltf/init.luau @@ -0,0 +1,248 @@ +--!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 .bin and the +-- images into opts.files) or .glb (opts.binary, or opts.format == "glb": the api passes the destination's extension). +-- Not supported: Draco (KHR_draco_mesh_compression) and meshopt (EXT_meshopt_compression) compressed primitives +-- (UNSUPPORTED), KHR_animation_pointer channels (skipped and counted in the animation's extras). + +-- ------------------------------------------------------------------------------------------------ requires +local Err = require("@formats/core/Err") +local Bytes = require("@formats/core/Bytes") +local Types = require("@formats/Types") +local Json = require("@formats/codecs/Json") +local Base64 = require("@formats/codecs/Base64") +local Read = require("@formats/model/gltf/Read") +local Write = require("@formats/model/gltf/Write") + +-- ------------------------------------------------------------------------------------------------ contract +local Gltf = { + name = "gltf", + category = "model", + extensions = { "gltf", "glb" }, + mime = { "model/gltf+json", "model/gltf-binary" }, + deps = { "core/Err", "core/Bytes", "Types", "codecs/Json", "codecs/Base64" }, + caps = { decode = true, encode = true, binary = true, materials = true, animation = true, skins = true, morphTargets = true, cameras = true, lights = true }, +} + +-- ------------------------------------------------------------------------------------------------ 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) +} +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) + files: { [string]: any }?, -- receives .bin and images with external = true + name: string?, -- the destination's file name (names the external files) + embedImages: boolean?, -- default true (false with external = true) +} + +-- ------------------------------------------------------------------------------------------------ constants +local GLB_MAGIC = 0x46546C67 -- "glTF" +local CHUNK_JSON = 0x4E4F534A +local CHUNK_BIN = 0x004E4942 + +-- ------------------------------------------------------------------------------------------------ sniff +function Gltf.sniff(r: Bytes.Reader): number + if r:peek(4) == "glTF" then + return 1 + end + local head = r:peek(1024) + local s = string.gsub(head, "^\239\187\191", "") + if string.find(s, "^%s*{") and string.find(s, "\"asset\"", 1, true) then + return 0.9 + end + if string.find(s, "^%s*{") and (string.find(s, "\"accessors\"", 1, true) or string.find(s, "\"bufferViews\"", 1, true)) then + return 0.6 + end + return 0 +end + +-- ------------------------------------------------------------------------------------------------ decode +local function fetcher(opts: DecodeOptions?): Read.Fetch + return function(uri: string): buffer? + if not opts then + return nil + end + local decoded = string.gsub(uri, "%%(%x%x)", function(h: string): string + return string.char(tonumber(h, 16) :: number) + end) + local v: any = nil + if type(opts.files) == "table" then + v = opts.files[uri] or opts.files[decoded] + end + if v == nil and type(opts.resolve) == "function" then + local ok, res = pcall(opts.resolve, uri) + v = if ok then res else nil + end + if type(v) == "string" then + return buffer.fromstring(v) + end + return if type(v) == "buffer" then v else nil + 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 + return nil, nil, r.err + end + if magic ~= GLB_MAGIC then + return nil, nil, Err.new(Err.CORRUPT, "bad GLB magic") + end + if version ~= 2 then + return nil, nil, Err.new(Err.UNSUPPORTED, "GLB version " .. version) + end + if length > r:size() then + return nil, nil, Err.new(Err.TRUNCATED, "the GLB is shorter than its header says", r.base + 8) + end + local json: string? = nil + local bin: buffer? = nil + while r:tell() + 8 <= length do + local clen, ctype = r:u32le(), r:u32le() + if clen > length - r:tell() then + return nil, nil, Err.new(Err.TRUNCATED, "a GLB chunk runs past the end", r.base + r:tell() - 8) + end + if ctype == CHUNK_JSON and json == nil then + json = r:string(clen) + elseif ctype == CHUNK_BIN and bin == nil and json ~= nil then + bin = r:bytes(clen) + else + r:skip(clen) + end + if r.err then + return nil, nil, r.err + end + end + if not json then + return nil, nil, Err.new(Err.CORRUPT, "GLB without a JSON chunk") + end + return json, bin, nil +end + +function Gltf.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Scene?, Err.Err?) + local binary = r:peek(4) == "glTF" + local text: string?, bin: buffer? + if binary then + local t, b, err = glb(r) + if not t then + return nil, err + end + text, bin = t, b + else + text = buffer.readstring(r.buf, r.base, r.limit - r.base) + end + local doc, jerr = Json.decode(text :: string) + if doc == nil then + return nil, jerr + end + local scene, err = Read.scene(doc, bin, fetcher(opts), opts) + if not scene then + return nil, err + end + scene.meta.source = { format = "gltf", binary = binary, generator = type(doc.asset) == "table" and doc.asset.generator or nil } + return scene, nil +end + +-- ------------------------------------------------------------------------------------------------ encode +local EXT = { ["image/png"] = "png", ["image/jpeg"] = "jpg", ["image/webp"] = "webp", ["image/ktx2"] = "ktx2", ["image/avif"] = "avif" } + +function Gltf.encode(scene: Types.Scene, opts: EncodeOptions?): (buffer?, Err.Err?) + if type(scene) ~= "table" or scene.kind ~= "scene" then + return nil, Err.new(Err.ARG, "needs a Scene") + end + local binary = opts and (opts.binary or opts.format == "glb") or false + local external = opts and opts.external == true and type(opts.files) == "table" and not binary + local embedImages = if opts and opts.embedImages ~= nil then opts.embedImages else not external + local out, err = Write.build(scene, { binary = binary, embedImages = embedImages }) + if not out then + return nil, err + end + 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 + if type(im.uri) == "string" and string.sub(im.uri, 1, 1) == "\0" then + for _, o in out.images do + if o.name == im.uri then + if string.sub(im.uri, 1, 6) == "\0image" or type(files) ~= "table" then + im.uri = Base64.dataUri(o.data, o.mime or "image/png") + else + n += 1 + local fname = base .. "_" .. n .. "." .. (EXT[o.mime or ""] or "png") + files[fname] = o.data + im.uri = fname + end + break + end + end + elseif type(im.uri) == "string" and type(files) == "table" and not embedImages then + for _, o in out.images do + if o.name == im.uri then + files[im.uri] = o.data + end + end + end + end + end + local binLen = buffer.len(out.bin) + if binLen > 0 then + local b = Types.object() + b.byteLength = binLen + if not binary then + if external then + local fname = base .. ".bin" + b.uri = fname + local ff: any = files + ff[fname] = out.bin + else + b.uri = Base64.dataUri(out.bin, "application/octet-stream") + end + end + doc.buffers = { b } + end + local text, jerr = Json.encode(doc, if binary then nil else { indent = 2 }) + if not text then + return nil, Err.new(Err.ARG, "JSON: " .. tostring(jerr and jerr.message or jerr)) + end + if not binary then + return buffer.fromstring(text :: string), nil + end + local jpad = (4 - #(text :: string) % 4) % 4 + local bpad = (4 - binLen % 4) % 4 + local w = Bytes.writer(12 + 8 + #(text :: string) + jpad + 8 + binLen + bpad) + w:u32le(GLB_MAGIC) + w:u32le(2) + local lenAt = w:tell() + w:u32le(0) + w:u32le(#(text :: string) + jpad) + w:u32le(CHUNK_JSON) + w:string(text :: string) + w:string(string.rep(" ", jpad)) + if binLen > 0 then + w:u32le(binLen + bpad) + w:u32le(CHUNK_BIN) + w:bytes(out.bin) + w:fill(0, bpad) + end + w:setU32le(lenAt, w:tell()) + return w:finish(), nil +end + +return Gltf diff --git a/tests/fixtures/gltf/AnimatedMorphCube/LICENSE.md b/tests/fixtures/gltf/AnimatedMorphCube/LICENSE.md new file mode 100644 index 0000000..ae8546c --- /dev/null +++ b/tests/fixtures/gltf/AnimatedMorphCube/LICENSE.md @@ -0,0 +1,17 @@ +# LICENSE file for the model: Animated Morph Cube + +All files in this directory tree are licensed as indicated below. + +* All files directly associated with the model including all text, image and binary files: + + * [Creative Commons Zero v1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/legalcode) [SPDX license identifier: "CC0-1.0"] + +* This file and all other metadocumentation files including "metadata.json": + + * [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"] + +Full license text of these licenses are available at the links above. + +This license excludes logos and associated trademarks. + + diff --git a/tests/fixtures/gltf/AnimatedMorphCube/glTF-Quantized/AnimatedMorphCube.bin b/tests/fixtures/gltf/AnimatedMorphCube/glTF-Quantized/AnimatedMorphCube.bin new file mode 100644 index 0000000..7520d98 Binary files /dev/null and b/tests/fixtures/gltf/AnimatedMorphCube/glTF-Quantized/AnimatedMorphCube.bin differ diff --git a/tests/fixtures/gltf/AnimatedMorphCube/glTF-Quantized/AnimatedMorphCube.gltf b/tests/fixtures/gltf/AnimatedMorphCube/glTF-Quantized/AnimatedMorphCube.gltf new file mode 100644 index 0000000..870695e --- /dev/null +++ b/tests/fixtures/gltf/AnimatedMorphCube/glTF-Quantized/AnimatedMorphCube.gltf @@ -0,0 +1,259 @@ +{ + "buffers":[ + { + "uri":"AnimatedMorphCube.bin", + "byteLength":1700 + } + ], + "asset":{ + "version":"2.0", + "generator":"gltfpack 0.13" + }, + "extensionsUsed":[ + "KHR_mesh_quantization" + ], + "extensionsRequired":[ + "KHR_mesh_quantization" + ], + "bufferViews":[ + { + "buffer":0, + "byteOffset":0, + "byteLength":288, + "byteStride":4, + "target":34962 + }, + { + "buffer":0, + "byteOffset":288, + "byteLength":576, + "byteStride":8, + "target":34962 + }, + { + "buffer":0, + "byteOffset":864, + "byteLength":72, + "target":34963 + }, + { + "buffer":0, + "byteOffset":936, + "byteLength":508 + }, + { + "buffer":0, + "byteOffset":1444, + "byteLength":254 + } + ], + "accessors":[ + { + "bufferView":0, + "byteOffset":0, + "componentType":5120, + "count":24, + "type":"VEC3", + "normalized":true + }, + { + "bufferView":1, + "byteOffset":0, + "componentType":5123, + "count":24, + "type":"VEC3", + "min":[ + 0, + 5451, + 0 + ], + "max":[ + 5481, + 10932, + 5481 + ] + }, + { + "bufferView":0, + "byteOffset":96, + "componentType":5120, + "count":24, + "type":"VEC3", + "normalized":true + }, + { + "bufferView":1, + "byteOffset":192, + "componentType":5122, + "count":24, + "type":"VEC3", + "min":[ + 0, + 0, + 0 + ], + "max":[ + 0, + 5188, + 0 + ] + }, + { + "bufferView":0, + "byteOffset":192, + "componentType":5120, + "count":24, + "type":"VEC3", + "normalized":true + }, + { + "bufferView":1, + "byteOffset":384, + "componentType":5122, + "count":24, + "type":"VEC3", + "min":[ + 0, + 0, + 0 + ], + "max":[ + 0, + 5451, + 0 + ] + }, + { + "bufferView":2, + "byteOffset":0, + "componentType":5123, + "count":36, + "type":"SCALAR" + }, + { + "bufferView":3, + "byteOffset":0, + "componentType":5126, + "count":127, + "type":"SCALAR", + "min":[ + 0 + ], + "max":[ + 4.19999981 + ] + }, + { + "bufferView":4, + "byteOffset":0, + "componentType":5121, + "count":254, + "type":"SCALAR", + "normalized":true + } + ], + "materials":[ + { + "name":"Material", + "pbrMetallicRoughness":{ + "baseColorFactor":[ + 0.603827417, + 0.603827417, + 0.603827417, + 1 + ], + "metallicFactor":0, + "roughnessFactor":0.5 + } + } + ], + "meshes":[ + { + "primitives":[ + { + "attributes":{ + "NORMAL":0, + "POSITION":1 + }, + "mode":4, + "targets":[ + { + "NORMAL":2, + "POSITION":3 + }, + { + "NORMAL":4, + "POSITION":5 + } + ], + "indices":6, + "material":0 + } + ], + "weights":[ + 0, + 0 + ] + } + ], + "animations":[ + { + "name":"Square", + "samplers":[ + { + "input":7, + "output":8 + } + ], + "channels":[ + { + "sampler":0, + "target":{ + "node":0, + "path":"weights" + } + } + ] + } + ], + "nodes":[ + { + "mesh":0, + "translation":[ + -0.0100000044, + -0.0298908409, + -0.00999999978 + ], + "scale":[ + 3.64900689e-06, + 3.64900689e-06, + 3.64900689e-06 + ] + }, + { + "name":"AnimatedMorphCube", + "rotation":[ + 0, + 0.707106709, + -0.707106829, + 0 + ], + "scale":[ + 100, + 100, + 100 + ], + "children":[ + 0 + ] + } + ], + "scenes":[ + { + "nodes":[ + 1 + ] + } + ], + "scene":0 +} \ No newline at end of file diff --git a/tests/fixtures/gltf/AnimatedTriangle/LICENSE.md b/tests/fixtures/gltf/AnimatedTriangle/LICENSE.md new file mode 100644 index 0000000..e940ed1 --- /dev/null +++ b/tests/fixtures/gltf/AnimatedTriangle/LICENSE.md @@ -0,0 +1,17 @@ +# LICENSE file for the model: Animated Triangle + +All files in this directory tree are licensed as indicated below. + +* All files directly associated with the model including all text, image and binary files: + + * [Creative Commons Zero v1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/legalcode) [SPDX license identifier: "CC0-1.0"] + +* This file and all other metadocumentation files including "metadata.json": + + * [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"] + +Full license text of these licenses are available at the links above. + +This license excludes logos and associated trademarks. + + diff --git a/tests/fixtures/gltf/AnimatedTriangle/glTF/AnimatedTriangle.gltf b/tests/fixtures/gltf/AnimatedTriangle/glTF/AnimatedTriangle.gltf new file mode 100644 index 0000000..b7b1e25 --- /dev/null +++ b/tests/fixtures/gltf/AnimatedTriangle/glTF/AnimatedTriangle.gltf @@ -0,0 +1,118 @@ +{ + "scene" : 0, + "scenes" : [ + { + "nodes" : [ 0 ] + } + ], + + "nodes" : [ + { + "mesh" : 0, + "rotation" : [ 0.0, 0.0, 0.0, 1.0 ] + } + ], + + "meshes" : [ + { + "primitives" : [ { + "attributes" : { + "POSITION" : 1 + }, + "indices" : 0 + } ] + } + ], + + "animations": [ + { + "samplers" : [ + { + "input" : 2, + "interpolation" : "LINEAR", + "output" : 3 + } + ], + "channels" : [ { + "sampler" : 0, + "target" : { + "node" : 0, + "path" : "rotation" + } + } ] + } + ], + + "buffers" : [ + { + "uri" : "AnimatedTriangle_geometry.bin", + "byteLength" : 44 + }, + { + "uri" : "AnimatedTriangle_animation.bin", + "byteLength" : 100 + } + ], + "bufferViews" : [ + { + "buffer" : 0, + "byteOffset" : 0, + "byteLength" : 6, + "target" : 34963 + }, + { + "buffer" : 0, + "byteOffset" : 8, + "byteLength" : 36, + "target" : 34962 + }, + { + "buffer" : 1, + "byteOffset" : 0, + "byteLength" : 100 + } + ], + "accessors" : [ + { + "bufferView" : 0, + "byteOffset" : 0, + "componentType" : 5123, + "count" : 3, + "type" : "SCALAR", + "max" : [ 2 ], + "min" : [ 0 ] + }, + { + "bufferView" : 1, + "byteOffset" : 0, + "componentType" : 5126, + "count" : 3, + "type" : "VEC3", + "max" : [ 1.0, 1.0, 0.0 ], + "min" : [ 0.0, 0.0, 0.0 ] + }, + { + "bufferView" : 2, + "byteOffset" : 0, + "componentType" : 5126, + "count" : 5, + "type" : "SCALAR", + "max" : [ 1.0 ], + "min" : [ 0.0 ] + }, + { + "bufferView" : 2, + "byteOffset" : 20, + "componentType" : 5126, + "count" : 5, + "type" : "VEC4", + "max" : [ 0.0, 0.0, 1.0, 1.0 ], + "min" : [ 0.0, 0.0, 0.0, -0.707 ] + } + ], + + "asset" : { + "version" : "2.0" + } + +} diff --git a/tests/fixtures/gltf/AnimatedTriangle/glTF/AnimatedTriangle_animation.bin b/tests/fixtures/gltf/AnimatedTriangle/glTF/AnimatedTriangle_animation.bin new file mode 100644 index 0000000..fa20e9f Binary files /dev/null and b/tests/fixtures/gltf/AnimatedTriangle/glTF/AnimatedTriangle_animation.bin differ diff --git a/tests/fixtures/gltf/AnimatedTriangle/glTF/AnimatedTriangle_geometry.bin b/tests/fixtures/gltf/AnimatedTriangle/glTF/AnimatedTriangle_geometry.bin new file mode 100644 index 0000000..d642500 Binary files /dev/null and b/tests/fixtures/gltf/AnimatedTriangle/glTF/AnimatedTriangle_geometry.bin differ diff --git a/tests/fixtures/gltf/AnisotropyStrengthTest/LICENSE.md b/tests/fixtures/gltf/AnisotropyStrengthTest/LICENSE.md new file mode 100644 index 0000000..329c208 --- /dev/null +++ b/tests/fixtures/gltf/AnisotropyStrengthTest/LICENSE.md @@ -0,0 +1,17 @@ +# LICENSE file for the model: Anisotropy Strength Test + +All files in this directory tree are licensed as indicated below. + +* All files directly associated with the model including all text, image and binary files: + + * [Creative Commons Zero v1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/legalcode) [SPDX license identifier: "CC0-1.0"] + +* This file and all other metadocumentation files including "metadata.json": + + * [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"] + +Full license text of these licenses are available at the links above. + +This license excludes logos and associated trademarks. + + diff --git a/tests/fixtures/gltf/AnisotropyStrengthTest/glTF-Binary/AnisotropyStrengthTest.glb b/tests/fixtures/gltf/AnisotropyStrengthTest/glTF-Binary/AnisotropyStrengthTest.glb new file mode 100644 index 0000000..6161291 Binary files /dev/null and b/tests/fixtures/gltf/AnisotropyStrengthTest/glTF-Binary/AnisotropyStrengthTest.glb differ diff --git a/tests/fixtures/gltf/AttenuationTest/LICENSE.md b/tests/fixtures/gltf/AttenuationTest/LICENSE.md new file mode 100644 index 0000000..4329dc8 --- /dev/null +++ b/tests/fixtures/gltf/AttenuationTest/LICENSE.md @@ -0,0 +1,17 @@ +# LICENSE file for the model: Attenuation Test + +All files in this directory tree are licensed as indicated below. + +* All files directly associated with the model including all text, image and binary files: + + * [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"] + +* This file and all other metadocumentation files including "metadata.json": + + * [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"] + +Full license text of these licenses are available at the links above. + +This license excludes logos and associated trademarks. + + diff --git a/tests/fixtures/gltf/AttenuationTest/glTF-Binary/AttenuationTest.glb b/tests/fixtures/gltf/AttenuationTest/glTF-Binary/AttenuationTest.glb new file mode 100644 index 0000000..070457d Binary files /dev/null and b/tests/fixtures/gltf/AttenuationTest/glTF-Binary/AttenuationTest.glb differ diff --git a/tests/fixtures/gltf/Box/LICENSE.md b/tests/fixtures/gltf/Box/LICENSE.md new file mode 100644 index 0000000..87f5e5e --- /dev/null +++ b/tests/fixtures/gltf/Box/LICENSE.md @@ -0,0 +1,17 @@ +# LICENSE file for the model: Box + +All files in this directory tree are licensed as indicated below. + +* All files directly associated with the model including all text, image and binary files: + + * [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"] + +* This file and all other metadocumentation files including "metadata.json": + + * [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"] + +Full license text of these licenses are available at the links above. + +This license excludes logos and associated trademarks. + + diff --git a/tests/fixtures/gltf/Box/glTF-Binary/Box.glb b/tests/fixtures/gltf/Box/glTF-Binary/Box.glb new file mode 100644 index 0000000..95ec886 Binary files /dev/null and b/tests/fixtures/gltf/Box/glTF-Binary/Box.glb differ diff --git a/tests/fixtures/gltf/Box/glTF/Box.gltf b/tests/fixtures/gltf/Box/glTF/Box.gltf new file mode 100644 index 0000000..7f603f0 --- /dev/null +++ b/tests/fixtures/gltf/Box/glTF/Box.gltf @@ -0,0 +1,142 @@ +{ + "asset": { + "generator": "COLLADA2GLTF", + "version": "2.0" + }, + "scene": 0, + "scenes": [ + { + "nodes": [ + 0 + ] + } + ], + "nodes": [ + { + "children": [ + 1 + ], + "matrix": [ + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + -1.0, + 0.0, + 0.0, + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0 + ] + }, + { + "mesh": 0 + } + ], + "meshes": [ + { + "primitives": [ + { + "attributes": { + "NORMAL": 1, + "POSITION": 2 + }, + "indices": 0, + "mode": 4, + "material": 0 + } + ], + "name": "Mesh" + } + ], + "accessors": [ + { + "bufferView": 0, + "byteOffset": 0, + "componentType": 5123, + "count": 36, + "max": [ + 23 + ], + "min": [ + 0 + ], + "type": "SCALAR" + }, + { + "bufferView": 1, + "byteOffset": 0, + "componentType": 5126, + "count": 24, + "max": [ + 1.0, + 1.0, + 1.0 + ], + "min": [ + -1.0, + -1.0, + -1.0 + ], + "type": "VEC3" + }, + { + "bufferView": 1, + "byteOffset": 288, + "componentType": 5126, + "count": 24, + "max": [ + 0.5, + 0.5, + 0.5 + ], + "min": [ + -0.5, + -0.5, + -0.5 + ], + "type": "VEC3" + } + ], + "materials": [ + { + "pbrMetallicRoughness": { + "baseColorFactor": [ + 0.800000011920929, + 0.0, + 0.0, + 1.0 + ], + "metallicFactor": 0.0 + }, + "name": "Red" + } + ], + "bufferViews": [ + { + "buffer": 0, + "byteOffset": 576, + "byteLength": 72, + "target": 34963 + }, + { + "buffer": 0, + "byteOffset": 0, + "byteLength": 576, + "byteStride": 12, + "target": 34962 + } + ], + "buffers": [ + { + "byteLength": 648, + "uri": "Box0.bin" + } + ] +} diff --git a/tests/fixtures/gltf/Box/glTF/Box0.bin b/tests/fixtures/gltf/Box/glTF/Box0.bin new file mode 100644 index 0000000..d7798ab Binary files /dev/null and b/tests/fixtures/gltf/Box/glTF/Box0.bin differ diff --git a/tests/fixtures/gltf/BoxInterleaved/LICENSE.md b/tests/fixtures/gltf/BoxInterleaved/LICENSE.md new file mode 100644 index 0000000..2c7c940 --- /dev/null +++ b/tests/fixtures/gltf/BoxInterleaved/LICENSE.md @@ -0,0 +1,17 @@ +# LICENSE file for the model: Box with interleaved position and normal attributes + +All files in this directory tree are licensed as indicated below. + +* All files directly associated with the model including all text, image and binary files: + + * [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"] + +* This file and all other metadocumentation files including "metadata.json": + + * [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"] + +Full license text of these licenses are available at the links above. + +This license excludes logos and associated trademarks. + + diff --git a/tests/fixtures/gltf/BoxInterleaved/glTF-Binary/BoxInterleaved.glb b/tests/fixtures/gltf/BoxInterleaved/glTF-Binary/BoxInterleaved.glb new file mode 100644 index 0000000..25cb404 Binary files /dev/null and b/tests/fixtures/gltf/BoxInterleaved/glTF-Binary/BoxInterleaved.glb differ diff --git a/tests/fixtures/gltf/BoxTextured/LICENSE.md b/tests/fixtures/gltf/BoxTextured/LICENSE.md new file mode 100644 index 0000000..c8993e0 --- /dev/null +++ b/tests/fixtures/gltf/BoxTextured/LICENSE.md @@ -0,0 +1,19 @@ +# LICENSE file for the model: Box Textured + +All files in this directory tree are licensed as indicated below. + +* All files directly associated with the model including all text, image and binary files: + + * [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"] + + * [Cesium Trademark or Logo](../../LICENSES/LicenseRef-LegalMark-Cesium.txt) + +* This file and all other metadocumentation files including "metadata.json": + + * [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"] + +Full license text of these licenses are available at the links above. + +This license excludes logos and associated trademarks. + + diff --git a/tests/fixtures/gltf/BoxTextured/glTF-Embedded/BoxTextured.gltf b/tests/fixtures/gltf/BoxTextured/glTF-Embedded/BoxTextured.gltf new file mode 100644 index 0000000..2743fc1 --- /dev/null +++ b/tests/fixtures/gltf/BoxTextured/glTF-Embedded/BoxTextured.gltf @@ -0,0 +1,181 @@ +{ + "asset": { + "generator": "COLLADA2GLTF", + "version": "2.0" + }, + "scene": 0, + "scenes": [ + { + "nodes": [ + 0 + ] + } + ], + "nodes": [ + { + "children": [ + 1 + ], + "matrix": [ + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + -1.0, + 0.0, + 0.0, + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0 + ] + }, + { + "mesh": 0 + } + ], + "meshes": [ + { + "primitives": [ + { + "attributes": { + "NORMAL": 1, + "POSITION": 2, + "TEXCOORD_0": 3 + }, + "indices": 0, + "mode": 4, + "material": 0 + } + ], + "name": "Mesh" + } + ], + "accessors": [ + { + "bufferView": 0, + "byteOffset": 0, + "componentType": 5123, + "count": 36, + "max": [ + 23 + ], + "min": [ + 0 + ], + "type": "SCALAR" + }, + { + "bufferView": 1, + "byteOffset": 0, + "componentType": 5126, + "count": 24, + "max": [ + 1.0, + 1.0, + 1.0 + ], + "min": [ + -1.0, + -1.0, + -1.0 + ], + "type": "VEC3" + }, + { + "bufferView": 1, + "byteOffset": 288, + "componentType": 5126, + "count": 24, + "max": [ + 0.5, + 0.5, + 0.5 + ], + "min": [ + -0.5, + -0.5, + -0.5 + ], + "type": "VEC3" + }, + { + "bufferView": 2, + "byteOffset": 0, + "componentType": 5126, + "count": 24, + "max": [ + 6.0, + 1.0 + ], + "min": [ + 0.0, + 0.0 + ], + "type": "VEC2" + } + ], + "materials": [ + { + "pbrMetallicRoughness": { + "baseColorTexture": { + "index": 0 + }, + "metallicFactor": 0.0 + }, + "name": "Texture" + } + ], + "textures": [ + { + "sampler": 0, + "source": 0 + } + ], + "images": [ + { + "uri": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAMAAABrrFhUAAAAYFBMVEXc3Ny+1ejU2t6tzOaXwuVyseJprN9srd9gqd9/tuKHuuPh7vn////1+fnL2+ns8Onm6+B+nlyyw6GXsH1zl0ljjTBahiFchydRggWLp2u9yq+mupHM1MPg3+HY3NPf3t2inO6qAAAOAUlEQVR42uzWh7nkOAwDYIkBINmE+u/yJl3aHDyW9NZ/B4D1wWznuVwul8vlchnf8AdEb03+1aX3Ll3+1T50DXLXVc2sKv0GN36TVWWm2uWufUCjSVezdD44/wMg6XTeed6LkDY+0LNvomqV6e4k7kiCXwCA9JusZws3m4d/vvhyR+CO34Unet1L6DJutv3y9/TJCAD8SQAimGbaRfbrYDQR6ZaIAPjLgIhIU5HtRkHUHDf8fQDcVHZ6/E0tnYdytz1+DY/Zq3QCPBAAz7Lexlh+9a0cAA8HhJeprNvBGK/dA98EEW4qsmgDImoIgG8ERJSKtBVpOXgCoFTaYoZoOU/jpTLWim9JgCcBkLZOBaN1TQR4IgRS1/gpjiZaCPBkCNQSp5F0C4ATAFFdpuc3B6eBm8x9/lpOcBrQS9uYd/lZApwKSJM5WzikmwOcDHDrMqMB0QxwAYhUmbl+84WbnH77pHMhnr2NU0/f5FJAVxkn5vcAl4I4sQExD04zfwikAC4IOOcy7g5wSYD3E47f5MLy7YexJsBlAan751+4AVEHuLZwlfflB7g84G0NqHMHCJXxlv13cAtwlTF//+Y2sH/+1RroCXAfh9+EkgQ3Ah7awJDidqqP4/IbwN3AZByVXx3cDvywBjSDG4rUw34A3FJkbweQcnBL4F/cnAdiAykMRZcBPqJI3gtkuf8pt6VnKshjxnkXiIYItS8cp3sEQB+eldcwoA6AYTQAqHPlVt0VVJMwvLkjn5xLEUToCANVeQFo+LzfWSOSRYx17XIEKS/B+Aog2lzeye0TWcCpMmCi0d+fy1eyD41QMhoJKGBsHnO5fCenRpMQ0vPOgMjl8pPc6pTw3VrB5Mc6ACUpcyRSa2c8PWcPCLJc5rBtTAXo7QsNwlAQpSwhEc0n2ekAYShkc1kiWwptoGs4MlwFISnLGGrXSnpqYApjoVyWkWbLqMMFnMdlDwA4vx40kcJVDyD7nqZI4QDXuwLomAy06gAIoyFRxACdUlIvsQZKhssSbCh0kFqqIePDeMit1AF9Mwpvnk0IgZeyhPE4WSip+39iYCnIjnr10np4FYauInKXOd09+uHFkWochUuAJPpWqL0jqJeRAhGS+ZkB+nV6wNaDgzC60vJrLp9k1Z4uuemYA1xICwTISeZXsjiCLqYccoFrLQOAKFojIsZGIihjyjExlMLF8MH74IMaRDNQC1GAVx60PHZ9NVyTVfbD4DTg+0duz02z56B//Gqmqe4uxP1mDwhx9wD83cIW/Qf+4xJhlF4xewshemsBIvLOWmPEWKv+RTUt/5uTXs0xdjpbDQFRdEZyzvw/OWcxTl3D6H576Ys5t5ftRjBCv9Ahmct3sljnCSM8P1rz3ZzbX5t9ACl7l2RzWSTb5IGHxzw3GyzeThyFwLtcVskPXzjzSbj8hF/O2okCvf69VVgS4aHvx3jBHv7znE4YIJu5bMLZgsKDmP87du9ArdZDNbrYJZsHxUKQW3NHXo+CtfsGANFwOQBr397ooxGfMQxDNGUNxVRP8f28bsHL/dcCEUw5jIk43/+5rMK3radxehlvH+sxQFTbiYIaTRxkc2mALeGB63UNQcAF9O5zNpFPlZ4QhDsPIHV9P1IujeQzU4G3e+VIbduK0CeAGSx+SAJ4rwXrHV9HAba0w6cFwiP+eKt3fB64FQB5IxmfJL9QlPIPb1eiHSEOw/Yaz7HjwnA45mj4/7/cx170sFoETPUDTTSOoigOhVDgBMDn0fYpbjn21TBU/VjeYZ/H8RAkAJrn8VT9mBURsKkxSE6x4hbj0PgMb4YxHhLb9b1nQ9ap7/wfdGOpiAB0JcITXgytu6Vkydy9KjT0xCI/JAA6dvNw7J/xdBkRQJt0pLjlwyz9D/Mux4vgeBUI16MOracF3vQZJOJCC8Cf8fxbS29g1pUhAzseZIATiYbzb8zSAkvNGIvgWQ5R3KlzS+9gbVfGbkCe7wC0as3eD8fGHNqAsxwhAOXglj7AvC5jN3CcEEpcjzq29un36PMU2YCzHNHFNrinTzCvNGTgLE9+YJK7T8OxtjqCALmGAjA2ngKYj+FeyPkhPpIoBk+fCRjGIwh4iQXQLUXwLmSAkwHekQ7BcCzV4+teAuQcCoB2raUQ5nXBdz7vrcc+qEdIAEoDiNBRK7ME4M2gcTYgRxAQOtL8iMfTEQRwimuWILwNTTF+DEt1foQbUp2i8RhHAK+4ANZaBu8A5SkOoOjd0lMIEMGKmzDMu+kZIalInMmNjuqxIQhgFBcI4ALkBkR2hqBoQ47RIgL4MxdWXCCE4/HZgFzCeixrt0RVwG116hgrboMUEBwMiWyAqEdwBKSXAK+4XaS4AQPFsdkAEAAF9UgQQCpu5ZZWwFvgBrbOP65HzS2ev+0hQC6E4kaw2A3oRjeA6rFJlo6vAOwAxoentQS0U9g7sUkG5Izq8cshrCMAKK5SihsAZAPwtTJ/Daoj2JAJI7RbcTHMh4JyA7wD6DwRBIDTIKG42HIAIeyVcQP8EcDTLgIwTqEAAsXF8Mcx2YDE9bgcgQC25gEoBHyAP0i7gZcL+fyBcQAgD1iACVgWgPJHIKDDdbgIKBmQsB41gx0QRGJEKowcQOuJhrX93mzgghypWfqWgDzhewGsuHQGgGHWxDJwEyFCebYeQSqMb4Z4xSXcQHgsCtwA40i1d1tTfoCALYprlrbBB40YWCkDQmQAgRunL0eR4lYNP/+lELdnA7KE8rwjtTZPRH8Aqbj73cB1syPXIJMKD4N5IjtEoOK6pc0wA1emsrExT/vWV5VeTADuEYKKW3naA0tDsaWBStCtnJmtIqDLE9UlhjKAWHEJmMfZwFKKTGNeXlmP1gx5ovoE2QyAgDMh6XIrd99Tj95UmeoUlQupuAS8y/hLOfhIztcjbpHBn07AX7bkMwA6G7gIduQ769EfmegW36m4a+oRXJnixjxCAMD9FPFeQM6h5dLRKQvI35WAQ4FIvCHVra0/iU7E1zOQ4vICiI9FJWinFqIRKvl6xgfizRBohS4HT0fB2m61G0Ct+dkZA9oTr8ZiAbz3Zuk4WK8rGbiA+TfGbDzjim9IAQdEKy4vAzgmhpFEOThDQD2t+ZQsmD/ohHyOG3j3zhQ/zdWKDOVfv/mPyv/QLiKnxXGwisu7gZiBq7wZDngLytWjN9VMAGbgejrLjPPpFq9/7fkjMHtlulwX3U7zeObhXMHTrJJbjz7fCWAUOrM+44pegmRLh8O8GRW8LvrjfBG5wOFox9WjzychjFLv81cvXuYvToD5Y8J3wNKjBBOch/MCh6MVN3/zeQVgvBbvHtcQiksB9FEi4OHoSOqRNf1MAMYyCkC4edoP1EBFgw7lfbkUAiVwByAVl4d5f2fB30r5ciUACMA/A1ZcHqidmgS/Hm0pgBgTXANAcZ8vAxhV4/S5YyGAXwM6AAfwZDcABTBohSYuxQAmxQLIFhzPQKWMACbjTx145ngNHJsBcTExRuYzSRyIYxnEfQfP2gp09fwTgSAPhtC4/o+fP3BqvAEgLuN+WYFCoxPgnltArkyXkyFGj9c/htkSBXAyqLluseAeroT1+K3/4fR/WQELAYwdLvsdCQgP964vv9z+Bt80Hq8DBQBHwgVa5to9/STMvc4FOv6VVeO2bXHBgyDeCVVz527ppzFToPp5Lf7Vvn2mua7CYADWAs45MwYhBKjsf5d3TG6vcVzxzTvld/QZRMnjXj6/vNVWWDgELEwpnyRNzf6UwIfElFYcNx2epB8fZhJamTAT5VMQZZxKC2KfH98/Pk1qiwVX9GJCUXiSW4xlQmJmyqchYiacSowtxlIwrfo4xM0cnuQy8ReifDbiX639OCjwNLeKlC+G1u6vzOFpDiVTvhNCMViiTnyr+lM0WKQfNu+Di8AyGpDvNACawzJujelOA8BhIa33GQL9FLCUW7hNABxFYTGVQnSTAKrDcm413SIA4mYKL3Brd0iA0iQOLzGZbjAJGIM5vMYb8g32gA4L3G4/yEXgdS6Fh58ADmsEpNFXAIcV1BoPPgEUVlEZ+GaAMgqsZYJE4x4CzWEta8jj34KsYTHxmA2wCGxBZczdAE/VYRMqhcffAayhFelmDXD5yXi4AJoobMatjdUIKRVx2NJYCVAuAttyGSgB4iIOG1NpiYapvypsTiUOciqgqSrswEc5F6WqsAsb4aKcKInBPhzk8scC4qmaw160JzB8/1tBr70aUt65fvA5gXxZac0N2PjfFxFFcdifBeQrRsCpCRzCarleAsQYxOEQ6hITX6/9m8JRVCISXWr3U0QdjqPWMF9IiuJwLKsT03Wmv8HhTFq6RATMUQyO52qhMNP5j7+JO5xB4fReSJxKMIWzuLUpnRgBpcfjP5FLzOfpZ7+TmdXCTGc1f4OzuZsEPD4CZmxi7nA+V6vt2AiIGWM1dbiGviIe94IZEWFp8ij/UhGkTEfU318pVIersVqIjtn5mMEF+WNBYNp38pcgBhelJrVNPYP9Wl9v/VflqlZbRGai7V8jTaUFUXW4NFeVVhAzbZcBfUlYmpg6jMC9timllLeSEsZq7uAwCjPZphtQn/liZjAUdzORUBK/ngIR94lfpTe+4bi6SQ0tIs+IFpU+w9JCFQFVGJSrqklosUyY5qJo9u/drteecCpxrl5VHcbmrupSewiIc2ukf5RTSoi9+Crei78NB4ceQ8H0q/yQfoHYSze4K/uZ1BpCay3GWGKMrbVQq4hYBzfmD2Az+Y3NwDv4P/BerM7m/ycU/vb29vb29vb2E95qsPCUXPMVAAAAAElFTkSuQmCC" + } + ], + "samplers": [ + { + "magFilter": 9729, + "minFilter": 9986, + "wrapS": 10497, + "wrapT": 10497 + } + ], + "bufferViews": [ + { + "buffer": 0, + "byteOffset": 768, + "byteLength": 72, + "target": 34963 + }, + { + "buffer": 0, + "byteOffset": 0, + "byteLength": 576, + "byteStride": 12, + "target": 34962 + }, + { + "buffer": 0, + "byteOffset": 576, + "byteLength": 192, + "byteStride": 8, + "target": 34962 + } + ], + "buffers": [ + { + "byteLength": 840, + "uri": "data:application/octet-stream;base64,AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AACAPwAAAAAAAAAAAACAPwAAAAAAAAAAAACAPwAAAAAAAAAAAACAPwAAAAAAAAAAAAAAAAAAgD8AAAAAAAAAAAAAgD8AAAAAAAAAAAAAgD8AAAAAAAAAAAAAgD8AAAAAAAAAAAAAgL8AAAAAAAAAAAAAgL8AAAAAAAAAAAAAgL8AAAAAAAAAAAAAgL8AAAAAAACAvwAAAAAAAAAAAACAvwAAAAAAAAAAAACAvwAAAAAAAAAAAACAvwAAAAAAAAAAAAAAAAAAAAAAAIC/AAAAAAAAAAAAAIC/AAAAAAAAAAAAAIC/AAAAAAAAAAAAAIC/AAAAvwAAAL8AAAA/AAAAPwAAAL8AAAA/AAAAvwAAAD8AAAA/AAAAPwAAAD8AAAA/AAAAPwAAAD8AAAA/AAAAPwAAAL8AAAA/AAAAPwAAAD8AAAC/AAAAPwAAAL8AAAC/AAAAvwAAAD8AAAA/AAAAPwAAAD8AAAA/AAAAvwAAAD8AAAC/AAAAPwAAAD8AAAC/AAAAPwAAAL8AAAA/AAAAvwAAAL8AAAA/AAAAPwAAAL8AAAC/AAAAvwAAAL8AAAC/AAAAvwAAAL8AAAA/AAAAvwAAAD8AAAA/AAAAvwAAAL8AAAC/AAAAvwAAAD8AAAC/AAAAvwAAAL8AAAC/AAAAvwAAAD8AAAC/AAAAPwAAAL8AAAC/AAAAPwAAAD8AAAC/AADAQAAAAAAAAKBAAAAAAAAAwED+/38/AACgQP7/fz8AAIBAAAAAAAAAoEAAAAAAAACAQAAAgD8AAKBAAACAPwAAAEAAAAAAAACAPwAAAAAAAABAAACAPwAAgD8AAIA/AABAQAAAAAAAAIBAAAAAAAAAQEAAAIA/AACAQAAAgD8AAEBAAAAAAAAAAEAAAAAAAABAQAAAgD8AAABAAACAPwAAAAAAAAAAAAAAAP7/fz8AAIA/AAAAAAAAgD/+/38/AAABAAIAAwACAAEABAAFAAYABwAGAAUACAAJAAoACwAKAAkADAANAA4ADwAOAA0AEAARABIAEwASABEAFAAVABYAFwAWABUA" + } + ] +} diff --git a/tests/fixtures/gltf/BoxTextured/glTF/BoxTextured.gltf b/tests/fixtures/gltf/BoxTextured/glTF/BoxTextured.gltf new file mode 100644 index 0000000..eff658f --- /dev/null +++ b/tests/fixtures/gltf/BoxTextured/glTF/BoxTextured.gltf @@ -0,0 +1,181 @@ +{ + "asset": { + "generator": "COLLADA2GLTF", + "version": "2.0" + }, + "scene": 0, + "scenes": [ + { + "nodes": [ + 0 + ] + } + ], + "nodes": [ + { + "children": [ + 1 + ], + "matrix": [ + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + -1.0, + 0.0, + 0.0, + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0 + ] + }, + { + "mesh": 0 + } + ], + "meshes": [ + { + "primitives": [ + { + "attributes": { + "NORMAL": 1, + "POSITION": 2, + "TEXCOORD_0": 3 + }, + "indices": 0, + "mode": 4, + "material": 0 + } + ], + "name": "Mesh" + } + ], + "accessors": [ + { + "bufferView": 0, + "byteOffset": 0, + "componentType": 5123, + "count": 36, + "max": [ + 23 + ], + "min": [ + 0 + ], + "type": "SCALAR" + }, + { + "bufferView": 1, + "byteOffset": 0, + "componentType": 5126, + "count": 24, + "max": [ + 1.0, + 1.0, + 1.0 + ], + "min": [ + -1.0, + -1.0, + -1.0 + ], + "type": "VEC3" + }, + { + "bufferView": 1, + "byteOffset": 288, + "componentType": 5126, + "count": 24, + "max": [ + 0.5, + 0.5, + 0.5 + ], + "min": [ + -0.5, + -0.5, + -0.5 + ], + "type": "VEC3" + }, + { + "bufferView": 2, + "byteOffset": 0, + "componentType": 5126, + "count": 24, + "max": [ + 6.0, + 1.0 + ], + "min": [ + 0.0, + 0.0 + ], + "type": "VEC2" + } + ], + "materials": [ + { + "pbrMetallicRoughness": { + "baseColorTexture": { + "index": 0 + }, + "metallicFactor": 0.0 + }, + "name": "Texture" + } + ], + "textures": [ + { + "sampler": 0, + "source": 0 + } + ], + "images": [ + { + "uri": "CesiumLogoFlat.png" + } + ], + "samplers": [ + { + "magFilter": 9729, + "minFilter": 9986, + "wrapS": 10497, + "wrapT": 10497 + } + ], + "bufferViews": [ + { + "buffer": 0, + "byteOffset": 768, + "byteLength": 72, + "target": 34963 + }, + { + "buffer": 0, + "byteOffset": 0, + "byteLength": 576, + "byteStride": 12, + "target": 34962 + }, + { + "buffer": 0, + "byteOffset": 576, + "byteLength": 192, + "byteStride": 8, + "target": 34962 + } + ], + "buffers": [ + { + "byteLength": 840, + "uri": "BoxTextured0.bin" + } + ] +} diff --git a/tests/fixtures/gltf/BoxTextured/glTF/BoxTextured0.bin b/tests/fixtures/gltf/BoxTextured/glTF/BoxTextured0.bin new file mode 100644 index 0000000..d2a7355 Binary files /dev/null and b/tests/fixtures/gltf/BoxTextured/glTF/BoxTextured0.bin differ diff --git a/tests/fixtures/gltf/BoxTextured/glTF/CesiumLogoFlat.png b/tests/fixtures/gltf/BoxTextured/glTF/CesiumLogoFlat.png new file mode 100644 index 0000000..8d5a3ad Binary files /dev/null and b/tests/fixtures/gltf/BoxTextured/glTF/CesiumLogoFlat.png differ diff --git a/tests/fixtures/gltf/BoxVertexColors/LICENSE.md b/tests/fixtures/gltf/BoxVertexColors/LICENSE.md new file mode 100644 index 0000000..afa6d28 --- /dev/null +++ b/tests/fixtures/gltf/BoxVertexColors/LICENSE.md @@ -0,0 +1,17 @@ +# LICENSE file for the model: Box Vertex Colors + +All files in this directory tree are licensed as indicated below. + +* All files directly associated with the model including all text, image and binary files: + + * [Creative Commons Zero v1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/legalcode) [SPDX license identifier: "CC0-1.0"] + +* This file and all other metadocumentation files including "metadata.json": + + * [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"] + +Full license text of these licenses are available at the links above. + +This license excludes logos and associated trademarks. + + diff --git a/tests/fixtures/gltf/BoxVertexColors/glTF-Binary/BoxVertexColors.glb b/tests/fixtures/gltf/BoxVertexColors/glTF-Binary/BoxVertexColors.glb new file mode 100644 index 0000000..875d95a Binary files /dev/null and b/tests/fixtures/gltf/BoxVertexColors/glTF-Binary/BoxVertexColors.glb differ diff --git a/tests/fixtures/gltf/Cameras/LICENSE.md b/tests/fixtures/gltf/Cameras/LICENSE.md new file mode 100644 index 0000000..f718127 --- /dev/null +++ b/tests/fixtures/gltf/Cameras/LICENSE.md @@ -0,0 +1,17 @@ +# LICENSE file for the model: Cameras + +All files in this directory tree are licensed as indicated below. + +* All files directly associated with the model including all text, image and binary files: + + * [Creative Commons Zero v1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/legalcode) [SPDX license identifier: "CC0-1.0"] + +* This file and all other metadocumentation files including "metadata.json": + + * [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"] + +Full license text of these licenses are available at the links above. + +This license excludes logos and associated trademarks. + + diff --git a/tests/fixtures/gltf/Cameras/glTF/Cameras.bin b/tests/fixtures/gltf/Cameras/glTF/Cameras.bin new file mode 100644 index 0000000..a6edb3b Binary files /dev/null and b/tests/fixtures/gltf/Cameras/glTF/Cameras.bin differ diff --git a/tests/fixtures/gltf/Cameras/glTF/Cameras.gltf b/tests/fixtures/gltf/Cameras/glTF/Cameras.gltf new file mode 100644 index 0000000..48d5adf --- /dev/null +++ b/tests/fixtures/gltf/Cameras/glTF/Cameras.gltf @@ -0,0 +1,99 @@ +{ + "scene" : 0, + "scenes" : [ + { + "nodes" : [ 0, 1, 2 ] + } + ], + "nodes" : [ + { + "rotation" : [ -0.383, 0.0, 0.0, 0.92375 ], + "mesh" : 0 + }, + { + "translation" : [ 0.5, 0.5, 3.0 ], + "camera" : 0 + }, + { + "translation" : [ 0.5, 0.5, 3.0 ], + "camera" : 1 + } + ], + + "cameras" : [ + { + "type": "perspective", + "perspective": { + "aspectRatio": 1.0, + "yfov": 0.7, + "zfar": 100, + "znear": 0.01 + } + }, + { + "type": "orthographic", + "orthographic": { + "xmag": 1.0, + "ymag": 1.0, + "zfar": 100, + "znear": 0.01 + } + } + ], + + "meshes" : [ + { + "primitives" : [ { + "attributes" : { + "POSITION" : 1 + }, + "indices" : 0 + } ] + } + ], + + "buffers" : [ + { + "uri" : "Cameras.bin", + "byteLength" : 60 + } + ], + "bufferViews" : [ + { + "buffer" : 0, + "byteOffset" : 0, + "byteLength" : 12, + "target" : 34963 + }, + { + "buffer" : 0, + "byteOffset" : 12, + "byteLength" : 48, + "target" : 34962 + } + ], + "accessors" : [ + { + "bufferView" : 0, + "byteOffset" : 0, + "componentType" : 5123, + "count" : 6, + "type" : "SCALAR", + "max" : [ 3 ], + "min" : [ 0 ] + }, + { + "bufferView" : 1, + "byteOffset" : 0, + "componentType" : 5126, + "count" : 4, + "type" : "VEC3", + "max" : [ 1.0, 1.0, 0.0 ], + "min" : [ 0.0, 0.0, 0.0 ] + } + ], + + "asset" : { + "version" : "2.0" + } +} diff --git a/tests/fixtures/gltf/ClearCoatCarPaint/LICENSE.md b/tests/fixtures/gltf/ClearCoatCarPaint/LICENSE.md new file mode 100644 index 0000000..2ec4dac --- /dev/null +++ b/tests/fixtures/gltf/ClearCoatCarPaint/LICENSE.md @@ -0,0 +1,17 @@ +# LICENSE file for the model: Clear Coat Car Paint + +All files in this directory tree are licensed as indicated below. + +* All files directly associated with the model including all text, image and binary files: + + * [Creative Commons Zero v1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/legalcode) [SPDX license identifier: "CC0-1.0"] + +* This file and all other metadocumentation files including "metadata.json": + + * [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"] + +Full license text of these licenses are available at the links above. + +This license excludes logos and associated trademarks. + + diff --git a/tests/fixtures/gltf/ClearCoatCarPaint/glTF-Binary/ClearCoatCarPaint.glb b/tests/fixtures/gltf/ClearCoatCarPaint/glTF-Binary/ClearCoatCarPaint.glb new file mode 100644 index 0000000..6258704 Binary files /dev/null and b/tests/fixtures/gltf/ClearCoatCarPaint/glTF-Binary/ClearCoatCarPaint.glb differ diff --git a/tests/fixtures/gltf/EmissiveStrengthTest/LICENSE.md b/tests/fixtures/gltf/EmissiveStrengthTest/LICENSE.md new file mode 100644 index 0000000..b2e3125 --- /dev/null +++ b/tests/fixtures/gltf/EmissiveStrengthTest/LICENSE.md @@ -0,0 +1,17 @@ +# LICENSE file for the model: Emissive Strength Test + +All files in this directory tree are licensed as indicated below. + +* All files directly associated with the model including all text, image and binary files: + + * [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"] + +* This file and all other metadocumentation files including "metadata.json": + + * [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"] + +Full license text of these licenses are available at the links above. + +This license excludes logos and associated trademarks. + + diff --git a/tests/fixtures/gltf/EmissiveStrengthTest/glTF-Binary/EmissiveStrengthTest.glb b/tests/fixtures/gltf/EmissiveStrengthTest/glTF-Binary/EmissiveStrengthTest.glb new file mode 100644 index 0000000..6020aa6 Binary files /dev/null and b/tests/fixtures/gltf/EmissiveStrengthTest/glTF-Binary/EmissiveStrengthTest.glb differ diff --git a/tests/fixtures/gltf/InterpolationTest/LICENSE.md b/tests/fixtures/gltf/InterpolationTest/LICENSE.md new file mode 100644 index 0000000..98cc3eb --- /dev/null +++ b/tests/fixtures/gltf/InterpolationTest/LICENSE.md @@ -0,0 +1,17 @@ +# LICENSE file for the model: Interpolation Test + +All files in this directory tree are licensed as indicated below. + +* All files directly associated with the model including all text, image and binary files: + + * [Creative Commons Zero v1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/legalcode) [SPDX license identifier: "CC0-1.0"] + +* This file and all other metadocumentation files including "metadata.json": + + * [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"] + +Full license text of these licenses are available at the links above. + +This license excludes logos and associated trademarks. + + diff --git a/tests/fixtures/gltf/InterpolationTest/glTF-Binary/InterpolationTest.glb b/tests/fixtures/gltf/InterpolationTest/glTF-Binary/InterpolationTest.glb new file mode 100644 index 0000000..4200fcc Binary files /dev/null and b/tests/fixtures/gltf/InterpolationTest/glTF-Binary/InterpolationTest.glb differ diff --git a/tests/fixtures/gltf/LightVisibility/LICENSE.md b/tests/fixtures/gltf/LightVisibility/LICENSE.md new file mode 100644 index 0000000..d95f2cf --- /dev/null +++ b/tests/fixtures/gltf/LightVisibility/LICENSE.md @@ -0,0 +1,17 @@ +# LICENSE file for the model: LightVisibility + +All files in this directory tree are licensed as indicated below. + +* All files directly associated with the model including all text, image and binary files: + + * [Creative Commons Zero v1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/legalcode) [SPDX license identifier: "CC0-1.0"] + +* This file and all other metadocumentation files including "metadata.json": + + * [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"] + +Full license text of these licenses are available at the links above. + +This license excludes logos and associated trademarks. + + diff --git a/tests/fixtures/gltf/LightVisibility/glTF-Binary/LightVisibility.glb b/tests/fixtures/gltf/LightVisibility/glTF-Binary/LightVisibility.glb new file mode 100644 index 0000000..861a523 Binary files /dev/null and b/tests/fixtures/gltf/LightVisibility/glTF-Binary/LightVisibility.glb differ diff --git a/tests/fixtures/gltf/MeshPrimitiveModes/LICENSE.md b/tests/fixtures/gltf/MeshPrimitiveModes/LICENSE.md new file mode 100644 index 0000000..083a4b6 --- /dev/null +++ b/tests/fixtures/gltf/MeshPrimitiveModes/LICENSE.md @@ -0,0 +1,17 @@ +# LICENSE file for the model: Mesh Primitive Modes + +All files in this directory tree are licensed as indicated below. + +* All files directly associated with the model including all text, image and binary files: + + * [Creative Commons Zero v1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/legalcode) [SPDX license identifier: "CC0-1.0"] + +* This file and all other metadocumentation files including "metadata.json": + + * [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"] + +Full license text of these licenses are available at the links above. + +This license excludes logos and associated trademarks. + + diff --git a/tests/fixtures/gltf/MeshPrimitiveModes/glTF/MeshPrimitiveModes.gltf b/tests/fixtures/gltf/MeshPrimitiveModes/glTF/MeshPrimitiveModes.gltf new file mode 100644 index 0000000..b392211 --- /dev/null +++ b/tests/fixtures/gltf/MeshPrimitiveModes/glTF/MeshPrimitiveModes.gltf @@ -0,0 +1,233 @@ +{ + "asset": { + "version": "2.0" + }, + + "scene": 0, + "scenes": [ + { + "nodes": [0, 1, 2, 3, 4, 5, 6] + } + ], + + "nodes": [ + { + "translation": [-0, 3, 0], + "mesh": 0 + }, + { + "translation": [-2, 0, 0], + "mesh": 1 + }, + { + "translation": [0, 0, 0], + "mesh": 2 + }, + { + "translation": [2, 0, 0], + "mesh": 3 + }, + { + "translation": [-2, -3, 0], + "mesh": 4 + }, + { + "translation": [0, -3, 0], + "mesh": 5 + }, + { + "translation": [2, -3, 0], + "mesh": 6 + } + ], + + "meshes": [ + { + "name": "mesh with POINTS", + "primitives": [ + { + "attributes": { + "POSITION": 7 + }, + "indices": 0, + "mode": 0 + } + ] + }, + { + "name": "mesh with LINES", + "primitives": [ + { + "attributes": { + "POSITION": 7 + }, + "indices": 1, + "mode": 1 + } + ] + }, + { + "name": "mesh with LINE_LOOP", + "primitives": [ + { + "attributes": { + "POSITION": 7 + }, + "indices": 2, + "mode": 2 + } + ] + }, + { + "name": "mesh with LINE_STRIP", + "primitives": [ + { + "attributes": { + "POSITION": 7 + }, + "indices": 3, + "mode": 3 + } + ] + }, + { + "name": "mesh with TRIANGLES", + "primitives": [ + { + "attributes": { + "POSITION": 7 + }, + "indices": 4, + "mode": 4 + } + ] + }, + { + "name": "mesh with GL_TRIANGLE_STRIP", + "primitives": [ + { + "attributes": { + "POSITION": 7 + }, + "indices": 5, + "mode": 5 + } + ] + }, + { + "name": "mesh with GL_TRIANGLE_FAN", + "primitives": [ + { + "attributes": { + "POSITION": 7 + }, + "indices": 6, + "mode": 6 + } + ] + } + ], + + "buffers": [ + { + "uri": "buffer.bin", + "byteLength": 216 + } + ], + "bufferViews": [ + { + "buffer": 0, + "byteOffset": 0, + "byteLength": 130, + "target": 34963 + }, + { + "buffer": 0, + "byteOffset": 132, + "byteLength": 84, + "target": 34962 + } + ], + "accessors": [ + { + "name": "indices for POINTS", + "bufferView": 0, + "byteOffset": 0, + "componentType": 5123, + "count": 7, + "type": "SCALAR", + "max": [6], + "min": [0] + }, + { + "name": "indices for LINES", + "bufferView": 0, + "byteOffset": 14, + "componentType": 5123, + "count": 12, + "type": "SCALAR", + "max": [6], + "min": [0] + }, + { + "name": "indices for LINE_LOOP", + "bufferView": 0, + "byteOffset": 38, + "componentType": 5123, + "count": 7, + "type": "SCALAR", + "max": [6], + "min": [0] + }, + { + "name": "indices for LINE_STRIP", + "bufferView": 0, + "byteOffset": 52, + "componentType": 5123, + "count": 7, + "type": "SCALAR", + "max": [6], + "min": [0] + }, + { + "name": "indices for TRIANGLES", + "bufferView": 0, + "byteOffset": 66, + "componentType": 5123, + "count": 18, + "type": "SCALAR", + "max": [6], + "min": [0] + }, + { + "name": "indices for TRIANGLE_STRIP", + "bufferView": 0, + "byteOffset": 102, + "componentType": 5123, + "count": 6, + "type": "SCALAR", + "max": [6], + "min": [1] + }, + { + "name": "indices for TRIANGLE_FAN", + "bufferView": 0, + "byteOffset": 114, + "componentType": 5123, + "count": 8, + "type": "SCALAR", + "max": [6], + "min": [0] + }, + { + "name": "positions", + "bufferView": 1, + "byteOffset": 0, + "componentType": 5126, + "count": 7, + "type": "VEC3", + "max": [0.866, 1.0, 0.0], + "min": [-0.866, -1.0, 0.0] + } + ] +} diff --git a/tests/fixtures/gltf/MeshPrimitiveModes/glTF/buffer.bin b/tests/fixtures/gltf/MeshPrimitiveModes/glTF/buffer.bin new file mode 100644 index 0000000..069020a Binary files /dev/null and b/tests/fixtures/gltf/MeshPrimitiveModes/glTF/buffer.bin differ diff --git a/tests/fixtures/gltf/MultiUVTest/LICENSE.md b/tests/fixtures/gltf/MultiUVTest/LICENSE.md new file mode 100644 index 0000000..367cc0d --- /dev/null +++ b/tests/fixtures/gltf/MultiUVTest/LICENSE.md @@ -0,0 +1,19 @@ +# LICENSE file for the model: MultiUV Test + +All files in this directory tree are licensed as indicated below. + +* All files directly associated with the model including all text, image and binary files: + + * [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"] + + * [Khronos Trademark or Logo](../../LICENSES/LicenseRef-LegalMark-Khronos.txt) + +* This file and all other metadocumentation files including "metadata.json": + + * [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"] + +Full license text of these licenses are available at the links above. + +This license excludes logos and associated trademarks. + + diff --git a/tests/fixtures/gltf/MultiUVTest/glTF-Binary/MultiUVTest.glb b/tests/fixtures/gltf/MultiUVTest/glTF-Binary/MultiUVTest.glb new file mode 100644 index 0000000..69ed2fe Binary files /dev/null and b/tests/fixtures/gltf/MultiUVTest/glTF-Binary/MultiUVTest.glb differ diff --git a/tests/fixtures/gltf/MultipleScenes/LICENSE.md b/tests/fixtures/gltf/MultipleScenes/LICENSE.md new file mode 100644 index 0000000..1ba45c7 --- /dev/null +++ b/tests/fixtures/gltf/MultipleScenes/LICENSE.md @@ -0,0 +1,17 @@ +# LICENSE file for the model: Multiple Scenes + +All files in this directory tree are licensed as indicated below. + +* All files directly associated with the model including all text, image and binary files: + + * [Creative Commons Zero v1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/legalcode) [SPDX license identifier: "CC0-1.0"] + +* This file and all other metadocumentation files including "metadata.json": + + * [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"] + +Full license text of these licenses are available at the links above. + +This license excludes logos and associated trademarks. + + diff --git a/tests/fixtures/gltf/MultipleScenes/glTF/MultipleScenes.gltf b/tests/fixtures/gltf/MultipleScenes/glTF/MultipleScenes.gltf new file mode 100644 index 0000000..a61070a --- /dev/null +++ b/tests/fixtures/gltf/MultipleScenes/glTF/MultipleScenes.gltf @@ -0,0 +1,118 @@ +{ + "scene" : 1, + "scenes" : [ + { + "nodes" : [ 0 ] + }, + { + "nodes" : [ 1 ] + } + ], + + "nodes" : [ + { + "mesh" : 0 + }, + { + "mesh" : 1 + } + ], + + "meshes" : [ + { + "primitives" : [ { + "attributes" : { + "POSITION" : 1 + }, + "indices" : 0 + } ] + }, + { + "primitives" : [ { + "attributes" : { + "POSITION" : 3 + }, + "indices" : 2 + } ] + } + ], + + "buffers" : [ + { + "uri" : "MultipleScenes_triangle.bin", + "byteLength" : 44 + }, + { + "uri" : "MultipleScenes_square.bin", + "byteLength" : 60 + } + ], + "bufferViews" : [ + { + "buffer" : 0, + "byteOffset" : 0, + "byteLength" : 6, + "target" : 34963 + }, + { + "buffer" : 0, + "byteOffset" : 8, + "byteLength" : 36, + "target" : 34962 + }, + { + "buffer" : 1, + "byteOffset" : 0, + "byteLength" : 12, + "target" : 34963 + }, + { + "buffer" : 1, + "byteOffset" : 12, + "byteLength" : 48, + "target" : 34962 + } + ], + "accessors" : [ + { + "bufferView" : 0, + "byteOffset" : 0, + "componentType" : 5123, + "count" : 3, + "type" : "SCALAR", + "max" : [ 2 ], + "min" : [ 0 ] + }, + { + "bufferView" : 1, + "byteOffset" : 0, + "componentType" : 5126, + "count" : 3, + "type" : "VEC3", + "max" : [ 1.0, 1.0, 0.0 ], + "min" : [ 0.0, 0.0, 0.0 ] + }, + { + "bufferView" : 2, + "byteOffset" : 0, + "componentType" : 5123, + "count" : 6, + "type" : "SCALAR", + "max" : [ 3 ], + "min" : [ 0 ] + }, + { + "bufferView" : 3, + "byteOffset" : 0, + "componentType" : 5126, + "count" : 4, + "type" : "VEC3", + "max" : [ 1.0, 1.0, 0.0 ], + "min" : [ 0.0, 0.0, 0.0 ] + } + ], + + "asset" : { + "version" : "2.0" + } +} diff --git a/tests/fixtures/gltf/MultipleScenes/glTF/MultipleScenes_square.bin b/tests/fixtures/gltf/MultipleScenes/glTF/MultipleScenes_square.bin new file mode 100644 index 0000000..a6edb3b Binary files /dev/null and b/tests/fixtures/gltf/MultipleScenes/glTF/MultipleScenes_square.bin differ diff --git a/tests/fixtures/gltf/MultipleScenes/glTF/MultipleScenes_triangle.bin b/tests/fixtures/gltf/MultipleScenes/glTF/MultipleScenes_triangle.bin new file mode 100644 index 0000000..d642500 Binary files /dev/null and b/tests/fixtures/gltf/MultipleScenes/glTF/MultipleScenes_triangle.bin differ diff --git a/tests/fixtures/gltf/NegativeScaleTest/LICENSE.md b/tests/fixtures/gltf/NegativeScaleTest/LICENSE.md new file mode 100644 index 0000000..7fbbd09 --- /dev/null +++ b/tests/fixtures/gltf/NegativeScaleTest/LICENSE.md @@ -0,0 +1,17 @@ +# LICENSE file for the model: Negative Scale Test + +All files in this directory tree are licensed as indicated below. + +* All files directly associated with the model including all text, image and binary files: + + * [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"] + +* This file and all other metadocumentation files including "metadata.json": + + * [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"] + +Full license text of these licenses are available at the links above. + +This license excludes logos and associated trademarks. + + diff --git a/tests/fixtures/gltf/NegativeScaleTest/glTF-Binary/NegativeScaleTest.glb b/tests/fixtures/gltf/NegativeScaleTest/glTF-Binary/NegativeScaleTest.glb new file mode 100644 index 0000000..00efded Binary files /dev/null and b/tests/fixtures/gltf/NegativeScaleTest/glTF-Binary/NegativeScaleTest.glb differ diff --git a/tests/fixtures/gltf/PointLightIntensityTest/LICENSE.md b/tests/fixtures/gltf/PointLightIntensityTest/LICENSE.md new file mode 100644 index 0000000..3e0f6ce --- /dev/null +++ b/tests/fixtures/gltf/PointLightIntensityTest/LICENSE.md @@ -0,0 +1,17 @@ +# LICENSE file for the model: Point Light Intensity Test + +All files in this directory tree are licensed as indicated below. + +* All files directly associated with the model including all text, image and binary files: + + * [Creative Commons Zero v1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/legalcode) [SPDX license identifier: "CC0-1.0"] + +* This file and all other metadocumentation files including "metadata.json": + + * [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"] + +Full license text of these licenses are available at the links above. + +This license excludes logos and associated trademarks. + + diff --git a/tests/fixtures/gltf/PointLightIntensityTest/glTF-Binary/PointLightIntensityTest.glb b/tests/fixtures/gltf/PointLightIntensityTest/glTF-Binary/PointLightIntensityTest.glb new file mode 100644 index 0000000..ff8ae99 Binary files /dev/null and b/tests/fixtures/gltf/PointLightIntensityTest/glTF-Binary/PointLightIntensityTest.glb differ diff --git a/tests/fixtures/gltf/RiggedSimple/LICENSE.md b/tests/fixtures/gltf/RiggedSimple/LICENSE.md new file mode 100644 index 0000000..2a98e37 --- /dev/null +++ b/tests/fixtures/gltf/RiggedSimple/LICENSE.md @@ -0,0 +1,17 @@ +# LICENSE file for the model: Rigged Simple + +All files in this directory tree are licensed as indicated below. + +* All files directly associated with the model including all text, image and binary files: + + * [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"] + +* This file and all other metadocumentation files including "metadata.json": + + * [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"] + +Full license text of these licenses are available at the links above. + +This license excludes logos and associated trademarks. + + diff --git a/tests/fixtures/gltf/RiggedSimple/glTF-Binary/RiggedSimple.glb b/tests/fixtures/gltf/RiggedSimple/glTF-Binary/RiggedSimple.glb new file mode 100644 index 0000000..d56b94e Binary files /dev/null and b/tests/fixtures/gltf/RiggedSimple/glTF-Binary/RiggedSimple.glb differ diff --git a/tests/fixtures/gltf/SimpleMeshes/LICENSE.md b/tests/fixtures/gltf/SimpleMeshes/LICENSE.md new file mode 100644 index 0000000..6c1201c --- /dev/null +++ b/tests/fixtures/gltf/SimpleMeshes/LICENSE.md @@ -0,0 +1,17 @@ +# LICENSE file for the model: Simple Meshes + +All files in this directory tree are licensed as indicated below. + +* All files directly associated with the model including all text, image and binary files: + + * [Creative Commons Zero v1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/legalcode) [SPDX license identifier: "CC0-1.0"] + +* This file and all other metadocumentation files including "metadata.json": + + * [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"] + +Full license text of these licenses are available at the links above. + +This license excludes logos and associated trademarks. + + diff --git a/tests/fixtures/gltf/SimpleMeshes/glTF/SimpleMeshes.bin b/tests/fixtures/gltf/SimpleMeshes/glTF/SimpleMeshes.bin new file mode 100644 index 0000000..291b43c Binary files /dev/null and b/tests/fixtures/gltf/SimpleMeshes/glTF/SimpleMeshes.bin differ diff --git a/tests/fixtures/gltf/SimpleMeshes/glTF/SimpleMeshes.gltf b/tests/fixtures/gltf/SimpleMeshes/glTF/SimpleMeshes.gltf new file mode 100644 index 0000000..c3f3d44 --- /dev/null +++ b/tests/fixtures/gltf/SimpleMeshes/glTF/SimpleMeshes.gltf @@ -0,0 +1,84 @@ +{ + "scene" : 0, + "scenes" : [ + { + "nodes" : [ 0, 1] + } + ], + "nodes" : [ + { + "mesh" : 0 + }, + { + "mesh" : 0, + "translation" : [ 1.0, 0.0, 0.0 ] + } + ], + + "meshes" : [ + { + "primitives" : [ { + "attributes" : { + "POSITION" : 1, + "NORMAL" : 2 + }, + "indices" : 0 + } ] + } + ], + + "buffers" : [ + { + "uri" : "SimpleMeshes.bin", + "byteLength" : 80 + } + ], + "bufferViews" : [ + { + "buffer" : 0, + "byteOffset" : 0, + "byteLength" : 6, + "target" : 34963 + }, + { + "buffer" : 0, + "byteOffset" : 8, + "byteLength" : 72, + "byteStride" : 12, + "target" : 34962 + } + ], + "accessors" : [ + { + "bufferView" : 0, + "byteOffset" : 0, + "componentType" : 5123, + "count" : 3, + "type" : "SCALAR", + "max" : [ 2 ], + "min" : [ 0 ] + }, + { + "bufferView" : 1, + "byteOffset" : 0, + "componentType" : 5126, + "count" : 3, + "type" : "VEC3", + "max" : [ 1.0, 1.0, 0.0 ], + "min" : [ 0.0, 0.0, 0.0 ] + }, + { + "bufferView" : 1, + "byteOffset" : 36, + "componentType" : 5126, + "count" : 3, + "type" : "VEC3", + "max" : [ 0.0, 0.0, 1.0 ], + "min" : [ 0.0, 0.0, 1.0 ] + } + ], + + "asset" : { + "version" : "2.0" + } +} diff --git a/tests/fixtures/gltf/SimpleMorph/LICENSE.md b/tests/fixtures/gltf/SimpleMorph/LICENSE.md new file mode 100644 index 0000000..b889d88 --- /dev/null +++ b/tests/fixtures/gltf/SimpleMorph/LICENSE.md @@ -0,0 +1,17 @@ +# LICENSE file for the model: Simple Morph + +All files in this directory tree are licensed as indicated below. + +* All files directly associated with the model including all text, image and binary files: + + * [Creative Commons Zero v1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/legalcode) [SPDX license identifier: "CC0-1.0"] + +* This file and all other metadocumentation files including "metadata.json": + + * [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"] + +Full license text of these licenses are available at the links above. + +This license excludes logos and associated trademarks. + + diff --git a/tests/fixtures/gltf/SimpleMorph/glTF/SimpleMorph.gltf b/tests/fixtures/gltf/SimpleMorph/glTF/SimpleMorph.gltf new file mode 100644 index 0000000..0d5f960 --- /dev/null +++ b/tests/fixtures/gltf/SimpleMorph/glTF/SimpleMorph.gltf @@ -0,0 +1,189 @@ +{ + "scene" : 0, + "scenes":[ + { + "nodes":[ + 0 + ] + } + ], + "nodes":[ + { + "mesh":0 + } + ], + "meshes":[ + { + "primitives":[ + { + "attributes":{ + "POSITION":1 + }, + "targets":[ + { + "POSITION":2 + }, + { + "POSITION":3 + } + ], + "indices":0 + } + ], + "weights":[ + 0.5, + 0.5 + ] + } + ], + "animations":[ + { + "samplers":[ + { + "input":4, + "interpolation":"LINEAR", + "output":5 + } + ], + "channels":[ + { + "sampler":0, + "target":{ + "node":0, + "path":"weights" + } + } + ] + } + ], + "buffers":[ + { + "uri" : "SimpleMorph_geometry.bin", + "byteLength":116 + }, + { + "uri" : "SimpleMorph_animation.bin", + "byteLength":60 + } + ], + "bufferViews":[ + { + "buffer":0, + "byteOffset":0, + "byteLength":6, + "target":34963 + }, + { + "buffer":0, + "byteOffset":8, + "byteLength":108, + "byteStride":12, + "target":34962 + }, + { + "buffer":1, + "byteOffset":0, + "byteLength":20 + }, + { + "buffer":1, + "byteOffset":20, + "byteLength":40 + } + ], + "accessors":[ + { + "bufferView":0, + "byteOffset":0, + "componentType":5123, + "count":3, + "type":"SCALAR", + "max":[ + 2 + ], + "min":[ + 0 + ] + }, + { + "bufferView":1, + "byteOffset":0, + "componentType":5126, + "count":3, + "type":"VEC3", + "max":[ + 1.0, + 0.5, + 0.0 + ], + "min":[ + 0.0, + 0.0, + 0.0 + ] + }, + { + "bufferView":1, + "byteOffset":36, + "componentType":5126, + "count":3, + "type":"VEC3", + "max":[ + 0.0, + 1.0, + 0.0 + ], + "min":[ + -1.0, + 0.0, + 0.0 + ] + }, + { + "bufferView":1, + "byteOffset":72, + "componentType":5126, + "count":3, + "type":"VEC3", + "max":[ + 1.0, + 1.0, + 0.0 + ], + "min":[ + 0.0, + 0.0, + 0.0 + ] + }, + { + "bufferView":2, + "byteOffset":0, + "componentType":5126, + "count":5, + "type":"SCALAR", + "max":[ + 4.0 + ], + "min":[ + 0.0 + ] + }, + { + "bufferView":3, + "byteOffset":0, + "componentType":5126, + "count":10, + "type":"SCALAR", + "max":[ + 1.0 + ], + "min":[ + 0.0 + ] + } + ], + "asset":{ + "version":"2.0" + } +} diff --git a/tests/fixtures/gltf/SimpleMorph/glTF/SimpleMorph_animation.bin b/tests/fixtures/gltf/SimpleMorph/glTF/SimpleMorph_animation.bin new file mode 100644 index 0000000..bbd0ee6 Binary files /dev/null and b/tests/fixtures/gltf/SimpleMorph/glTF/SimpleMorph_animation.bin differ diff --git a/tests/fixtures/gltf/SimpleMorph/glTF/SimpleMorph_geometry.bin b/tests/fixtures/gltf/SimpleMorph/glTF/SimpleMorph_geometry.bin new file mode 100644 index 0000000..70b73c2 Binary files /dev/null and b/tests/fixtures/gltf/SimpleMorph/glTF/SimpleMorph_geometry.bin differ diff --git a/tests/fixtures/gltf/SimpleSkin/LICENSE.md b/tests/fixtures/gltf/SimpleSkin/LICENSE.md new file mode 100644 index 0000000..8437c87 --- /dev/null +++ b/tests/fixtures/gltf/SimpleSkin/LICENSE.md @@ -0,0 +1,17 @@ +# LICENSE file for the model: Simple Skin + +All files in this directory tree are licensed as indicated below. + +* All files directly associated with the model including all text, image and binary files: + + * [Creative Commons Zero v1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/legalcode) [SPDX license identifier: "CC0-1.0"] + +* This file and all other metadocumentation files including "metadata.json": + + * [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"] + +Full license text of these licenses are available at the links above. + +This license excludes logos and associated trademarks. + + diff --git a/tests/fixtures/gltf/SimpleSkin/glTF/SimpleSkin.gltf b/tests/fixtures/gltf/SimpleSkin/glTF/SimpleSkin.gltf new file mode 100644 index 0000000..1d586df --- /dev/null +++ b/tests/fixtures/gltf/SimpleSkin/glTF/SimpleSkin.gltf @@ -0,0 +1,131 @@ +{ + "scene" : 0, + "scenes" : [ { + "nodes" : [ 0, 1 ] + } ], + + "nodes" : [ { + "skin" : 0, + "mesh" : 0 + }, { + "children" : [ 2 ] + }, { + "translation" : [ 0.0, 1.0, 0.0 ], + "rotation" : [ 0.0, 0.0, 0.0, 1.0 ] + } ], + + "meshes" : [ { + "primitives" : [ { + "attributes" : { + "POSITION" : 1, + "JOINTS_0" : 2, + "WEIGHTS_0" : 3 + }, + "indices" : 0 + } ] + } ], + + "skins" : [ { + "inverseBindMatrices" : 4, + "joints" : [ 1, 2 ] + } ], + + "animations" : [ { + "channels" : [ { + "sampler" : 0, + "target" : { + "node" : 2, + "path" : "rotation" + } + } ], + "samplers" : [ { + "input" : 5, + "interpolation" : "LINEAR", + "output" : 6 + } ] + } ], + + "buffers" : [ { + "uri" : "SimpleSkin_geometry.bin", + "byteLength" : 168 + }, { + "uri" : "SimpleSkin_skinningData.bin", + "byteLength" : 320 + }, { + "uri" : "SimpleSkin_inverseBindMatrices.bin", + "byteLength" : 128 + }, { + "uri" : "SimpleSkin_animation.bin", + "byteLength" : 240 + } ], + + "bufferViews" : [ { + "buffer" : 0, + "byteLength" : 48, + "target" : 34963 + }, { + "buffer" : 0, + "byteOffset" : 48, + "byteLength" : 120, + "target" : 34962 + }, { + "buffer" : 1, + "byteLength" : 320, + "byteStride" : 16 + }, { + "buffer" : 2, + "byteLength" : 128 + }, { + "buffer" : 3, + "byteLength" : 240 + } ], + + "accessors" : [ { + "bufferView" : 0, + "componentType" : 5123, + "count" : 24, + "type" : "SCALAR" + }, { + "bufferView" : 1, + "componentType" : 5126, + "count" : 10, + "type" : "VEC3", + "max" : [ 0.5, 2.0, 0.0 ], + "min" : [ -0.5, 0.0, 0.0 ] + }, { + "bufferView" : 2, + "componentType" : 5123, + "count" : 10, + "type" : "VEC4" + }, { + "bufferView" : 2, + "byteOffset" : 160, + "componentType" : 5126, + "count" : 10, + "type" : "VEC4" + }, { + "bufferView" : 3, + "componentType" : 5126, + "count" : 2, + "type" : "MAT4" + }, { + "bufferView" : 4, + "componentType" : 5126, + "count" : 12, + "type" : "SCALAR", + "max" : [ 5.5 ], + "min" : [ 0.0 ] + }, { + "bufferView" : 4, + "byteOffset" : 48, + "componentType" : 5126, + "count" : 12, + "type" : "VEC4", + "max" : [ 0.0, 0.0, 0.707, 1.0 ], + "min" : [ 0.0, 0.0, -0.707, 0.707 ] + } ], + + "asset" : { + "version" : "2.0" + } +} \ No newline at end of file diff --git a/tests/fixtures/gltf/SimpleSkin/glTF/SimpleSkin_animation.bin b/tests/fixtures/gltf/SimpleSkin/glTF/SimpleSkin_animation.bin new file mode 100644 index 0000000..ff550c6 Binary files /dev/null and b/tests/fixtures/gltf/SimpleSkin/glTF/SimpleSkin_animation.bin differ diff --git a/tests/fixtures/gltf/SimpleSkin/glTF/SimpleSkin_geometry.bin b/tests/fixtures/gltf/SimpleSkin/glTF/SimpleSkin_geometry.bin new file mode 100644 index 0000000..15375c4 Binary files /dev/null and b/tests/fixtures/gltf/SimpleSkin/glTF/SimpleSkin_geometry.bin differ diff --git a/tests/fixtures/gltf/SimpleSkin/glTF/SimpleSkin_inverseBindMatrices.bin b/tests/fixtures/gltf/SimpleSkin/glTF/SimpleSkin_inverseBindMatrices.bin new file mode 100644 index 0000000..5af0b5e Binary files /dev/null and b/tests/fixtures/gltf/SimpleSkin/glTF/SimpleSkin_inverseBindMatrices.bin differ diff --git a/tests/fixtures/gltf/SimpleSkin/glTF/SimpleSkin_skinningData.bin b/tests/fixtures/gltf/SimpleSkin/glTF/SimpleSkin_skinningData.bin new file mode 100644 index 0000000..fd0c165 Binary files /dev/null and b/tests/fixtures/gltf/SimpleSkin/glTF/SimpleSkin_skinningData.bin differ diff --git a/tests/fixtures/gltf/SimpleSparseAccessor/LICENSE.md b/tests/fixtures/gltf/SimpleSparseAccessor/LICENSE.md new file mode 100644 index 0000000..acf8487 --- /dev/null +++ b/tests/fixtures/gltf/SimpleSparseAccessor/LICENSE.md @@ -0,0 +1,17 @@ +# LICENSE file for the model: Simple Sparse Accessor + +All files in this directory tree are licensed as indicated below. + +* All files directly associated with the model including all text, image and binary files: + + * [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"] + +* This file and all other metadocumentation files including "metadata.json": + + * [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"] + +Full license text of these licenses are available at the links above. + +This license excludes logos and associated trademarks. + + diff --git a/tests/fixtures/gltf/SimpleSparseAccessor/glTF-Embedded/SimpleSparseAccessor.gltf b/tests/fixtures/gltf/SimpleSparseAccessor/glTF-Embedded/SimpleSparseAccessor.gltf new file mode 100644 index 0000000..ca69e2f --- /dev/null +++ b/tests/fixtures/gltf/SimpleSparseAccessor/glTF-Embedded/SimpleSparseAccessor.gltf @@ -0,0 +1,77 @@ +{ + "scene" : 0, + "scenes" : [ { + "nodes" : [ 0 ] + } ], + + "nodes" : [ { + "mesh" : 0 + } ], + + "meshes" : [ { + "primitives" : [ { + "attributes" : { + "POSITION" : 1 + }, + "indices" : 0 + } ] + } ], + + "buffers" : [ { + "uri" : "data:application/gltf-buffer;base64,AAAIAAcAAAABAAgAAQAJAAgAAQACAAkAAgAKAAkAAgADAAoAAwALAAoAAwAEAAsABAAMAAsABAAFAAwABQANAAwABQAGAA0AAAAAAAAAAAAAAAAAAACAPwAAAAAAAAAAAAAAQAAAAAAAAAAAAABAQAAAAAAAAAAAAACAQAAAAAAAAAAAAACgQAAAAAAAAAAAAADAQAAAAAAAAAAAAAAAAAAAgD8AAAAAAACAPwAAgD8AAAAAAAAAQAAAgD8AAAAAAABAQAAAgD8AAAAAAACAQAAAgD8AAAAAAACgQAAAgD8AAAAAAADAQAAAgD8AAAAACAAKAAwAAAAAAIA/AAAAQAAAAAAAAEBAAABAQAAAAAAAAKBAAACAQAAAAAA=", + "byteLength" : 284 + } ], + + "bufferViews" : [ { + "buffer" : 0, + "byteOffset" : 0, + "byteLength" : 72, + "target" : 34963 + }, { + "buffer" : 0, + "byteOffset" : 72, + "byteLength" : 168 + }, { + "buffer" : 0, + "byteOffset" : 240, + "byteLength" : 6 + }, { + "buffer" : 0, + "byteOffset" : 248, + "byteLength" : 36 + } ], + + "accessors" : [ { + "bufferView" : 0, + "byteOffset" : 0, + "componentType" : 5123, + "count" : 36, + "type" : "SCALAR", + "max" : [ 13 ], + "min" : [ 0 ] + }, { + "bufferView" : 1, + "byteOffset" : 0, + "componentType" : 5126, + "count" : 14, + "type" : "VEC3", + "max" : [ 6.0, 4.0, 0.0 ], + "min" : [ 0.0, 0.0, 0.0 ], + "sparse" : { + "count" : 3, + "indices" : { + "bufferView" : 2, + "byteOffset" : 0, + "componentType" : 5123 + }, + "values" : { + "bufferView" : 3, + "byteOffset" : 0 + } + } + } ], + + "asset" : { + "version" : "2.0" + } +} \ No newline at end of file diff --git a/tests/fixtures/gltf/TextureCoordinateTest/LICENSE.md b/tests/fixtures/gltf/TextureCoordinateTest/LICENSE.md new file mode 100644 index 0000000..ba67d93 --- /dev/null +++ b/tests/fixtures/gltf/TextureCoordinateTest/LICENSE.md @@ -0,0 +1,17 @@ +# LICENSE file for the model: Texture Coordinate Test + +All files in this directory tree are licensed as indicated below. + +* All files directly associated with the model including all text, image and binary files: + + * [Creative Commons Zero v1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/legalcode) [SPDX license identifier: "CC0-1.0"] + +* This file and all other metadocumentation files including "metadata.json": + + * [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"] + +Full license text of these licenses are available at the links above. + +This license excludes logos and associated trademarks. + + diff --git a/tests/fixtures/gltf/TextureCoordinateTest/glTF-Binary/TextureCoordinateTest.glb b/tests/fixtures/gltf/TextureCoordinateTest/glTF-Binary/TextureCoordinateTest.glb new file mode 100644 index 0000000..39d3da6 Binary files /dev/null and b/tests/fixtures/gltf/TextureCoordinateTest/glTF-Binary/TextureCoordinateTest.glb differ diff --git a/tests/fixtures/gltf/TextureTransformTest/LICENSE.md b/tests/fixtures/gltf/TextureTransformTest/LICENSE.md new file mode 100644 index 0000000..1315107 --- /dev/null +++ b/tests/fixtures/gltf/TextureTransformTest/LICENSE.md @@ -0,0 +1,17 @@ +# LICENSE file for the model: Texture Transform Test + +All files in this directory tree are licensed as indicated below. + +* All files directly associated with the model including all text, image and binary files: + + * [Creative Commons Zero v1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/legalcode) [SPDX license identifier: "CC0-1.0"] + +* This file and all other metadocumentation files including "metadata.json": + + * [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"] + +Full license text of these licenses are available at the links above. + +This license excludes logos and associated trademarks. + + diff --git a/tests/fixtures/gltf/TextureTransformTest/glTF/Arrow.png b/tests/fixtures/gltf/TextureTransformTest/glTF/Arrow.png new file mode 100644 index 0000000..fe3405b Binary files /dev/null and b/tests/fixtures/gltf/TextureTransformTest/glTF/Arrow.png differ diff --git a/tests/fixtures/gltf/TextureTransformTest/glTF/Correct.png b/tests/fixtures/gltf/TextureTransformTest/glTF/Correct.png new file mode 100644 index 0000000..e332824 Binary files /dev/null and b/tests/fixtures/gltf/TextureTransformTest/glTF/Correct.png differ diff --git a/tests/fixtures/gltf/TextureTransformTest/glTF/Error.png b/tests/fixtures/gltf/TextureTransformTest/glTF/Error.png new file mode 100644 index 0000000..35acf6e Binary files /dev/null and b/tests/fixtures/gltf/TextureTransformTest/glTF/Error.png differ diff --git a/tests/fixtures/gltf/TextureTransformTest/glTF/NotSupported.png b/tests/fixtures/gltf/TextureTransformTest/glTF/NotSupported.png new file mode 100644 index 0000000..721e7fd Binary files /dev/null and b/tests/fixtures/gltf/TextureTransformTest/glTF/NotSupported.png differ diff --git a/tests/fixtures/gltf/TextureTransformTest/glTF/TextureTransformTest.bin b/tests/fixtures/gltf/TextureTransformTest/glTF/TextureTransformTest.bin new file mode 100644 index 0000000..6765a13 Binary files /dev/null and b/tests/fixtures/gltf/TextureTransformTest/glTF/TextureTransformTest.bin differ diff --git a/tests/fixtures/gltf/TextureTransformTest/glTF/TextureTransformTest.gltf b/tests/fixtures/gltf/TextureTransformTest/glTF/TextureTransformTest.gltf new file mode 100644 index 0000000..6dde51d --- /dev/null +++ b/tests/fixtures/gltf/TextureTransformTest/glTF/TextureTransformTest.gltf @@ -0,0 +1,540 @@ +{ + "accessors": [ + { + "bufferView": 0, + "componentType": 5126, + "count": 4, + "type": "VEC3", + "max": [ + 0.5, + 0.5, + 0.0 + ], + "min": [ + -0.5, + -0.5, + 0.0 + ], + "name": "Positions" + }, + { + "bufferView": 1, + "componentType": 5126, + "count": 4, + "type": "VEC2", + "name": "UV0" + }, + { + "bufferView": 2, + "componentType": 5126, + "count": 4, + "type": "VEC2", + "name": "UV1" + }, + { + "bufferView": 3, + "componentType": 5125, + "count": 6, + "type": "SCALAR", + "name": "Indices" + } + ], + "asset": { + "version": "2.0" + }, + "buffers": [ + { + "uri": "TextureTransformTest.bin", + "byteLength": 136 + } + ], + "bufferViews": [ + { + "buffer": 0, + "byteLength": 48, + "name": "Positions" + }, + { + "buffer": 0, + "byteOffset": 48, + "byteLength": 32, + "name": "UV0" + }, + { + "buffer": 0, + "byteOffset": 80, + "byteLength": 32, + "name": "UV1" + }, + { + "buffer": 0, + "byteOffset": 112, + "byteLength": 24, + "name": "Indices" + } + ], + "extensionsUsed": [ + "KHR_texture_transform" + ], + "images": [ + { + "uri": "UV.png" + }, + { + "uri": "Arrow.png" + }, + { + "uri": "Correct.png" + }, + { + "uri": "NotSupported.png" + }, + { + "uri": "Error.png" + } + ], + "materials": [ + { + "name": "Offset U", + "pbrMetallicRoughness": { + "baseColorTexture": { + "index": 0, + "extensions": { + "KHR_texture_transform": { + "offset": [ + 0.5, + 0.0 + ] + } + } + }, + "metallicFactor": 0 + } + }, + { + "name": "Offset V", + "pbrMetallicRoughness": { + "baseColorTexture": { + "index": 0, + "extensions": { + "KHR_texture_transform": { + "offset": [ + 0.0, + 0.5 + ] + } + } + }, + "metallicFactor": 0 + } + }, + { + "name": "Offset UV", + "pbrMetallicRoughness": { + "baseColorTexture": { + "index": 0, + "extensions": { + "KHR_texture_transform": { + "offset": [ + 0.5, + 0.5 + ] + } + } + }, + "metallicFactor": 0 + } + }, + { + "name": "Rotation", + "pbrMetallicRoughness": { + "baseColorTexture": { + "index": 1, + "extensions": { + "KHR_texture_transform": { + "rotation": 0.39269908169872415480783042290994 + } + } + }, + "metallicFactor": 0 + } + }, + { + "name": "Scale", + "pbrMetallicRoughness": { + "baseColorTexture": { + "index": 1, + "extensions": { + "KHR_texture_transform": { + "scale": [ + 1.5, + 1.5 + ] + } + } + }, + "metallicFactor": 0 + } + }, + { + "name": "All", + "pbrMetallicRoughness": { + "baseColorTexture": { + "index": 1, + "extensions": { + "KHR_texture_transform": { + "offset": [ + -0.2, + -0.1 + ], + "rotation": 0.3, + "scale": [ + 1.5, + 1.5 + ] + } + } + }, + "metallicFactor": 0 + } + }, + { + "name": "Correct", + "pbrMetallicRoughness": { + "baseColorTexture": { + "index": 2 + }, + "metallicFactor": 0 + } + }, + { + "name": "NotSupported", + "pbrMetallicRoughness": { + "baseColorTexture": { + "index": 3 + }, + "metallicFactor": 0 + } + }, + { + "name": "Error", + "pbrMetallicRoughness": { + "baseColorTexture": { + "index": 4 + }, + "metallicFactor": 0 + } + } + ], + "meshes": [ + { + "name": "Offset U", + "primitives": [ + { + "attributes": { + "POSITION": 0, + "TEXCOORD_0": 2 + }, + "indices": 3, + "material": 0 + } + ] + }, + { + "name": "Offset V", + "primitives": [ + { + "attributes": { + "POSITION": 0, + "TEXCOORD_0": 2 + }, + "indices": 3, + "material": 1 + } + ] + }, + { + "name": "Offset UV", + "primitives": [ + { + "attributes": { + "POSITION": 0, + "TEXCOORD_0": 2 + }, + "indices": 3, + "material": 2 + } + ] + }, + { + "name": "Rotation", + "primitives": [ + { + "attributes": { + "POSITION": 0, + "TEXCOORD_0": 1 + }, + "indices": 3, + "material": 3 + } + ] + }, + { + "name": "Scale", + "primitives": [ + { + "attributes": { + "POSITION": 0, + "TEXCOORD_0": 1 + }, + "indices": 3, + "material": 4 + } + ] + }, + { + "name": "All", + "primitives": [ + { + "attributes": { + "POSITION": 0, + "TEXCOORD_0": 1 + }, + "indices": 3, + "material": 5 + } + ] + }, + { + "name": "Correct Marker", + "primitives": [ + { + "attributes": { + "POSITION": 0, + "TEXCOORD_0": 1 + }, + "indices": 3, + "material": 6 + } + ] + }, + { + "name": "Not Supported Marker", + "primitives": [ + { + "attributes": { + "POSITION": 0, + "TEXCOORD_0": 1 + }, + "indices": 3, + "material": 7 + } + ] + }, + { + "name": "Error Marker", + "primitives": [ + { + "attributes": { + "POSITION": 0, + "TEXCOORD_0": 1 + }, + "indices": 3, + "material": 8 + } + ] + } + ], + "nodes": [ + { + "name": "Offset U", + "mesh": 0, + "translation": [ + -1.1, + 0.55, + 0 + ] + }, + { + "name": "Offset V", + "mesh": 1, + "translation": [ + 0, + 0.55, + 0 + ] + }, + { + "name": "Offset UV", + "mesh": 2, + "translation": [ + 1.1, + 0.55, + 0 + ] + }, + { + "name": "Rotation", + "mesh": 3, + "translation": [ + -1.1, + -0.55, + 0 + ], + "children": [ + 4, + 5, + 6 + ] + }, + { + "name": "Rotation - Correct", + "mesh": 6, + "translation": [ + -0.07904822439840125109869401756656, + -0.51626748576241543174100150833647, + 0.01 + ], + "scale": [ + 0.15, + 0.15, + 0.15 + ] + }, + { + "name": "Rotation - Not Supported", + "mesh": 7, + "translation": [ + 0.27781745930520227684092879831533, + -0.27781745930520227684092879831533, + 0.01 + ], + "scale": [ + 0.15, + 0.15, + 0.15 + ] + }, + { + "name": "Rotation - Error", + "mesh": 8, + "translation": [ + 0.51626748576241543174100150833647, + 0.07904822439840125109869401756656, + 0.01 + ], + "scale": [ + 0.15, + 0.15, + 0.15 + ] + }, + { + "name": "Scale", + "mesh": 4, + "translation": [ + 0, + -0.55, + 0 + ], + "children": [ + 8, + 9 + ] + }, + { + "name": "Scale - Correct", + "mesh": 6, + "translation": [ + 0.01854497287013485122728586554355, + -0.01854497287013485122728586554355, + 0.01 + ], + "scale": [ + 0.1, + 0.1, + 0.1 + ] + }, + { + "name": "Scale - Not Supported", + "mesh": 7, + "translation": [ + 0.27781745930520227684092879831533, + -0.27781745930520227684092879831533, + 0.01 + ], + "scale": [ + 0.15, + 0.15, + 0.15 + ] + }, + { + "name": "All", + "mesh": 5, + "translation": [ + 1.1, + -0.55, + 0 + ], + "children": [ + 11 + ] + }, + { + "name": "All - Correct", + "mesh": 6, + "translation": [ + -0.07, + -0.25, + 0.01 + ], + "scale": [ + 0.1, + 0.1, + 0.1 + ] + } + ], + "scene": 0, + "scenes": [ + { + "nodes": [ + 0, + 1, + 2, + 3, + 7, + 10 + ] + } + ], + "textures": [ + { + "source": 0, + "sampler": 0 + }, + { + "source": 1, + "sampler": 0 + }, + { + "source": 2 + }, + { + "source": 3 + }, + { + "source": 4 + } + ], + "samplers": [ + { + "wrapS": 33071, + "wrapT": 33071, + "magFilter": 9729, + "minFilter": 9729 + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/gltf/TextureTransformTest/glTF/UV.png b/tests/fixtures/gltf/TextureTransformTest/glTF/UV.png new file mode 100644 index 0000000..c1a6d4d Binary files /dev/null and b/tests/fixtures/gltf/TextureTransformTest/glTF/UV.png differ diff --git a/tests/fixtures/gltf/Triangle/LICENSE.md b/tests/fixtures/gltf/Triangle/LICENSE.md new file mode 100644 index 0000000..65dc616 --- /dev/null +++ b/tests/fixtures/gltf/Triangle/LICENSE.md @@ -0,0 +1,17 @@ +# LICENSE file for the model: Triangle + +All files in this directory tree are licensed as indicated below. + +* All files directly associated with the model including all text, image and binary files: + + * [Creative Commons Zero v1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/legalcode) [SPDX license identifier: "CC0-1.0"] + +* This file and all other metadocumentation files including "metadata.json": + + * [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"] + +Full license text of these licenses are available at the links above. + +This license excludes logos and associated trademarks. + + diff --git a/tests/fixtures/gltf/Triangle/glTF-Embedded/Triangle.gltf b/tests/fixtures/gltf/Triangle/glTF-Embedded/Triangle.gltf new file mode 100644 index 0000000..40cab5a --- /dev/null +++ b/tests/fixtures/gltf/Triangle/glTF-Embedded/Triangle.gltf @@ -0,0 +1,70 @@ +{ + "scene" : 0, + "scenes" : [ + { + "nodes" : [ 0 ] + } + ], + + "nodes" : [ + { + "mesh" : 0 + } + ], + + "meshes" : [ + { + "primitives" : [ { + "attributes" : { + "POSITION" : 1 + }, + "indices" : 0 + } ] + } + ], + + "buffers" : [ + { + "uri" : "data:application/octet-stream;base64,AAABAAIAAAAAAAAAAAAAAAAAAAAAAIA/AAAAAAAAAAAAAAAAAACAPwAAAAA=", + "byteLength" : 44 + } + ], + "bufferViews" : [ + { + "buffer" : 0, + "byteOffset" : 0, + "byteLength" : 6, + "target" : 34963 + }, + { + "buffer" : 0, + "byteOffset" : 8, + "byteLength" : 36, + "target" : 34962 + } + ], + "accessors" : [ + { + "bufferView" : 0, + "byteOffset" : 0, + "componentType" : 5123, + "count" : 3, + "type" : "SCALAR", + "max" : [ 2 ], + "min" : [ 0 ] + }, + { + "bufferView" : 1, + "byteOffset" : 0, + "componentType" : 5126, + "count" : 3, + "type" : "VEC3", + "max" : [ 1.0, 1.0, 0.0 ], + "min" : [ 0.0, 0.0, 0.0 ] + } + ], + + "asset" : { + "version" : "2.0" + } +} diff --git a/tests/fixtures/gltf/TriangleWithoutIndices/LICENSE.md b/tests/fixtures/gltf/TriangleWithoutIndices/LICENSE.md new file mode 100644 index 0000000..4c12f0e --- /dev/null +++ b/tests/fixtures/gltf/TriangleWithoutIndices/LICENSE.md @@ -0,0 +1,17 @@ +# LICENSE file for the model: Triangle Without Indices + +All files in this directory tree are licensed as indicated below. + +* All files directly associated with the model including all text, image and binary files: + + * [Creative Commons Zero v1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/legalcode) [SPDX license identifier: "CC0-1.0"] + +* This file and all other metadocumentation files including "metadata.json": + + * [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"] + +Full license text of these licenses are available at the links above. + +This license excludes logos and associated trademarks. + + diff --git a/tests/fixtures/gltf/TriangleWithoutIndices/glTF/TriangleWithoutIndices.bin b/tests/fixtures/gltf/TriangleWithoutIndices/glTF/TriangleWithoutIndices.bin new file mode 100644 index 0000000..f9f96d8 Binary files /dev/null and b/tests/fixtures/gltf/TriangleWithoutIndices/glTF/TriangleWithoutIndices.bin differ diff --git a/tests/fixtures/gltf/TriangleWithoutIndices/glTF/TriangleWithoutIndices.gltf b/tests/fixtures/gltf/TriangleWithoutIndices/glTF/TriangleWithoutIndices.gltf new file mode 100644 index 0000000..b3acc55 --- /dev/null +++ b/tests/fixtures/gltf/TriangleWithoutIndices/glTF/TriangleWithoutIndices.gltf @@ -0,0 +1,55 @@ +{ + "scene" : 0, + "scenes" : [ + { + "nodes" : [ 0 ] + } + ], + + "nodes" : [ + { + "mesh" : 0 + } + ], + + "meshes" : [ + { + "primitives" : [ { + "attributes" : { + "POSITION" : 0 + } + } ] + } + ], + + "buffers" : [ + { + "uri" : "TriangleWithoutIndices.bin", + "byteLength" : 36 + } + ], + "bufferViews" : [ + { + "buffer" : 0, + "byteOffset" : 0, + "byteLength" : 36, + "target" : 34962 + } + ], + "accessors" : [ + { + "bufferView" : 0, + "byteOffset" : 0, + "componentType" : 5126, + "count" : 3, + "type" : "VEC3", + "max" : [ 1.0, 1.0, 0.0 ], + "min" : [ 0.0, 0.0, 0.0 ] + } + ], + + "asset" : { + "version" : "2.0" + } +} + diff --git a/tests/fixtures/gltf/UnicodeTest/LICENSE.md b/tests/fixtures/gltf/UnicodeTest/LICENSE.md new file mode 100644 index 0000000..06103d1 --- /dev/null +++ b/tests/fixtures/gltf/UnicodeTest/LICENSE.md @@ -0,0 +1,17 @@ +# LICENSE file for the model: Unicode❤♻Test + +All files in this directory tree are licensed as indicated below. + +* All files directly associated with the model including all text, image and binary files: + + * [Creative Commons Zero v1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/legalcode) [SPDX license identifier: "CC0-1.0"] + +* This file and all other metadocumentation files including "metadata.json": + + * [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"] + +Full license text of these licenses are available at the links above. + +This license excludes logos and associated trademarks. + + diff --git a/tests/fixtures/gltf/UnicodeTest/glTF-Binary/UnicodeTest.glb b/tests/fixtures/gltf/UnicodeTest/glTF-Binary/UnicodeTest.glb new file mode 100644 index 0000000..e5e8409 Binary files /dev/null and b/tests/fixtures/gltf/UnicodeTest/glTF-Binary/UnicodeTest.glb differ diff --git a/tests/fixtures/gltf/UnlitTest/LICENSE.md b/tests/fixtures/gltf/UnlitTest/LICENSE.md new file mode 100644 index 0000000..2fc6a6a --- /dev/null +++ b/tests/fixtures/gltf/UnlitTest/LICENSE.md @@ -0,0 +1,17 @@ +# LICENSE file for the model: Unlit Test + +All files in this directory tree are licensed as indicated below. + +* All files directly associated with the model including all text, image and binary files: + + * [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"] + +* This file and all other metadocumentation files including "metadata.json": + + * [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) [SPDX license identifier: "CC-BY-4.0"] + +Full license text of these licenses are available at the links above. + +This license excludes logos and associated trademarks. + + diff --git a/tests/fixtures/gltf/UnlitTest/glTF-Binary/UnlitTest.glb b/tests/fixtures/gltf/UnlitTest/glTF-Binary/UnlitTest.glb new file mode 100644 index 0000000..6998aea Binary files /dev/null and b/tests/fixtures/gltf/UnlitTest/glTF-Binary/UnlitTest.glb differ diff --git a/tests/model/gltf.luau b/tests/model/gltf.luau new file mode 100644 index 0000000..b737320 --- /dev/null +++ b/tests/model/gltf.luau @@ -0,0 +1,351 @@ +-- model/gltf tests: Khronos glTF-Sample-Assets models (JSON with external / embedded buffers, GLB, sparse, interleaved, +-- quantized, morph targets, skins, animations, cameras, lights, texture transforms, material extensions), gltfpack +-- quantized variants and assimp's exporter output, against assimp (meshes, faces, bounds, animations, cameras, +-- lights) and trimesh (area, triangles); full-structure round trips through GLB, embedded .gltf and external files; +-- assimp / trimesh reading our output (gltf_xcheck); textures decoded lazily at the api layer; errors; the fuzz +-- no-throw pass. Fixtures: tools/fixtures/gltf.py. +local T = require("@tests/T") +local F = require("@formats") +local Gltf = require("@formats/model/gltf") +local MeshOps = require("@formats/ops/MeshOps") +local Bytes = require("@formats/core/Bytes") +local Err = require("@formats/core/Err") +local Types = require("@formats/Types") +local Cases = require("@tests/gen/gltf_cases") +local Xcheck = require("@tests/gen/gltf_xcheck") + +local t = T.suite("gltf") + +local function decode(data: any, opts: any?): (any, any) + local b = if type(data) == "string" then buffer.fromstring(data) else data + return Gltf.decode(Bytes.reader(b), opts) +end + +t:eq(Gltf.name, "gltf", "name") +t:eq(Gltf.category, "model", "category") +t:check(Gltf.caps.decode and Gltf.caps.encode and table.find(Gltf.extensions, "glb"), "contract") + +local function near(a: number, b: number, eps: number): boolean + return math.abs(a - b) <= eps * math.max(1, math.abs(a), math.abs(b)) +end + +local function triArea(prim: any): number + local pos = prim.attributes.POSITION + local ind = prim.indices + if not ind then + return 0 + end + local area = 0 + local function P(i: number, k: number): number + return buffer.readf32(pos.data, (i * 3 + k) * 4) + end + for tri = 0, ind.count // 3 - 1 do + local a, b, c = buffer.readu32(ind.data, tri * 12), buffer.readu32(ind.data, tri * 12 + 4), buffer.readu32(ind.data, tri * 12 + 8) + local e1 = { P(b, 0) - P(a, 0), P(b, 1) - P(a, 1), P(b, 2) - P(a, 2) } + local e2 = { P(c, 0) - P(a, 0), P(c, 1) - P(a, 1), P(c, 2) - P(a, 2) } + local x, y, z = e1[2] * e2[3] - e1[3] * e2[2], e1[3] * e2[1] - e1[1] * e2[3], e1[1] * e2[2] - e1[2] * e2[1] + area += math.sqrt(x * x + y * y + z * z) / 2 + end + return area +end + +-- assimp's counts: one mesh per primitive, faces after strips / fans / loops are unrolled +local function counts(scene: any): (number, number) + local prims, faces = 0, 0 + -- the meshes of the default scene (assimp imports that one only) + local meshes, seen = {}, {} + for _, pl in Types.Scene.flatten(scene) do + if not seen[pl.mesh] then + seen[pl.mesh] = true + table.insert(meshes, scene.meshes[pl.mesh]) + end + end + for _, m in meshes do + for _, p in m.primitives do + prims += 1 + local n = if p.indices then p.indices.count else p.attributes.POSITION.count + local mode = p.mode + faces += if mode == "triangles" then n // 3 + elseif mode == "triangle_strip" or mode == "triangle_fan" then math.max(n - 2, 0) + elseif mode == "lines" then n // 2 + elseif mode == "line_strip" then math.max(n - 1, 0) + elseif mode == "line_loop" then n + else n + end + end + return prims, faces +end + +-- every value of two scenes equal (buffers by content), meta skipped +local function same(a: any, b: any, path: string, seen: { [any]: boolean }?, skip: { [string]: boolean }?): (boolean, string?) + local s = seen or {} + local sk = skip or { meta = true, extras = true } + if type(a) == "buffer" and type(b) == "buffer" then + return buffer.tostring(a) == buffer.tostring(b), path + end + if type(a) ~= "table" or type(b) ~= "table" then + if type(a) == "number" and type(b) == "number" then + return near(a, b, 1e-6), path + end + return a == b, path + end + if s[a] then + return true, nil + end + s[a] = true + for k, v in a do + if not sk[k] then + local ok, where = same(v, b[k], path .. "." .. tostring(k), s, sk) + if not ok then + return false, where + end + end + end + for k, v in b do + if not sk[k] and a[k] == nil and v ~= nil then + return false, path .. "." .. tostring(k) .. " (extra)" + end + end + return true, nil +end + +local byName = {} +local checked = { assimp = 0, trimesh = 0, roundTrips = 0 } +for i, c in Cases do + byName[c.name] = c + local scene, err = decode(c.data, { files = c.files }) + t:check(scene, c.name .. ": decode: " .. tostring(err)) + local ref = if c.like then nil else c.assimp + local prims, faces = counts(scene) + if ref and not ref.failed then + t:eq(prims, ref.meshes, c.name .. ": meshes (assimp)") + t:eq(faces, ref.faces, c.name .. ": faces (assimp)") + if ref.animations then + t:eq(#scene.animations, ref.animations, c.name .. ": animations (assimp)") + end + if ref.cameras then + t:eq(#scene.cameras, ref.cameras, c.name .. ": cameras (assimp)") + end + if ref.lights then + t:eq(#scene.lights, ref.lights, c.name .. ": lights (assimp)") + end + checked.assimp += 1 + end + -- trimesh: the whole scene in world space (quantized variants: against the original model, within quantization) + local tm = if c.like then byName[c.like].trimesh else c.trimesh + local merged = MeshOps.merge(scene) + local onlyTriangles = true -- trimesh reads TRIANGLES primitives only (not strips / fans) + for _, m in scene.meshes do + for _, p in m.primitives do + if p.mode == "triangle_strip" or p.mode == "triangle_fan" then + onlyTriangles = false + end + end + end + -- trimesh ignores sparse accessors + local sparse = string.find(c.data, "\"sparse\"", 1, true) ~= nil + if tm and not tm.failed and tm.faces > 0 and onlyTriangles and not sparse then + local eps = if c.like then 2e-3 else 1e-5 + t:eq(merged.indices.count // 3, tm.faces, c.name .. ": triangles (trimesh)") + t:check(near(triArea(merged), tm.area, eps), string.format("%s: area %.6g, trimesh %.6g", c.name, triArea(merged), tm.area)) + local lo, hi = MeshOps.bounds(merged) + for k = 1, 3 do + t:check(near(lo[k], tm.bounds[k], eps * 10) and near(hi[k], tm.bounds[k + 3], eps * 10), c.name .. ": bounds (trimesh)") + end + checked.trimesh += 1 + end + -- round trips: GLB, embedded .gltf, external files + local glb, gerr = Gltf.encode(scene, { binary = true }) + t:check(glb, c.name .. ": encode glb: " .. tostring(gerr)) + local back = decode(glb) + t:check(back, c.name .. ": decode our glb") + local SKIP = { meta = true, extras = true, uri = true } -- embedded images lose their file names + local ok, where = same(scene, back, "scene", nil, SKIP) + t:check(ok, c.name .. ": glb round trip differs at " .. tostring(where)) + local text = Gltf.encode(scene) :: buffer + local back2 = decode(text) + local ok2, where2 = same(scene, back2, "scene", nil, SKIP) + t:check(ok2, c.name .. ": embedded .gltf round trip differs at " .. tostring(where2)) + local files = {} + local ext = Gltf.encode(scene, { external = true, files = files, name = "x.gltf" }) :: buffer + t:check(files["x.bin"] ~= nil or #scene.meshes == 0, c.name .. ": external .bin") + local back3 = decode(ext, { files = files }) + local ok3, where3 = same(scene, back3, "scene", nil, SKIP) + t:check(ok3, c.name .. ": external .gltf round trip differs at " .. tostring(where3)) + -- writing what we read back gives the same bytes + t:check(buffer.tostring(Gltf.encode(back, { binary = true }) :: buffer) == buffer.tostring(glb :: buffer), c.name .. ": writing is stable") + checked.roundTrips += 1 + c.index = i +end +t:note("%d files: %d against assimp, %d against trimesh, %d round trips", #Cases, checked.assimp, checked.trimesh, checked.roundTrips) + +-- the reference tools read our files like the originals +local nx = 0 +for _, x in Xcheck do + local c = Cases[x.case] + local a, ca = x.assimp, c.assimp + if not ca.failed then + t:check(not a.failed, x.name .. ": assimp reads our file") + t:eq(a.faces, ca.faces, x.name .. ": assimp faces of our file (" .. c.name .. ")") + t:eq(a.meshes, ca.meshes, x.name .. ": assimp meshes of our file") + for k = 1, 3 do + t:check(near(a.min[k], ca.min[k], 1e-4) and near(a.max[k], ca.max[k], 1e-4), x.name .. ": assimp bounds of our file (" .. c.name .. ")") + end + t:eq(a.animations, ca.animations, x.name .. ": assimp animations of our file") + t:eq(a.cameras, ca.cameras, x.name .. ": assimp cameras of our file") + t:eq(a.lights, ca.lights, x.name .. ": assimp lights of our file") + end + if c.trimesh and not c.trimesh.failed and c.trimesh.faces > 0 and c.name ~= "MeshPrimitiveModes/glTF" and not string.find(c.data, "\"sparse\"", 1, true) then + t:check(not x.trimesh.failed and near(x.trimesh.area, c.trimesh.area, 1e-5) and x.trimesh.faces == c.trimesh.faces, x.name .. ": trimesh area of our file (" .. c.name .. ")") + end + nx += 1 +end +t:note("%d of our files read back by assimp / trimesh like the originals", nx) + +-- details +do + local function load(name: string): any + local c = byName[name] + return decode(c.data, { files = c.files }) + end + local box = load("Box/glTF") + t:check(box.nodes[box.roots[1]].matrix ~= nil and box.meta.source.binary == false, "Box: a matrix node, JSON") + t:check(box.materials[1].metallic == 0 and near(box.materials[1].baseColor[1], 0.8, 1e-6), "Box: material") + local bt = load("BoxTextured/glTF") + local tex = bt.textures[1] + t:check(tex.uri == "CesiumLogoFlat.png" and tex.mime == "image/png" and buffer.tostring(tex.data) == byName["BoxTextured/glTF"].files["CesiumLogoFlat.png"], "BoxTextured: the image bytes from opts.files") + t:check(tex.sampler and tex.sampler.wrapS == "repeat" and tex.sampler.minFilter == "nearest_mipmap_linear", "sampler") + -- the api decodes textures lazily (PNG here) + local _, terrs = F.model.loadTextures(bt) + t:check(tex.image and tex.image.width == 256 and next(terrs) == nil, "F.model.loadTextures decodes the PNG") + local files = {} + local ext = Gltf.encode(bt, { external = true, files = files, name = "bt.gltf" }) :: buffer + t:check(files["CesiumLogoFlat.png"] ~= nil and string.find(buffer.tostring(ext), "\"uri\": \"CesiumLogoFlat.png\"", 1, true) ~= nil, "external images keep their file names") + local emb = load("BoxTextured/glTF-Embedded") + t:check(emb.textures[1].data and buffer.tostring(emb.textures[1].data) == buffer.tostring(tex.data), "embedded data: URI image = the external file") + local sparse = load("SimpleSparseAccessor/glTF-Embedded") + local pos = sparse.meshes[1].primitives[1].attributes.POSITION + local maxY = -math.huge + for v = 0, pos.count - 1 do + maxY = math.max(maxY, buffer.readf32(pos.data, v * 12 + 4)) + end + t:eq(maxY, 4, "sparse values substituted (the raised vertices, max = the accessor max)") + local cams = load("Cameras/glTF") + t:check(#cams.cameras == 2 and cams.cameras[1].type == "perspective" and cams.cameras[2].type == "orthographic", "cameras") + local skin = load("SimpleSkin/glTF") + t:check(#skin.skins == 1 and #skin.skins[1].joints == 2 and skin.skins[1].inverseBindMatrices.matrix and skin.skins[1].inverseBindMatrices.components == 16, "skin") + t:check(#skin.animations == 1 and skin.animations[1].channels[1].path == "rotation", "skin animation") + local morph = load("SimpleMorph/glTF") + t:check(#morph.meshes[1].primitives[1].targets == 2 and morph.meshes[1].weights[1] == 0.5, "morph targets, weights") + local q = load("AnimatedMorphCube/glTF-Quantized") + local qp = q.meshes[1].primitives[1] + t:check(qp.attributes.NORMAL.type == "snorm8" and qp.targets and qp.targets[1].POSITION.type == "i16", "quantized normals / target deltas") + local unlit = load("UnlitTest/glTF-Binary") + t:check(unlit.materials[1].extensions and unlit.materials[1].extensions.KHR_materials_unlit ~= nil, "KHR_materials_unlit") + local es = load("EmissiveStrengthTest/glTF-Binary") + local strength = 0 + for _, m in es.materials do + local e = m.extensions and m.extensions.KHR_materials_emissive_strength + if e then + strength = math.max(strength, e.emissiveStrength) + end + end + t:check(strength > 1, "KHR_materials_emissive_strength") + local cc = load("ClearCoatCarPaint/glTF-Binary") + local clear = cc.materials[1].extensions and cc.materials[1].extensions.KHR_materials_clearcoat + t:check(clear and clear.clearcoatFactor ~= nil, "KHR_materials_clearcoat") + local tt = load("TextureTransformTest/glTF") + local nt = 0 + for _, m in tt.materials do + if m.baseColorTexture and m.baseColorTexture.transform then + nt += 1 + end + end + t:check(nt >= 5, "KHR_texture_transform on " .. nt .. " materials") + local lights = load("PointLightIntensityTest/glTF-Binary") + t:check(#lights.lights > 0 and lights.lights[1].type == "point", "KHR_lights_punctual") + local ms = load("MultipleScenes/glTF") + t:check(#ms.meta.gltf.scenes == 2, "multiple scenes kept") + local modes = load("MeshPrimitiveModes/glTF") + local seen = {} + for _, m in modes.meshes do + for _, p in m.primitives do + seen[p.mode] = true + end + end + t:check(seen.points and seen.lines and seen.line_loop and seen.line_strip and seen.triangle_strip and seen.triangle_fan, "every primitive mode") + local inter = load("BoxInterleaved/glTF-Binary") + t:check(inter.meshes[1].primitives[1].attributes.NORMAL.count == 24, "interleaved (byteStride) attributes") + -- quantized output declares KHR_mesh_quantization + local qglb = Gltf.encode(q, { binary = true }) :: buffer + t:check(string.find(buffer.tostring(qglb), "KHR_mesh_quantization", 1, true) ~= nil, "KHR_mesh_quantization written") + -- a Scene made by hand (an OBJ-like mesh with u8 colours and polygons) writes and reads back + local s = Types.Scene.new() + local p = Types.Scene.accessor(nil, "f32", 3, 4) + for v, xyz in { { 0, 0, 0 }, { 1, 0, 0 }, { 1, 1, 0 }, { 0, 1, 0 } } do + for k = 1, 3 do + buffer.writef32(p.data, ((v - 1) * 3 + k - 1) * 4, xyz[k]) + end + end + local col = Types.Scene.accessor(nil, "unorm8", 3, 4) + local faces = Types.Scene.accessor(nil, "u32", 1, 1) + buffer.writeu32(faces.data, 0, 4) + local ind = Types.Scene.accessor(nil, "u32", 1, 4) + for k = 0, 3 do + buffer.writeu32(ind.data, k * 4, k) + end + local s2 = Types.Scene.fromPrimitive({ attributes = { POSITION = p, COLOR_0 = col }, indices = ind, faces = faces, mode = "polygons" }, "quad") + local out = Gltf.encode(s2, { binary = true }) :: buffer + local back = decode(out) + t:check(back and back.meshes[1].primitives[1].indices.count == 6 and back.meshes[1].primitives[1].attributes.COLOR_0.type == "unorm8", "polygons fan-triangulated, unorm8 VEC3 colours (padded stride)") + -- through the api: the destination's extension picks GLB + local viaApi = F.save(s2, nil, { format = "glb" }) + t:check(viaApi and buffer.readstring(viaApi, 0, 4) == "glTF", "F.save format glb") + local viaApi2 = F.save(s2, nil, { format = "gltf" }) + t:check(viaApi2 and buffer.readstring(viaApi2, 0, 1) == "{", "F.save format gltf") + local loaded = F.load(viaApi) + t:check(loaded and loaded.kind == "scene" and loaded.meta.source.format == "gltf", "F.load detects GLB") +end + +-- errors +do + local _, e = decode("{ not json") + t:check(e and (e.code == Err.CORRUPT or e.code == Err.TRUNCATED), "bad JSON: " .. tostring(e)) + local _, e2 = decode('{"asset": {"version": "1.0"}}') + t:check(e2 and e2.code == Err.UNSUPPORTED, "glTF 1: " .. tostring(e2)) + local _, e3 = decode('{"asset": {"version": "2.0"}, "extensionsRequired": ["KHR_draco_mesh_compression"]}') + t:check(e3 and e3.code == Err.UNSUPPORTED, "Draco: " .. tostring(e3)) + local c = byName["Box/glTF"] + local _, e4 = decode(c.data) + t:check(e4 and e4.code == Err.IO, "missing .bin: " .. tostring(e4)) + local _, e5 = decode('{"asset": {"version": "2.0"}, "buffers": [{"byteLength": 4, "uri": "data:application/octet-stream;base64,AAAAAA=="}], "bufferViews": [{"buffer": 0, "byteLength": 4}], "accessors": [{"bufferView": 0, "componentType": 5126, "count": 2, "type": "SCALAR"}]}') + t:check(e5 and e5.code == Err.CORRUPT, "accessor past its view: " .. tostring(e5)) + local glb = byName["Box/glTF-Binary"].data + local _, e6 = decode(string.sub(glb, 1, 100)) + t:check(e6 and e6.code == Err.TRUNCATED, "truncated GLB: " .. tostring(e6)) + local _, e7 = Gltf.encode({} :: any) + t:check(e7 and e7.code == Err.ARG, "encode junk") + local bad = Types.Scene.fromPrimitive({ attributes = { POSITION = Types.Scene.accessor(buffer.create(4), "f32", 3, 10) }, mode = "triangles" }) + local _, e8 = Gltf.encode(bad) + t:check(e8 and e8.code == Err.ARG, "encode a short accessor: " .. tostring(e8)) +end + +-- fuzz +do + local samples = {} + for _, c in Cases do + if #c.data < 40000 then + table.insert(samples, c.data) + end + end + t:fuzz("decode", function(b: buffer) + local s = Gltf.decode(Bytes.reader(b)) + if s then + Gltf.encode(s, { binary = true }) + MeshOps.merge(s) + end + return s + end, samples, { mutations = 20 }) +end + +t:done() diff --git a/tools/fixtures/_gltf_encode.luau b/tools/fixtures/_gltf_encode.luau new file mode 100644 index 0000000..b7c037f --- /dev/null +++ b/tools/fixtures/_gltf_encode.luau @@ -0,0 +1,34 @@ +-- tools/fixtures/_gltf_encode: run by tools/fixtures/gltf.py (luau CLI, repo root): decodes every glTF case with our +-- reader and encodes it with our writer as .glb and as .gltf with an external .bin and image files, printing +-- "\t" lines for the reference tools (assimp, trimesh) to read back. Files: rt_.glb, rt_.gltf. +local Gltf = require("@formats/model/gltf") +local Bytes = require("@formats/core/Bytes") +local Cases = require("@tests/gen/gltf_cases") + +local HEX = {} +for i = 0, 255 do + HEX[i] = string.format("%02x", i) +end +local function hex(s: string): string + local out = table.create(#s) + for i = 1, #s do + out[i] = HEX[string.byte(s, i)] + end + return table.concat(out) +end + +for i, c in Cases do + local scene, err = Gltf.decode(Bytes.reader(buffer.fromstring(c.data)), { files = c.files }) + if scene then + local glb = assert(Gltf.encode(scene, { binary = true })) + print(string.format("rt_%d.glb\t%s", i, hex(buffer.tostring(glb)))) + local files = {} + local gltf = assert(Gltf.encode(scene, { external = true, files = files, name = "rt_" .. i .. ".gltf" })) + print(string.format("rt_%d.gltf\t%s", i, hex(buffer.tostring(gltf)))) + for name, data in files do + print(name .. "\t" .. hex(if type(data) == "string" then data else buffer.tostring(data))) + end + else + print("skipped " .. c.name .. ": " .. tostring(err)) + end +end diff --git a/tools/fixtures/_model_ref.py b/tools/fixtures/_model_ref.py index fbc7db1..6cd3ede 100644 --- a/tools/fixtures/_model_ref.py +++ b/tools/fixtures/_model_ref.py @@ -1,5 +1,5 @@ # Shared helpers for the model fixture generators (obj.py, gltf.py): reference tools through nix. -# assimp_info(ctx, paths) -> [ { meshes, materials, vertices, faces, nodes, min, max, perMesh = [ { vertices, faces } ] } ] +# assimp_info(ctx, paths, raw?) -> [ { meshes, materials, vertices, faces, nodes, min, max, perMesh = [ { vertices, faces } ] } ] # trimesh_metrics(ctx, paths) -> [ { area, faces, bounds, volume? } ] (trimesh, process=False, every geometry merged) # luau_encode(ctx, script) -> { name: bytes }: runs a Luau script (repo-relative, .luaurc aliases) that prints # "\t" lines: how a generator gets our encoder's output for the reference tools to read back. @@ -8,10 +8,15 @@ import json, os, re, subprocess, tempfile, shutil FLOAT = r"(-?[\d.]+(?:e[-+]?\d+)?|-?nan|-?inf)" -def assimp_info(ctx, paths): +def assimp_info(ctx, paths, raw=False): + # raw: `assimp info -r` (no post-processing: no joined vertices, no merged identical meshes) out = [] for p in paths: - txt = ctx.nix("assimp", ["assimp", "info", p]).decode("utf-8", "replace") + try: + txt = ctx.nix("assimp", ["assimp", "info", p] + (["-r"] if raw else [])).decode("utf-8", "replace") + except subprocess.CalledProcessError: + out.append({"failed": True}) + continue def num(label): m = re.search(r"^" + label + r":\s+(\d+)", txt, re.M) @@ -33,8 +38,11 @@ TRIMESH = r""" import json, sys, trimesh, numpy as np res = [] for p in json.loads(sys.stdin.read()): - m = trimesh.load(p, force="mesh", process=False) - d = {"area": float(m.area), "faces": int(len(m.faces)), "bounds": [float(v) for v in np.asarray(m.bounds).ravel()] if len(m.faces) else []} + try: + m = trimesh.load(p, force="mesh", process=False) + d = {"area": float(m.area), "faces": int(len(m.faces)), "bounds": [float(v) for v in np.asarray(m.bounds).ravel()] if len(m.faces) else []} + except Exception as e: + d = {"failed": True} res.append(d) print(json.dumps(res)) """ diff --git a/tools/fixtures/gltf.py b/tools/fixtures/gltf.py new file mode 100644 index 0000000..a424fcf --- /dev/null +++ b/tools/fixtures/gltf.py @@ -0,0 +1,115 @@ +# glTF fixtures (tools/fixtures.py): Khronos glTF-Sample-Assets models (tests/fixtures/gltf, licences per model +# folder), gltfpack (meshoptimizer) quantized variants (KHR_mesh_quantization, normalized and integer positions, +# KHR_texture_transform), and files exported by assimp, with reference values from assimp (`assimp info`: meshes, faces, +# bounds, materials, animations, cameras, lights) and trimesh (area, triangles, bounds of the whole scene). +# tests/gen/gltf_cases.luau { name, main, data, files = { uri -> bytes }, assimp, trimesh, like? (the original of a +# quantized variant: compare against its references with a tolerance) } +# tests/gen/gltf_xcheck.luau our encoder's .glb and .gltf for every case (tools/fixtures/_gltf_encode.luau), read back +# by assimp and trimesh: { name, case, assimp, trimesh } +import importlib.util, json, os, struct + +INPUTS = ["tests/fixtures/gltf", "src/Formats/model/gltf", "src/Formats/codecs/Json", "src/Formats/codecs/Base64", + "tools/fixtures/_model_ref.py", "tools/fixtures/_gltf_encode.luau"] + + +def ref_module(ctx): + spec = importlib.util.spec_from_file_location("_model_ref", os.path.join(ctx.root, "tools", "fixtures", "_model_ref.py")) + m = importlib.util.module_from_spec(spec) + spec.loader.exec_module(m) + return m + + +def assimp_extra(ctx, path): + # cameras / lights / animations counts from assimp info (the shared helper parses meshes / faces / bounds) + import re, subprocess + try: + txt = ctx.nix("assimp", ["assimp", "info", path, "-r"]).decode("utf-8", "replace") + except subprocess.CalledProcessError: + return {} + out = {} + for label in ("Animations", "Cameras", "Lights", "Bones"): + m = re.search(r"^" + label + r":\s+(\d+)", txt, re.M) + if m: + out[label.lower()] = int(m.group(1)) + return out + + +def ply_torus(R=2.0, r=0.5, a=16, b=8): + import math + vs, fs = [], [] + for i in range(a): + for j in range(b): + u, v = 2 * math.pi * i / a, 2 * math.pi * j / b + vs.append(((R + r * math.cos(v)) * math.cos(u), r * math.sin(v), (R + r * math.cos(v)) * math.sin(u))) + for i in range(a): + for j in range(b): + p, q = i * b + j, ((i + 1) % a) * b + j + p2, q2 = i * b + (j + 1) % b, ((i + 1) % a) * b + (j + 1) % b + fs.append((p, p2, q2)) + fs.append((p, q2, q)) + head = "ply\nformat ascii 1.0\nelement vertex %d\nproperty float x\nproperty float y\nproperty float z\nelement face %d\nproperty list uchar int vertex_indices\nend_header\n" % (len(vs), len(fs)) + return (head + "".join("%r %r %r\n" % v for v in vs) + "".join("3 %d %d %d\n" % f for f in fs)).encode() + + +def generate(ctx): + M = ref_module(ctx) + root = os.path.join(ctx.root, "tests", "fixtures", "gltf") + cases = [] + for model in sorted(os.listdir(root)): + for variant in sorted(os.listdir(os.path.join(root, model))): + d = os.path.join(root, model, variant) + if not os.path.isdir(d): + continue + mains = [f for f in sorted(os.listdir(d)) if f.endswith(".gltf") or f.endswith(".glb")] + if not mains: + continue + files = {f: open(os.path.join(d, f), "rb").read() for f in sorted(os.listdir(d)) if f != mains[0]} + cases.append({"name": model + "/" + variant, "main": mains[0], "path": os.path.join(d, mains[0]), "files": files}) + # gltfpack variants of a few models: default (integer positions + texture transform), -vpn (normalized positions), + # -vpf (float positions, quantized normals / uvs) + tmp = M.tempdir() + for model, variant, main in (("BoxTextured", "glTF", "BoxTextured.gltf"), ("Box", "glTF-Binary", "Box.glb"), ("SimpleSkin", "glTF", "SimpleSkin.gltf"), ("MultiUVTest", "glTF-Binary", "MultiUVTest.glb")): + for flag in ("", "-vpn", "-vpf", "-vpi"): + out = os.path.join(tmp, "%s_q%s.glb" % (model, flag)) + args = ["gltfpack", "-i", os.path.join(root, model, variant, main), "-o", out, "-kn", "-km"] + ([flag] if flag else []) + ctx.nix("meshoptimizer", args) + cases.append({"name": "gltfpack/%s%s" % (model, flag), "main": os.path.basename(out), "path": out, "files": {}, "like": model + "/" + variant}) + # assimp's glTF exporters + ply = os.path.join(tmp, "torus.ply") + with open(ply, "wb") as f: + f.write(ply_torus()) + for ext in ("glb", "gltf"): + out = os.path.join(tmp, "torus_assimp." + ext) + ctx.nix("assimp", ["assimp", "export", ply, out, "-f" + ("glb2" if ext == "glb" else "gltf2")]) + files = {} + for f in os.listdir(tmp): + if f.startswith("torus_assimp") and f.endswith(".bin"): + files[f] = open(os.path.join(tmp, f), "rb").read() + cases.append({"name": "assimp/torus." + ext, "main": os.path.basename(out), "path": out, "files": files}) + infos = M.assimp_info(ctx, [c["path"] for c in cases], raw=True) + tms = M.trimesh_metrics(ctx, [c["path"] for c in cases]) + for c, a, t in zip(cases, infos, tms): + a.update(assimp_extra(ctx, c["path"])) + c["assimp"] = a + c["trimesh"] = t + c["data"] = open(c["path"], "rb").read() + del c["path"] + ctx.emit("gltf_cases", cases) + + # the reference tools read our output + ours = M.luau_encode(ctx, "tools/fixtures/_gltf_encode.luau") + xtmp = M.tempdir() + names = [] + for name, data in sorted(ours.items()): + with open(os.path.join(xtmp, name), "wb") as f: + f.write(data) + if name.endswith(".glb") or name.endswith(".gltf"): + names.append(name) + paths = [os.path.join(xtmp, n) for n in names] + xi = M.assimp_info(ctx, paths, raw=True) + xt = M.trimesh_metrics(ctx, paths) + out = [] + for n, a, t in zip(names, xi, xt): + a.update(assimp_extra(ctx, os.path.join(xtmp, n))) + out.append({"name": n, "case": int(n.split("_")[1].split(".")[0]), "assimp": a, "trimesh": t}) + ctx.emit("gltf_xcheck", out)