rename: src/Formats -> src/Rosetta, @formats -> @rosetta requires, build/luajit/rosetta + rosetta._compat, build/roblox/Rosetta, ROSETTA_* env/globals, writer vendor strings
This commit is contained in:
1 parent
2956576d7f
commit
22ddcd78fa
941 files changed
+3364
-3364
No files matched your search
@@ -0,0 +1,77 @@
|
||||
--!strict
|
||||
-- model/vrml: VRML97 (ISO/IEC 14772-1, `#VRML V2.0 utf8`) .wrl files, plain or gzipped (.wrz), a thin format over
|
||||
-- codecs/model/Vrml (the scene-graph engine model/x3d shares). New code.
|
||||
-- Reads: the scene graph (Transform with center / scaleOrientation, Group, Anchor, Billboard, Collision, Switch, LOD,
|
||||
-- Inline through opts.files / opts.resolve), DEF / USE (shared meshes and materials), PROTO instances (expanded) and
|
||||
-- EXTERNPROTO, Shape / Appearance / Material / ImageTexture / PixelTexture / TextureTransform, IndexedFaceSet (coord,
|
||||
-- normal, color, texCoord with their own indices, per-vertex / per-face normals and colours, ccw, solid -> doubleSided),
|
||||
-- IndexedLineSet, PointSet, ElevationGrid, Extrusion, the primitives Box / Sphere / Cone / Cylinder tessellated
|
||||
-- (opts.segments), Viewpoint -> cameras, DirectionalLight / PointLight / SpotLight -> lights, TimeSensor ->
|
||||
-- Position- / OrientationInterpolator -> Transform ROUTEs -> animations, WorldInfo -> meta.source.title / info. Polygons
|
||||
-- are fan-triangulated unless opts.triangulate = false; texture t is flipped to glTF's top-left origin unless
|
||||
-- opts.flipV = false. meta.up = "y", meta.unit = 1 (metres).
|
||||
-- Writes: VRML97 text (see codecs/model/Vrml/Write: Transforms from the node tree, Shapes with IndexedFaceSet /
|
||||
-- IndexedLineSet / PointSet, Appearance / Material / ImageTexture (texture files into opts.files), Viewpoints, lights,
|
||||
-- TimeSensor + interpolator animations; DEF / USE for shared meshes and materials).
|
||||
-- Not supported: VRML 1.0, Text / FontStyle (no glyphs), Script behaviour, sensors, sound, NURBS, morph targets and
|
||||
-- skins on write (the rest pose is written).
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ 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 Wrl = {
|
||||
name = "vrml",
|
||||
category = "model",
|
||||
extensions = { "wrl", "wrz", "vrml" },
|
||||
mime = { "model/vrml", "x-world/x-vrml" },
|
||||
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 },
|
||||
}
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ types
|
||||
export type DecodeOptions = {
|
||||
files: { [string]: any }?, -- textures / Inline files by uri or base name (buffer or string)
|
||||
resolve: ((uri: string) -> any)?, -- or: reads them (the api sets it for paths)
|
||||
triangulate: boolean?, -- fan-triangulate polygons (default true); false keeps "polygons" primitives
|
||||
flipV: boolean?, -- texture t -> 1 - t (default true: glTF's convention)
|
||||
segments: number?, -- Sphere / Cone / Cylinder segments around (default 32)
|
||||
maxVertices: number?, -- per geometry (default 2^24)
|
||||
}
|
||||
export type EncodeOptions = {
|
||||
files: { [string]: any }?, -- receives the texture images (else url = texture.uri)
|
||||
name: string?, -- the destination's file name (names the image files)
|
||||
flipV: boolean?, -- default true (the inverse of decode)
|
||||
}
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ sniff
|
||||
function Wrl.sniff(r: Bytes.Reader): number
|
||||
local head = r:peek(16)
|
||||
if string.sub(head, 1, 3) == "\239\187\191" then
|
||||
head = string.sub(head, 4)
|
||||
end
|
||||
return if string.sub(head, 1, 10) == "#VRML V2.0" then 1 elseif string.sub(head, 1, 6) == "#VRML " then 0.6 else 0
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ decode
|
||||
function Wrl.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Scene?, Err.Err?)
|
||||
local o: any = table.clone(opts or {})
|
||||
o.format = "vrml"
|
||||
return Vrml.decode(buffer.readstring(r.buf, r.base, r.limit - r.base), o)
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ encode
|
||||
function Wrl.encode(scene: Types.Scene, opts: EncodeOptions?): (buffer?, Err.Err?)
|
||||
local o: any = table.clone(opts or {})
|
||||
o.encoding = "vrml97"
|
||||
local text, err = Vrml.encode(scene, o)
|
||||
if not text then
|
||||
return nil, err
|
||||
end
|
||||
return buffer.fromstring(text), nil
|
||||
end
|
||||
|
||||
return Wrl
|
||||
Reference in new issue
Block a user