Class Mesh

Class Mesh

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

Mesh 也可以通过子路径导入获取 @aspose/3d/entities.

Mesh 是主要的多边形几何实体,位于 @aspose/3d.。它将顶点位置存储为控制点,通过顶点索引列表定义多边形面,并支持多个顶点元素数据层,例如法线和 UV 坐标。.

export class Mesh extends Geometry

Properties

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

PropertiesPropertiesProperties
controlPointsVector4[]网格的顶点位置。每个点使用齐次坐标(x, y, z, w)。在定义多边形之前,通过向此数组推入来添加点。.
polygonCountnumber只读。当前在网格上定义的多边形(面)数量。.
polygonsnumber[][]只读。多边形索引表。每个条目是一个控制点索引数组,用于定义一个面。.
edgesnumber[]边缘列表,用于硬边标记和折痕加权。.
vertexElementsVertexElement[]附加到此网格的顶点元素层(法线、UV、顶点颜色等)的集合。.
visibleboolean网格是否被渲染。默认是 true.
castShadowsboolean网格在支持的渲染器中是否投射阴影。默认是 true.
receiveShadowsboolean网格是否接收来自其他对象的阴影。默认是 true.

Properties

createPolygon(…indices)

使用提供的控制点索引定义一个新的多边形面。索引必须引用中有效的位置在 controlPoints.

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

Properties

...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(): Mesh

Properties

Mesh

三角化后的网格。.

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),
);
mesh.createPolygon(0, 1, 2, 3); // quad
const triangulated = mesh.triangulate();
console.log(`Polygons after triangulation: ${triangulated.polygonCount}`); // 2

toMesh()

将网格返回为一个 Mesh 实例。对于 Mesh 对象而言,这是一种恒等操作;该方法在继承自的原始几何类型上更有意义。 Geometry.

toMesh(): Mesh

Properties

Mesh

此网格实例。.


static union(a, b)

NOT IMPLEMENTED. 此方法在 API surface 中定义,但会抛出 Error('union is not implemented') 在运行时。不要在生产代码中调用它。.

对两个网格执行布尔并集。结果包含两个输入的组合体积。.

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

Properties

a Mesh

第一个网格操作数。.

b Mesh

第二个网格操作数。.

Properties

Mesh

一个表示以下并集的新的 mesh ab.

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): Mesh

Properties

a Mesh

基础网格。.

b Mesh

要从中减去的网格 a.

Properties

Mesh

表示的新网格 ab.

Properties

import { Mesh } from '@aspose/3d/entities';

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') 在运行时。不要在生产代码中调用它。.

对两个网格执行布尔交集。结果仅包含重叠的体积。.

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

Properties

a Mesh

第一个网格操作数。.

b Mesh

第二个网格操作数。.

Properties

Mesh

表示交集的新网格 ab.

Properties

import { Mesh } from '@aspose/3d/entities';

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

createElement(type, mapping?, reference?)

创建一个新的 VertexElement 在此网格上用于自定义每顶点属性的数据层。.

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

Properties

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
): VertexElementUV

Properties

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}`);
 中文