Mesh
الحزمة: aspose.threed.entities (aspose-3d-foss 26.1.0)
Mesh يخزن هندسة المضلع كقائمة من نقاط التحكم (مواقع الرؤوس) وقائمة من وجوه المضلع. كل وجه من المضلعات هو قائمة من الفهارس التي تبدأ من الصفر إلى مصفوفة نقاط التحكم. قد تكون الوجوه مثلثات أو رباعيات أو مضلعات ذات أعداد أضلاع أعلى. يتم إرفاق بيانات إضافية لكل رأس؛ مثل المتجهات العمودية، إحداثيات UV، ألوان الرؤوس؛ كـ VertexElement طبقات.
class Mesh(Geometry):Methods
A3DObject → SceneObject → Entity → Geometry → Mesh
Methods
إنشاء شبكة مثلثية واحدة من الصفر:
from aspose.threed import Scene
from aspose.threed.entities import Mesh
from aspose.threed.utilities import Vector4
# Create the mesh and add three vertex positions
# IMPORTANT: control_points returns a copy of the internal list.
# Append to _control_points directly — appending to control_points discards the vertex.
# This is a known library limitation; a public mutation API does not yet exist.
mesh = Mesh()
mesh._control_points.append(Vector4(0.0, 0.0, 0.0, 1.0)) # vertex 0
mesh._control_points.append(Vector4(1.0, 0.0, 0.0, 1.0)) # vertex 1
mesh._control_points.append(Vector4(0.5, 1.0, 0.0, 1.0)) # vertex 2
# Define one triangle face using vertex indices
mesh.create_polygon(0, 1, 2)
# Attach to a scene and save
scene = Scene()
scene.root_node.create_child_node("triangle", mesh)
scene.save("triangle.stl")إنشاء شبكة رباعية وتثليثها قبل التصدير:
from aspose.threed import Scene
from aspose.threed.entities import Mesh
from aspose.threed.utilities import Vector4
mesh = Mesh()
# Four corners of a unit square in the XZ plane
# 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))
# One quad face
mesh.create_polygon(0, 1, 2, 3)
print(f"Polygons before triangulate: {mesh.polygon_count}") # 1
triangulated = mesh.triangulate()
print(f"Polygons after triangulate: {triangulated.polygon_count}") # 2
scene = Scene()
scene.root_node.create_child_node("quad", triangulated)
scene.save("quad.glb")Methods
control_points, polygon_count, polygons, edges, و vertex_elements جميعها خصائص; يمكن الوصول إليها دون أقواس.
| Methods | Methods | Methods | Methods |
|---|---|---|---|
control_points | list[Vector4] | قراءة | مصفوفة مواقع الرؤوس. كل إدخال هو a Vector4(x, y, z, w) أين w هو 1.0 لبيانات الموقع. يرجع نسخة — لا تقم بإلحاقها بالقائمة المرجعة. استخدم mesh._control_points.append(v) لإضافة رؤوس (قيد معروف؛ واجهة برمجة التطبيقات العامة للتعديل غير متاحة بعد). |
polygon_count | int | قراءة | عدد أوجه المضلع المعرفة على هذا النموذج. |
polygons | list[list[int]] | قراءة | جميع تعريفات الأوجه كقائمة من قوائم الفهارس. كل قائمة داخلية تحتفظ بفهارس الرؤوس (في control_points) لوجه واحد. |
edges | list[int] | قراءة | بيانات فهرس الحواف الخام. تُستخدم أساسًا للاستخدام الداخلي واستعلامات الطوبولوجيا المتقدمة. |
vertex_elements | list[VertexElement] | قراءة | جميع طبقات عناصر الرؤوس المرفقة حاليًا بهذه الشبكة (العمليات العادية، UVs، الألوان، إلخ). |
visible | bool | قراءة/كتابة | Methods False,، تكون الشبكة مخفية في العارضات التي تحترم الرؤية. |
cast_shadows | bool | قراءة/كتابة | ما إذا كانت هذه الشبكة تُسقِط ظلالًا في عارضات تدعم خرائط الظلال. |
receive_shadows | bool | قراءة/كتابة | ما إذا كان هذا النموذج يتلقى الظلال من هندسة أخرى تُسقط الظلال. |
Methods
create_polygon(*indices)
عرّف وجهًا متعدد الأضلاع جديدًا عن طريق توفير مؤشرات الرؤوس بالترتيب. المؤشرات تشير إلى المواقع في control_points. يقبل ثلاثة مؤشرات أو أكثر للمثلثات، الرباعيات، والمتعددات n.
| Methods | Methods | Methods |
|---|---|---|
*indices | int | معاملات مؤشر الرؤوس بترتيب اللف (عادةً عكس اتجاه عقارب الساعة عند النظر من الخارج). |
الإرجاع: None
mesh = Mesh()
# ... populate control_points ...
mesh.create_polygon(0, 1, 2) # triangle
mesh.create_polygon(0, 1, 2, 3) # quad
print(mesh.polygon_count) # 2triangulate()
أرجع جديدًا Mesh حيث يتم تقسيم كل مضلع إلى مثلثات باستخدام طريقة التثليث بالمروحة. النموذج الأصلي لا يتغير. مفيد قبل التصدير إلى صيغ تتطلب هندسة مكوّنة من مثلثات فقط (مثل STL أو بعض خطوط أنابيب glTF).
الإرجاع: Mesh; شبكة جديدة تحتوي فقط على مثلثات.
from aspose.threed.entities import Mesh
from aspose.threed.utilities import Vector4
mesh = Mesh()
# Use _control_points to mutate the backing list (control_points returns a copy)
for v in [(0,0,0), (1,0,0), (1,1,0), (0,1,0)]:
mesh._control_points.append(Vector4(*v, 1.0))
mesh.create_polygon(0, 1, 2, 3) # one quad
tri_mesh = mesh.triangulate()
print(tri_mesh.polygon_count) # 2to_mesh()
أرجع هذا Mesh كـ Mesh مثال. لـ Mesh الكائنات، هذه عملية هوية (تُعيد self). معرفة على الـ Geometry الفئة الأساسية لتوفير واجهة تحويل موحدة عند العمل مع العامة Geometry المراجع.
الإرجاع: Mesh
from aspose.threed.entities import Geometry
def ensure_mesh(geom: Geometry):
return geom.to_mesh()create_element(element_type, mapping_mode, reference_mode)
أضف جديدًا VertexElement طبقة من النوع المحدد إلى الشبكة. استخدم هذا لإرفاق normals، tangents، binormals، vertex colours، و smoothing groups.
| Methods | Methods | Methods |
|---|---|---|
element_type | VertexElementType | نوع البيانات التي تحتفظ بها هذه الطبقة (مثالاً،., VertexElementType.NORMAL). |
mapping_mode | MappingMode | كيفية ربط البيانات بالهندسة: CONTROL_POINT, POLYGON_VERTEX, POLYGON, إلخ. |
reference_mode | ReferenceMode | كيفية استخدام الفهارس: DIRECT أو INDEX_TO_DIRECT. |
القيم المرجعة: VertexElement
from aspose.threed.entities import Mesh, VertexElementType, MappingMode, ReferenceMode
from aspose.threed.utilities import Vector4
mesh = Mesh()
# Use _control_points to mutate the backing list (control_points returns a copy)
mesh._control_points.append(Vector4(0, 0, 0, 1))
mesh._control_points.append(Vector4(1, 0, 0, 1))
mesh._control_points.append(Vector4(0.5, 1, 0, 1))
mesh.create_polygon(0, 1, 2)
normal_element = mesh.create_element(
VertexElementType.NORMAL,
MappingMode.CONTROL_POINT,
ReferenceMode.DIRECT,
)create_element_uv(uv_mapping, mapping_mode, reference_mode)
أضف طبقة إحداثيات UV إلى الشبكة. هذه هي الطريقة المفضلة لإرفاق بيانات إحداثيات القوام.
| Methods | Methods | Methods |
|---|---|---|
uv_mapping | TextureMapping | غرض قناة UV: DIFFUSE, SPECULAR, NORMAL, AMBIENT, إلخ. |
mapping_mode | MappingMode | كيف يتم ربط UVs بعناصر الهندسة. |
reference_mode | ReferenceMode | وضع الفهرسة: DIRECT أو INDEX_TO_DIRECT. |
الإرجاع: VertexElementUV
from aspose.threed.entities import Mesh, TextureMapping, MappingMode, ReferenceMode
mesh = Mesh()
# ... define control_points and polygons ...
uv_element = mesh.create_element_uv(
TextureMapping.DIFFUSE,
MappingMode.POLYGON_VERTEX,
ReferenceMode.INDEX_TO_DIRECT,
)