Scene

Methods

Methods Scene คลาสใน Aspose.3D ทำหน้าที่เป็นคอนเทนเนอร์รากสำหรับเนื้อหา 3D, จัดการวัตถุระดับบนสุดและเปิดใช้งานการจัดการความสัมพันธ์พาเรนท์/ชิลด์สำหรับลำดับชั้นของซีน. มันให้การเข้าถึงโหนดรากและซับซีน, เป็นจุดเริ่มต้นสำหรับการโหลด, สร้าง, และบันทึกซีน 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 คลาสสามารถสร้างอินสแตนซ์โดยไม่มีอาร์กิวเมนต์เพื่อสร้างซีนเปล่า, หรือด้วยพารามิเตอร์ทางเลือก.

MethodsMethodsMethods
namestrชื่อของซีน (ไม่บังคับ)
entityEntityเอนทิตี้ (ไม่บังคับ) ที่จะผูกกับโหนดรากเมื่อสร้าง
parent_sceneSceneซีนพาเรนท์ (ไม่บังคับ) (สำหรับซับซีน)
from aspose.threed import Scene

# Empty scene
scene = Scene()

# Access the root node (property, not a method)
root = scene.root_node

เมธอดของคลาส

Methodsประเภทค่าที่คืนกลับMethods
Scene.from_file(file_path)Sceneโหลดซีนจากเส้นทางไฟล์ที่ระบุ, ตรวจจับรูปแบบโดยอัตโนมัติ. รับอาร์กิวเมนต์เพียงหนึ่งค่าเท่านั้น.
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 และแอตทริบิวต์ระดับซีนอื่น ๆ คือ คุณสมบัติ; เข้าถึงได้โดยไม่ต้องใช้วงเล็บ.

MethodsMethodsMethods
root_nodeNodeโหนดรากของลำดับชั้นซีน. เข้าถึงเป็นคุณสมบัติ: scene.root_node
sub_sceneslist[Scene]ซับซีนที่ซ้อนอยู่ภายในซีนนี้
asset_infoAssetInfoเมตาดาต้าแอสเซ็ต เช่น ผู้เขียน, วันที่สร้าง, และหน่วยวัด
animation_clipslist[AnimationClip]คลิปแอนิเมชันที่กำหนดในซีน
current_animation_clip`AnimationClipNone`
librarylist[CustomObject]อ็อบเจ็กต์เมตาดาต้ากำหนดโดยผู้ใช้ที่ผูกกับซีน.
namestrชื่อของอ็อบเจ็กต์ฉาก
propertiesPropertyCollectionคุณสมบัติกำหนดเองที่แนบกับฉาก

Methods

Methodsประเภทการคืนค่าMethods
save(file_path)Noneบันทึกฉากลงในไฟล์; รูปแบบสรุปจากนามสกุล
save(file_path, format)Noneบันทึกฉากลงในไฟล์ตามที่ระบุ FileFormat
save(file_path, options)Noneบันทึกฉากโดยใช้ตัวเลือกการบันทึกที่เฉพาะเจาะจงตามรูปแบบ
get_property(name)Anyดึงค่าคุณสมบัติตามชื่อ
find_property(name)Optional[Property]ค้นหาคุณสมบัติตามชื่อ
create_animation_clip(name)AnimationClipสร้างคลิปแอนิเมชันที่มีชื่อใหม่และเพิ่มลงในฉาก
get_animation_clip(name)`AnimationClipNone`
clear()Noneล้างเนื้อหาทั้งหมดออกจากฉาก

หมายเหตุ: root_node เป็น คุณสมบัติ บน Scene คลาส, ไม่ใช่วิธีการ. อย่าเขียน scene.root_node(); การเข้าถึงที่ถูกต้องคือ scene.root_node.

Methods

สร้างฉาก, เพิ่มโหนดเมช, และบันทึกเป็น 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)

ดูเพิ่มเติม

 ภาษาไทย