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.
new IndexedTriangleSet():
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.
Float32Array
<ArrayBufferLike
>
Array of vertices in {x,y,z} format [x,y,z,x,y,z,...].
Vertex indices array.
Uint16Array
<ArrayBufferLike
> | Uint32Array
<ArrayBufferLike
>
Float32Array
<ArrayBufferLike
>
Array of vertex normals in {x,y,z} format [x,y,z,x,y,z,...].
Normal indices array.
Uint16Array
<ArrayBufferLike
> | Uint32Array
<ArrayBufferLike
>
Float32Array
<ArrayBufferLike
>
Array of colors in RGB ([r,g,b,r,g,b,...]) format.
Color indices array.
Uint16Array
<ArrayBufferLike
> | Uint32Array
<ArrayBufferLike
>
Float32Array
<ArrayBufferLike
>
Array of vertex UV coordinates in {u,v} format [u,v,u,v,...].
UV coordinate indices array.
Uint16Array
<ArrayBufferLike
> | Uint32Array
<ArrayBufferLike
>
Uint8Array
<ArrayBufferLike
>
Bounding volume hierarchy.
PolyShape.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.
WARNING: Inconsistency in data will result to creation of empty triangle set.
BaseXYZ
[]
Array of vertices in [{x,y,z},{x,y,z},...] format.
number
[]
Vertex indices array.
BaseXYZ
[]
Array of vertex normals in [{x,y,z},{x,y,z},...] format.
number
[]
Normal indices array.
BaseRGB
[]
Array of colors in [{r,g,b},{r,g,b},...] format.
number
[]
Color indices array.
BaseXY
[]
Array of vertex UV coordinates in [{x,y},{x,y},...] format.
number
[]
UV coordinate indices array.
PolyShape.constructor
get bvh():
null
|Uint8Array
<ArrayBufferLike
>
Returns bounding volume hierarchy.
null
| Uint8Array
<ArrayBufferLike
>
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.
Float32Array
<ArrayBufferLike
>
get id():
bigint
Returns object id.
bigint
get name():
null
|string
Returns name of the Shape. null
if the element has no name (by default).
null
| string
set name(
name
):void
Sets name of the Shape.
Name of the Shape.
null
| string
void
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.
Float32Array
<ArrayBufferLike
>
get numberOfColors():
number
Returns number of unique colors.
number
get numberOfNormals():
number
Returns number of unique normals.
number
get numberOfTriangles():
number
Returns number of triangles.
number
get numberOfUVCoordinates():
number
Returns number of unique uv coordinates.
number
get numberOfVertices():
number
Returns number of unique vertices.
number
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.
Float32Array
<ArrayBufferLike
>
get vertexIndices():
Uint16Array
<ArrayBufferLike
> |Uint32Array
<ArrayBufferLike
>
Returns vertex indices.
Uint16Array
<ArrayBufferLike
> | Uint32Array
<ArrayBufferLike
>
get vertices():
Float32Array
<ArrayBufferLike
>
Returns unique vertices in {x,y,z} format [x,y,z,x,y,z,...].
Float32Array
<ArrayBufferLike
>
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.
Added indexed triangle set.
boolean
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.
Float32Array
<ArrayBufferLike
>
Array of vertices in {x,y,z} format [x,y,z,x,y,z,...].
Vertex indices array.
Uint16Array
<ArrayBufferLike
> | Uint32Array
<ArrayBufferLike
>
Float32Array
<ArrayBufferLike
>
Array of vertex normals in {x,y,z} format [x,y,z,x,y,z,...].
Normal indices array.
Uint16Array
<ArrayBufferLike
> | Uint32Array
<ArrayBufferLike
>
Float32Array
<ArrayBufferLike
>
Array of colors in RGB ([R,G,B,R,G,B,...]) format.
Color indices array.
Uint16Array
<ArrayBufferLike
> | Uint32Array
<ArrayBufferLike
>
Float32Array
<ArrayBufferLike
>
Array of vertex UV coordinates in {u,v} format [u,v,u,v,...].
UV coordinate indices array.
Uint16Array
<ArrayBufferLike
> | Uint32Array
<ArrayBufferLike
>
boolean
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.
BaseXYZ
[]
Array of vertices in [{x,y,z},{x,y,z},...] format.
number
[]
Vertex indices array.
BaseXYZ
[]
Array of vertex normals in [{x,y,z},{x,y,z},...] format.
number
[]
Normal indices array.
BaseRGB
[]
Array of colors in [{r,g,b},{r,g,b},...] format.
number
[]
Color indices array.
BaseXY
[]
Array of vertex UV coordinates in [{x,y},{x,y},...] format.
number
[]
UV coordinate indices array.
boolean
color(
index
):Color
Returns color. index
must be in the range [0, numberOfColors()-1]
. Otherwise the result is undefined.
number
Color index.
hasColors():
boolean
Returns true
if the triangle set has explicitly defined colors.
boolean
hasNormals():
boolean
Returns true
if the triangle set has explicitly defined normals.
boolean
hasUVCoordinates():
boolean
Returns true
if the triangle set has explicitly defined uv coordinates.
boolean
internalAddTriangles(
vertices
,vertexIndices
,normals
?,normalIndices
?,colors
?,colorIndices
?,uvCoordinates
?,uvCoordinateIndices
?):boolean
Float32Array
<ArrayBufferLike
> | BaseXYZ
[]
number
[] | Uint16Array
<ArrayBufferLike
> | Uint32Array
<ArrayBufferLike
>
Float32Array
<ArrayBufferLike
> | BaseXYZ
[]
number
[] | Uint16Array
<ArrayBufferLike
> | Uint32Array
<ArrayBufferLike
>
Float32Array
<ArrayBufferLike
> | BaseRGB
[]
number
[] | Uint16Array
<ArrayBufferLike
> | Uint32Array
<ArrayBufferLike
>
Float32Array
<ArrayBufferLike
> | BaseXY
[]
number
[] | Uint16Array
<ArrayBufferLike
> | Uint32Array
<ArrayBufferLike
>
boolean
normal(
index
):Vector
Returns normal. index
must be in the range [0, numberOfNormals()-1]
. Otherwise the result is undefined.
number
Normal index.
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.
number
Triangle index
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.
number
Triangle index.
number
Vertex index in triangle.
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.
number
Triangle index.
number
Vertex index in triangle.
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.
number
Triangle index.
number
Vertex index in triangle.
number
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.
number
Triangle index.
number
Vertex index in triangle.
number
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.
number
Triangle index.
number
Vertex index in triangle.
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.
number
Triangle index.
number
Vertex index in triangle.
number
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.
number
Triangle index.
number
Vertex index in triangle.
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.
number
Triangle index.
number
Vertex index in triangle.
number
uvCoordinate(
index
):XY
Returns uv coordinate. index
must be in the range [0, numberOfUVCoordinates()-1]
. Otherwise the result is undefined.
number
Normal index.
vertex(
index
):Point
Returns vertex. index
must be in the range [0, numberOfVertices()-1]
. Otherwise the result is undefined.
number
Vertex index.