Mesh
包:: @aspose/3d (v24.12.0)
Mesh 也可以通过子路径导入获取 @aspose/3d/entities.
Mesh 是主要的多边形几何实体,位于 @aspose/3d.。它将顶点位置存储为控制点,通过顶点索引列表定义多边形面,并支持多个顶点元素数据层,例如法线和 UV 坐标。.
export class Mesh extends GeometryProperties
A3DObject ← SceneObject ← Entity ← Geometry ← Mesh
Properties
构建一个单三角形网格,将其附加到场景中,并保存为 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
Properties
| 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. |
Properties
createPolygon(…indices)
使用提供的控制点索引定义一个新的多边形面。索引必须引用中有效的位置在 controlPoints.
createPolygon(...indices: number[]): voidProperties
...indices number[]
三个或更多基于零的索引,指向 controlPoints 数组,以逆时针方向的环绕顺序。.
Properties
void
Properties
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(): MeshProperties
Mesh
三角化后的网格。.
Properties
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(): MeshProperties
Mesh
此网格实例。.
static union(a, b)
NOT IMPLEMENTED. 此方法在 API surface 中定义,但会抛出 Error('union is not implemented') 在运行时。不要在生产代码中调用它。.
对两个网格执行布尔并集。结果包含两个输入的组合体积。.
static union(a: Mesh, b: Mesh): MeshProperties
a Mesh
第一个网格操作数。.
b Mesh
第二个网格操作数。.
Properties
Mesh
一个表示以下并集的新的 mesh a 和 b.
Properties
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 surface 中定义,但会抛出 Error('difference is not implemented') 在运行时。不要在生产代码中调用它。.
执行布尔差运算,减去 mesh 的体积 b 从 mesh a.
static difference(a: Mesh, b: Mesh): MeshProperties
a Mesh
基础网格。.
b Mesh
要从中减去的网格 a.
Properties
Mesh
表示的新网格 a 减 b.
Properties
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): MeshProperties
a Mesh
第一个网格操作数。.
b Mesh
第二个网格操作数。.
Properties
Mesh
表示交集的新网格 a 和 b.
Properties
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
): VertexElementProperties
type VertexElementType
要创建的顶点属性类型(例如,, VertexElementType.Normal).
mapping MappingMode (可选)
元素数据如何映射到网格拓扑。默认值为 MappingMode.ControlPoint.
reference ReferenceMode (可选)
元素索引如何引用数据数组。默认值为 ReferenceMode.Direct.
Properties
VertexElement
新创建的顶点元素层。.
createElementUV(mapping, mappingMode?, referenceMode?)
在此网格上创建 UV 坐标层。.
createElementUV(
mapping: TextureMapping,
mappingMode?: MappingMode,
referenceMode?: ReferenceMode
): VertexElementUVProperties
mapping TextureMapping
要创建的 UV 通道(例如,, TextureMapping.Diffuse).
mappingMode MappingMode (可选)
UV 坐标如何映射到顶点。.
referenceMode ReferenceMode (可选)
UV 索引数据如何引用 UV 数组。.
Properties
VertexElementUV
新创建的 UV 元素图层。.
Properties
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}`);