--!strict -- model/x3d: X3D (ISO/IEC 19775-1) XML (.x3d, 19776-1) and classic VRML (.x3dv, 19776-2) encodings, plain or gzipped, -- over codecs/model/Vrml; new code. Supports: the model/vrml set plus the X3D geometry and material nodes. -- Not supported: binary encodings (.x3db Fast Infoset / EXI), X3D JSON, Text, NURBS, shaders, H-Anim skinning, scripts. -- ------------------------------------------------------------------------------------------------ requires local Err = require("@rosetta/core/Err") local Bytes = require("@rosetta/core/Bytes") local Types = require("@rosetta/Types") local Vrml = require("@rosetta/codecs/model/Vrml") -- ------------------------------------------------------------------------------------------------ contract local X3d = { name = "x3d", category = "model", extensions = { "x3d", "x3dv", "x3dz", "x3dvz", "x3db" }, mime = { "model/x3d+xml", "model/x3d-vrml", "model/x3d+fastinfoset" }, deps = { "core/Err", "core/Bytes", "Types", "codecs/model/Vrml" }, caps = { decode = true, encode = true, materials = true, polygons = true, animation = true, cameras = true, lights = true, lines = true, points = true, xml = true, classic = true }, } -- ------------------------------------------------------------------------------------------------ types export type DecodeOptions = { files: { [string]: any }?, -- by uri or base name resolve: ((uri: string) -> any)?, triangulate: boolean?, -- default true flipV: boolean?, -- default true segments: number?, -- default 32 maxVertices: number?, -- per geometry (default 2^24) } export type EncodeOptions = { encoding: ("xml" | "x3dv")?, -- default "xml" format: string?, -- "x3dv" / "x3dvz" select the classic encoding files: { [string]: any }?, -- else url = texture.uri name: string?, flipV: boolean?, -- default true (the inverse of decode) } -- ------------------------------------------------------------------------------------------------ sniff function X3d.sniff(r: Bytes.Reader): number local head = r:peek(1024) if string.sub(head, 1, 3) == "\239\187\191" then head = string.sub(head, 4) end if string.sub(head, 1, 5) == "#X3D " then return 1 end if string.sub(head, 1, 4) == "\224\0\0\1" and string.find(head, "x3d", 1, true) then return 0.9 end if string.find(head, "]") or string.find(head, "