Light — Aspose.3D FOSS for Python API Reference

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

Light 是一个 Entity 向 3D 场景添加光源的组件。类似 Camera,,它附加到一个 Node 以控制其位置和方向。.

class Light(Camera):

Properties

A3DObjectSceneObjectEntityCameraLight

Light 继承自 Camera. Light 类本身并未公开除从 CameraEntity. LightType 枚举用于对灯光进行分类,但没有 light_type 属性在 Light 类。.


Properties

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

Properties

PropertiesPropertiesProperties
namestr光对象的名称(继承自 A3DObject).

Light 也继承所有 Camera 属性(near_plane, far_plane,,等等),尽管这些对光对象没有意义。注意: Light 类未公开 a light_type 当前 API 表面的属性。.


LightType 值

from aspose.threed.entities import LightType
PropertiesPropertiesProperties
LightType.POINT"POINT"从单一点向所有方向均匀发光。.
LightType.DIRECTIONAL"DIRECTIONAL"来自无限远源(如阳光)的平行光线。.
LightType.SPOT"SPOT"锥形光束;位置和方向很重要。.
LightType.AREA"AREA"从矩形区域发出的光。.
LightType.VOLUME"VOLUME"体积/全局光照光。.

使用示例

点光源

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)

方向光源

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

同时添加相机和光源

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)

枚举导入场景中的光源

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)

另见

 中文