Fix b3d->glTF conv. of models without materials

This commit is contained in:
Lars Mueller 2023-03-14 17:23:52 +01:00
parent 64c5a04a1f
commit 2425862045

10
b3d.lua

@ -819,10 +819,16 @@ do
return 3 * #triangle_set.vertex_ids return 3 * #triangle_set.vertex_ids
end) end)
-- Each triangle set is equivalent to one glTF "primitive" -- Each triangle set is equivalent to one glTF "primitive"
local brush_id = triangle_set.brush_id or mesh.brush_id
if brush_id == 0 then -- default brush
brush_id = nil -- TODO (?) add default material if there are UVs
else
brush_id = brush_id - 1 -- 0-based
end
primitives[i] = { primitives[i] = {
attributes = attributes, attributes = attributes,
indices = index_accessor, indices = index_accessor,
material = (triangle_set.brush_id or mesh.brush_id) - 1, -- 0-based material = brush_id,
-- `mode = 4` (triangles) is the default already, no need to set it -- `mode = 4` (triangles) is the default already, no need to set it
} }
end end
@ -996,7 +1002,7 @@ do
}, },
-- Textures -- Textures
textures = textures[1] and textures, -- glTF does not allow empty lists textures = textures[1] and textures, -- glTF does not allow empty lists
materials = materials, materials = materials[1] and materials,
-- Accessors, buffer views & buffers -- Accessors, buffer views & buffers
accessors = accessors, accessors = accessors,
bufferViews = buffer_views, bufferViews = buffer_views,