Currently SceneJS supports only one mesh per vertex list, and
therefore does not allow multiple materials to be applied to
different sections of the same mesh.
In other words, a material can only be applied to the
entire mesh:
new SceneJS.Material({ ... },
new SceneJS.Geometry({
positions: [...],
uv: [...],
indices: [...]
}));
This was discovered when parsing OBJ files that define material
groups that cut across meshes. Although OBJ files can be converted
to split meshes for material groups, this increases the file size
considerably.
Solution
Allow a mesh to be constructed by multiple Geometry nodes, such
that one supplies the positions and uv coords, while other child
Geometry nodes each supply a portion of the indices. When a
geometry is defined with positions but no indices, then child
Geometry nodes are expected to supply the indices. Materials
wrapping the child Geometry nodes will be applied to each of their
face lists.
new SceneJS.Geometry({
positions: [...],
uv: [...]
},
new SceneJS.Material({ baseColor: { r: 1 } },
new SceneJS.Geometry({
indices: [...],
primitive: "triangles"
})),
new SceneJS.Material({ baseColor: { g: 1 } },
new SceneJS.Geometry({
indices: [...],
primitive: "triangles"
})
)
);
Plays well with BoundingBox nodes
We'll be able to wrap the face sections with BoundingBox's
new SceneJS.Geometry({
positions: [...],
uv: [...]
},
new SceneJS.BoundingBox({ ... extents of first set of faces.... },
new SceneJS.Material({ baseColor: { r: 1 } },
new SceneJS.Geometry({
indices: [...],
primitive: "triangles"
}))),
new SceneJS.BoundingBox({ ... extents of second set of faces.... },
new SceneJS.Material({ baseColor: { g: 1 } },
new SceneJS.Geometry({
indices: [...],
primitive: "triangles"
})))
);
Addition benefit
- This will allow more speed in static scenes where the vertices
for everything can be bound in one operation.
- Will support OBJ multi materials