Node

Methods

Methods Node class đại diện cho một phần tử có tên trong đồ thị cảnh Aspose.3D. Mỗi node có thể chứa một Entity (như một Mesh, Camera, hoặc Light), duy trì quan hệ cha-con với các node khác, và mang một phép biến đổi cục bộ. Các node là cách chính để tổ chức các đối tượng 3D trong một cây phân cấp cảnh.

from aspose.threed import Scene, Node

scene = Scene()

# Access the root node: root_node is a property on Scene
root = scene.root_node

# Create a child node
child = root.create_child_node("my_node")

# child_nodes is a property: access without parentheses
for node in root.child_nodes:
    print(node.name)

Methods

Methods Node constructor khởi tạo một node với tên tùy chọn.

MethodsMethodsMethods
namestrTên tùy chọn cho node

Methods

Tất cả các thuộc tính của node bên dưới là các thuộc tính; truy cập chúng mà không cần dấu ngoặc đơn.

MethodsMethodsMethods
namestrĐịnh danh có thể đọc được cho node
entity`EntityNone`
entitieslist[Entity]Tất cả các thực thể được gắn vào node này (chỉ đọc). Một node có thể tham chiếu nhiều hơn một thực thể.
material`MaterialNone`
materialslist[Material]Tất cả các vật liệu được gán cho node này (chỉ đọc).
child_nodeslist[Node]Danh sách các node con. Sử dụng child_nodes: không children
parent_node`NodeNone`
parent_nodeslist[Node]Tất cả các nút cha (kế thừa từ Entity; hỗ trợ instancing)
visibleboolMethods False, nút và cây con của nó bị ẩn trong các trình xem tôn trọng tính hiển thị.
excludedboolMethods True, nút này bị loại trừ khỏi việc render
transformTransformBiến đổi cục bộ (dịch chuyển, quay, tỷ lệ)
global_transformGlobalTransformMa trận biến đổi không gian thế giới
asset_info`AssetInfoNone`
propertiesPropertyCollectionThuộc tính tùy chỉnh được gắn vào nút này

Methods

MethodsKiểu trả vềMethods
create_child_node(name)NodeTạo và gắn một nút con mới với tên đã cho
create_child_node(name, entity)NodeTạo một nút con và gán một thực thể cho nó
add_child_node(node)NoneThêm một nút hiện có làm con của nút này
get_child(name)Optional[Node]Tìm một nút con trực tiếp theo tên
add_entity(entity)NoneGắn một thực thể bổ sung vào nút này
merge(node)NoneHợp nhất các nút con và thực thể của một nút khác vào nút này
evaluate_global_transform(with_geometric_transform)Matrix4Trả về ma trận biến đổi không gian thế giới; truyền True để bao gồm các độ dịch hình học
get_bounding_box()BoundingBoxTính hộp bao trục trục của nút trong không gian thế giới
get_property(name)AnyLấy giá trị thuộc tính theo tên
find_property(name)Optional[Property]Tìm thuộc tính theo tên

Methods

Tạo một scene, gắn một mesh vào node, và duyệt đồ thị cảnh:

from aspose.threed import Scene, Node
from aspose.threed.entities import Mesh
from aspose.threed.utilities import Vector4

scene = Scene()
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)

# Attach mesh to a child node
node = scene.root_node.create_child_node("triangle", mesh)

# Traverse child_nodes (property, not a method)
for child in scene.root_node.child_nodes:
    entity = child.entity
    if entity is not None:
        print(f"Node '{child.name}': {type(entity).__name__}")
        # excluded is a property
        print(f"  Excluded: {entity.excluded}")

Xem thêm

 Tiếng Việt