Mesh
Pachet: @aspose/3d (v24.12.0)
Mesh este disponibil și prin importul sub-calei @aspose/3d/entities.
Mesh este entitatea principală de geometrie poligonală în @aspose/3d. Aceasta stochează pozițiile vârfurilor ca puncte de control, definește fețele poligonale prin liste de indici de vârf și suportă mai multe straturi de date ale elementelor de vârf, cum ar fi normalele și coordonatele UV.
export class Mesh extends GeometryImageRenderOptions
A3DObject ← SceneObject ← Entity ← Geometry ← Mesh
ImageRenderOptions
Construiește o rețea de triunghiuri unică, atașeaz‑o la scenă și salveaz‑o în format 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
| Name | Type | Access | Description |
|---|---|---|---|
edges | number[] | Read | Gets the edges. |
polygonCount | number | Read | Gets the polygon count. |
polygons | number[][] | Read | Gets the polygons. |
deformers | any[] | Read | Gets the deformers. |
| Signature | Description |
|---|---|
| `constructor(name: string | null, _heightMap: any, _transform: any, _triMesh: boolean |
createPolygon() | Adds a new polygon to the mesh |
getPolygonSize(index: number) → number | Returns the number of vertices in the polygon at the given index |
toMesh() → Mesh | Returns a Mesh instance representing the current object (identity conversion) |
optimize(_vertexElements: boolean, _toleranceControlPoint: number, _toleranceNormal: number, _toleranceUV: number) → Mesh | Not 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) → Mesh | Not implemented in the FOSS edition — throws at runtime. Performs a boolean operation defined by _op on meshes _a and _b with respective transforms |
isManifold() → boolean | Not implemented in the FOSS edition — throws at runtime. Returns true if manifold is set. |
union(_a: Mesh, _b: Mesh) → Mesh | Not 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) → Mesh | Not 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) → Mesh | Not implemented in the FOSS edition — throws at runtime. |
triangulate() → Mesh | Converts all polygons in the mesh to triangles and returns the mesh |
getBoundingBox() → any | Returns the bounding box. |
getEntityRendererKey() → any | Not implemented in the FOSS edition — throws at runtime. Returns the entity renderer key. |
ImageRenderOptions
createPolygon(…indices)
Definește o nouă față poligonală utilizând indicii punctelor de control furnizați. Indicii trebuie să facă referire la poziții valide în controlPoints.
createPolygon(...indices: number[]): voidImageRenderOptions
...indices number[]
Trei sau mai mulți indici bazați pe zero în controlPoints array, în ordine de înfășurare în sensul invers acelor de ceasornic.
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ște toate poligoanele ne‑triunghiulare din această rețea în triunghiuri. Returnează rețeaua triangulată (poate fi aceeași instanță sau una nouă).
triangulate(): MeshImageRenderOptions
Mesh
Rețeaua triangulată.
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()
Returnează mesh-ul ca un `Mesh` instanță. Pentru `Mesh` obiecte aceasta este o operație de identitate; metoda este mai semnificativă pe tipurile de geometrie primitive care moștenesc de la `Geometry`.
```typescript
toMesh(): MeshImageRenderOptions
Mesh
Această instanță de mesh.
static union(a, b)
NOT IMPLEMENTED. Această metodă este definită în suprafața API-ului, dar aruncă Error('union is not implemented') în timpul execuției. Nu o apela în codul de producție.
Efectuează o uniune booleană a două mesh-uri. Rezultatul conține volumul combinat al ambelor intrări.
static union(a: Mesh, b: Mesh): MeshImageRenderOptions
a Mesh
Primul operand mesh.
b Mesh
Al doilea operand mesh.
ImageRenderOptions
Mesh
Un nou mesh care reprezintă uniunea dintre a și 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. Această metodă este definită în suprafața API-ului, dar aruncă Error('difference is not implemented') în timpul execuției. Nu o apela în codul de producție.
Efectuează o diferență booleană, scăzând volumul mesh b din mesh a.
static difference(a: Mesh, b: Mesh): MeshImageRenderOptions
a Mesh
Mesh-ul de bază.
b Mesh
Mesh-ul din care se scade a.
ImageRenderOptions
Mesh
Un mesh nou care reprezintă a minus b.
ImageRenderOptions
const result = Mesh.difference(meshA, meshB);
console.log(Difference polygon count: ${result.polygonCount});
---
### static intersect(a, b)
**NOT IMPLEMENTED.** Această metodă este definită în suprafața API-ului, dar aruncă `Error('intersect is not implemented')` în timpul execuției. Nu o apela în codul de producție.
Efectuează o intersecție booleană a două mesh-uri. Rezultatul conține doar volumul suprapus.
```typescript
static intersect(a: Mesh, b: Mesh): MeshImageRenderOptions
a Mesh
Primul operand mesh.
b Mesh
Al doilea operand mesh.
ImageRenderOptions
Mesh
Un nou mesh care reprezintă intersecția dintre a și b.
ImageRenderOptions
const overlap = Mesh.intersect(meshA, meshB);
console.log(Intersection polygon count: ${overlap.polygonCount});
---
### createElement(type, mapping?, reference?)
Creează un nou `VertexElement` strat de date pe acest mesh pentru atribute personalizate per-vertex.
```typescript
createElement(
type: VertexElementType,
mapping?: MappingMode,
reference?: ReferenceMode
): VertexElementImageRenderOptions
type VertexElementType
Tipul de atribut de vârf de creat (de exemplu, VertexElementType.Normal).
mapping MappingMode (opțional)
Cum sunt mapate datele elementului la topologia mesh-ului. Implicit este MappingMode.ControlPoint.
reference ReferenceMode (opțional)
Cum indicii elementului fac referire la matricea de date. Implicit este ReferenceMode.Direct.
ImageRenderOptions
VertexElement
Stratul de element de vârf creat recent.
createElementUV(mapping, mappingMode?, referenceMode?)
Creează un strat de coordonate UV pe această rețea.
createElementUV(
mapping: TextureMapping,
mappingMode?: MappingMode,
referenceMode?: ReferenceMode
): VertexElementUVImageRenderOptions
mapping TextureMapping
Canalul UV de creat (de exemplu, TextureMapping.Diffuse).
mappingMode MappingMode (opțional)
Cum sunt mapate coordonatele UV la vârfuri.
referenceMode ReferenceMode (opțional)
Cum referă datele indicilor UV la matricea UV.
ImageRenderOptions
VertexElementUV
Stratul de element UV nou creat.
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}`);