model/gltf: mesh.extras.targetNames from and to glTF mesh extras; ops/MeshOps.merge: targets = true concatenates morph targets by name
This commit is contained in:
1 parent
835ddde65b
commit
4231149f3e
6 files changed
+148
-2
No files matched your search
@@ -460,6 +460,16 @@ function Read.scene(doc: any, bin: buffer?, fetch: Fetch, opts: any?): (Types.Sc
|
||||
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) }
|
||||
-- morph target names: the extras.targetNames convention (Blender's exporter, three.js, Babylon)
|
||||
local tn = type(m.extras) == "table" and m.extras.targetNames
|
||||
if type(tn) == "table" and #tn > 0 then
|
||||
local names = {}
|
||||
for k, v in tn do
|
||||
names[k] = if type(v) == "string" then v else tostring(v)
|
||||
end
|
||||
mesh.extras = mesh.extras or {}
|
||||
;(mesh.extras :: any).targetNames = names
|
||||
end
|
||||
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))
|
||||
|
||||
@@ -445,6 +445,11 @@ function Write.build(scene: Types.Scene, opts: Options?): (Out?, Err.Err?)
|
||||
end
|
||||
g.weights = mesh.weights
|
||||
restore(g, mesh.extras)
|
||||
local tn = mesh.extras and (mesh.extras :: any).targetNames
|
||||
if type(tn) == "table" and #tn > 0 and g.extras == nil then
|
||||
g.extras = object()
|
||||
g.extras.targetNames = table.clone(tn)
|
||||
end
|
||||
table.insert(meshes, g)
|
||||
end
|
||||
local cameras: { any } = {}
|
||||
|
||||
Reference in new issue
Block a user