Mesh

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

Mesh juga tersedia melalui import sub-laluan @aspose/3d/entities.

Mesh adalah entiti geometri poligon utama dalam @aspose/3d. Ia menyimpan kedudukan vertex sebagai titik kawalan, mendefinisikan muka poligon melalui senarai indeks vertex, dan menyokong pelbagai lapisan data elemen vertex seperti normal dan koordinat UV.

export class Mesh extends Geometry

ImageRenderOptions

A3DObject ← SceneObject ← Entity ← Geometry ← Mesh

ImageRenderOptions

Bina satu mesh segitiga tunggal, lampirkan kepada adegan, dan simpan ke 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)

Mendefinisikan muka poligon baru menggunakan indeks titik kawalan yang disediakan. Indeks mesti merujuk kepada kedudukan sah dalam controlPoints.

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

ImageRenderOptions

...indices number[]

Tiga atau lebih indeks berasaskan sifar ke dalam controlPoints array, dalam urutan lilitan berlawanan arah jam.

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

Menukarkan semua poligon bukan segitiga dalam mesh ini menjadi segitiga. Mengembalikan mesh yang telah ditriangulasi (mungkin merupakan contoh yang sama atau yang baru).

triangulate(): Mesh

ImageRenderOptions

Mesh

Mesh yang telah ditriangulasi.

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

Mengembalikan mesh sebagai `Mesh` instans. Untuk `Mesh` objek ini adalah operasi identiti; kaedah ini lebih bermakna pada jenis geometri primitif yang mewarisi daripada `Geometry`.

```typescript
toMesh(): Mesh

ImageRenderOptions

Mesh

Instans mesh ini.


static union(a, b)

NOT IMPLEMENTED. Kaedah ini ditakrifkan dalam permukaan API tetapi throws Error('union is not implemented') pada masa jalan. Jangan panggil ia dalam kod produksi.

Melakukan penyatuan Boolean bagi dua mesh. Hasilnya mengandungi isipadu gabungan kedua-dua input.

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

ImageRenderOptions

a Mesh

Operand mesh pertama.

b Mesh

Operand mesh kedua.

ImageRenderOptions

Mesh

Mesh baru yang mewakili penyatuan a dan 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. Kaedah ini ditakrifkan dalam permukaan API tetapi throws Error('difference is not implemented') pada masa jalan. Jangan panggil ia dalam kod produksi.

Melakukan perbezaan Boolean, menolak isipadu mesh b daripada mesh a.

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

ImageRenderOptions

a Mesh

Mesh asas.

b Mesh

Mesh yang akan ditolak a.

ImageRenderOptions

Mesh

Mesh baru yang mewakili a tolak b.

ImageRenderOptions

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


---

### static intersect(a, b)

**NOT IMPLEMENTED.** Kaedah ini ditakrifkan dalam permukaan API tetapi throws `Error('intersect is not implemented')` pada masa jalan. Jangan panggil ia dalam kod produksi.

Melakukan persilangan Boolean pada dua mesh. Hasilnya hanya mengandungi isipadu yang bertindih.

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

ImageRenderOptions

a Mesh

Operand mesh pertama.

b Mesh

Operand mesh kedua.

ImageRenderOptions

Mesh

Mesh baru yang mewakili persilangan antara a dan b.

ImageRenderOptions

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


---

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

Mencipta yang baru `VertexElement` lapisan data pada mesh ini untuk atribut per-vertex khusus.

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

ImageRenderOptions

type VertexElementType

Jenis atribut vertex yang akan dibuat (contohnya, VertexElementType.Normal).

mapping MappingMode (pilihan)

Bagaimana data elemen dipetakan ke topologi mesh. Lalai kepada MappingMode.ControlPoint.

reference ReferenceMode (pilihan)

Bagaimana indeks elemen merujuk kepada tatasusunan data. Lalai kepada ReferenceMode.Direct.

ImageRenderOptions

VertexElement

Lapisan elemen vertex yang baru dibuat.


createElementUV(mapping, mappingMode?, referenceMode?)

Mencipta lapisan koordinat UV pada mesh ini.

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

ImageRenderOptions

mapping TextureMapping

Saluran UV yang akan dibuat (contohnya, TextureMapping.Diffuse).

mappingMode MappingMode (pilihan)

Bagaimana koordinat UV dipetakan ke vertex.

referenceMode ReferenceMode (pilihan)

Bagaimana data indeks UV merujuk kepada tatasusunan UV.

ImageRenderOptions

VertexElementUV

Lapisan elemen UV yang baru dibuat.

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