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_node

Methods

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.

MethodsMethodsMethods
namestrTên tùy chọn của cảnh
entityEntityThực thể tùy chọn để gắn vào nút gốc khi tạo
parent_sceneSceneCả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_node

Các phương thức lớp

MethodsKiểu trả vềMethods
Scene.from_file(file_path)SceneTả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.

MethodsMethodsMethods
root_nodeNodeNú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_sceneslist[Scene]Các cảnh phụ lồng trong cảnh này
asset_infoAssetInfoSiêu dữ liệu tài sản như tác giả, ngày tạo và đơn vị
animation_clipslist[AnimationClip]Các đoạn clip hoạt hình được định nghĩa trong cảnh
current_animation_clip`AnimationClipNone`
librarylist[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.
namestrTên của đối tượng cảnh
propertiesPropertyCollectionCác thuộc tính tùy chỉnh được gắn vào cảnh

Methods

MethodsKiểu trả vềMethods
save(file_path)NoneLưu cảnh vào tệp; định dạng được suy ra từ phần mở rộng
save(file_path, format)NoneLưu cảnh vào tệp trong định dạng được chỉ định FileFormat
save(file_path, options)NoneLư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)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
create_animation_clip(name)AnimationClipTạ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)`AnimationClipNone`
clear()NoneXó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)

Xem thêm

 Tiếng Việt