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:
Note: Meshes are per-engine, they can thus be shared by multiple scenes.
- Mesh
.constructor(engine, params) ⇒ Mesh- .indexData
- .vertexCount
- .attribute(attr) ⇒ null | MeshAttributeAccessor<TypedArrayCtor>
- .destroy() ⇒ void
- .getBoundingSphere<T>(out) ⇒ Float32Array | T
- .toString() ⇒ string
- .update() ⇒ void
.constructor(engine: WonderlandEngine, params: number | Partial<MeshParameters>) ⇒ Mesh
Deprecated: Use create instead, accessible via meshes:
Param | Type | Description |
---|---|---|
engine | WonderlandEngine | |
params | number | 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.
Param | Type | Description |
---|---|---|
attr | MeshAttribute | Attribute 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:
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.
Param | Type | Description |
---|---|---|
out | Float32Array | T | Preallocated 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 Param | Type Definition |
---|---|
T | extends 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.