Scene — Aspose.3D FOSS for Java
Overview
Overview Scene คลาสใน Aspose.3D ทำหน้าที่เป็นคอนเทนเนอร์ระดับรากสำหรับเนื้อหา 3D, จัดการวัตถุระดับบนสุดและเปิดใช้งานการจัดการความสัมพันธ์พาเรนท์/ชิลด์สำหรับลำดับชั้นของซีน. มันให้การเข้าถึงโหนดรากและซีนย่อย, เป็นจุดเริ่มต้นสำหรับการโหลด, สร้าง, และบันทึกซีน 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();Overview
Overview Scene คลาสสามารถสร้างอินสแตนซ์โดยไม่มีอาร์กิวเมนต์เพื่อสร้างซีนเปล่า, หรือด้วยพารามิเตอร์ทางเลือก.
| Overview | Overview | Overview |
|---|---|---|
entity | Entity | เอนทิตี้ทางเลือกที่จะผูกกับโหนดรากเมื่อสร้าง |
parentScene | Scene | ซีนพาเรนท์ทางเลือก (สำหรับซีนย่อย); ต้องมีชื่อ |
name | String | ชื่อซีน (ใช้เฉพาะกับคอนสตรัคเตอร์สองอาร์กิวเมนต์ Scene(Scene, String) คอนสตรัคเตอร์) |
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();เมธอดของคลาส
| Overview | ประเภทค่าที่คืนกลับ | Overview |
|---|---|---|
Scene.fromFile(String filePath) | Scene | โหลดซีนจากเส้นทางไฟล์ที่ระบุ, ตรวจจับรูปแบบโดยอัตโนมัติ. |
Scene.fromFile(String filePath, LoadOptions options) | Scene | โหลดซีนพร้อมตัวเลือกการโหลดที่เฉพาะเจาะจงตามรูปแบบ. |
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);Overview
คุณสมบัติต่าง ๆ ถูกเข้าถึงผ่านเมธอด getter/setter.
| Overview | Overview | Overview | Overview | Overview |
|---|---|---|---|---|
rootNode | Node | getRootNode() | – | โหนดรากของลำดับชั้นซีน |
subScenes | List<Scene> | getSubScenes() | – | ซีนย่อยที่ซ้อนอยู่ภายในซีนนี้ |
assetInfo | AssetInfo | getAssetInfo() | setAssetInfo(AssetInfo) | เมตาดาต้าแอสเซ็ต เช่น ผู้เขียน, วันที่สร้าง, และหน่วยวัด |
animationClips | List<AnimationClip> | getAnimationClips() | – | คลิปแอนิเมชันที่กำหนดในซีน |
currentAnimationClip | AnimationClip | getCurrentAnimationClip() | setCurrentAnimationClip(AnimationClip) | คลิปแอนิเมชันที่กำลังใช้งานอยู่ในขณะนี้ |
library | List<A3DObject> | getLibrary() | – | อ็อบเจ็กต์เมตาดาต้ากำหนดโดยผู้ใช้ที่ผูกกับซีน |
name | String | getName() | setName(String) | ชื่อของอ็อบเจ็กต์ฉาก |
properties | PropertyCollection | getProperties() | – | คุณสมบัติกำหนดเองที่แนบกับฉาก |
Overview
| Overview | ประเภทค่าที่คืนกลับ | Overview |
|---|---|---|
save(String filePath) | void | บันทึกฉากลงไฟล์; รูปแบบจะถูกสรุปจากนามสกุลไฟล์ |
save(String filePath, FileFormat format) | void | บันทึกฉากลงไฟล์ในที่กำหนด FileFormat |
save(String filePath, SaveOptions options) | void | บันทึกฉากโดยใช้ตัวเลือกการบันทึกที่เฉพาะเจาะจงตามรูปแบบ |
open(String filePath) | void | เปิดไฟล์เข้าสู่ฉากนี้; รูปแบบจะถูกสรุปจากนามสกุลไฟล์ |
open(String filePath, LoadOptions options) | void | เปิดไฟล์โดยใช้ตัวเลือกการโหลดที่เฉพาะเจาะจงตามรูปแบบ |
getProperty(String name) | Object | ดึงค่าคุณสมบัติตามชื่อ |
findProperty(String name) | Property | ค้นหาคุณสมบัติตามชื่อ |
createAnimationClip(String name) | AnimationClip | สร้างคลิปแอนิเมชันใหม่ที่มีชื่อและเพิ่มลงในฉาก |
getAnimationClip(String name) | AnimationClip | ค้นหาคลิปแอนิเมชันที่มีอยู่ตามชื่อ, หรือ null หากไม่พบ |
clear() | void | ลบเนื้อหาทั้งหมดออกจากฉาก |
Overview
สร้างฉาก, เพิ่มโหนดเมช, และบันทึกเป็น 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);