Hide menu
Loading...
Searching...
No Matches
IndexedTriangleSet

Defines a polygonal shape consisting of triangles.

Triangles are defined by an array of unique vertices and triplets of indices into this array. This describes connectivity while reducing the amount of data required to represent the triangle set.

The triangle set can optionally contain normals, colors, and UV coordinates defined per vertex. These attributes can also use indexing in the same manner as vertices.

Extends

Constructors

Constructor

new IndexedTriangleSet(): IndexedTriangleSet

Returns

IndexedTriangleSet

Overrides

MeshShape.constructor

Constructor

new IndexedTriangleSet(vertices, vertexIndices, normals?, normalIndices?, colors?, colorIndices?, uvCoordinates?, uvCoordinateIndices?, bvh?): IndexedTriangleSet

Number of vertex attributes (normals / colors / UV coordinates) should be the same as vertices. Otherwise, the appropriate attributes indices array should be specified. If specified, attribute indices array should have the same length as vertex indices array.

If the provided data is inconsistent, an empty triangle set is created. This includes vertex indices outside the provided vertex array and cases where the same vertex index is associated with different normal, color, or UV coordinate indices within the input data.

Parameters

vertices

Float32Array

Array of vertices in {x,y,z} format [x,y,z,x,y,z,...].

vertexIndices

Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike>

Vertex indices array.

normals?

Float32Array<ArrayBufferLike>

Array of vertex normals in {x,y,z} format [x,y,z,x,y,z,...].

normalIndices?

Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike>

Normal indices array.

colors?

Float32Array<ArrayBufferLike>

Array of colors in RGB ([r,g,b,r,g,b,...]) or RGBA ([r,g,b,a,r,g,b,a,...]) format.

colorIndices?

Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike>

Color indices array.

uvCoordinates?

Float32Array<ArrayBufferLike>

Array of vertex UV coordinates in {u,v} format [u,v,u,v,...].

uvCoordinateIndices?

Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike>

UV coordinate indices array.

bvh?

Uint8Array<ArrayBufferLike>

Bounding volume hierarchy.

Returns

IndexedTriangleSet

Overrides

MeshShape.constructor

Constructor

new IndexedTriangleSet(vertices, vertexIndices, normals?, normalIndices?, colors?, colorIndices?, uvCoordinates?, uvCoordinateIndices?): IndexedTriangleSet

Number of vertex attributes (normals / colors / UV coordinates) should be the same as vertices. Otherwise, the appropriate attributes indices array should be specified. If specified, attribute indices array should have the same length as vertex indices array.

If the provided data is inconsistent, an empty triangle set is created. This includes vertex indices outside the provided vertex array and cases where the same vertex index is associated with different normal, color, or UV coordinate indices within the input data.

Parameters

vertices

BaseXYZ[]

Array of vertices in [{x,y,z},{x,y,z},...] format.

vertexIndices

number[]

Vertex indices array.

normals?

BaseXYZ[]

Array of vertex normals in [{x,y,z},{x,y,z},...] format.

normalIndices?

number[]

Normal indices array.

colors?

(BaseRGBA | BaseRGB)[]

Array of colors in RGB and / or RGBA [{r,g,b},{r,g,b,a},...] format.

colorIndices?

number[]

Color indices array.

uvCoordinates?

BaseXY[]

Array of vertex UV coordinates in [{x,y},{x,y},...] format.

uvCoordinateIndices?

number[]

UV coordinate indices array.

Returns

IndexedTriangleSet

Overrides

MeshShape.constructor

Accessors

bvh

Get Signature

get bvh(): Uint8Array<ArrayBufferLike> | null

Bounding volume hierarchy.

Returns

Uint8Array<ArrayBufferLike> | null


colors

Get Signature

get colors(): Float32Array

Returns array with colors in RGBA ([r,g,b,a,r,g,b,a,...]) format for each vertex (i.e. taking into account colors indices), if specified. Otherwise, returns empty array.

Returns

Float32Array


id

Get Signature

get id(): bigint

Returns the unique identifier of the object.

Returns

bigint

Inherited from

MeshShape.id


name

Get Signature

get name(): string | null

Name of the mesh shape.

The default value is null.

Returns

string | null

Set Signature

set name(name): void

Sets the name of the mesh shape.

Parameters

name

string | null

Mesh shape name.

Returns

void

Inherited from

MeshShape.name


normals

Get Signature

get normals(): Float32Array

Returns array with normals in {x,y,z} format [x,y,z,x,y,z,...] for each vertex (i.e. taking into account normal indices), if specified. Otherwise, returns empty array.

Returns

Float32Array


numberOfColors

Get Signature

get numberOfColors(): number

Number of unique colors.

Returns

number


numberOfNormals

Get Signature

get numberOfNormals(): number

Number of unique normals.

Returns

number


numberOfTriangles

Get Signature

get numberOfTriangles(): number

Number of triangles.

Returns

number


numberOfUVCoordinates

Get Signature

get numberOfUVCoordinates(): number

Number of unique UV coordinates.

Returns

number


numberOfVertices

Get Signature

get numberOfVertices(): number

Number of unique vertices.

Returns

number


uvCoordinates

Get Signature

get uvCoordinates(): Float32Array

Returns array with UV coordinates in {u,v} format [u,v,u,v,...] for each vertex (i.e. taking into account UV coordinate indices), if specified. Otherwise, returns empty array.

Returns

Float32Array


vertexIndices

Get Signature

get vertexIndices(): Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike>

Vertex indices.

Returns

Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike>


vertices

Get Signature

get vertices(): Float32Array

Unique vertices in {x,y,z} format [x,y,z,x,y,z,...].

Returns

Float32Array

Methods

addTriangles()

Call Signature

addTriangles(triangleSet): boolean

Adds triangles from another indexed triangle set.

Returns true if triangles were added successfully. This triangle set and triangleSet must define the same kinds of attributes. Otherwise, triangles are not added.

Parameters

triangleSet

IndexedTriangleSet

Indexed triangle set to add.

Returns

boolean

Call Signature

addTriangles(vertices, vertexIndices, normals?, normalIndices?, colors?, colorIndices?, uvCoordinates?, uvCoordinateIndices?): boolean

Adds triangles to this triangle set.

Returns true if triangles were added successfully. This triangle set must already define the same kinds of attributes as the triangles being added. Otherwise, triangles are not added.

Parameters

vertices

Float32Array

Array of vertices in {x,y,z} format [x,y,z,x,y,z,...].

vertexIndices

Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike>

Vertex indices array.

normals?

Float32Array<ArrayBufferLike>

Array of vertex normals in {x,y,z} format [x,y,z,x,y,z,...].

normalIndices?

Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike>

Normal indices array.

colors?

Float32Array<ArrayBufferLike>

Array of colors in RGB ([r,g,b,r,g,b,...]) or RGBA ([r,g,b,a,r,g,b,a,...]) format.

colorIndices?

Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike>

Color indices array.

uvCoordinates?

Float32Array<ArrayBufferLike>

Array of vertex UV coordinates in {u,v} format [u,v,u,v,...].

uvCoordinateIndices?

Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike>

UV coordinate indices array.

Returns

boolean

Call Signature

addTriangles(vertices, vertexIndices, normals?, normalIndices?, colors?, colorIndices?, uvCoordinates?, uvCoordinateIndices?): boolean

Adds triangles to this triangle set.

Returns true if triangles were added successfully. This triangle set must already define the same kinds of attributes as the triangles being added. Otherwise, triangles are not added.

Parameters

vertices

BaseXYZ[]

Array of vertices in [{x,y,z},{x,y,z},...] format.

vertexIndices

number[]

Vertex indices array.

normals?

BaseXYZ[]

Array of vertex normals in [{x,y,z},{x,y,z},...] format.

normalIndices?

number[]

Normal indices array.

colors?

(BaseRGBA | BaseRGB)[]

Array of colors in RGB and / or RGBA [{r,g,b},{r,g,b,a},...] format.

colorIndices?

number[]

Color indices array.

uvCoordinates?

BaseXY[]

Array of vertex UV coordinates in [{x,y},{x,y},...] format.

uvCoordinateIndices?

number[]

UV coordinate indices array.

Returns

boolean


color()

color(index): Color

Returns a color.

index must be in the range [0, numberOfColors() - 1]. Otherwise the result is undefined.

Parameters

index

number

Color index.

Returns

Color


hasColors()

hasColors(): boolean

Returns whether the triangle set has explicitly defined colors.

Returns

boolean


hasNormals()

hasNormals(): boolean

Returns whether the triangle set has explicitly defined normals.

Returns

boolean


hasUVCoordinates()

hasUVCoordinates(): boolean

Returns whether the triangle set has explicitly defined UV coordinates.

Returns

boolean


internalAddTriangles()

internalAddTriangles(vertices, vertexIndices, normals?, normalIndices?, colors?, colorIndices?, uvCoordinates?, uvCoordinateIndices?): boolean

Internal helper adding triangles from normalized input representations.

Parameters

vertices

Float32Array<ArrayBufferLike> | BaseXYZ[]

vertexIndices

number[] | Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike>

normals?

Float32Array<ArrayBufferLike> | BaseXYZ[]

normalIndices?

number[] | Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike>

colors?

Float32Array<ArrayBufferLike> | (BaseRGBA | BaseRGB)[]

colorIndices?

number[] | Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike>

uvCoordinates?

Float32Array<ArrayBufferLike> | BaseXY[]

uvCoordinateIndices?

number[] | Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike>

Returns

boolean


normal()

normal(index): Vector

Returns a normal.

index must be in the range [0, numberOfNormals() - 1]. Otherwise the result is undefined.

Parameters

index

number

Normal index.

Returns

Vector


triangleNormal()

triangleNormal(triangleIndex): Vector

Returns the normal of a triangle.

The normal is calculated on the fly from the triangle vertices. In case of a degenerate triangle, or if triangleIndex is outside the range [0, numberOfTriangles() - 1], the zero vector is returned.

Parameters

triangleIndex

number

Triangle index.

Returns

Vector


triangleVertex()

triangleVertex(triangleIndex, vertexSlot): Point

Returns a vertex of a triangle.

triangleIndex must be in the range [0, numberOfTriangles() - 1]. vertexSlot must be in the range [0, 2]. Otherwise the result is undefined.

Parameters

triangleIndex

number

Triangle index.

vertexSlot

number

Vertex slot in the triangle.

Returns

Point


triangleVertexColor()

triangleVertexColor(triangleIndex, vertexSlot): Color

Returns a color at vertex in a triangle.

triangleIndex must be in the range [0, numberOfTriangles() - 1]. vertexSlot must be in the range [0, 2]. Otherwise the result is undefined.

Parameters

triangleIndex

number

Triangle index.

vertexSlot

number

Vertex slot in the triangle.

Returns

Color


triangleVertexColorIndex()

triangleVertexColorIndex(triangleIndex, vertexSlot): number

Returns a color index for vertex in a triangle.

triangleIndex must be in the range [0, numberOfTriangles() - 1]. vertexSlot must be in the range [0, 2]. If the color index was not found, -1 is returned.

Parameters

triangleIndex

number

Triangle index.

vertexSlot

number

Vertex slot in the triangle.

Returns

number


triangleVertexIndex()

triangleVertexIndex(triangleIndex, vertexSlot): number

Returns a vertex index in a triangle.

triangleIndex must be in the range [0, numberOfTriangles() - 1]. vertexSlot must be in the range [0, 2]. If the vertex index was not found -1 will be returned.

Parameters

triangleIndex

number

Triangle index.

vertexSlot

number

Vertex slot in the triangle.

Returns

number


triangleVertexNormal()

triangleVertexNormal(triangleIndex, vertexSlot): Vector

Returns a normal at vertex in a triangle.

triangleIndex must be in the range [0, numberOfTriangles() - 1]. vertexSlot must be in the range [0, 2]. Otherwise the result is undefined.

Parameters

triangleIndex

number

Triangle index.

vertexSlot

number

Vertex slot in the triangle.

Returns

Vector


triangleVertexNormalIndex()

triangleVertexNormalIndex(triangleIndex, vertexSlot): number

Returns a normal index for vertex in a triangle.

triangleIndex must be in the range [0, numberOfTriangles() - 1]. vertexSlot must be in the range [0, 2]. If the normal index was not found, -1 is returned.

Parameters

triangleIndex

number

Triangle index.

vertexSlot

number

Vertex slot in the triangle.

Returns

number


triangleVertexUVCoordinate()

triangleVertexUVCoordinate(triangleIndex, vertexSlot): XY

Returns a UV coordinate at a vertex in a triangle.

triangleIndex must be in the range [0, numberOfTriangles() - 1]. vertexSlot must be in the range [0, 2]. Otherwise the result is undefined.

Parameters

triangleIndex

number

Triangle index.

vertexSlot

number

Vertex slot in the triangle.

Returns

XY


triangleVertexUVCoordinateIndex()

triangleVertexUVCoordinateIndex(triangleIndex, vertexSlot): number

Returns a UV coordinate index for a vertex in a triangle.

triangleIndex must be in the range [0, numberOfTriangles() - 1]. vertexSlot must be in the range [0, 2]. If the UV coordinate index was not found, -1 is returned.

Parameters

triangleIndex

number

Triangle index.

vertexSlot

number

Vertex slot in the triangle.

Returns

number


uvCoordinate()

uvCoordinate(index): XY

Returns a UV coordinate.

index must be in the range [0, numberOfUVCoordinates() - 1]. Otherwise the result is undefined.

Parameters

index

number

UV coordinate index.

Returns

XY


vertex()

vertex(index): Point

Returns a vertex.

index must be in the range [0, numberOfVertices() - 1]. Otherwise the result is undefined.

Parameters

index

number

Vertex index.

Returns

Point