Mesh

Gói: @aspose/3d (v24.12.0)

Mesh cũng có sẵn thông qua việc nhập theo đường dẫn phụ @aspose/3d/entities.

Mesh là thực thể hình học đa giác chính trong @aspose/3d. Nó lưu trữ vị trí các đỉnh dưới dạng các điểm điều khiển, định nghĩa các mặt đa giác bằng danh sách chỉ mục đỉnh, và hỗ trợ nhiều lớp dữ liệu phần tử đỉnh như pháp tuyến và tọa độ UV.

export class Mesh extends Geometry

Enumerations

A3DObject ← SceneObject ← Entity ← Geometry ← Mesh

Enumerations

Xây dựng một lưới tam giác đơn, gắn nó vào cảnh, và lưu dưới dạng 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

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.

Enumerations

createPolygon(…indices)

Định nghĩa một mặt đa giác mới bằng cách sử dụng các chỉ mục điểm điều khiển được cung cấp. Các chỉ mục phải tham chiếu tới các vị trí hợp lệ trong controlPoints.

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

Enumerations

...indices number[]

Ba hoặc nhiều hơn các chỉ số bắt đầu từ 0 vào controlPoints mảng, theo thứ tự quấn ngược chiều kim đồng hồ.

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

Chuyển đổi tất cả các đa giác không phải tam giác trong lưới này thành các tam giác. Trả về lưới đã được chia tam giác (có thể là cùng một thể hiện hoặc một thể hiện mới).

triangulate(): Mesh

Enumerations

Mesh

Lưới đã được chia tam giác.

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

Trả về lưới dưới dạng một `Mesh` đối tượng. Đối với `Mesh` các đối tượng, đây là một phép toán đồng nhất; phương pháp này có ý nghĩa hơn trên các kiểu hình học nguyên thủy kế thừa từ `Geometry`.

```typescript
toMesh(): Mesh

Enumerations

Mesh

Đối tượng mesh này.


static union(a, b)

NOT IMPLEMENTED. Phương thức này được định nghĩa trong API nhưng ném Error('union is not implemented') khi chạy. Không gọi nó trong mã sản xuất.

Thực hiện phép hợp Boolean của hai mesh. Kết quả chứa thể tích kết hợp của cả hai đầu vào.

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

Enumerations

a Mesh

Toán hạng lưới đầu tiên.

b Mesh

Toán hạng lưới thứ hai.

Enumerations

Mesh

Một lưới mới đại diện cho hợp của ab.

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. Phương thức này được định nghĩa trong API nhưng ném Error('difference is not implemented') khi chạy. Không gọi nó trong mã sản xuất.

Thực hiện phép trừ Boolean, trừ thể tích của lưới b từ lưới a.

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

Enumerations

a Mesh

Mesh cơ sở.

b Mesh

Lưới để trừ từ a.

Enumerations

Mesh

Một lưới mới đại diện cho a trừ b.

Enumerations

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


---

### static intersect(a, b)

**NOT IMPLEMENTED.** Phương thức này được định nghĩa trong API nhưng ném `Error('intersect is not implemented')` khi chạy. Không gọi nó trong mã sản xuất.

Thực hiện phép giao Boolean của hai lưới. Kết quả chỉ chứa thể tích chồng lên nhau.

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

Enumerations

a Mesh

Toán hạng lưới đầu tiên.

b Mesh

Toán hạng lưới thứ hai.

Enumerations

Mesh

Một lưới mới đại diện cho giao điểm của ab.

Enumerations

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


---

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

Tạo một `VertexElement` lớp dữ liệu trên lưới này cho các thuộc tính tùy chỉnh theo đỉnh.

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

Enumerations

type VertexElementType

Loại thuộc tính đỉnh cần tạo (ví dụ, VertexElementType.Normal).

mapping MappingMode (tùy chọn)

Cách dữ liệu phần tử được ánh xạ tới cấu trúc lưới. Mặc định là MappingMode.ControlPoint.

reference ReferenceMode (tùy chọn)

Cách các chỉ số phần tử tham chiếu tới mảng dữ liệu. Mặc định là ReferenceMode.Direct.

Enumerations

VertexElement

Lớp phần tử đỉnh mới được tạo.


createElementUV(mapping, mappingMode?, referenceMode?)

Tạo một lớp tọa độ UV trên lưới này.

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

Enumerations

mapping TextureMapping

Kênh UV cần tạo (ví dụ, TextureMapping.Diffuse).

mappingMode MappingMode (tùy chọn)

Cách tọa độ UV được ánh xạ tới các đỉnh.

referenceMode ReferenceMode (tùy chọn)

Cách dữ liệu chỉ mục UV tham chiếu tới mảng UV.

Enumerations

VertexElementUV

Lớp phần tử UV mới được tạo.

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}`);
 Tiếng Việt