blender python 常见操作

参考:Basics of Adding Background Images And Textures To Your 3-D Models

blender相关版本下载:blender-release安装包下载_开源镜像站-阿里云

 当前的Quixel Bridge支持的导出资产blender版本最高为2.9.3

blender 版本:3.1.2

1、添加相机,并且相机配置上背图片:x

filepath = "G:/git_alg/dengta/digital_man/data/backgroud.jpg"
img = bpy.data.images.load(filepath)
# cam is a camera object.
cam.show_background_images = True
bg = cam.background_images.new()
bg.image =img
bg.alpha=1
bg.display_depth='BACK'
bg.frame_method="STRETCH"
bg.source="IMAGE"
bpy.context.scene.render.film_transparent = True

2、添加背景图片并且可渲染:渲染时,动态将展示内容和背景合并,对应代码如下:

### Compositing

# scene = bpy.context.scene
# nodetree = scene.node_tree
bpy.context.scene.use_nodes = True
tree = bpy.context.scene.node_tree

for every_node in tree.nodes:
    tree.nodes.remove(every_node)

#渲染层
RenderLayers_node = tree.nodes.new('CompositorNodeRLayers')
RenderLayers_node.location = -300, 300
#合成
comp_node = tree.nodes.new('CompositorNodeComposite')
comp_node.location = 400, 300


#alpha上叠
AplhaOver_node = tree.nodes.new(type="CompositorNodeAlphaOver")
AplhaOver_node.location = 150, 450


#scale_node
Scale_node = tree.nodes.new(type="CompositorNodeScale")
Scale_node.space = 'RENDER_SIZE'
Scale_node.location = -150, 500

#添加图像层
Image_node = tree.nodes.new(type="CompositorNodeImage")
Image_node.image = img
Image_node.location = -550, 500

links = tree.links
link1 = links.new(RenderLayers_node.outputs[0], AplhaOver_node.inputs[2])

link2 = links.new(AplhaOver_node.outputs[0], comp_node.inputs[0])
link3 = links.new(Scale_node.outputs[0], AplhaOver_node.inputs[1])
link4 = links.new(Image_node.outputs[0], Scale_node.inputs[0])

3、灯光布置:

light_data = bpy.data.lights.new(name="light001", type='SUN')
light_data.energy = 30

# create new object with our light datablock
light_object = bpy.data.objects.new(name="light001", 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 = (-2, -6, 5)
light_object.rotation_euler=(49.1,-20,37)
light_object.scale=(20, 20, 20)

亲测有效

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

会发paper的学渣

您的鼓励和将是我前进的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值