PolygonModifier

PolygonModifier

แพคเกจ: aspose.threed.entities (aspose-3d-foss 26.1.0)

PolygonModifier เป็นคลาสยูทิลิตี้แบบสแตติกที่ให้การดำเนินการตัดแบ่งโพลิกอนบน Mesh และ Scene อ็อบเจ็กต์ทั้งหมด วิธีการทั้งหมดเป็นเมธอดของคลาส; PolygonModifier จะไม่ถูกสร้างอินสแตนซ์โดยตรงเลย.

from aspose.threed.entities import PolygonModifier

การดำเนินการหลักคือการทำให้เป็นสามเหลี่ยม: แปลงควอดและ n‑gon ให้เป็นสามเหลี่ยมโดยใช้วิธี ear‑clipping ซึ่งจำเป็นก่อนการส่งออกไปยังฟอร์แมตที่รับเฉพาะเรขาคณิตแบบสามเหลี่ยม (STL, บาง pipeline ของ glTF).


Methods

triangulate(arg) — ทำไตรแองเกิลให้กับ Mesh

คืนค่าใหม่ Mesh ซึ่งทุกโพลิกอนได้ถูกแปลงเป็นสามเหลี่ยมแล้ว โครงข่ายต้นฉบับไม่ได้รับการแก้ไข ชั้นขององค์ประกอบเวอร์เท็กซ์ (normals, UVs, colours) จะถูกคัดลอกไปยังโครงข่ายใหม่.

@staticmethod
def triangulate(mesh: Mesh) -> Mesh
MethodsMethodsMethods
meshMeshโครงข่ายต้นทางที่ต้องทำการแปลงเป็นสามเหลี่ยม.

คืนค่า: Mesh — โครงข่ายใหม่ที่มีเพียงโพลิกอนรูปสามเหลี่ยมเท่านั้น.

from aspose.threed.entities import Mesh, PolygonModifier
from aspose.threed.utilities import Vector4

mesh = Mesh()
# Use _control_points to mutate the backing list (control_points returns a copy)
for x, z in [(0, 0), (1, 0), (1, 1), (0, 1)]:
    mesh._control_points.append(Vector4(float(x), 0.0, float(z), 1.0))
mesh.create_polygon(0, 1, 2, 3)   # one quad

tri_mesh = PolygonModifier.triangulate(mesh)
print(tri_mesh.polygon_count)     # 2

triangulate(scene) — แปลงเป็นสามเหลี่ยมทุกโครงข่ายใน a Scene

สำรวจกราฟฉากทั้งหมดและแปลงเป็นสามเหลี่ยมทุก Mesh เอนทิตีในที่เดิม หลังจากเรียกนี้แล้ว จะไม่มีโพลิกอนที่ไม่ใช่สามเหลี่ยมเหลืออยู่ในฉาก.

@staticmethod
def triangulate(scene: Scene) -> None
MethodsMethodsMethods
sceneSceneฉากที่เอนทิตีโครงข่ายจะถูกแปลงเป็นสามเหลี่ยม.

คืนค่า: None

from aspose.threed import Scene
from aspose.threed.entities import PolygonModifier

scene = Scene.from_file("model_with_quads.obj")
PolygonModifier.triangulate(scene)
scene.save("model_triangulated.stl")

triangulate(control_points, polygon) — แยกเหลี่ยมรูปหลายเหลี่ยมเดียว

โอเวอร์โหลดระดับต่ำ: ให้รายการของจุดควบคุมและรายการของดัชนีเวอร์เท็กซ์ที่ประกอบเป็นโพลิกอนหนึ่ง คืนค่ารายการของชุดดัชนีสามเหลี่ยมที่ได้จากการทำ fan triangulation.

@staticmethod
def triangulate(
    control_points: list[Vector4],
    polygon: list[int],
) -> list[list[int]]
MethodsMethodsMethods
control_pointslist[Vector4]อาร์เรย์ตำแหน่งเวอร์เท็กซ์ทั้งหมด.
polygonlist[int]ดัชนีไปยัง control_points กำหนดรูปหลายเหลี่ยมที่จะแบ่ง.

คืนค่า: list[list[int]] — รายการของ [i, j, k] ชุดของสามค่า, แต่ละชุดแสดงถึงสามเหลี่ยมผลลัพธ์หนึ่งรูป.

from aspose.threed.entities import PolygonModifier
from aspose.threed.utilities import Vector4

pts = [
    Vector4(0.0, 0.0, 0.0, 1.0),
    Vector4(1.0, 0.0, 0.0, 1.0),
    Vector4(1.0, 1.0, 0.0, 1.0),
    Vector4(0.0, 1.0, 0.0, 1.0),
]
quad_indices = [0, 1, 2, 3]
triangles = PolygonModifier.triangulate(pts, quad_indices)
print(triangles)   # e.g. [[0, 1, 2], [0, 2, 3]]

triangulate(control_points, polygons, generate_normals, normals_out) — แยกเหลี่ยมแบบกลุ่มพร้อมการสร้าง normal แบบเลือกได้

แยกเหลี่ยมแบบกลุ่มรายการของดัชนีรูปหลายเหลี่ยม. สามารถคำนวณ face normal สำหรับแต่ละสามเหลี่ยมผลลัพธ์และต่อท้ายลงใน normals_out.

@staticmethod
def triangulate(
    control_points: list[Vector4],
    polygons: list[list[int]],
    generate_normals: bool = False,
    normals_out: list[Vector3] | None = None,
) -> list[list[int]]
MethodsMethodsMethods
control_pointslist[Vector4]อาร์เรย์ตำแหน่งเวอร์เท็กซ์.
polygonslist[list[int]]รายการของการกำหนดรูปหลายเหลี่ยม, แต่ละรายการเป็นรายการของดัชนีเวอร์เท็กซ์.
generate_normalsboolMethods True, คำนวณ face normal สำหรับแต่ละสามเหลี่ยมผลลัพธ์.
normals_out`list[Vector3]None`

คืนค่า: list[list[int]] — แสดงผลชุดสามเหลี่ยมทั้งหมดตามลำดับ.

from aspose.threed.entities import PolygonModifier
from aspose.threed.utilities import Vector4, Vector3

pts = [
    Vector4(0, 0, 0, 1), Vector4(1, 0, 0, 1),
    Vector4(1, 1, 0, 1), Vector4(0, 1, 0, 1),
]
polys = [[0, 1, 2, 3]]
normals: list[Vector3] = []
tris = PolygonModifier.triangulate(pts, polys, True, normals)
print(len(tris))     # 2
print(len(normals))  # 2

ดูเพิ่มเติม

 ภาษาไทย