Scene — Aspose.3D FOSS for Java
Properties
Properties 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 cây 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 để tải, xây dựng và lưu các cảnh 3D.
import com.aspose.threed.Scene;
// Create an empty scene
Scene scene = new Scene();
// Access the root node via getter method
Node root = scene.getRootNode();Properties
Properties Scene class có thể được khởi tạo 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.
| Properties | Properties | Properties |
|---|---|---|
entity | Entity | Thực thể tùy chọn để gắn vào nút gốc khi tạo |
parentScene | Scene | Cảnh cha tùy chọn (cho các cảnh phụ); yêu cầu một tên |
name | String | Tên cảnh (chỉ được sử dụng với hàm khởi tạo hai đối số Scene(Scene, String) hàm khởi tạo) |
import com.aspose.threed.Scene;
// Empty scene
Scene scene = new Scene();
// Scene with an initial entity
Scene scene = new Scene(new Mesh());
// Access the root node (getter method)
Node root = scene.getRootNode();Các phương thức lớp
| Properties | Kiểu trả về | Properties |
|---|---|---|
Scene.fromFile(String filePath) | 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. |
Scene.fromFile(String filePath, LoadOptions options) | Scene | Tải một cảnh với các tùy chọn tải đặc thù cho định dạng. |
import com.aspose.threed.Scene;
// Load from file (format detected from extension)
Scene scene = Scene.fromFile("model.obj");
// Load with options
ObjLoadOptions opts = new ObjLoadOptions();
Scene scene = Scene.fromFile("model.obj", opts);Properties
Tất cả các thuộc tính được truy cập thông qua các phương thức getter/setter.
| Properties | Properties | Properties | Properties | Properties |
|---|---|---|---|---|
rootNode | Node | getRootNode() | – | Nút gốc của cấu trúc cây cảnh |
subScenes | List<Scene> | getSubScenes() | – | Các cảnh phụ lồng trong cảnh này |
assetInfo | AssetInfo | getAssetInfo() | setAssetInfo(AssetInfo) | Siêu dữ liệu tài sản như tác giả, ngày tạo và đơn vị |
animationClips | List<AnimationClip> | getAnimationClips() | – | Các đoạn hoạt hình được định nghĩa trong cảnh |
currentAnimationClip | AnimationClip | getCurrentAnimationClip() | setCurrentAnimationClip(AnimationClip) | Đoạn hoạt hình đang hoạt động hiện tại |
library | List<A3DObject> | getLibrary() | – | Các đối tượng metadata do người dùng định nghĩa được gắn vào cảnh |
name | String | getName() | setName(String) | Tên của đối tượng cảnh |
properties | PropertyCollection | getProperties() | – | Các thuộc tính tùy chỉnh được gắn vào cảnh |
Properties
| Properties | Kiểu trả về | Properties |
|---|---|---|
save(String filePath) | void | Lưu cảnh vào tệp; định dạng được suy ra từ phần mở rộng |
save(String filePath, FileFormat format) | void | Lưu cảnh vào tệp trong vị trí được chỉ định FileFormat |
save(String filePath, SaveOptions options) | void | Lưu cảnh bằng các tùy chọn lưu đặc thù cho định dạng |
open(String filePath) | void | Mở tệp vào cảnh này; định dạng được suy ra từ phần mở rộng |
open(String filePath, LoadOptions options) | void | Mở tệp với các tùy chọn tải đặc thù cho định dạng |
getProperty(String name) | Object | Lấy giá trị thuộc tính theo tên |
findProperty(String name) | Property | Tìm thuộc tính theo tên |
createAnimationClip(String name) | AnimationClip | Tạo một clip hoạt hình mới có tên và thêm nó vào cảnh |
getAnimationClip(String name) | AnimationClip | Tìm một clip hoạt hình hiện có theo tên, hoặc null nếu không tìm thấy |
clear() | void | Xóa tất cả nội dung khỏi cảnh |
Properties
Tạo một cảnh, thêm một nút mesh, và lưu dưới dạng GLB:
import com.aspose.threed.Scene;
import com.aspose.threed.FileFormat;
// Create scene and mesh
Scene scene = new Scene();
Mesh mesh = new Mesh();
mesh.getControlPoints().add(new Vector4(0, 0, 0, 1));
mesh.getControlPoints().add(new Vector4(1, 0, 0, 1));
mesh.getControlPoints().add(new Vector4(0.5, 1, 0, 1));
mesh.createPolygon(0, 1, 2);
// Add node to root
Node node = scene.getRootNode().createChildNode("triangle", mesh);
// Save as GLB
GltfSaveOptions glbOpts = new GltfSaveOptions();
glbOpts.setContentType(FileContentType.BINARY);
scene.save("triangle.glb", glbOpts);