Mesh

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

Mesh je također dostupan putem uvoza pod-puta @aspose/3d/entities.

Mesh je primarna entiteta poligonalne geometrije u @aspose/3d. Pohranjuje položaje vrhova kao kontrolne točke, definira poligonalna lica pomoću popisa indeksa vrhova i podržava više slojeva podataka elemenata vrhova poput normala i UV koordinata.

export class Mesh extends Geometry

A3DObject ← SceneObject ← Entity ← Geometry ← Mesh

Izradite jedinstveni trokutni mesh, pričvrstite ga na scenu i spremite 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)

Definira novo poligonalno lice koristeći navedene indekse kontrolnih točaka. Indeksi moraju referencirati valjane položaje u controlPoints.

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

...indices number[]

Tri ili više zero-based indeksa u controlPoints niz, u smjeru 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-trokutne poligone u ovom mesh-u u trokute. 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 mrežu kao `Mesh` instanca. Za `Mesh` objekti ovo je identična operacija; metoda je smislenija na primitivnim tipovima geometrije koji nasljeđuju od `Geometry`.

```typescript
toMesh(): Mesh

Mesh

Ova instanca mreže.


static union(a, b)

NOT IMPLEMENTED. Ova metoda je definirana u API sučelju, ali baca Error('union is not implemented') u vrijeme izvođenja. Nemojte je pozivati u produkcijskom kodu.

Izvršava Boolean uniju dviju mreža. Rezultat sadrži kombinirani volumen oba ulaza.

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

a Mesh

Prvi operand mreže.

b Mesh

Drugi operand mreže.

Mesh

Nova mreža koja 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 definirana u API sučelju, ali baca Error('difference is not implemented') u vrijeme izvođenja. Nemojte je pozivati u produkcijskom kodu.

Izvršava Booleovu razliku, oduzimajući volumen mreže b od mreže a.

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

a Mesh

Osnovna mreža.

b Mesh

Mreža iz 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 definirana u API sučelju, ali baca `Error('intersect is not implemented')` u vrijeme izvođenja. Nemojte je pozivati u produkcijskom kodu.

Izvršava Booleovu intersekciju dviju mreža. Rezultat sadrži samo preklapajući volumen.

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

a Mesh

Prvi operand mreže.

b Mesh

Drugi operand mreže.

Mesh

Novi mesh koji predstavlja presjek a i b.

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


---

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

Stvara novi `VertexElement` podatkovni sloj na ovom meshu za prilagođene atribute po vrhu.

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

type VertexElementType

Vrsta vertex atributa koji se stvara (na primjer, VertexElementType.Normal).

mapping MappingMode (opcionalno)

Kako se podaci elementa mapiraju na topologiju mesh-a. Zadano je MappingMode.ControlPoint.

reference ReferenceMode (opcionalno)

Kako indeksi elementa referenciraju niz podataka. Zadano je ReferenceMode.Direct.

VertexElement

Novo stvoreni sloj elementa vrha.


createElementUV(mapping, mappingMode?, referenceMode?)

Stvara UV koordinatni sloj na ovoj mreži.

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

mapping TextureMapping

UV kanal koji se stvara (na primjer, TextureMapping.Diffuse).

mappingMode MappingMode (opcionalno)

Kako se UV koordinate mapiraju na vrhove.

referenceMode ReferenceMode (opcionalno)

Kako UV podaci indeksa referenciraju UV niz.

VertexElementUV

Nedavno kreirani UV elementni 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}`);
 Hrvatski