Error in user YAML: (<unknown>): could not find expected ':' while scanning a simple key at line 3 column 1
---
- oeasy Python 0740
- 这是 oeasy 系统化 Python 教程,从基础一步步讲,扎实、完整、不跳步。愿意花时间学,就能真正学会。
本教程同步发布在:
个人网站: `https://oeasy.org`
蓝桥云课: `https://www.lanqiao.cn/courses/3584`
GitHub: `https://github.com/overmind1980/oeasy-python-tutorial`
Gitee: `https://gitee.com/overmind1980/oeasypython`
---import bpy
import random
# 删除所有对象
bpy.ops.object.select_all(action="SELECT")
bpy.ops.object.delete()
def create_material(name, color):
material = bpy.data.materials.new(name=name)
material.diffuse_color = color
return material
# 创建雪地
bpy.ops.mesh.primitive_plane_add(size=40)
snow = bpy.context.object
snow.name = "Snow"
snow.location = (0, 0, -7.6)
snow_material = create_material("SnowMaterial", (1, 1, 1, 1)) # 白色
snow.data.materials.append(snow_material)
# 创建雪花粒子系统
bpy.ops.mesh.primitive_plane_add(size=40, location=(0, 0, 20))
snow_plane = bpy.context.object
snow_plane.name = "SnowPlane"
snow_plane_material = create_material("SnowPlaneMaterial", (1, 1, 1, 0)) # 透明
snow_plane.data.materials.append(snow_plane_material)
bpy.ops.object.particle_system_add()
particle_system = snow_plane.particle_systems[0]
particle_system.name = "Snowfall"
settings = particle_system.settings
settings.type = 'EMITTER'
settings.render_type = 'HALO'
settings.lifetime = 200
settings.frame_start = 1
settings.frame_end = 250
settings.count = 1000
# 初始化相机
def init_camera():
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 # 焦距(毫米)
camera.sensor_width = 36 # 传感器宽度(毫米)
camera.sensor_height = 24 # 传感器高度(毫米)
camera_obj.location = (23.3, 5.9, 8.1) # 相机位置 (X, Y, Z)
camera_obj.rotation_euler = (1.172, 0, 1.8) # 相机欧拉角旋转
bpy.context.scene.camera = camera_obj
init_camera()
# 初始化光源
def init_light():
bpy.ops.object.light_add(type='SPOT', radius=3)
bpy.context.object.data.energy = 12000
bpy.context.object.location = (11.77, 11.81, 24.43)
bpy.context.object.rotation_euler = (36.3/180*3.14, 0, 124.3/180*3.14)
init_light()
# 渲染
def render():
bpy.context.scene.render.engine = 'CYCLES'
bpy.context.scene.render.filepath = '/tmp/render.png'
bpy.ops.render.render(write_still=True)
render()
- 本文来自 oeasy Python 系统教程。
- 想完整、扎实学 Python,
- 搜索 oeasy 即可。
