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] | อ่าน | อาร์เรย์ตำแหน่งเวอร์เท็กซ์. แต่ละรายการเป็น Vector4(x, y, z, w) ที่ w คือ 1.0 สำหรับข้อมูลตำแหน่ง. คืนสำเนา — อย่าเพิ่มต่อท้ายรายการที่คืนกลับ. ใช้ mesh._control_points.append(v) เพื่อเพิ่มจุดยอด (ข้อจำกัดที่ทราบ; API การเปลี่ยนแปลงสาธารณะยังไม่พร้อมให้ใช้). |
polygon_count | int | อ่าน | จำนวนหน้าโพลิกอนที่กำหนดบนเมชนี้. |
polygons | list[list[int]] | อ่าน | การกำหนดหน้าต่างทั้งหมดเป็นรายการของรายการดัชนี แต่ละรายการภายในเก็บดัชนีของจุดยอด (ใน control_points) สำหรับหนึ่งหน้า. |
edges | list[int] | อ่าน | ข้อมูลดัชนีขอบดิบ ใช้เป็นหลักสำหรับการใช้งานภายในและการสอบถามโทโพโลยีขั้นสูง. |
vertex_elements | list[VertexElement] | อ่าน | ชั้นขององค์ประกอบเวอร์เท็กซ์ทั้งหมดที่แนบอยู่กับเมชนี้ (normals, UVs, colours, etc.). |
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 โดยที่ทุกโพลิกอนถูกแยกเป็นสามเหลี่ยมโดยใช้ fan triangulation. เมชต้นฉบับจะไม่ถูกแก้ไข. มีประโยชน์ก่อนการส่งออกเป็นฟอร์แมตที่ต้องการรูปทรงเฉพาะสามเหลี่ยม (เช่น STL หรือบาง glTF pipelines).
คืนค่า: 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 objects นี้เป็นการดำเนินการแบบอัตลักษณ์ (คืนค่า self). กำหนดบน the Geometry คลาสฐานเพื่อให้มีอินเทอร์เฟซการแปลงที่สอดคล้องกันเมื่อทำงานกับ generic 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 layer ของประเภทที่ระบุลงในเมช ใช้เพื่อแนบ 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,
)