Wrapper around a native mesh data.

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


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

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

Create a new instance.

paramsnumber | Partial<MeshParameters>Either a mesh index to wrap or set of parameters to create a new mesh. For more information, please have a look at the MeshParameters interface.

.engine: WonderlandEngine 

Hosting engine instance.

.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.

attrMeshAttributeAttribute to get access to

.destroy() ⇒ void 


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.

.equals(otherMesh: undefined | null | Mesh) ⇒ boolean 


Checks equality by comparing whether the wrapped native mesh ids are equal.

Returns: Whether this mesh equals the given mesh.

otherMeshundefined | null | MeshMesh to check equality with.

.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.

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

.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.