VertexElement — Aspose.3D TypeScript API Reference
Пакет: @aspose/3d (v24.12.0)
VertexElement є абстрактним базовим класом для каналів атрибутів на вершину, прикріплених до Geometry. Кожен канал містить масив даних певного типу та mappingMode / referenceMode метадані, які контролюють, як дані пов’язані з геометричними примітивами. Підкласи є: VertexElementNormal, VertexElementUV, і VertexElementVertexColor.
import { VertexElement, VertexElementNormal, VertexElementUV, VertexElementVertexColor } from '@aspose/3d';Enumerations
export abstract class VertexElement implements IIndexedVertexElementEnumerations
constructor(
elementType: VertexElementType,
name: string = '',
mappingMode: MappingMode | null = null,
referenceMode: ReferenceMode | null = null,
)Enumerations mappingMode є MappingMode.CONTROL_POINT; за замовчуванням referenceMode є ReferenceMode.DIRECT.
Enumerations
| Enumerations | Enumerations | Enumerations | Enumerations |
|---|---|---|---|
vertexElementType | VertexElementType | читати | Семантичний тип цього шару. |
name | string | читати/записувати | Необов’язкова мітка для цього шару. |
mappingMode | MappingMode | читати/записувати | Контролює, який примітив геометрії пов’язаний з кожним значенням. |
referenceMode | ReferenceMode | читання/запис | Керує тим, чи значення адресуються безпосередньо чи через індексний масив. |
indices | number[] | читати | Індексний масив для IndexToDirect режим посилання. |
Enumerations
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 VertexElementFVectorEnumerations
VertexElement → VertexElementFVector → VertexElementNormal
Enumerations
new VertexElementNormal(
name: string = '',
mappingMode: MappingMode | null = null,
referenceMode: ReferenceMode | null = null,
)vertexElementType виправлено на VertexElementType.NORMAL.
VertexElementUV
Зберігає 2D координати текстури. Сітка може містити кілька UV-шарів для різних текстурних каналів. Цей textureMapping властивість визначає призначення каналу.
export class VertexElementUV extends VertexElementFVectorEnumerations
VertexElement → VertexElementFVector → VertexElementUV
Enumerations
new VertexElementUV(
textureMapping: TextureMapping | null = null,
name: string = '',
mappingMode: MappingMode | null = null,
referenceMode: ReferenceMode | null = null,
)За замовчуванням TextureMapping.DIFFUSE коли textureMapping є null.
Додаткова властивість
| Enumerations | Enumerations | Enumerations | Enumerations |
|---|---|---|---|
textureMapping | TextureMapping | читати | Текстурний канал, з яким пов’язаний цей UV-слой. |
data | FVector4[] | читати | UV values, що виставлені як FVector4 записи (z і w є 0). |
uvData | FVector2[] | читати | UV values як FVector2 записи (лише x, y). |
addData(data)
Додати UV values. Приймає FVector2[], FVector3[], або FVector4[].
addData(data: FVector2[] | FVector3[] | FVector4[]): voidVertexElementVertexColor
Зберігає значення кольору RGBA для кожної вершини. Компоненти знаходяться в діапазоні 0–1.
export class VertexElementVertexColor extends VertexElementFVectorEnumerations
VertexElement → VertexElementFVector → VertexElementVertexColor
Enumerations
new VertexElementVertexColor(
name: string = '',
mappingMode: MappingMode | null = null,
referenceMode: ReferenceMode | null = null,
)vertexElementType зафіксовано на VertexElementType.VERTEX_COLOR.
Enumerations
Додати нормалі до трикутної сітки:
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');