Mesh

Wrapper around a native mesh data.

For more information about how to create meshes, have a look at the MeshManager class.

Update 

To modify a mesh, you get access to a MeshAttributeAccessor that allows you to modify the content of the buffers:

Usage:

1const mesh = engine.es.create({vertexCount: 3, indexData: [0, 1, 2]});
2const positions = mesh.attribute(MeshAttribute.Position);
3...

Note: Meshes are per-engine, they can thus be shared by multiple scenes.

.constructor(engine: WonderlandEngine, params: number | Partial<MeshParameters>) ⇒ Mesh 

Deprecated: Use create instead, accessible via meshes:

1const mesh = engine.meshes.create({vertexCount: 3, indexData: [0, 1, 2]});
2...
3mesh.update();
ParamTypeDescription
engineWonderlandEngine
paramsnumber | Partial<MeshParameters>

.indexData: null | Uint8Array | Uint16Array | Uint32Array 

Index data (read-only) or null if the mesh is not indexed.

.vertexCount: number 

Number of vertices in this mesh.

.attribute(attr: MeshAttribute) ⇒ null | MeshAttributeAccessor<TypedArrayCtor

.attribute(attr: Position) ⇒ null | MeshAttributeAccessor<Float32ArrayConstructor>

.attribute(attr: Tangent) ⇒ null | MeshAttributeAccessor<Float32ArrayConstructor>

.attribute(attr: Normal) ⇒ null | MeshAttributeAccessor<Float32ArrayConstructor>

.attribute(attr: TextureCoordinate) ⇒ null | MeshAttributeAccessor<Float32ArrayConstructor>

.attribute(attr: Color) ⇒ null | MeshAttributeAccessor<Float32ArrayConstructor>

.attribute(attr: JointId) ⇒ null | MeshAttributeAccessor<Uint16ArrayConstructor>

.attribute(attr: JointWeight) ⇒ null | MeshAttributeAccessor<Float32ArrayConstructor>

Get an attribute accessor to retrieve or modify data of give attribute.

Returns: Attribute to get access to or null, if mesh does not have this attribute.

Call update for changes to vertex attributes to take effect.

If there are no shaders in the scene that use TextureCoordinate for example, no meshes will have the TextureCoordinate attribute.

For flexible reusable components, take this into account that only Position is guaranteed to be present at all time.

ParamTypeDescription
attrMeshAttributeAttribute to get access to

.destroy() ⇒ void 

0.9.0+

Destroy and free the meshes memory.

It is best practice to set the mesh variable to null after calling destroy to prevent accidental use:

1  mesh.destroy();
2  mesh = null;

Accessing the mesh after destruction behaves like accessing an empty mesh.

.getBoundingSphere<T>(out: Float32Array | T) ⇒ Float32Array | T 

.getBoundingSphere() ⇒ Float32Array

.getBoundingSphere<T>(out: T) ⇒ T

Mesh bounding sphere.

Returns: Bounding sphere, 0-2 sphere origin, 3 radius.

ParamTypeDescription
outFloat32Array | TPreallocated array to write into, to avoid garbage, otherwise will allocate a new Float32Array. js const sphere = new Float32Array(4); for(...) { mesh.getBoundingSphere(sphere); ... } If the position data is changed, call update to update the bounding sphere.
Template ParamType Definition
Textends NumberArray

.toString() ⇒ string 

.update() ⇒ void 

Apply changes to vertex attributes.

Uploads the updated vertex attributes to the GPU and updates the bounding sphere to match the new vertex positions.

Since this is an expensive operation, call it only once you have performed all modifications on a mesh and avoid calling if you did not perform any modifications at all.