Entity
Methods
Methods Entity class là lớp cơ sở trừu tượng cho objects có thể được gắn vào một Node trong Aspose.3D scene graph. Các subclasses cụ thể bao gồm Mesh, Camera, Light, và Geometry. Entity cung cấp quyền truy cập vào cấu trúc cây node cha và phơi bày excluded property để kiểm soát hiển thị.
Tất cả các attributes được liệt kê dưới đây là properties; truy cập chúng mà không cần dấu ngoặc.
from aspose.threed import Scene
from aspose.threed.entities import Mesh
scene = Scene.from_file("model.obj")
for node in scene.root_node.child_nodes:
entity = node.entity
if entity is not None:
# excluded is a property, not a method call
if not entity.excluded:
# parent_node is a property, not a method call
parent = entity.parent_node
print(f"Active entity '{entity.name}', parent: {parent.name if parent else 'None'}")Methods
A3DObject → SceneObject → Entity
Subclasses: Geometry → Mesh, Camera, Light, và các khác.
Methods
Entity là một lớp cơ sở trừu tượng và không được khởi tạo trực tiếp. Sử dụng một lớp con cụ thể như Mesh.
Methods
| Methods | Methods | Methods |
|---|---|---|
parent_nodes | list[Node] (chỉ đọc) | Tất cả các nút cha mà thực thể này được gắn vào. Hỗ trợ tạo thể hiện (cùng một thực thể được tham chiếu từ nhiều nút). |
parent_node | Optional[Node] (đọc/ghi) | Nút cha chính, hoặc None nếu thực thể không được gắn. |
excluded | bool (đọc/ghi) | Methods True, thực thể này bị loại trừ khỏi việc render. Truy cập và đặt như một thuộc tính: entity.excluded = True. |
name | str (đọc/ghi) | Tên có thể đọc được cho con người cho thực thể này. |
properties | PropertyCollection (chỉ đọc) | Tập hợp các thuộc tính tùy chỉnh. |
Methods
| Methods | Kiểu trả về | Methods |
|---|---|---|
get_property(name) | Any | Lấy giá trị thuộc tính theo tên. |
find_property(name) | Optional[Property] | Tìm thuộc tính theo tên. |
Quan trọng: parent_node, parent_nodes, và excluded là các thuộc tính, không phải là phương thức. Đừng gọi chúng bằng dấu ngoặc đơn. Các mẫu đúng là:
# CORRECT
is_excluded = entity.excluded
parent = entity.parent_node
parents = entity.parent_nodes
# WRONG: do not do this
is_excluded = entity.excluded() # TypeError
parent = entity.parent_node() # TypeErrorĐể thiết lập parent_node, gán cho thuộc tính:
entity.parent_node = some_node # CORRECTMethods
Kiểm tra trạng thái của entity sau khi tải một cảnh:
from aspose.threed import Scene
from aspose.threed.entities import Mesh
scene = Scene.from_file("model.stl")
for node in scene.root_node.child_nodes:
entity = node.entity
if entity is None:
continue
# Properties accessed without parentheses
print(f"Entity: {entity.name or '(unnamed)'}")
print(f" Type: {type(entity).__name__}")
print(f" Excluded: {entity.excluded}")
print(f" Parent node: {entity.parent_node.name if entity.parent_node else 'None'}")
if isinstance(entity, Mesh):
print(f" Vertices: {len(entity.control_points)}")
print(f" Polygons: {entity.polygon_count}")