Mesh

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

Mesh è disponibile anche tramite l’importazione del sotto-percorso @aspose/3d/entities.

Mesh è l’entità primaria di geometria poligonale in @aspose/3d. Memorizza le posizioni dei vertici come punti di controllo, definisce le facce poligonali mediante elenchi di indici dei vertici e supporta più livelli di dati degli elementi dei vertici, come normali e coordinate UV.

export class Mesh extends Geometry

ImageRenderOptions

A3DObject ← SceneObject ← Entity ← Geometry ← Mesh

ImageRenderOptions

Crea una mesh triangolare singola, collegala alla scena e salvala in 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)

Definisce una nuova faccia poligonale usando gli indici dei punti di controllo forniti. Gli indici devono fare riferimento a posizioni valide in controlPoints.

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

ImageRenderOptions

...indices number[]

Tre o più indici basati su zero nel controlPoints array, in ordine di avvolgimento antiorario.

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 tutti i poligoni non triangolari in questa mesh in triangoli. Restituisce la mesh triangolata (può essere la stessa istanza o una nuova).

triangulate(): Mesh

ImageRenderOptions

Mesh

La mesh triangolata.

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()

Restituisce la mesh come una `Mesh` istanza. Per `Mesh` gli oggetti questa è un'operazione di identità; il metodo è più significativo sui tipi di geometria primitivi che ereditano da `Geometry`.

```typescript
toMesh(): Mesh

ImageRenderOptions

Mesh

Questa istanza di Mesh.


static union(a, b)

NOT IMPLEMENTED. Questo metodo è definito nell’interfaccia API ma genera Error('union is not implemented') a runtime. Non chiamarlo nel codice di produzione.

Esegue un’unione booleana di due mesh. Il risultato contiene il volume combinato di entrambi gli input.

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

ImageRenderOptions

a Mesh

Il primo operando mesh.

b Mesh

Il secondo operando mesh.

ImageRenderOptions

Mesh

Una nuova mesh che rappresenta l’unione di 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. Questo metodo è definito nell’interfaccia API ma genera Error('difference is not implemented') a runtime. Non chiamarlo nel codice di produzione.

Esegue una differenza booleana, sottraendo il volume della mesh b da mesh a.

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

ImageRenderOptions

a Mesh

La mesh di base.

b Mesh

La mesh da cui sottrarre a.

ImageRenderOptions

Mesh

Una nuova mesh che rappresenta a meno b.

ImageRenderOptions

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


---

### static intersect(a, b)

**NOT IMPLEMENTED.** Questo metodo è definito nell'interfaccia API ma genera `Error('intersect is not implemented')` a runtime. Non chiamarlo nel codice di produzione.

Esegue un'intersezione booleana di due mesh. Il risultato contiene solo il volume sovrapposto.

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

ImageRenderOptions

a Mesh

Il primo operando mesh.

b Mesh

Il secondo operando mesh.

ImageRenderOptions

Mesh

Una nuova mesh che rappresenta l’intersezione di a e b.

ImageRenderOptions

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


---

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

Crea un nuovo `VertexElement` data layer su questa mesh per attributi per-vertice personalizzati.

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

ImageRenderOptions

type VertexElementType

Il tipo di attributo per vertice da creare (ad esempio, VertexElementType.Normal).

mapping MappingMode (opzionale)

Come i dati dell’elemento sono mappati alla topologia della mesh. Il valore predefinito è MappingMode.ControlPoint.

reference ReferenceMode (opzionale)

Come gli indici dell’elemento fanno riferimento all’array di dati. Il valore predefinito è ReferenceMode.Direct.

ImageRenderOptions

VertexElement

Il nuovo livello di elemento del vertice creato.


createElementUV(mapping, mappingMode?, referenceMode?)

Crea un livello di coordinate UV su questa mesh.

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

ImageRenderOptions

mapping TextureMapping

Il canale UV da creare (ad esempio, TextureMapping.Diffuse).

mappingMode MappingMode (opzionale)

Come le coordinate UV vengono mappate ai vertici.

referenceMode ReferenceMode (opzionale)

Come i dati degli indici UV fanno riferimento all’array UV.

ImageRenderOptions

VertexElementUV

Il livello di elemento UV appena creato.

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}`);
 Italiano