Light

Methods: aspose.threed.entities (aspose-3d-foss)

Light เป็น Entity ที่เพิ่มแหล่งกำเนิดแสงให้กับฉาก 3D. เช่น Camera, มันถูกแนบกับ Node เพื่อควบคุมตำแหน่งและทิศทางของมัน.

class Light(Camera):

Methods

A3DObjectSceneObjectEntityCameraLight

Light สืบทอดจาก Camera. ในรุ่นปัจจุบัน, the Light คลาสเองไม่ได้เปิดเผยคุณสมบัติเพิ่มเติมใด ๆ นอกเหนือจากที่สืบทอดมาจาก Camera และ Entity. LightType มี enum สำหรับจัดประเภทไฟแต่ไม่มี light_type คุณสมบัติบน Light คลาส.


Methods

Light(name: str = None)
MethodsMethodsMethodsMethods
name`strNone`None

Methods

MethodsMethodsMethods
namestrชื่อของอ็อบเจกต์ไฟ (สืบทอดจาก A3DObject).

Light ยังสืบทอดคุณสมบัติทั้งหมด Camera คุณสมบัติ (near_plane, far_plane, ฯลฯ), แม้ว่าพวกนี้จะไม่มีความหมายสำหรับอ็อบเจกต์ไฟ. หมายเหตุ: Light คลาสไม่ได้เปิดเผย light_type คุณสมบัติใน API ปัจจุบัน.


ค่าของ LightType

from aspose.threed.entities import LightType
MethodsMethodsMethods
LightType.POINT"POINT"ปล่อยแสงเท่าเทียมในทุกทิศทางจากจุดเดียว.
LightType.DIRECTIONAL"DIRECTIONAL"รังสีขนานจากแหล่งที่อยู่ไกลไม่สิ้นสุด (เช่น แสงอาทิตย์).
LightType.SPOT"SPOT"ลำแสงรูปกรวย; ตำแหน่งและทิศทางมีความสำคัญ.
LightType.AREA"AREA"แสงที่ปล่อยจากพื้นที่สี่เหลี่ยมผืนผ้า.
LightType.VOLUME"VOLUME"แสงแบบปริมาณ/การส่องสว่างทั่วโลก.

ตัวอย่างการใช้งาน

ไฟแบบ Point

from aspose.threed import Scene, FileFormat
from aspose.threed.entities import Light, LightType

scene = Scene()

light = Light("PointLight")
node = scene.root_node.create_child_node("light", light)
node.transform.set_translation(0.0, 10.0, 0.0)

scene.save("lit-scene.glb", FileFormat.GLTF)

ไฟแบบ Directional

from aspose.threed import Scene
from aspose.threed.entities import Light, LightType

scene = Scene()

sun = Light("Sun")
node = scene.root_node.create_child_node("sun", sun)
# Direction is controlled by the node's rotation
node.transform.set_euler_angles(-45.0, 30.0, 0.0)  # degrees

scene.save("directional-light.glb")

เพิ่ม Camera และ Light ทั้งสอง

from aspose.threed import Scene, FileFormat
from aspose.threed.entities import Camera, Light, LightType, ProjectionType

scene = Scene()

# Camera
cam = Camera("Cam", ProjectionType.PERSPECTIVE)
cam.field_of_view = 60.0
cam_node = scene.root_node.create_child_node("camera", cam)
cam_node.transform.set_translation(0.0, 5.0, 15.0)

# Directional light
light = Light("DirLight")
light_node = scene.root_node.create_child_node("light", light)
light_node.transform.set_euler_angles(-30.0, 45.0, 0.0)

scene.save("camera-and-light.glb", FileFormat.GLTF)

แสดงรายการ Lights ใน Scene ที่นำเข้า

from aspose.threed import Scene
from aspose.threed.entities import Light

scene = Scene()
scene.open("model.glb")

def find_lights(node, depth=0):
    if isinstance(node.entity, Light):
        print(f"{'  ' * depth}Light: {node.name}")
    for child in node.child_nodes:
        find_lights(child, depth + 1)

find_lights(scene.root_node)

ดูเพิ่มเติม

 ภาษาไทย