【问题标题】:Can you add a light source in blender using python你可以使用python在搅拌机中添加光源吗
【发布时间】:2013-06-25 16:34:15
【问题描述】:

好吧,我对 Blender 完全陌生,我只是在寻找一些关于如何使用 python 来控制它的好教程。我希望能够通过 python 方法添加/删除/编辑光源......可以这样做吗?感谢您的建议。

【问题讨论】:

  • 你运行的是哪个版本的 Blender?

标签: python rendering blender light


【解决方案1】:

Blender 2.80 打破了旧 API,大部分步骤都发生了变化。下面更新了代码。

import bpy

# create light datablock, set attributes
light_data = bpy.data.lights.new(name="light_2.80", type='POINT')
light_data.energy = 30

# create new object with our light datablock
light_object = bpy.data.objects.new(name="light_2.80", object_data=light_data)

# link light object
bpy.context.collection.objects.link(light_object)

# make it active 
bpy.context.view_layer.objects.active = light_object

#change location
light_object.location = (5, 5, 5)

# update scene, if needed
dg = bpy.context.evaluated_depsgraph_get() 
dg.update()

【讨论】:

    【解决方案2】:

    答案是肯定的!

    看看最近的Python API

    下面的例子创建了一个新的 Lamp 对象,并把它放在当前场景中的默认位置 (5, 5, 5):

    Blender 2.63

    脚本应如下所示:

    import bpy
    
    scene = bpy.context.scene
    
    # Create new lamp datablock
    lamp_data = bpy.data.lamps.new(name="New Lamp", type='POINT')
    
    # Create new object with our lamp datablock
    lamp_object = bpy.data.objects.new(name="New Lamp", object_data=lamp_data)
    
    # Link lamp object to the scene so it'll appear in this scene
    scene.objects.link(lamp_object)
    
    # Place lamp to a specified location
    lamp_object.location = (5.0, 5.0, 5.0)
    
    # And finally select it make active
    lamp_object.select = True
    scene.objects.active = lamp_object
    

    【讨论】:

    • 谢谢!我会尝试一下。我还没有运行任何版本,但可能只会使用最新版本。
    • 我想我会的,我不是一个大艺术家......所以尝试让我的创意方面出现应该是一个爆炸:) 是否有任何真正好的资源来学习搅拌机你知道吗?
    • @innov83r 另外,还有一个用于搅拌机的 SE 站点。blender.stackexchange.com
    • 你知道如何在blender 2.80 python API中添加光。 API 似乎已更改为 Light,但我还没有让它工作。
    猜你喜欢
    • 2015-10-30
    • 2011-02-06
    • 2020-01-06
    • 2011-08-11
    • 1970-01-01
    • 2021-12-25
    • 1970-01-01
    • 2012-02-07
    • 2020-05-15
    相关资源
    最近更新 更多