PolygonModifier
الحزمة: aspose.threed.entities (aspose-3d-foss 26.1.0)
PolygonModifier هي فئة أداة ثابتة توفر عمليات تجزئة المضلع على Mesh و Scene الكائنات. جميع الأساليب هي أساليب فئة؛; PolygonModifier لا يتم إنشاء كائن منها مباشرةً.
from aspose.threed.entities import PolygonModifierالعملية الأساسية هي التثليث: تحويل المربعات (quads) والمتعددات n‑gon إلى مثلثات باستخدام طريقة قص الأذن. هذا مطلوب قبل التصدير إلى صيغ تقبل فقط هندسة المثلثات (STL، بعض خطوط أنابيب glTF).
Methods
triangulate(arg) — تحويل إلى مثلثات a 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()
# 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) # 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