PolygonModifier — Aspose.3D Python API Reference
الحزمة: aspose.threed.entities (aspose-3d-foss 26.1.0)
PolygonModifier هي فئة أداة ثابتة توفر عمليات تجزئة المضلع على Mesh و Scene الكائنات. جميع الأساليب هي أساليب فئة؛; PolygonModifier لا يتم إنشاء نسخة منها مباشرةً.
from aspose.threed.entities import PolygonModifierالعملية الأساسية هي التثليث: تحويل الأرباع والمتعدد الأضلاع (n-gons) إلى مثلثات باستخدام طريقة قص الأذن. هذا مطلوب قبل التصدير إلى صيغ تقبل فقط هندسة المثلثات (STL، بعض خطوط أنابيب glTF).
Methods
triangulate(arg) — تحويل إلى مثلثات لـ Mesh
إرجاع جديد Mesh حيث تم تحويل كل مضلع إلى مثلثات. لا يتم تعديل الشبكة الأصلية. يتم نسخ طبقات عناصر الرؤوس (normals, UVs, colours) إلى الشبكة الجديدة.
@staticmethod
def triangulate(mesh: Mesh) -> Mesh| Methods | Methods | Methods |
|---|---|---|
mesh | Mesh | شبكة المصدر لتثليثها. |
الإرجاع: Mesh — شبكة جديدة تحتوي فقط على مضلعات مثلثية.
from aspose.threed.entities import Mesh, PolygonModifier
from aspose.threed.utilities import Vector4
mesh = Mesh()
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) # 2triangulate(scene) — تثليث جميع الشبكات في Scene
استعرض كامل رسم المشهد البياني وقم بتثليث كل Mesh كيان في مكانه. بعد هذا الاستدعاء، لا تبقى أي مضلعات غير مثلثية في المشهد.
@staticmethod
def triangulate(scene: Scene) -> None| Methods | Methods | Methods |
|---|---|---|
scene | Scene | المشهد الذي ستُثَلّث كائنات الشبكة فيه. |
الإرجاع: 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) — تقسيم مضلع واحد إلى مثلثات
إصدار منخفض المستوى: يُعطى قائمة بنقاط التحكم وقائمة بمؤشرات الرؤوس التي تشكل مضلعًا واحدًا، يُعيد قائمة بثلاثيات مؤشرات المثلثات الناتجة عن تثليث المروحة.
@staticmethod
def triangulate(
control_points: list[Vector4],
polygon: list[int],
) -> list[list[int]]| Methods | Methods | Methods |
|---|---|---|
control_points | list[Vector4] | مصفوفة مواضع الرؤوس الكاملة. |
polygon | list[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) — تجزئة دفعية مع توليد عادي اختياري
تجزئة دفعية لقائمة من قوائم مؤشرات المضلع. اختياريًا احسب المتجهات العمودية للوجه لكل مثلث ناتج وأضفها إلى 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]]| Methods | Methods | Methods |
|---|---|---|
control_points | list[Vector4] | مصفوفة مواضع الرؤوس. |
polygons | list[list[int]] | قائمة تعريفات المضلع، كل منها قائمة بمؤشرات الرؤوس. |
generate_normals | bool | Methods True,، احسب المتجه العمودي للوجه لكل مثلث ناتج. |
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