ws-3d3: model/3ds writer samples camera / light channels through codecs/model/Sampler (drops its local sampler); scene.md intro wrap
This commit is contained in:
1 parent
44cda7256c
commit
406b894635
4 files changed
+10
-39
No files matched your search
+2
-1
@@ -3,7 +3,8 @@
|
|||||||
Every model format (glTF / GLB, OBJ, STL, PLY, OFF, FBX, Collada, 3MF, USDA, VOX, 3DS, MS3D, B3D, LDraw, LightWave
|
Every model format (glTF / GLB, OBJ, STL, PLY, OFF, FBX, Collada, 3MF, USDA, VOX, 3DS, MS3D, B3D, LDraw, LightWave
|
||||||
LWO, DirectX .x, IQM) loads as one `Scene`, a structure shaped like glTF 2.0: a node tree, meshes made of primitives,
|
LWO, DirectX .x, IQM) loads as one `Scene`, a structure shaped like glTF 2.0: a node tree, meshes made of primitives,
|
||||||
flat attribute buffers (accessors), PBR materials, textures, cameras, lights, skins and animations. Mesh-only formats
|
flat attribute buffers (accessors), PBR materials, textures, cameras, lights, skins and animations. Mesh-only formats
|
||||||
(STL, PLY, OFF) give a one-node scene. MagicaVoxel files also carry voxel grids (`scene.voxels`). Editing goes through `F.ops.mesh`.
|
(STL, PLY, OFF) give a one-node scene. MagicaVoxel files also carry voxel grids (`scene.voxels`). Editing goes through
|
||||||
|
`F.ops.mesh`.
|
||||||
|
|
||||||
```luau
|
```luau
|
||||||
local scene = assert(F.model.load(texturedGltfText))
|
local scene = assert(F.model.load(texturedGltfText))
|
||||||
|
|||||||
@@ -368,7 +368,7 @@ local list: { Entry } = {
|
|||||||
path = "model/3ds",
|
path = "model/3ds",
|
||||||
extensions = { "3ds" },
|
extensions = { "3ds" },
|
||||||
mime = { "application/x-3ds", "image/x-3ds" },
|
mime = { "application/x-3ds", "image/x-3ds" },
|
||||||
deps = { "core/Err", "core/Bytes", "Types", "codecs/model/Mat4", "codecs/model/MeshFlatten" },
|
deps = { "core/Err", "core/Bytes", "Types", "codecs/model/Mat4", "codecs/model/MeshFlatten", "codecs/model/Sampler" },
|
||||||
caps = { decode = true, encode = true, materials = true, textures = true, animation = true, cameras = true, lights = true, instancing = true },
|
caps = { decode = true, encode = true, materials = true, textures = true, animation = true, cameras = true, lights = true, instancing = true },
|
||||||
load = function()
|
load = function()
|
||||||
return require("@formats/model/3ds")
|
return require("@formats/model/3ds")
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
-- Mirroring nodes are written the way 3ds Max does (positive keyframer transform, mirror in the mesh matrix).
|
-- Mirroring nodes are written the way 3ds Max does (positive keyframer transform, mirror in the mesh matrix).
|
||||||
local Bytes = require("@formats/core/Bytes")
|
local Bytes = require("@formats/core/Bytes")
|
||||||
local Types = require("@formats/Types")
|
local Types = require("@formats/Types")
|
||||||
|
local Sampler = require("@formats/codecs/model/Sampler")
|
||||||
local Mat4 = require("@formats/codecs/model/Mat4")
|
local Mat4 = require("@formats/codecs/model/Mat4")
|
||||||
local Flatten = require("@formats/codecs/model/MeshFlatten")
|
local Flatten = require("@formats/codecs/model/MeshFlatten")
|
||||||
local Read = require("@formats/model/3ds/Read")
|
local Read = require("@formats/model/3ds/Read")
|
||||||
@@ -127,44 +128,13 @@ local function conj(q: { number }): { number }
|
|||||||
return { -q[1], -q[2], -q[3], q[4] }
|
return { -q[1], -q[2], -q[3], q[4] }
|
||||||
end
|
end
|
||||||
|
|
||||||
-- a channel's value at a time (linear; rotations normalized lerp along the short way)
|
-- a channel's value at a time (codecs/model/Sampler: STEP, LINEAR with slerp, CUBICSPLINE)
|
||||||
local function sample(ch: Types.Channel, t: number): { number }
|
local function sample(ch: Types.Channel, t: number): { number }
|
||||||
local IN, OUT = S.reader(ch.input) :: any, S.reader(ch.output) :: any
|
local f = Sampler.channel(ch)
|
||||||
local n = ch.input.count
|
if not f then
|
||||||
local comps = if ch.path == "rotation" then 4 else 3
|
return if ch.path == "rotation" then { 0, 0, 0, 1 } else { 0, 0, 0 }
|
||||||
local cubic = ch.interpolation == "CUBICSPLINE"
|
|
||||||
local function v(k: number): { number }
|
|
||||||
local e = if cubic then k * 3 + 1 else k
|
|
||||||
local r = table.create(comps, 0)
|
|
||||||
for c = 1, comps do
|
|
||||||
r[c] = OUT(e, c - 1)
|
|
||||||
end
|
|
||||||
return r
|
|
||||||
end
|
end
|
||||||
if n == 0 then
|
return f(t)
|
||||||
return if comps == 4 then { 0, 0, 0, 1 } else { 0, 0, 0 }
|
|
||||||
end
|
|
||||||
if t <= IN(0, 0) then
|
|
||||||
return v(0)
|
|
||||||
end
|
|
||||||
for k = 0, n - 2 do
|
|
||||||
local t0, t1 = IN(k, 0), IN(k + 1, 0)
|
|
||||||
if t <= t1 then
|
|
||||||
if ch.interpolation == "STEP" or t1 <= t0 then
|
|
||||||
return if t >= t1 then v(k + 1) else v(k)
|
|
||||||
end
|
|
||||||
local u = (t - t0) / (t1 - t0)
|
|
||||||
local a, b = v(k), v(k + 1)
|
|
||||||
if comps == 4 and a[1] * b[1] + a[2] * b[2] + a[3] * b[3] + a[4] * b[4] < 0 then
|
|
||||||
b = { -b[1], -b[2], -b[3], -b[4] }
|
|
||||||
end
|
|
||||||
for c = 1, comps do
|
|
||||||
a[c] += (b[c] - a[c]) * u
|
|
||||||
end
|
|
||||||
return a
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return v(n - 1)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- ------------------------------------------------------------------------------------------------ materials
|
-- ------------------------------------------------------------------------------------------------ materials
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ local ThreeDs = {
|
|||||||
category = "model",
|
category = "model",
|
||||||
extensions = { "3ds" },
|
extensions = { "3ds" },
|
||||||
mime = { "application/x-3ds", "image/x-3ds" },
|
mime = { "application/x-3ds", "image/x-3ds" },
|
||||||
deps = { "core/Err", "core/Bytes", "Types", "codecs/model/Mat4", "codecs/model/MeshFlatten" },
|
deps = { "core/Err", "core/Bytes", "Types", "codecs/model/Mat4", "codecs/model/MeshFlatten", "codecs/model/Sampler" },
|
||||||
caps = { decode = true, encode = true, materials = true, textures = true, animation = true, cameras = true, lights = true, instancing = true },
|
caps = { decode = true, encode = true, materials = true, textures = true, animation = true, cameras = true, lights = true, instancing = true },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user