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

ImageRenderOptions

export abstract class VertexElement implements IIndexedVertexElement

ImageRenderOptions

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

ImageRenderOptions mappingMode является MappingMode.CONTROL_POINT; по умолчанию referenceMode является ReferenceMode.DIRECT.

ImageRenderOptions

ImageRenderOptionsImageRenderOptionsImageRenderOptionsImageRenderOptions
vertexElementTypeVertexElementTypeчтениеСемантический тип этого слоя.
namestringчтение/записьНеобязательная метка для этого слоя.
mappingModeMappingModeчтение/записьОпределяет, с какой геометрической примитивой связано каждое значение.
referenceModeReferenceModeчтение/записьУправляет тем, обращаются ли значения напрямую или через индексный массив.
indicesnumber[]чтениеИндексный массив для IndexToDirect режим ссылки.

ImageRenderOptions

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

ImageRenderOptions

VertexElementVertexElementFVectorVertexElementNormal

ImageRenderOptions

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

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


VertexElementUV

Хранит 2D координаты текстуры. Сетка может содержать несколько UV‑слоёв для разных каналов текстур. Этот textureMapping свойство определяет назначение канала.

export class VertexElementUV extends VertexElementFVector

ImageRenderOptions

VertexElementVertexElementFVectorVertexElementUV

ImageRenderOptions

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

По умолчанию TextureMapping.DIFFUSE когда textureMapping является null.

Дополнительное свойство

ImageRenderOptionsImageRenderOptionsImageRenderOptionsImageRenderOptions
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

ImageRenderOptions

VertexElementVertexElementFVectorVertexElementVertexColor

ImageRenderOptions

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

vertexElementType зафиксировано на VertexElementType.VERTEX_COLOR.


ImageRenderOptions

Добавить нормали к треугольной сетке:

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

См. также

 Русский