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.

PropertiesPropertiesProperties
entityEntityThực thể tùy chọn để gắn vào nút gốc khi tạo
parentSceneSceneCảnh cha tùy chọn (cho các cảnh phụ); yêu cầu một tên
nameStringTê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

PropertiesKiểu trả vềProperties
Scene.fromFile(String filePath)SceneTả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)SceneTả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.

PropertiesPropertiesPropertiesPropertiesProperties
rootNodeNodegetRootNode()Nút gốc của cấu trúc cây cảnh
subScenesList<Scene>getSubScenes()Các cảnh phụ lồng trong cảnh này
assetInfoAssetInfogetAssetInfo()setAssetInfo(AssetInfo)Siêu dữ liệu tài sản như tác giả, ngày tạo và đơn vị
animationClipsList<AnimationClip>getAnimationClips()Các đoạn hoạt hình được định nghĩa trong cảnh
currentAnimationClipAnimationClipgetCurrentAnimationClip()setCurrentAnimationClip(AnimationClip)Đoạn hoạt hình đang hoạt động hiện tại
libraryList<A3DObject>getLibrary()Các đối tượng metadata do người dùng định nghĩa được gắn vào cảnh
nameStringgetName()setName(String)Tên của đối tượng cảnh
propertiesPropertyCollectiongetProperties()Các thuộc tính tùy chỉnh được gắn vào cảnh

Properties

PropertiesKiểu trả vềProperties
save(String filePath)voidLưu cảnh vào tệp; định dạng được suy ra từ phần mở rộng
save(String filePath, FileFormat format)voidLưu cảnh vào tệp trong vị trí được chỉ định FileFormat
save(String filePath, SaveOptions options)voidLưu cảnh bằng các tùy chọn lưu đặc thù cho định dạng
open(String filePath)voidMở 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)voidMở tệp với các tùy chọn tải đặc thù cho định dạng
getProperty(String name)ObjectLấy giá trị thuộc tính theo tên
findProperty(String name)PropertyTìm thuộc tính theo tên
createAnimationClip(String name)AnimationClipTạo một clip hoạt hình mới có tên và thêm nó vào cảnh
getAnimationClip(String name)AnimationClipTì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()voidXó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);

Xem thêm

 Tiếng Việt