Scene
Methods
Methods Scene class trong Aspose.3D đóng vai trò là container gốc cho nội dung 3D, quản lý các đối tượng cấp cao nhất và cho phép quản lý quan hệ cha/con cho cấu trúc phân cấp cảnh. Nó cung cấp quyền truy cập vào các nút gốc và các cảnh phụ, tạo thành điểm vào cho việc tải, xây dựng và lưu các cảnh 3D.
from aspose.threed import Scene
# Create an empty scene
scene = Scene()
# Access the root node: root_node is a property, not a method call
root = scene.root_nodeMethods
Methods Scene class có thể được khởi tạo mà không có đối số nào để tạo một cảnh trống, hoặc với các tham số tùy chọn.
| Methods | Methods | Methods |
|---|---|---|
name | str | Tên tùy chọn của cảnh |
entity | Entity | Thực thể tùy chọn để gắn vào nút gốc khi tạo |
parent_scene | Scene | Cảnh cha tùy chọn (cho các cảnh phụ) |
from aspose.threed import Scene
# Empty scene
scene = Scene()
# Access the root node (property, not a method)
root = scene.root_nodeCác phương thức lớp
| Methods | Kiểu trả về | Methods |
|---|---|---|
Scene.from_file(file_path) | Scene | Tải một cảnh từ đường dẫn tệp được chỉ định, tự động phát hiện định dạng. Chấp nhận đúng một đối số. |
from aspose.threed import Scene
from aspose.threed.formats import ObjLoadOptions
# Load from file (format detected from extension)
scene = Scene.from_file("model.obj")
# To pass load options, use scene.open() instead:
opts = ObjLoadOptions()
scene = Scene()
scene.open("model.obj", opts)Methods
root_node và các thuộc tính cấp cảnh khác là thuộc tính; truy cập chúng mà không cần dấu ngoặc đơn.
| Methods | Methods | Methods |
|---|---|---|
root_node | Node | Nút gốc của cây phân cấp cảnh. Truy cập như một thuộc tính: scene.root_node |
sub_scenes | list[Scene] | Các cảnh phụ lồng trong cảnh này |
asset_info | AssetInfo | Siêu dữ liệu tài sản như tác giả, ngày tạo và đơn vị |
animation_clips | list[AnimationClip] | Các đoạn clip hoạt hình được định nghĩa trong cảnh |
current_animation_clip | `AnimationClip | None` |
library | list[CustomObject] | Các đối tượng siêu dữ liệu do người dùng định nghĩa được gắn vào cảnh. |
name | str | Tên của đối tượng cảnh |
properties | PropertyCollection | Các thuộc tính tùy chỉnh được gắn vào cảnh |
Methods
| Methods | Kiểu trả về | Methods |
|---|---|---|
save(file_path) | None | Lưu cảnh vào tệp; định dạng được suy ra từ phần mở rộng |
save(file_path, format) | None | Lưu cảnh vào tệp trong định dạng được chỉ định FileFormat |
save(file_path, options) | None | Lưu cảnh bằng cách sử dụng các tùy chọn lưu riêng cho định dạng |
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 |
create_animation_clip(name) | AnimationClip | Tạo một đoạn hoạt hình có tên mới và thêm nó vào cảnh |
get_animation_clip(name) | `AnimationClip | None` |
clear() | None | Xóa toàn bộ nội dung khỏi cảnh |
Lưu ý: root_node là một thuộc tính trên Scene lớp, không phải phương thức. Không viết scene.root_node(); quyền truy cập đúng là scene.root_node.
Methods
Tạo một cảnh, thêm một nút mesh, và lưu dưới dạng GLB:
from aspose.threed import Scene
from aspose.threed.entities import Mesh
from aspose.threed.formats import GltfSaveOptions
from aspose.threed.utilities import Vector4
# Create scene and mesh
# Note: control_points returns a copy — use _control_points to add vertices
scene = Scene()
mesh = Mesh()
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)
# Add node to root: root_node is a property
node = scene.root_node.create_child_node("triangle", mesh)
# Save as GLB using GltfSaveOptions with binary_mode
opts = GltfSaveOptions()
opts.binary_mode = True
scene.save("triangle.glb", opts)