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 IIndexedVertexElementProperties
constructor(
elementType: VertexElementType,
name: string = '',
mappingMode: MappingMode | null = null,
referenceMode: ReferenceMode | null = null,
)Properties mappingMode 是 MappingMode.CONTROL_POINT;;默认 referenceMode 是 ReferenceMode.DIRECT.
Properties
| Properties | Properties | Properties | Properties |
|---|---|---|---|
vertexElementType | VertexElementType | 读取 | 此层的语义类型。. |
name | string | 读/写 | 此层的可选标签。. |
mappingMode | MappingMode | 读/写 | 控制每个值关联的几何基元。. |
referenceMode | ReferenceMode | 读/写 | 控制值是直接寻址还是通过索引数组进行寻址。. |
indices | number[] | 读 | 索引数组用于 IndexToDirect 引用模式。. |
Properties
setIndices(data)
NOT IMPLEMENTED. 在基类 VertexElement 中,此方法会抛出 Error('set_indices is not implemented') 运行时。子类 VertexElementFVector 和 VertexElementIntsTemplate 提供可工作的实现。.
替换索引数组。.
setIndices(data: number[]): voidclear()
NOT IMPLEMENTED. 在基类 VertexElement 中,此方法会抛出 Error('clear is not implemented') 运行时。子类 VertexElementFVector 和 VertexElementIntsTemplate 提供可工作的实现。.
移除该层的所有数据和索引。.
clear(): voidVertexElementNormal
存储表面法线向量。大多数渲染器需要法线数据以实现正确的光照。.
export class VertexElementNormal extends VertexElementFVectorProperties
VertexElement → VertexElementFVector → VertexElementNormal
Properties
new VertexElementNormal(
name: string = '',
mappingMode: MappingMode | null = null,
referenceMode: ReferenceMode | null = null,
)vertexElementType 被固定为 VertexElementType.NORMAL.
VertexElementUV
存储二维纹理坐标。网格可以携带多个 UV 层以对应不同的纹理通道。该 textureMapping 属性标识通道的用途。.
export class VertexElementUV extends VertexElementFVectorProperties
VertexElement → VertexElementFVector → VertexElementUV
Properties
new VertexElementUV(
textureMapping: TextureMapping | null = null,
name: string = '',
mappingMode: MappingMode | null = null,
referenceMode: ReferenceMode | null = null,
)默认值为 TextureMapping.DIFFUSE 何时 textureMapping 是 null.
附加属性
| Properties | Properties | Properties | Properties |
|---|---|---|---|
textureMapping | TextureMapping | 读取 | 此 UV 层关联的纹理通道。. |
data | FVector4[] | 读取 | UV 值暴露为 FVector4 条目(z 和 w 为 0). |
uvData | FVector2[] | 读取 | UV 值为 FVector2 条目(仅 x、y)。. |
addData(data)
追加 UV 值。接受 FVector2[], FVector3[],,或 FVector4[].
addData(data: FVector2[] | FVector3[] | FVector4[]): voidVertexElementVertexColor
存储每个顶点的 RGBA 颜色值。各分量的取值范围为 0–1。.
export class VertexElementVertexColor extends VertexElementFVectorProperties
VertexElement → VertexElementFVector → VertexElementVertexColor
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');