Mesh

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

Mesh je takođe dostupna putem uvoza pod‑putem @aspose/3d/entities.

Mesh je primarna entiteta poligonalne geometrije u @aspose/3d. Čuva položaje vrhova kao kontrolne tačke, definiše poligonalne površine pomoću lista indeksa vrhova i podržava više slojeva podataka elemenata vrhova, kao što su normale i UV koordinate.

export class Mesh extends Geometry

A3DObject ← SceneObject ← Entity ← Geometry ← Mesh

Izgradite jedinstveni trouglasti mesh, prikačite ga na scenu i sačuvajte u 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
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.

createPolygon(…indices)

Definiše novo poligonalno lice koristeći date indekse kontrolnih tačaka. Indeksi moraju referencirati važeće pozicije u controlPoints.

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

...indices number[]

Tri ili više indeksa zasnovanih na nuli u controlPoints niz, u smeru suprotnom od kazaljke na satu.

void

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

Pretvara sve ne‑trouglaste poligone u ovom mesh‑u u trouglove. Vraća triangulirani mesh (može biti ista instanca ili nova).

triangulate(): Mesh

Mesh

Triangulirani mesh.

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

Vraća mesh kao `Mesh` instancu. Za `Mesh` objekte je ovo identična operacija; metoda je značajnija za primitivne geometrijske tipove koji nasleđuju od `Geometry`.

```typescript
toMesh(): Mesh

Mesh

Ova instanca mreže.


static union(a, b)

NOT IMPLEMENTED. Ova metoda je definisana u API površini, ali baca Error('union is not implemented') u vreme izvršavanja. Nemojte je pozivati u produkcijskom kodu.

Izvršava Booleovu uniju dva mesh‑a. Rezultat sadrži kombinovani volumen oba ulaza.

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

a Mesh

Prvi operand mreže.

b Mesh

Drugi operand mreže.

Mesh

Novi mesh koji predstavlja uniju a i b.

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. Ova metoda je definisana u API površini, ali baca Error('difference is not implemented') u vreme izvršavanja. Nemojte je pozivati u produkcionom kodu.

Izvršava Boolean razliku, oduzimajući zapreminu mesha b od mesha a.

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

a Mesh

Osnovni mesh.

b Mesh

Mreža od koje se oduzima a.

Mesh

Nova mreža koja predstavlja a minus b.

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


---

### static intersect(a, b)

**NOT IMPLEMENTED.** Ova metoda je definisana u API površini, ali baca `Error('intersect is not implemented')` u vreme izvršavanja. Nemojte je pozivati u produkcionom kodu.

Izvršava Booleovu intersekciju dve mreže. Rezultat sadrži samo preklapajući zapreminu.

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

a Mesh

Prvi operand mreže.

b Mesh

Drugi operand mreže.

Mesh

Nova mreža koja predstavlja presek a i b.

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


---

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

Kreira novi `VertexElement` sloj podataka na ovoj mreži za prilagođene atribute po vrhu.

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

type VertexElementType

Vrsta atributa vrha koju treba kreirati (na primer, VertexElementType.Normal).

mapping MappingMode (opciono)

Kako se podaci elementa mapiraju na topologiju mreže. Podrazumevano je MappingMode.ControlPoint.

reference ReferenceMode (opciono)

Kako indeksi elemenata referišu na niz podataka. Podrazumevano je ReferenceMode.Direct.

VertexElement

Novokreirani sloj elementa vrha.


createElementUV(mapping, mappingMode?, referenceMode?)

Kreira UV koordinatni sloj na ovoj mreži.

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

mapping TextureMapping

UV kanal koji se kreira (na primer, TextureMapping.Diffuse).

mappingMode MappingMode (opciono)

Kako se UV koordinate mapiraju na vrhove.

referenceMode ReferenceMode (opciono)

Kako podaci UV indeksa referišu na UV niz.

VertexElementUV

Novo kreirani UV element sloj.

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}`);
 Српски