VertexElement

VertexElement — Aspose.3D TypeScript API Reference

包:: @aspose/3d (v24.12.0)

VertexElement 是附加到 a 的每顶点属性通道的抽象基类 Geometry.。每个通道持有一个类型化的数据数组,并且 mappingMode / referenceMode 元数据控制这些数据如何与几何基元相关。子类包括:: VertexElementNormal, VertexElementUV,,以及 VertexElementVertexColor.

import { VertexElement, VertexElementNormal, VertexElementUV, VertexElementVertexColor } from '@aspose/3d';

Properties

export abstract class VertexElement implements IIndexedVertexElement

Properties

constructor(
  elementType: VertexElementType,
  name: string = '',
  mappingMode: MappingMode | null = null,
  referenceMode: ReferenceMode | null = null,
)

Properties mappingModeMappingMode.CONTROL_POINT;;默认 referenceModeReferenceMode.DIRECT.

Properties

PropertiesPropertiesPropertiesProperties
vertexElementTypeVertexElementType读取此层的语义类型。.
namestring读/写此层的可选标签。.
mappingModeMappingMode读/写控制每个值关联的几何基元。.
referenceModeReferenceMode读/写控制值是直接寻址还是通过索引数组进行寻址。.
indicesnumber[]索引数组用于 IndexToDirect 引用模式。.

Properties

setIndices(data)

NOT IMPLEMENTED. 在基类 VertexElement 中,此方法会抛出 Error('set_indices is not implemented') 运行时。子类 VertexElementFVectorVertexElementIntsTemplate 提供可工作的实现。.

替换索引数组。.

setIndices(data: number[]): void

clear()

NOT IMPLEMENTED. 在基类 VertexElement 中,此方法会抛出 Error('clear is not implemented') 运行时。子类 VertexElementFVectorVertexElementIntsTemplate 提供可工作的实现。.

移除该层的所有数据和索引。.

clear(): void

VertexElementNormal

存储表面法线向量。大多数渲染器需要法线数据以实现正确的光照。.

export class VertexElementNormal extends VertexElementFVector

Properties

VertexElementVertexElementFVectorVertexElementNormal

Properties

new VertexElementNormal(
  name: string = '',
  mappingMode: MappingMode | null = null,
  referenceMode: ReferenceMode | null = null,
)

vertexElementType 被固定为 VertexElementType.NORMAL.


VertexElementUV

存储二维纹理坐标。网格可以携带多个 UV 层以对应不同的纹理通道。该 textureMapping 属性标识通道的用途。.

export class VertexElementUV extends VertexElementFVector

Properties

VertexElementVertexElementFVectorVertexElementUV

Properties

new VertexElementUV(
  textureMapping: TextureMapping | null = null,
  name: string = '',
  mappingMode: MappingMode | null = null,
  referenceMode: ReferenceMode | null = null,
)

默认值为 TextureMapping.DIFFUSE 何时 textureMappingnull.

附加属性

PropertiesPropertiesPropertiesProperties
textureMappingTextureMapping读取此 UV 层关联的纹理通道。.
dataFVector4[]读取UV 值暴露为 FVector4 条目(z 和 w 为 0).
uvDataFVector2[]读取UV 值为 FVector2 条目(仅 x、y)。.

addData(data)

追加 UV 值。接受 FVector2[], FVector3[],,或 FVector4[].

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

VertexElementVertexColor

存储每个顶点的 RGBA 颜色值。各分量的取值范围为 0–1。.

export class VertexElementVertexColor extends VertexElementFVector

Properties

VertexElementVertexElementFVectorVertexElementVertexColor

Properties

new VertexElementVertexColor(
  name: string = '',
  mappingMode: MappingMode | null = null,
  referenceMode: ReferenceMode | null = null,
)

vertexElementType 固定为 VertexElementType.VERTEX_COLOR.


Properties

向三角网格添加法线::

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

添加 UV 坐标::

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

另见

 中文