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 IIndexedVertexElement

Constructor

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

PropertyTypeAccessDescription
vertexElementTypeVertexElementTypereadSemantic type of this layer.
namestringread/writeOptional label for this layer.
mappingModeMappingModeread/writeControls which geometry primitive each value is associated with.
referenceModeReferenceModeread/writeControls whether values are addressed directly or through an index array.
indicesnumber[]readIndex array for IndexToDirect reference mode.

Methods

setIndices(data)

NOT IMPLEMENTED. On the base VertexElement class, this method throws Error('set_indices is not implemented') at runtime. The subclasses VertexElementFVector and VertexElementIntsTemplate provide working implementations.

Replace the index array.

setIndices(data: number[]): void

clear()

NOT IMPLEMENTED. On the base VertexElement class, this method throws Error('clear is not implemented') at runtime. The subclasses VertexElementFVector and VertexElementIntsTemplate provide working implementations.

Remove all data and indices from the layer.

clear(): void

VertexElementNormal

Stores surface normal vectors. Normal data is required by most renderers for correct lighting.

export class VertexElementNormal extends VertexElementFVector

Inheritance

VertexElementVertexElementFVectorVertexElementNormal

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 VertexElementFVector

Inheritance

VertexElementVertexElementFVectorVertexElementUV

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

PropertyTypeAccessDescription
textureMappingTextureMappingreadThe texture channel this UV layer is associated with.
dataFVector4[]readUV values exposed as FVector4 entries (z and w are 0).
uvDataFVector2[]readUV values as FVector2 entries (x, y only).

addData(data)

Append UV values. Accepts FVector2[], FVector3[], or FVector4[].

addData(data: FVector2[] | FVector3[] | FVector4[]): void

VertexElementVertexColor

Stores per-vertex RGBA colour values. Components are in the range 0–1.

export class VertexElementVertexColor extends VertexElementFVector

Inheritance

VertexElementVertexElementFVectorVertexElementVertexColor

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');

See Also