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 คลาสสามารถสร้างอินสแตนซ์โดยไม่มีอาร์กิวเมนต์เพื่อสร้างซีนเปล่า, หรือด้วยพารามิเตอร์ทางเลือก.

OverviewOverviewOverview
entityEntityเอนทิตี้ทางเลือกที่จะผูกกับโหนดรากเมื่อสร้าง
parentSceneSceneซีนพาเรนท์ทางเลือก (สำหรับซีนย่อย); ต้องมีชื่อ
nameStringชื่อซีน (ใช้เฉพาะกับคอนสตรัคเตอร์สองอาร์กิวเมนต์ 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.

OverviewOverviewOverviewOverviewOverview
rootNodeNodegetRootNode()โหนดรากของลำดับชั้นซีน
subScenesList<Scene>getSubScenes()ซีนย่อยที่ซ้อนอยู่ภายในซีนนี้
assetInfoAssetInfogetAssetInfo()setAssetInfo(AssetInfo)เมตาดาต้าแอสเซ็ต เช่น ผู้เขียน, วันที่สร้าง, และหน่วยวัด
animationClipsList<AnimationClip>getAnimationClips()คลิปแอนิเมชันที่กำหนดในซีน
currentAnimationClipAnimationClipgetCurrentAnimationClip()setCurrentAnimationClip(AnimationClip)คลิปแอนิเมชันที่กำลังใช้งานอยู่ในขณะนี้
libraryList<A3DObject>getLibrary()อ็อบเจ็กต์เมตาดาต้ากำหนดโดยผู้ใช้ที่ผูกกับซีน
nameStringgetName()setName(String)ชื่อของอ็อบเจ็กต์ฉาก
propertiesPropertyCollectiongetProperties()คุณสมบัติกำหนดเองที่แนบกับฉาก

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);

ดูเพิ่มเติม

 ภาษาไทย