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 IIndexedVertexElement

Enumerations

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

Enumerations mappingMode є MappingMode.CONTROL_POINT; за замовчуванням referenceMode є ReferenceMode.DIRECT.

Enumerations

EnumerationsEnumerationsEnumerationsEnumerations
vertexElementTypeVertexElementTypeчитатиСемантичний тип цього шару.
namestringчитати/записуватиНеобов’язкова мітка для цього шару.
mappingModeMappingModeчитати/записуватиКонтролює, який примітив геометрії пов’язаний з кожним значенням.
referenceModeReferenceModeчитання/записКерує тим, чи значення адресуються безпосередньо чи через індексний масив.
indicesnumber[]читатиІндексний масив для IndexToDirect режим посилання.

Enumerations

setIndices(data)

NOT IMPLEMENTED. У базовому VertexElement класі, цей метод викидає Error('set_indices is not implemented') під час виконання. Підкласи VertexElementFVector і VertexElementIntsTemplate надають робочі реалізації.

Замінити масив індексів.

setIndices(data: number[]): void

clear()

NOT IMPLEMENTED. У базовому VertexElement класі, цей метод викидає Error('clear is not implemented') під час виконання. Підкласи VertexElementFVector і VertexElementIntsTemplate надають робочі реалізації.

Видалити всі дані та індекси з шару.

clear(): void

VertexElementNormal

Зберігає вектори нормалей поверхні. Дані нормалей потрібні більшості рендерерів для правильного освітлення.

export class VertexElementNormal extends VertexElementFVector

Enumerations

VertexElementVertexElementFVectorVertexElementNormal

Enumerations

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

vertexElementType виправлено на VertexElementType.NORMAL.


VertexElementUV

Зберігає 2D координати текстури. Сітка може містити кілька UV-шарів для різних текстурних каналів. Цей textureMapping властивість визначає призначення каналу.

export class VertexElementUV extends VertexElementFVector

Enumerations

VertexElementVertexElementFVectorVertexElementUV

Enumerations

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

За замовчуванням TextureMapping.DIFFUSE коли textureMapping є null.

Додаткова властивість

EnumerationsEnumerationsEnumerationsEnumerations
textureMappingTextureMappingчитатиТекстурний канал, з яким пов’язаний цей UV-слой.
dataFVector4[]читатиUV values, що виставлені як FVector4 записи (z і w є 0).
uvDataFVector2[]читатиUV values як FVector2 записи (лише x, y).

addData(data)

Додати UV values. Приймає FVector2[], FVector3[], або FVector4[].

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

VertexElementVertexColor

Зберігає значення кольору RGBA для кожної вершини. Компоненти знаходяться в діапазоні 0–1.

export class VertexElementVertexColor extends VertexElementFVector

Enumerations

VertexElementVertexElementFVectorVertexElementVertexColor

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

Див. також

 Українська