Mesh

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

Mesh também está disponível via importação de subcaminho @aspose/3d/entities.

Mesh é a entidade principal de geometria de polígonos em @aspose/3d. Ele armazena posições dos vértices como pontos de controle, define faces de polígonos por listas de índices de vértices e suporta múltiplas camadas de dados de elementos de vértice, como normais e coordenadas UV.

export class Mesh extends Geometry

ImageRenderOptions

A3DObject ← SceneObject ← Entity ← Geometry ← Mesh

ImageRenderOptions

Crie uma malha de triângulo única, anexe-a à cena e salve em GLB.

import { Scene, Vector4 } from '@aspose/3d';
import { Mesh } from '@aspose/3d/entities';

// Create the mesh and define three control points (vertices)
const mesh = new Mesh();
mesh.controlPoints.push(
  new Vector4(0, 1, 0, 1),   // apex
  new Vector4(-1, 0, 0, 1),  // bottom-left
  new Vector4(1, 0, 0, 1),   // bottom-right
);

// Define one triangular polygon using vertex indices
mesh.createPolygon(0, 1, 2);

// Attach the mesh to the scene and save (extension infers GLB format)
const scene = new Scene();
scene.rootNode.createChildNode('triangle', mesh);
scene.save('triangle.glb');
console.log(`Polygon count: ${mesh.polygonCount}`); // 1

ImageRenderOptions

NameTypeAccessDescription
edgesnumber[]ReadGets the edges.
polygonCountnumberReadGets the polygon count.
polygonsnumber[][]ReadGets the polygons.
deformersany[]ReadGets the deformers.
SignatureDescription
`constructor(name: stringnull, _heightMap: any, _transform: any, _triMesh: boolean
createPolygon()Adds a new polygon to the mesh
getPolygonSize(index: number)numberReturns the number of vertices in the polygon at the given index
toMesh()MeshReturns a Mesh instance representing the current object (identity conversion)
optimize(_vertexElements: boolean, _toleranceControlPoint: number, _toleranceNormal: number, _toleranceUV: number)MeshNot implemented in the FOSS edition — throws at runtime. Reduces mesh complexity using vertex element flag and tolerance values for control points, normals, and UVs
doBoolean(_op: any, _a: Mesh, _transformA: any, _b: Mesh, _transformB: any)MeshNot implemented in the FOSS edition — throws at runtime. Performs a boolean operation defined by _op on meshes _a and _b with respective transforms
isManifold()booleanNot implemented in the FOSS edition — throws at runtime. Returns true if manifold is set.
union(_a: Mesh, _b: Mesh)MeshNot implemented in the FOSS edition — throws at runtime. Returns a new Mesh that is the union of meshes _a and _b
difference(_a: Mesh, _b: Mesh)MeshNot implemented in the FOSS edition — throws at runtime. Returns a new Mesh that is the difference of mesh _a minus mesh _b
intersect(_a: Mesh, _b: Mesh)MeshNot implemented in the FOSS edition — throws at runtime.
triangulate()MeshConverts all polygons in the mesh to triangles and returns the mesh
getBoundingBox()anyReturns the bounding box.
getEntityRendererKey()anyNot implemented in the FOSS edition — throws at runtime. Returns the entity renderer key.

ImageRenderOptions

createPolygon(…indices)

Define uma nova face poligonal usando os índices de pontos de controle fornecidos. Os índices devem referenciar posições válidas em controlPoints.

createPolygon(...indices: number[]): void

ImageRenderOptions

...indices number[]

Três ou mais índices baseados em zero para o controlPoints array, em ordem de enrolamento anti-horária.

ImageRenderOptions

void

ImageRenderOptions

import { Vector4 } from '@aspose/3d';
import { Mesh } from '@aspose/3d/entities';

const mesh = new Mesh();
mesh.controlPoints.push(
  new Vector4(0, 0, 0, 1),
  new Vector4(1, 0, 0, 1),
  new Vector4(1, 1, 0, 1),
  new Vector4(0, 1, 0, 1),
);
// Define a quad as two triangles, or a single quad polygon:
mesh.createPolygon(0, 1, 2, 3);
console.log(`Polygons: ${mesh.polygonCount}`); // 1

triangulate()

Converte todos os polígonos não triangulares desta malha em triângulos. Retorna a malha triangulada (pode ser a mesma instância ou uma nova).

triangulate(): Mesh

ImageRenderOptions

Mesh

A malha triangulada.

ImageRenderOptions

const mesh = new Mesh(); mesh.controlPoints.push( new Vector4(0, 0, 0, 1), new Vector4(1, 0, 0, 1), new Vector4(1, 1, 0, 1), new Vector4(0, 1, 0, 1), ); mesh.createPolygon(0, 1, 2, 3); // quad const triangulated = mesh.triangulate(); console.log(Polygons after triangulation: ${triangulated.polygonCount}); // 2


---

### toMesh()

Retorna a malha como um(a) `Mesh` instância. Para `Mesh` objetos, isso é uma operação de identidade; o método é mais significativo em tipos de geometria primitiva que herdam de `Geometry`.

```typescript
toMesh(): Mesh

ImageRenderOptions

Mesh

Esta instância de Mesh.


static union(a, b)

NOT IMPLEMENTED. Este método está definido na interface da API, mas lança Error('union is not implemented') em tempo de execução. Não o chame em código de produção.

Executa uma união booleana de duas malhas. O resultado contém o volume combinado de ambas as entradas.

static union(a: Mesh, b: Mesh): Mesh

ImageRenderOptions

a Mesh

O primeiro operando de malha.

b Mesh

O segundo operando de malha.

ImageRenderOptions

Mesh

Uma nova malha representando a união de a e b.

ImageRenderOptions

import { Mesh } from '@aspose/3d/entities';

// Assumes meshA and meshB are already populated Mesh instances
const combined = Mesh.union(meshA, meshB);
console.log(`Union polygon count: ${combined.polygonCount}`);

static difference(a, b)

NOT IMPLEMENTED. Este método está definido na interface da API, mas lança Error('difference is not implemented') em tempo de execução. Não o chame em código de produção.

Executa uma diferença Booleana, subtraindo o volume da malha b da malha a.

static difference(a: Mesh, b: Mesh): Mesh

ImageRenderOptions

a Mesh

A mesh base.

b Mesh

A mesh da qual subtrair a.

ImageRenderOptions

Mesh

Uma nova mesh representando a menos b.

ImageRenderOptions

const result = Mesh.difference(meshA, meshB); console.log(Difference polygon count: ${result.polygonCount});


---

### static intersect(a, b)

**NOT IMPLEMENTED.** Este método está definido na superfície da API, mas lança `Error('intersect is not implemented')` em tempo de execução. Não o chame em código de produção.

Executa uma interseção booleana de duas malhas. O resultado contém apenas o volume sobreposto.

```typescript
static intersect(a: Mesh, b: Mesh): Mesh

ImageRenderOptions

a Mesh

O primeiro operando de malha.

b Mesh

O segundo operando de malha.

ImageRenderOptions

Mesh

Uma nova mesh representando a interseção de a e b.

ImageRenderOptions

const overlap = Mesh.intersect(meshA, meshB); console.log(Intersection polygon count: ${overlap.polygonCount});


---

### createElement(type, mapping?, reference?)

Cria um novo `VertexElement` camada de dados nesta mesh para atributos personalizados por vértice.

```typescript
createElement(
  type: VertexElementType,
  mapping?: MappingMode,
  reference?: ReferenceMode
): VertexElement

ImageRenderOptions

type VertexElementType

O tipo de atributo de vértice a ser criado (por exemplo, VertexElementType.Normal).

mapping MappingMode (opcional)

Como os dados do elemento são mapeados para a topologia da mesh. O padrão é MappingMode.ControlPoint.

reference ReferenceMode (opcional)

Como os índices dos elementos referenciam o array de dados. O padrão é ReferenceMode.Direct.

ImageRenderOptions

VertexElement

A camada de elemento de vértice recém-criada.


createElementUV(mapping, mappingMode?, referenceMode?)

Cria uma camada de coordenadas UV nesta malha.

createElementUV(
  mapping: TextureMapping,
  mappingMode?: MappingMode,
  referenceMode?: ReferenceMode
): VertexElementUV

ImageRenderOptions

mapping TextureMapping

O canal UV a ser criado (por exemplo, TextureMapping.Diffuse).

mappingMode MappingMode (opcional)

Como as coordenadas UV são mapeadas para os vértices.

referenceMode ReferenceMode (opcional)

Como os dados de índice UV referenciam o array UV.

ImageRenderOptions

VertexElementUV

A camada de elemento UV recém‑criada.

ImageRenderOptions

import { Mesh } from '@aspose/3d/entities';
import { TextureMapping } from '@aspose/3d';

const mesh = new Mesh();
// ... define control points and polygons ...
const uvLayer = mesh.createElementUV(TextureMapping.Diffuse);
console.log(`UV element created: ${uvLayer !== undefined}`);
 Português