栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

blender python 常见操作

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

blender python 常见操作

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

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)

亲测有效

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/953953.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号