blender python 光源操作笔记

方向光,可以设置为负数

比如-0.1,


def create_fangxiang_light():
    light_data = bpy.data.lights.new(name='Direct_Light', type='POINT')

    # 将光源对象转换为方向光类型
    light_data.type = 'SUN'
    light_data.energy = 10
    # 将方向光源添加到场景中
    light_object = bpy.data.objects.new(name='My Directional Light', object_data=light_data)
    bpy.context.scene.collection.objects.link(light_object)

    # 设置方向光源的方向
    light_object.rotation_euler = Vector((0, 0, 0))
    light_object.rotation_euler.rotate_axis('X', 1.5708)  # 90度弧度值
    return light_object




light_object=create_point_light(location=(3,0,0), power=1000, radius=0.001, color=(1, 1, 1))
light_object=create_fangxiang_light()
def create_point_light(location=(0, 0, 0), power=1000, radius=1, color=(1, 1, 1)):
    # 创建一个新的点光源数据
    light_data = bpy.data.lights.new(name="PointLight", type="POINT")

    # 设置光源亮度、颜色和半径
    light_data.energy = power
    light_data.color = color
    light_data.shadow_soft_size = radius

    # 创建一个新的光源对象并链接到场景
    light_object = bpy.data.objects.new("PointLight", light_data)
    bpy.context.collection.objects.link(light_object)

    # 设置光源位置
    light_object.location = location
    light_object.rotation_euler.y = 1.5708
    return light_object

设置光强度:

        for light in bpy.data.lights:
            print('---light--------------',light)
            light.energy = -0.1
            # light.color = (0,0,0)

猜你喜欢

转载自blog.csdn.net/jacke121/article/details/129919217