Error in user YAML: (<unknown>): did not find expected key while parsing a block mapping at line 1 column 1
---
show: step
version: 1.0
enable_checker: true
- 本教程同步发布在:
- 个人网站: `https://oeasy.org`
- 蓝桥云课: `https://www.lanqiao.cn/courses/3584`
- GitHub: `https://github.com/overmind1980/oeasy-python-tutorial`
- Gitee: `https://gitee.com/overmind1980/oeasypython`
---- oeasy Python 0691
- 这是 oeasy 系统化 Python 教程,从基础一步步讲,扎实、完整、不跳步。愿意花时间学,就能真正学会。
- 配套视频
- 上次我们完成了摄影机的控制
- 控制位置
- 控制旋转角度
- 如何将 摄影机拍到的东西
- 渲染成图片呢?
- 重启系统
- 再从 terminal
- 启动 blender
- 设置渲染参数
- 并且 观察代码
- 在默认场景中
- 点击 渲染
- 将默认场景中的 画面
- 渲染
- 将 摄影机拍摄到的 画面
- 进行渲染
- 将图片 另存为1.png
- 可以将 渲染的过程
- 作为 程序进行输出吗?
import bpy
bpy.context.scene.render.resolution_x = 640
bpy.context.scene.render.resolution_y = 480
bpy.context.scene.render.resolution_percentage = 50
# Set the render engine (e.g., CYCLES, BLENDER_EEVEE)
bpy.context.scene.render.engine = 'CYCLES'
# Set the output file path
bpy.context.scene.render.filepath = './render.png'
# Render the current view
bpy.ops.render.render(write_still=True)
- 观察终端
- 经过6秒左右
- 渲染出render.png
- 新开终端标签页
- 在火狐浏览器中
- 打开render.png
- 可以看到 光影效果吗?
- Add Mesh - Plane
- 设置平面的
- scale
- location
- 预览效果
- 然后准备渲染
- 再次执行
- 渲染脚本
- 经过10秒以上
- 渲染完成
firefox render.png
- 结果有了影子
- 可以 把之前的 晴天娃娃
- 整合到一起吗?
- 构造环境
import bpy
bpy.ops.object.select_all(action="SELECT") # 选择所有物体
bpy.ops.object.delete() # 删除选定的物体
bpy.ops.mesh.primitive_uv_sphere_add()
head = bpy.context.object
bpy.context.object.name = "head"
r_eye = bpy.ops.mesh.primitive_uv_sphere_add()
bpy.context.object.name = "r_eye"
bpy.context.object.location = (0.7, 0.5, 0.3)
bpy.context.object.scale = (0.3, 0.3, 0.3)
mat = bpy.data.materials.new('mat_eye')
mat.use_nodes = True
color = (0, 0, 0, 1)
mat.node_tree.nodes["Principled BSDF"].inputs['Base Color'].default_value = color
bpy.context.object.data.materials.append(mat)
bpy.context.object.parent = head
l_eye = bpy.ops.mesh.primitive_uv_sphere_add()
bpy.context.object.name = "l_eye"
bpy.context.object.location = (0.7, -0.5, 0.3)
bpy.context.object.scale = (0.3, 0.3, 0.3)
bpy.context.object.data.materials.append(mat)
bpy.context.object.parent = head
bpy.ops.mesh.primitive_cone_add()
body = bpy.context.object
body.name = "body"
body.location = (0,0,-1)
body.scale = (1,1,2)
character = bpy.data.objects.new("character", None)
bpy.data.collections["Collection"].objects.link(character)
head.parent = character
body.parent = character
bpy.ops.mesh.primitive_plane_add(size=20)
bpy.context.object.location = (0,0,-3)
camera = bpy.data.cameras.new('Camera')
camera_obj = bpy.data.objects.new('Camera', camera)
bpy.data.collections["Collection"].objects.link(camera_obj)
camera.lens = 50 # Focal length in millimeters
camera.sensor_width = 36 # Sensor width in millimeters
camera.sensor_height = 24 # Sensor height in millimeters
camera_obj.location = (13.6, 5, 10.5) # X, Y, Z coordinates
camera_obj.rotation_euler = (-2.233,3.14,-1.047)
bpy.context.scene.camera = camera_obj
bpy.context.scene.render.resolution_x = 640
bpy.context.scene.render.resolution_y = 480
bpy.context.scene.render.resolution_percentage = 50
# Set the render engine (e.g., CYCLES, BLENDER_EEVEE)
bpy.context.scene.render.engine = 'CYCLES'
# Set the output file path
bpy.context.scene.render.filepath = './render2.png'
# Render the current view
bpy.ops.render.render(write_still=True)
- 结果
- 感觉需要
- 来个灯
- 这次我们
- 设置了 渲染 参数
- 大小
- 设置了 渲染 参数
- 以前的人物 渲染出来
- 没有灯光
- 效果不好
- 需要来一盏灯!🤔
- 我们下次再说!👋
- 配套视频
- 本文来自 oeasy Python 系统教程。
- 想完整、扎实学 Python,
- 搜索 oeasy 即可。













