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[]ตำแหน่งเวอร์เท็กซ์ของ mesh. แต่ละจุดใช้พิกัดเชิงเนื้อเดียว (x, y, z, w). เพิ่มจุดโดยการผลักใส่ลงในอาเรย์นี้ก่อนกำหนดหลายเหลี่ยม.
polygonCountnumberอ่านอย่างเดียว. จำนวนของหลายเหลี่ยม (faces) ที่กำหนดไว้ใน mesh ในขณะนี้.
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()

คืนค่าเมชเป็น a Mesh อินสแตนซ์. สำหรับ Mesh วัตถุ นี่เป็นการดำเนินการแบบอัตลักษณ์; วิธีการนี้มีความหมายมากขึ้นกับประเภทเรขาคณิตพื้นฐานที่สืบทอดจาก Geometry.

toMesh(): Mesh

Properties

Mesh

อินสแตนซ์เมชนี้.


static union(a, b)

NOT IMPLEMENTED. เมธอดนี้ถูกกำหนดใน API surface แต่ throws Error('union is not implemented') ที่รันไทม์. อย่าเรียกใช้ในโค้ดการผลิต.

ทำการยูเนียนแบบบูลีนของเมชสองอัน ผลลัพธ์จะมีปริมาณรวมของอินพุตทั้งสอง.

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

Properties

a Mesh

เมชออเปอแรนด์ตัวแรก.

b Mesh

เมชออเปอแรนด์ตัวที่สอง.

Properties

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 แต่ throws Error('difference is not implemented') ที่รันไทม์. อย่าเรียกใช้ในโค้ดการผลิต.

ทำการ Boolean difference, ลบปริมาณของเมช b จากเมช a.

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

Properties

a Mesh

เมชฐาน.

b Mesh

เมชที่ต้องลบออกจาก a.

Properties

Mesh

เมชใหม่ที่แสดงถึง a ลบ b.

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 surface แต่ throws Error('intersect is not implemented') ที่รันไทม์. อย่าเรียกใช้ในโค้ดการผลิต.

ทำการตัดกันแบบบูลีนของเมชสองอัน ผลลัพธ์จะมีเฉพาะปริมาณที่ทับซ้อนกันเท่านั้น.

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

Properties

a Mesh

เมชออเปอแรนด์ตัวแรก.

b Mesh

เมชออเปอแรนด์ตัวที่สอง.

Properties

Mesh

เมชใหม่ที่แสดงการตัดกันของ a และ b.

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}`);
 ภาษาไทย