VertexElement — Aspose.3D TypeScript API Reference
Package: @aspose/3d (v24.12.0)
VertexElement is the abstract base class for per-vertex attribute channels attached to a Geometry. Each channel holds a typed data array and mappingMode / referenceMode metadata that control how the data relates to geometry primitives. The subclasses are: VertexElementNormal, VertexElementUV, and VertexElementVertexColor.
import { VertexElement, VertexElementNormal, VertexElementUV, VertexElementVertexColor } from '@aspose/3d';VertexElement (abstract base)
export abstract class VertexElement implements IIndexedVertexElementConstructor
constructor(
elementType: VertexElementType,
name: string = '',
mappingMode: MappingMode | null = null,
referenceMode: ReferenceMode | null = null,
)Default mappingMode is MappingMode.CONTROL_POINT; default referenceMode is ReferenceMode.DIRECT.
Properties
| Property | Type | Access | Description |
|---|---|---|---|
vertexElementType | VertexElementType | read | Semantic type of this layer. |
name | string | read/write | Optional label for this layer. |
mappingMode | MappingMode | read/write | Controls which geometry primitive each value is associated with. |
referenceMode | ReferenceMode | read/write | Controls whether values are addressed directly or through an index array. |
indices | number[] | read | Index array for IndexToDirect reference mode. |
Methods
setIndices(data)
Replace the index array.
setIndices(data: number[]): voidclear()
Remove all data and indices from the layer.
clear(): voidVertexElementNormal
Stores surface normal vectors. Normal data is required by most renderers for correct lighting.
export class VertexElementNormal extends VertexElementFVectorInheritance
VertexElement → VertexElementFVector → VertexElementNormal
Constructor
new VertexElementNormal(
name: string = '',
mappingMode: MappingMode | null = null,
referenceMode: ReferenceMode | null = null,
)vertexElementType is fixed to VertexElementType.NORMAL.
VertexElementUV
Stores 2D texture coordinates. A mesh may carry multiple UV layers for different texture channels. The textureMapping property identifies the channel purpose.
export class VertexElementUV extends VertexElementFVectorInheritance
VertexElement → VertexElementFVector → VertexElementUV
Constructor
new VertexElementUV(
textureMapping: TextureMapping | null = null,
name: string = '',
mappingMode: MappingMode | null = null,
referenceMode: ReferenceMode | null = null,
)Defaults to TextureMapping.DIFFUSE when textureMapping is null.
Additional property
| Property | Type | Access | Description |
|---|---|---|---|
textureMapping | TextureMapping | read | The texture channel this UV layer is associated with. |
data | FVector4[] | read | UV values exposed as FVector4 entries (z and w are 0). |
uvData | FVector2[] | read | UV values as FVector2 entries (x, y only). |
addData(data)
Append UV values. Accepts FVector2[], FVector3[], or FVector4[].
addData(data: FVector2[] | FVector3[] | FVector4[]): voidVertexElementVertexColor
Stores per-vertex RGBA colour values. Components are in the range 0–1.
export class VertexElementVertexColor extends VertexElementFVectorInheritance
VertexElement → VertexElementFVector → VertexElementVertexColor
Constructor
new VertexElementVertexColor(
name: string = '',
mappingMode: MappingMode | null = null,
referenceMode: ReferenceMode | null = null,
)vertexElementType is fixed to VertexElementType.VERTEX_COLOR.
Examples
Add normals to a triangle mesh:
import { Scene, Mesh, Vector4, VertexElementType, MappingMode, ReferenceMode, FVector4 } from '@aspose/3d';
const mesh = new Mesh();
mesh.controlPoints.push(new Vector4(0, 0, 0, 1));
mesh.controlPoints.push(new Vector4(1, 0, 0, 1));
mesh.controlPoints.push(new Vector4(0.5, 1, 0, 1));
mesh.createPolygon(0, 1, 2);
const normals = mesh.createElement(
VertexElementType.NORMAL,
MappingMode.CONTROL_POINT,
ReferenceMode.DIRECT,
);
normals.setData([
new FVector4(0, 0, 1, 0),
new FVector4(0, 0, 1, 0),
new FVector4(0, 0, 1, 0),
]);
const scene = new Scene();
scene.rootNode.createChildNode('tri', mesh);
scene.save('triangle_normals.glb');Add UV coordinates:
import { Scene, Mesh, Vector4, TextureMapping, MappingMode, ReferenceMode, FVector2 } from '@aspose/3d';
const mesh = new Mesh();
for (const [x, z] of [[0,0],[1,0],[1,1],[0,1]]) {
mesh.controlPoints.push(new Vector4(x, 0, z, 1));
}
mesh.createPolygon(0, 1, 2, 3);
const uv = mesh.createElementUV(TextureMapping.DIFFUSE, MappingMode.CONTROL_POINT, ReferenceMode.DIRECT);
uv.addData([
new FVector2(0, 0),
new FVector2(1, 0),
new FVector2(1, 1),
new FVector2(0, 1),
]);
const scene = new Scene();
scene.rootNode.createChildNode('quad', mesh);
scene.save('quad_uv.glb');