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

Defines a polygonal shape consisting of triangles. Triangles are defined via array of unique vertices and triplets of indices in this array. This is to describe connectivity and to reduce data required to describe a triangle set. The triangle set can optionally contain normals, colors and uv coordinates which are defined per each vertex. They are also can use indexing in the same manner as vertices.

Extends

Constructors

new IndexedTriangleSet()

new IndexedTriangleSet(): IndexedTriangleSet

Returns

IndexedTriangleSet

Overrides

PolyShape.constructor

new IndexedTriangleSet()

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.

WARNING: Inconsistency in data will result to creation of empty triangle set.

Parameters

vertices

Float32Array<ArrayBufferLike>

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

vertexIndices

Vertex indices array.

Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike>

normals?

Float32Array<ArrayBufferLike>

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

normalIndices?

Normal indices array.

Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike>

colors?

Float32Array<ArrayBufferLike>

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

colorIndices?

Color indices array.

Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike>

uvCoordinates?

Float32Array<ArrayBufferLike>

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

uvCoordinateIndices?

UV coordinate indices array.

Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike>

bvh?

Uint8Array<ArrayBufferLike>

Bounding volume hierarchy.

Returns

IndexedTriangleSet

Overrides

PolyShape.constructor

new IndexedTriangleSet()

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.

WARNING: Inconsistency in data will result to creation of empty triangle set.

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?

BaseRGB[]

Array of colors in [{r,g,b},{r,g,b},...] 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

PolyShape.constructor

Accessors

bvh

Get Signature

get bvh(): null | Uint8Array<ArrayBufferLike>

Returns bounding volume hierarchy.

Returns

null | Uint8Array<ArrayBufferLike>


colors

Get Signature

get colors(): Float32Array<ArrayBufferLike>

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

Returns

Float32Array<ArrayBufferLike>


id

Get Signature

get id(): bigint

Returns object id.

Returns

bigint

Inherited from

PolyShape.id


name

Get Signature

get name(): null | string

Returns name of the Shape. null if the element has no name (by default).

Returns

null | string

Set Signature

set name(name): void

Sets name of the Shape.

Parameters

name

Name of the Shape.

null | string

Returns

void

Inherited from

PolyShape.name


normals

Get Signature

get normals(): Float32Array<ArrayBufferLike>

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


numberOfColors

Get Signature

get numberOfColors(): number

Returns number of unique colors.

Returns

number


numberOfNormals

Get Signature

get numberOfNormals(): number

Returns number of unique normals.

Returns

number


numberOfTriangles

Get Signature

get numberOfTriangles(): number

Returns number of triangles.

Returns

number


numberOfUVCoordinates

Get Signature

get numberOfUVCoordinates(): number

Returns number of unique uv coordinates.

Returns

number


numberOfVertices

Get Signature

get numberOfVertices(): number

Returns number of unique vertices.

Returns

number


uvCoordinates

Get Signature

get uvCoordinates(): Float32Array<ArrayBufferLike>

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

Returns

Float32Array<ArrayBufferLike>


vertexIndices

Get Signature

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

Returns vertex indices.

Returns

Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike>


vertices

Get Signature

get vertices(): Float32Array<ArrayBufferLike>

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

Returns

Float32Array<ArrayBufferLike>

Methods

addTriangles()

Call Signature

addTriangles(triangleSet): boolean

Adds vertices and attributes from another indexed triangle set. Returns true if triangles successfully added. this triangle set and added triangleSet should have the same specified attributes. Otherwise, triangles won't be added.

Parameters

triangleSet

IndexedTriangleSet

Added indexed triangle set.

Returns

boolean

Call Signature

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

Adds vertices and attributes to this triangle set. Returns true if triangles successfully added. this triangle set should have the same specified attributes as specified for new added triangles. Otherwise, triangles won't be added.

Parameters

vertices

Float32Array<ArrayBufferLike>

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

vertexIndices

Vertex indices array.

Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike>

normals?

Float32Array<ArrayBufferLike>

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

normalIndices?

Normal indices array.

Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike>

colors?

Float32Array<ArrayBufferLike>

Array of colors in RGB ([R,G,B,R,G,B,...]) format.

colorIndices?

Color indices array.

Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike>

uvCoordinates?

Float32Array<ArrayBufferLike>

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

uvCoordinateIndices?

UV coordinate indices array.

Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike>

Returns

boolean

Call Signature

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

Adds vertices and attributes to this triangle set. Returns true if triangles successfully added. this triangle set should have the same specified attributes as specified for new added triangles. Otherwise, triangles won't be 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?

BaseRGB[]

Array of colors in [{r,g,b},{r,g,b},...] 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 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 true if the triangle set has explicitly defined colors.

Returns

boolean


hasNormals()

hasNormals(): boolean

Returns true if the triangle set has explicitly defined normals.

Returns

boolean


hasUVCoordinates()

hasUVCoordinates(): boolean

Returns true if the triangle set has explicitly defined uv coordinates.

Returns

boolean


internalAddTriangles()

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

Parameters

vertices

Float32Array<ArrayBufferLike> | BaseXYZ[]

vertexIndices

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

normals?

Float32Array<ArrayBufferLike> | BaseXYZ[]

normalIndices?

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

colors?

Float32Array<ArrayBufferLike> | BaseRGB[]

colorIndices?

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

uvCoordinates?

Float32Array<ArrayBufferLike> | BaseXY[]

uvCoordinateIndices?

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

Returns

boolean


normal()

normal(index): Vector

Returns 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 a normal of a triangle. The normal is calculated on the fly based on the vertices of the triangle. In case of a degenerate triangle the zero vector will be returned. index must be in the range [0, numberOfTriangles()-1]. Otherwise the result is undefined.

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 index in 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 index in 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 vertex index was not found -1 will be returned.

Parameters

triangleIndex

number

Triangle index.

vertexSlot

number

Vertex index in 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 index in 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 index in 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 vertex index was not found -1 will be returned.

Parameters

triangleIndex

number

Triangle index.

vertexSlot

number

Vertex index in triangle.

Returns

number


triangleVertexUVCoordinate()

triangleVertexUVCoordinate(triangleIndex, vertexSlot): XY

Returns a uv coordinates 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 index in triangle.

Returns

XY


triangleVertexUVCoordinateIndex()

triangleVertexUVCoordinateIndex(triangleIndex, vertexSlot): number

Returns a uv coordinates 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 vertex index was not found -1 will be returned.

Parameters

triangleIndex

number

Triangle index.

vertexSlot

number

Vertex index in triangle.

Returns

number


uvCoordinate()

uvCoordinate(index): XY

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

Parameters

index

number

Normal index.

Returns

XY


vertex()

vertex(index): Point

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

Parameters

index

number

Vertex index.

Returns

Point