Mesh
Пакет: @aspose/3d (v24.12.0)
Mesh також доступний через імпорт підшляху @aspose/3d/entities.
Mesh є основною сутністю полігональної геометрії в @aspose/3d. Вона зберігає позиції вершин як контрольні точки, визначає полігональні грані за списками індексів вершин і підтримує кілька шарів даних елементів вершин, таких як нормалі та UV‑координати.
export class Mesh extends GeometryEnumerations
A3DObject ← SceneObject ← Entity ← Geometry ← Mesh
Enumerations
Створіть один трикутний меш, приєднайте його до сцени та збережіть у форматі 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
Enumerations
| 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. |
Enumerations
createPolygon(…indices)
Визначає нову грань полігона, використовуючи надані індекси контрольних точок. Індекси мають посилатися на дійсні позиції у controlPoints.
createPolygon(...indices: number[]): voidEnumerations
...indices number[]
Три або більше індексів, що нумеруються з нуля, у controlPoints масиві, у проти годинникової стрілки порядку обертання.
Enumerations
void
Enumerations
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()
Перетворює всі не трикутні полігони в цьому меші на трикутники. Повертає триангуляційний меш (може бути тим же екземпляром або новим).
triangulate(): MeshEnumerations
Mesh
Триангуляційний меш.
Enumerations
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()
Повертає сітку як `Mesh` екземпляр. Для `Mesh` об’єктів це операція ідентичності; метод має більше сенсу для примітивних типів геометрії, які успадковують від `Geometry`.
```typescript
toMesh(): MeshEnumerations
Mesh
Цей екземпляр Mesh.
static union(a, b)
NOT IMPLEMENTED. Цей метод визначений у API, але викидає Error('union is not implemented') під час виконання. Не викликайте його у продакшн-коді.
Виконує булеве об’єднання двох Mesh. Результат містить сумарний об’єм обох вхідних даних.
static union(a: Mesh, b: Mesh): MeshEnumerations
a Mesh
Перший операнд сітки.
b Mesh
Другий операнд сітки.
Enumerations
Mesh
Нова сітка, що представляє об’єднання a і b.
Enumerations
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. Цей метод визначений у API, але викидає Error('difference is not implemented') під час виконання. Не викликайте його у продакшн‑коді.
Виконує булеву різницю, віднімаючи об’єм сітки b з сітки a.
static difference(a: Mesh, b: Mesh): MeshEnumerations
a Mesh
Базова Mesh.
b Mesh
Сітка, з якої треба відняти a.
Enumerations
Mesh
Нова сітка, що представляє a мінус b.
Enumerations
const result = Mesh.difference(meshA, meshB);
console.log(Difference polygon count: ${result.polygonCount});
---
### static intersect(a, b)
**NOT IMPLEMENTED.** Цей метод визначений у API, але викидає `Error('intersect is not implemented')` під час виконання. Не викликайте його у продакшн-коді.
Виконує булеве перетинання двох сіток. Результат містить лише об'єм, що перекривається.
```typescript
static intersect(a: Mesh, b: Mesh): MeshEnumerations
a Mesh
Перший операнд сітки.
b Mesh
Другий операнд сітки.
Enumerations
Mesh
Новий меш, що представляє перетин a і b.
Enumerations
const overlap = Mesh.intersect(meshA, meshB);
console.log(Intersection polygon count: ${overlap.polygonCount});
---
### createElement(type, mapping?, reference?)
Створює новий `VertexElement` шар даних на цьому меші для користувацьких атрибутів вершини.
```typescript
createElement(
type: VertexElementType,
mapping?: MappingMode,
reference?: ReferenceMode
): VertexElementEnumerations
type VertexElementType
Тип атрибуту вершини, який потрібно створити (наприклад, VertexElementType.Normal).
mapping MappingMode (необов’язково)
Як дані елементів відображаються на топологію сітки. За замовчуванням MappingMode.ControlPoint.
reference ReferenceMode (необов’язково)
Як індекси елементів посилаються на масив даних. За замовчуванням ReferenceMode.Direct.
Enumerations
VertexElement
Новостворений шар елементу вершини.
createElementUV(mapping, mappingMode?, referenceMode?)
Створює шар UV‑координат у цій сітці.
createElementUV(
mapping: TextureMapping,
mappingMode?: MappingMode,
referenceMode?: ReferenceMode
): VertexElementUVEnumerations
mapping TextureMapping
Канал UV, який створюється (наприклад, TextureMapping.Diffuse).
mappingMode MappingMode (необов’язково)
Як UV‑координати відображаються на вершини.
referenceMode ReferenceMode (необов’язково)
Як дані індексів UV посилаються на масив UV.
Enumerations
VertexElementUV
Новостворений шар UV‑елементу.
Enumerations
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}`);