MeshBuilder

MeshBuilder

Combines the MeshData of passed-in entities into one new MeshData. This can be useful to reduce draw calls.
Combination is currently limited to 65536 vertices.
Keep in mind that combined MeshData can only use one diffuse color texture, so this is best suited for MeshData that can share the same texture.

Constructor

new MeshBuilder()

Example
var meshBuilder = new MeshBuilder();
var transform = new Transform();

var box1 = new Box(0.3, 1, 1.6);
var box2 = new Box(0.2, 0.15, 0.7);

transform.translation.setDirect(0, 0, 1.3);
transform.update();
meshBuilder.addMeshData(box1, transform);

transform.translation.setDirect(0, 0, 0);
transform.update();
meshBuilder.addMeshData(box2, transform);

var meshData = meshBuilder.build()[0];
sumerian.world.createEntity( meshData, new Material(ShaderLib.simpleLit)).addToWorld();

Methods

addEntity(entity)

add the MeshData of an entity to this MeshBuilder

Parameters:
Name Type Description
entity Entity

addMeshData(meshData, transform)

add MeshData to this MeshBuilder

Parameters:
Name Type Description
meshData MeshData
transform Transform

build() → {Array.<MeshData>}

build the unified MeshData from all the added MeshData so far and then reset in the internal state.

reset()

reset in the internal state.