show | version | enable_checker |
---|---|---|
step |
1.0 |
true |
- 上次通过python设置了舞台基本要素
- 灯光
- 物体
- 摄像机
- 并且将结果渲染为一张png
- 有什么优秀作品可以看一下吗??🤔
import bpy
from math import pi
bpy.ops.object.select_all(action="SELECT")
bpy.ops.object.delete()
collection = bpy.data.collections["Collection"]
robot = bpy.data.objects.new("robot", None)
collection.objects.link(robot)
bpy.ops.mesh.primitive_cube_add(size=1.5, location=(0, 0, 4))
bpy.context.object.parent = robot
bpy.context.object.name = "head"
yellow_material = bpy.data.materials.new('YellowMaterial')
color = (1, 1, 0, 1)
yellow_material.diffuse_color = color
bpy.context.object.data.materials.append(yellow_material)
bpy.context.object.data.materials.append(yellow_material)
bpy.ops.mesh.primitive_cube_add(size=2, location=(0, 0, 2.5))
bpy.context.object.parent = robot
bpy.context.object.name = "body"
green_material = bpy.data.materials.new('GreenMaterial')
color = (0, 1, 0, 1)
green_material.diffuse_color = color
bpy.context.object.data.materials.append(green_material)
bpy.ops.mesh.primitive_cylinder_add(radius=0.3, depth=1.5, location=(-1.75, 0, 2.5))
bpy.context.object.rotation_euler[1] = pi / 2
bpy.context.object.parent = robot
bpy.context.object.name = "left_arm"
red_material = bpy.data.materials.new('RedMaterial')
color = (1, 0, 0, 1)
red_material.diffuse_color = color
bpy.context.object.data.materials.append(red_material)
bpy.context.object.data.materials.append(red_material)
bpy.ops.mesh.primitive_cylinder_add(radius=0.3, depth=1.5, location=(1.75, 0, 2.5))
bpy.context.object.rotation_euler[1] = pi / 2
bpy.context.object.parent = robot
bpy.context.object.name = "right_arm"
red_material = bpy.data.materials.new('RedMaterial')
color = (1, 0, 0, 1)
red_material.diffuse_color = color
bpy.context.object.data.materials.append(red_material)
bpy.context.object.data.materials.append(red_material)
bpy.ops.mesh.primitive_cylinder_add(radius=0.4, depth=2, location=(-0.5, 0, 0.5))
bpy.context.object.parent = robot
bpy.context.object.name = "left_leg"
yellow_material = bpy.data.materials.new('YellowMaterial')
color = (1, 1, 0, 1)
yellow_material.diffuse_color = color
bpy.context.object.data.materials.append(yellow_material)
bpy.context.object.data.materials.append(yellow_material)
bpy.ops.mesh.primitive_cylinder_add(radius=0.4, depth=2, location=(0.5, 0, 0.5))
bpy.context.object.parent = robot
bpy.context.object.name = "right_leg"
yellow_material = bpy.data.materials.new('YellowMaterial')
color = (1, 1, 0, 1)
yellow_material.diffuse_color = color
bpy.context.object.data.materials.append(yellow_material)
bpy.context.object.data.materials.append(yellow_material)
bpy.ops.mesh.primitive_uv_sphere_add(radius=0.2, location=(-0.5, 0.75, 4.25))
bpy.context.object.parent = robot
bpy.context.object.name = "left_eye"
black_material = bpy.data.materials.new('BlackMaterial')
color = (0, 0, 0, 1)
black_material.diffuse_color = color
bpy.context.object.data.materials.append(black_material)
bpy.context.object.data.materials.append(black_material)
bpy.ops.mesh.primitive_uv_sphere_add(radius=0.2, location=(0.5, 0.75, 4.25))
bpy.context.object.parent = robot
bpy.context.object.name = "right_eye"
black_material = bpy.data.materials.new('BlackMaterial')
color = (0, 0, 0, 1)
black_material.diffuse_color = color
bpy.context.object.data.materials.append(black_material)
bpy.context.object.data.materials.append(black_material)
camera = bpy.data.cameras.new('MyCamera')
camera_obj = bpy.data.objects.new('CameraObj', camera)
bpy.context.scene.collection.objects.link(camera_obj)
camera_obj.location = (-12.36, 13.48, 9.76)
camera_obj.rotation_euler = (69 * pi / 180, 0, -133 * pi / 180)
bpy.ops.mesh.primitive_plane_add(size=50, location=(0, 0, 0))
bpy.context.scene.camera = camera_obj
bpy.context.scene.render.filepath = '/tmp/rendered_robot.png'
bpy.context.scene.render.image_settings.file_format = 'PNG'
bpy.ops.object.light_add(type='SPOT', radius=10, location=(-16.02, 10, 10))
spot_light = bpy.context.object
spot_light.data.energy = 8000
spot_light.data.spot_size = pi / 4
spot_light.data.spot_blend = 0.5
spot_light.rotation_euler = (-5*pi / 180, -58*pi / 180, -27*pi / 180)
bpy.context.scene.render.resolution_x = 640
bpy.context.scene.render.resolution_y = 480
bpy.context.scene.render.resolution_percentage = 50
bpy.ops.render.render(write_still=True)
import bpy
bpy.ops.object.select_all(action="SELECT") # 取消选择所有物体
bpy.ops.object.delete() # 删除选定的物体
body = bpy.ops.mesh.primitive_cone_add()
bpy.context.object.name = "body"
bpy.context.object.location=(0, 0, 0.9)
bpy.context.object.scale=(0.85, 0.85, 0.9)
mat = bpy.data.materials.new('mat_body')
color = (1, 0.3, 0.2, 1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
bottom = bpy.ops.mesh.primitive_cylinder_add(radius=1, depth=0.08)
bpy.context.object.name = "bottom"
bpy.context.object.location=(0, 0, 0)
bpy.context.object.scale=(1, 1, 1)
mat = bpy.data.materials.new('mat_bottom')
color = (1, 0.3, 0.2, 1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
whitecircle = bpy.ops.surface.primitive_nurbs_surface_torus_add(radius=0.7)
bpy.context.object.name = "whitecircle"
bpy.context.object.location=(0, 0, 0.35)
bpy.context.object.scale=(1, 1, 1.7)
mat = bpy.data.materials.new('mat_whitecircle')
color = (2.25, 2.25, 2.25, 1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
l_eye_w = bpy.ops.mesh.primitive_uv_sphere_add()
bpy.context.object.name = "l_eye_w"
bpy.context.object.location=(0.35, -0.17, 1)
bpy.context.object.scale=(0.2,0.2,0.3)
mat = bpy.data.materials.new('mat_l_eye_w')
color = (2.25, 2.25, 2.25, 1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
r_eye_w = bpy.ops.mesh.primitive_uv_sphere_add()
bpy.context.object.name = "r_eye_w"
bpy.context.object.location=(0.35, 0.17, 1)
bpy.context.object.scale=(0.2,0.2,0.3)
mat = bpy.data.materials.new('mat_r_eye_w')
color = (2.25, 2.25, 2.25, 1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
l_eye_b = bpy.ops.mesh.primitive_uv_sphere_add()
bpy.context.object.name = "l_eye_b"
bpy.context.object.location=(0.55, -0.17, 1.1)
bpy.context.object.scale=(0.1,0.1,0.15)
mat = bpy.data.materials.new('mat_l_eye_b')
color = (0, 0, 0, 1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
r_eye_b = bpy.ops.mesh.primitive_uv_sphere_add()
bpy.context.object.name = "r_eye_b"
bpy.context.object.location=(0.55, 0.17, 1.1)
bpy.context.object.scale=(0.1,0.1,0.15)
mat = bpy.data.materials.new('mat_r_eye_b')
color = (0, 0, 0, 1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
l_mm = bpy.ops.mesh.primitive_cube_add()
bpy.context.object.name = "l_mm"
bpy.context.object.location=(0.25, -0.17, 1.35)
bpy.context.object.scale=(0.05,0.15,0.05)
mat = bpy.data.materials.new('mat_l_mm')
color = (0, 0, 0, 1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
r_mm = bpy.ops.mesh.primitive_cube_add()
bpy.context.object.name = "r_mm"
bpy.context.object.location=(0.25, 0.17, 1.35)
bpy.context.object.scale=(0.05,0.15,0.05)
mat = bpy.data.materials.new('mat_r_mm')
color = (0, 0, 0, 1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
# 添加地面
bpy.ops.mesh.primitive_plane_add(size=20, location=(0, 0, -2)) # 这里的size可以根据需要调整
# 设置地面类型为Shadow Catcher
ground = bpy.context.object
ground.name = "Ground"
ground.cycles.is_shadow_catcher = True
# 设置摄影机
bpy.ops.object.camera_add(location=(7,0.4,1.36),rotation=(-1.59, 3.14, -1.52))
camera = bpy.context.object
camera.name = "Camera"
bpy.context.scene.camera = camera
# 设置灯光
bpy.ops.object.light_add(type='SPOT',radius=1,location=(0,-2.5,2.5),rotation=(2.53, 2.62, 0.61))
light = bpy.context.object
light.name = "Light"
light.data.energy=2000#设置光照强度
# 调整渲染设置
bpy.context.scene.render.engine = 'CYCLES' # 使用Cycles渲染引擎
# 设置渲染分辨率
bpy.context.scene.render.resolution_x = 640
bpy.context.scene.render.resolution_y = 480
bpy.context.scene.render.resolution_percentage = 50
# 设置渲染输出路径
bpy.context.scene.render.filepath = "/tmp/my_render_output.png"
# 渲染图像
bpy.ops.render.render(write_still=True)
import bpy
# 清空场景
bpy.ops.object.select_all(action='DESELECT')
bpy.ops.object.select_by_type(type='MESH')
bpy.ops.object.delete()
# 创建头部
bpy.ops.mesh.primitive_cube_add(size=3, location=(0, 0, 2.5))
head = bpy.context.object
head.name = "SpongeBob_Head"
head.scale = (1.5, 0.5, 1.4)
mat = bpy.data.materials.new(name="Yellow")# 添加一个新材质
head.data.materials.append(mat)
mat.diffuse_color = (1, 0.9, 0, 1) # 设置材质的颜色为黄色
# 创建身体
bpy.ops.mesh.primitive_cube_add(size=3, location=(0, 0, -0.5))
body = bpy.context.object
body.name = "SpongeBob_Body"
body.scale = (1.5, 0.5, 0.6)
mat = bpy.data.materials.new(name="Yellow")# 添加一个新材质
body.data.materials.append(mat)
mat.diffuse_color = (1, 0.9, 0, 1) # 设置材质的颜色为黄色
# 创建鼻子
bpy.ops.object.metaball_add(type='CAPSULE', enter_editmode=False, align='WORLD', location=(0, 1, 2), scale=(0.1, 0.1, 0.1))
nose = bpy.context.object
nose.name = "Nose"
bpy.ops.object.mode_set(mode='EDIT')# 进入编辑模式
nose.scale = (0.2, 0.2, 0.2) # 调整鼻子的大小
nose.rotation_euler.x = 0.7854 # 45度旋转,X轴方向# 调整鼻子的朝向
nose.rotation_euler.y = 1.5708 # 180度旋转,Y轴方向
nose.rotation_euler.z = 0 # 0度旋转,Z轴方向
bpy.ops.object.mode_set(mode='OBJECT')# 离开编辑模式
mat_nose = bpy.data.materials.new(name="Yellow_Nose")# 添加黄色材质到鼻子上
nose.data.materials.append(mat_nose)
mat_nose.diffuse_color = (1, 0.9, 0, 1)
# 创建眼睛
bpy.ops.mesh.primitive_uv_sphere_add(radius=0.7, location=(-1, 0.7,2.7))
eye_left = bpy.context.object
eye_left.name = "Eye_Left"
bpy.ops.mesh.primitive_uv_sphere_add(radius=0.7, location=(1, 0.7, 2.7))
eye_right = bpy.context.object
eye_right.name = "Eye_Right"
mat_eye = bpy.data.materials.new(name="White_Eye")# 创建白色材质
mat_eye.diffuse_color = (1, 1, 1, 1)
for eye in [eye_left, eye_right]:# 将白色材质应用于眼睛
if eye.data.materials:
eye.data.materials[0] = mat_eye
else:
eye.data.materials.append(mat_eye)
# 创建大眼球
bpy.ops.mesh.primitive_uv_sphere_add(radius=0.5, location=(-1, 1,2.7))
Beye_left = bpy.context.object
Beye_left.name = "Beye_Left"
bpy.ops.mesh.primitive_uv_sphere_add(radius=0.5, location=(1, 1, 2.7))
Beye_right = bpy.context.object
Beye_right.name = "Beye_Right"
mat_blue_eye = bpy.data.materials.new(name="Blue_Eye")# 创建蓝色材质
mat_blue_eye.diffuse_color = (0, 0.5, 1, 1) # 蓝色,完全不透明
for eye in [Beye_left, Beye_right]:# 将蓝色材质应用于大眼球
if eye.data.materials:
eye.data.materials[0] = mat_blue_eye
else:
eye.data.materials.append(mat_blue_eye)
# 创建小眼球
bpy.ops.mesh.primitive_uv_sphere_add(radius=0.325, location=(-1, 1.2,2.65))
Seye_left = bpy.context.object
Seye_left.name = "Seye_Left"
bpy.ops.mesh.primitive_uv_sphere_add(radius=0.325, location=(1, 1.2, 2.65))
Seye_right = bpy.context.object
Seye_right.name = "Seye_Right"
# 创建黑色材质
mat_black_eye = bpy.data.materials.new(name="Black_Eye")
mat_black_eye.diffuse_color = (0, 0, 0, 0.7) # 黑色,完全不透明
# 将黑色材质应用于小眼球
for eye in [Seye_left, Seye_right]:
if eye.data.materials:
eye.data.materials[0] = mat_black_eye
else:
eye.data.materials.append(mat_black_eye)
# 创建嘴巴
bpy.ops.mesh.primitive_torus_add(align='WORLD', location=(0, 0, 1.25), rotation=(0, 0, 0), major_radius=1, minor_radius=0.25, abso_major_rad=1.25, abso_minor_rad=0.75)
mouth = bpy.context.object
mouth.name = "Mouth"
mouth.location.y = 0.9# 调整嘴巴的位置和大小
mouth.scale = (0.6, 0.6, 0.6)
# 创建红色材质
mat_red_mouth = bpy.data.materials.new(name="Red_Mouth")
mat_red_mouth.diffuse_color = (0.6, 0, 0, 1) # 红色,完全不透明
# 将红色材质应用于嘴巴
if mouth.data.materials:
mouth.data.materials[0] = mat_red_mouth
else:
mouth.data.materials.append(mat_red_mouth)
# 创建牙齿
bpy.ops.mesh.primitive_cube_add(size=0.4, location=(-0.1, 1.25, 1))
tooth1 = bpy.context.object
tooth1.name = "Tooth1"
tooth1.scale = (0.5, 0.5, 1) # 将长方体拉长,使其成为长方体形状
bpy.ops.mesh.primitive_cube_add(size=0.4, location=(0.1, 1.25, 1))
tooth2 = bpy.context.object
tooth2.name = "Tooth2"
tooth2.scale = (0.5, 0.5, 1) # 将长方体拉长,使其成为长方体形状
# 创建白色材质
mat_white_tooth = bpy.data.materials.new(name="White_Tooth")
mat_white_tooth.diffuse_color = (1, 1, 1, 1) # 白色,完全不透明
# 将白色材质应用于牙齿
for tooth in [tooth1, tooth2]:
if tooth.data.materials:
tooth.data.materials[0] = mat_white_tooth
else:
tooth.data.materials.append(mat_white_tooth)
# 创建袖子
bpy.ops.mesh.primitive_cone_add(radius1=0.7, radius2=0, depth=1, location=(-2.3, 0, 1))
cone1 = bpy.context.object
cone1.name = "Cone1"
bpy.ops.mesh.primitive_cone_add(radius1=0.7, radius2=0, depth=1, location=(2.3, 0, 1))
cone2 = bpy.context.object
cone2.name = "Cone2"
# 创建白色材质
mat_white_sleeve = bpy.data.materials.new(name="White_Sleeve")
mat_white_sleeve.diffuse_color = (1, 1, 1, 1) # 白色,完全不透明
# 将白色材质应用于袖子
for cone in [cone1, cone2]:
if cone.data.materials:
cone.data.materials[0] = mat_white_sleeve
else:
cone.data.materials.append(mat_white_sleeve)
#创建手臂
bpy.ops.mesh.primitive_cylinder_add(radius=0.1, depth=2, location=(-2.6, 0, -0.5))
arm_left = bpy.context.object
arm_left.name = "Arm_Left"
bpy.ops.mesh.primitive_cylinder_add(radius=0.1, depth=2, location=(2.6, 0,-0.5))
arm_right = bpy.context.object.copy()
arm_right.name = "Arm_Right"
# 创建手
bpy.ops.mesh.primitive_uv_sphere_add(radius=0.3, location=(-2.6, 0, -1.3))
hand_left = bpy.context.object
hand_left.name = "Hand_Left"
bpy.ops.mesh.primitive_uv_sphere_add(radius=0.3, location=(2.6, 0, -1.3))
hand_right = bpy.context.object
hand_right.name = "Hand_Right"
# 创建黄色材质
mat_yellow_arm_hand = bpy.data.materials.new(name="Yellow_Arm_Hand")
mat_yellow_arm_hand.diffuse_color = (1, 1, 0, 1) # 黄色,完全不透明
# 将黄色材质应用于手臂和手
for obj in [arm_left, arm_right, hand_left, hand_right]:
if obj.data.materials:
obj.data.materials[0] = mat_yellow_arm_hand
else:
obj.data.materials.append(mat_yellow_arm_hand)
# 创建裤子
bpy.ops.mesh.primitive_cylinder_add(radius=0.6, depth=0.5, location=(1, 0, -1.5))
pant_left = bpy.context.object
pant_left.name = "Pant_Left"
bpy.ops.mesh.primitive_cylinder_add(radius=0.6, depth=0.5, location=(-1, 0, -1.5))
pant_right = bpy.context.object.copy()
pant_right.name = "Pant_Right"
# 创建棕色材质
mat_brown_pants = bpy.data.materials.new(name="Brown_Pants")
mat_brown_pants.diffuse_color = (0.6, 0.4, 0.2, 1) # 棕色,完全不透明
# 将棕色材质应用于裤子
for pant in [pant_left, pant_right]:
if pant.data.materials:
pant.data.materials[0] = mat_brown_pants
else:
pant.data.materials.append(mat_brown_pants)
# 创建腿
bpy.ops.mesh.primitive_cylinder_add(radius=0.2, depth=2, location=(1, 0, -2.5))
leg_left = bpy.context.object
leg_left.name = "Leg_Left"
bpy.ops.mesh.primitive_cylinder_add(radius=0.2, depth=2, location=(-1, 0, -2.5))
leg_right = bpy.context.object.copy()
leg_right.name = "Leg_Right"
# 创建黄色材质
mat_yellow_leg = bpy.data.materials.new(name="Yellow_Leg")
mat_yellow_leg.diffuse_color = (1, 1, 0, 1) # 黄色,完全不透明
# 将黄色材质应用于腿
for leg in [leg_left, leg_right]:
if leg.data.materials:
leg.data.materials[0] = mat_yellow_leg
else:
leg.data.materials.append(mat_yellow_leg)
# 创建鞋跟
bpy.ops.mesh.primitive_cube_add(size=0.7, location=(1, 0, -3.5))
heel_left = bpy.context.object
heel_left.name = "Heel_Left"
bpy.ops.mesh.primitive_cube_add(size=0.7, location=(-1, 0, -3.5))
heel_right = bpy.context.object
heel_right.name = "Heel_Right"
# 创建鞋头
bpy.ops.mesh.primitive_uv_sphere_add(radius=0.6, location=(1, 0.6, -3.5))
toe_left = bpy.context.object
toe_left.name = "Toe_Left"
bpy.ops.mesh.primitive_uv_sphere_add(radius=0.6, location=(-1, 0.6, -3.5))
toe_right = bpy.context.object
toe_right.name = "Toe_Right"
# 创建黑色材质
mat_black_shoe = bpy.data.materials.new(name="Black_Shoe")
mat_black_shoe.diffuse_color = (0, 0, 0, 1) # 黑色,完全不透明
# 将黑色材质应用于鞋跟和鞋头
for obj in [heel_left, heel_right, toe_left, toe_right]:
if obj.data.materials:
obj.data.materials[0] = mat_black_shoe
else:
obj.data.materials.append(mat_black_shoe)
# 创建领带
bpy.ops.mesh.primitive_cube_add(size=0.5, location=(0, 0.75, 0.15))
tie_main = bpy.context.object
tie_main.name = "Tie_Main"
# 创建领结
bpy.ops.mesh.primitive_cone_add(radius1=0.3, radius2=0, depth=0.8, location=(0, 0.75, -0.4))
tie_knot = bpy.context.object
tie_knot.name = "Tie_Knot"
# 创建正圆锥
bpy.ops.mesh.primitive_cone_add(radius1=0.3, radius2=0, depth=0.4, location=(0, 0.75, -1))
cone_positive = bpy.context.object
cone_positive.name = "Cone_Positive"
# 创建倒圆锥
bpy.ops.mesh.primitive_cone_add(radius1=0.3, radius2=0, depth=0.4, location=(0, 0.75, -1))
cone_negative = bpy.context.object
cone_negative.name = "Cone_Negative"
cone_negative.rotation_euler.y = 3.1416 # 调整倒圆锥的位置使其倒立
# 创建棕色材质
mat_brown_tie = bpy.data.materials.new(name="Brown_Tie")
mat_brown_tie.diffuse_color = (0.6, 0.4, 0.2, 1) # 棕色,完全不透明
# 将棕色材质应用于领带
for obj in [tie_main, tie_knot, cone_positive, cone_negative]:
if obj.data.materials:
obj.data.materials[0] = mat_brown_tie
else:
obj.data.materials.append(mat_brown_tie)
# 添加地面
bpy.ops.mesh.primitive_plane_add(size=20, location=(0, 0, -4)) # 这里的size可以根据需要调整
# 设置地面类型为Shadow Catcher
ground = bpy.context.object
ground.name = "Ground"
ground.cycles.is_shadow_catcher = True
# 设置摄影机
camera_data = bpy.data.cameras.new('Camera') # 创建摄影机数据
camera_obj = bpy.data.objects.new('Camera', camera_data) # 使用摄影机数据创建摄影机对象
bpy.data.collections["Collection"].objects.link(camera_obj) # 将摄影机对象添加到场景中
camera_data.lens = 50 # 焦距(毫米)
camera_data.sensor_width = 36 # 传感器宽度(毫米)
camera_data.sensor_height = 24 # 传感器高度(毫米)
camera_obj.location =(13.6, 8, 12) # 摄影机位置(X、Y、Z坐标)
camera_obj.rotation_euler = (-2.233, 3.14, -1.047)# 摄影机旋转欧拉角
bpy.context.scene.camera = camera_obj # 将当前摄影机设置为场景摄影机
# 添加聚光灯
bpy.ops.object.light_add(type='SPOT', radius=3) # 添加聚光灯
spot_light = bpy.context.object # 获取新添加的聚光灯对象
spot_light.data.energy = 5000 # 设置聚光灯能量
spot_light.location = (7, -7, 5) # 设置聚光灯位(X、Y、Z坐标)
spot_light.rotation_euler = (1.172 ,0, 0.907) # 设置聚光灯旋转欧拉角
# 设置渲染分辨率
bpy.context.scene.render.resolution_x = 640 # 渲染分辨率宽度
bpy.context.scene.render.resolution_y = 480 # 渲染分辨率高度
bpy.context.scene.render.resolution_percentage = 50 # 渲染分辨率百分比
# 渲染设置
bpy.context.scene.render.engine = 'CYCLES'
bpy.context.scene.render.filepath = "/tmp/r.png" # 设置渲染结果保存路径
# 执行渲染
bpy.ops.render.render(write_still=True)
import bpy
import math
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete()
bpy.ops.mesh.primitive_torus_add(
align='WORLD',
location=(0, 0, 0),
rotation=(2, 0, 0),
major_radius=2,
minor_radius=1,
abso_major_rad=1.25,
abso_minor_rad=0.75
)
torus = bpy.context.object
torus.name = "身体"
torus.rotation_euler = (math.pi / 2, 0, 0)
bpy.ops.mesh.primitive_uv_sphere_add(
radius=0.3,
location=(-0.8, -1, 1.5)
)
sphere = bpy.context.object
sphere.name = "左眼"
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.transform.resize(value=(-1.3, -1, 1.8))
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.mesh.primitive_uv_sphere_add(
radius=0.3,
location=(0.8, -1, 1.5)
)
sphere = bpy.context.object
sphere.name = "右眼"
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.transform.resize(value=(1.3, -1, 1.8))
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.mesh.primitive_uv_sphere_add(
radius=0.15,
location=(-0.8, -1.2, 1.5)
)
sphere = bpy.context.object
sphere.name = "左眼珠"
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.transform.resize(value=(-1.3, -1.2, 1.8))
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.mesh.primitive_uv_sphere_add(
radius=0.15,
location=(0.8, -1.2, 1.5)
)
sphere = bpy.context.object
sphere.name = "右眼珠"
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.transform.resize(value=(1.3, -1.2, 1.8))
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.mesh.primitive_torus_add(
align='WORLD',
location=(0, -1, -1.5),
rotation=(0, 0, 0),
major_radius=0.5,
minor_radius=0.25,
abso_major_rad=1.25,
abso_minor_rad=0.75
)
torus = bpy.context.object
torus.name = "嘴"
torus.rotation_euler = (math.pi / 2, 0, 0)
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.transform.resize(value=(1, -1, 1.2))
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.mesh.primitive_torus_add(
align='WORLD',
location=(-3, -0.3, 0),
rotation=(0, 0, 0),
major_radius=0.8,
minor_radius=0.3,
abso_major_rad=1.25,
abso_minor_rad=0.75
)
torus = bpy.context.object
torus.name = "左胳膊"
torus.rotation_euler = (math.pi / 2, 0, 0)
bpy.ops.mesh.primitive_torus_add(
align='WORLD',
location=(3, -0.3, 0),
rotation=(0, 0, 0),
major_radius=0.8,
minor_radius=0.3,
abso_major_rad=1.25,
abso_minor_rad=0.75
)
torus = bpy.context.object
torus.name = "右胳膊"
torus.rotation_euler = (math.pi / 2, 0, 0)
bpy.ops.mesh.primitive_cylinder_add(
radius=0.2,
depth=2,
enter_editmode=False,
align='WORLD',
location=(-1, -0.3, -3),
scale=(1, 1, 1)
)
torus = bpy.context.object
torus.name = "左腿"
bpy.ops.mesh.primitive_cylinder_add(
radius=0.2,
depth=2,
enter_editmode=False,
align='WORLD',
location=(1, -0.3, -3),
scale=(1, 1, 1)
)
torus = bpy.context.object
torus.name = "右腿"
bpy.ops.mesh.primitive_uv_sphere_add(
radius=0.4,
location=(-1, -0.15, -4)
)
sphere = bpy.context.object
sphere.name = "左脚"
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.transform.resize(value=(-3, -1, -1))
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.transform.translate(value=(-0.4, -0.15, 0))
bpy.ops.transform.resize(value=(0.7, 1, 1))
bpy.ops.mesh.primitive_uv_sphere_add(
radius=0.4,
location=(1, -0.15, -4)
)
sphere = bpy.context.object
sphere.name = "右脚"
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.transform.resize(value=(3, -1, -1))
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.transform.translate(value=(0.4, -0.15, 0))
bpy.ops.transform.resize(value=(0.7, 1, 1))
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.shade_smooth()
from mathutils import Color
bpy.data.objects['身体'].select_set(True)
bpy.context.view_layer.objects.active = bpy.data.objects['身体']
mat = bpy.data.materials.new('mat_eye')
color = (0.013,0.718,0.290,1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
from mathutils import Color
bpy.data.objects['左眼珠'].select_set(True)
bpy.context.view_layer.objects.active = bpy.data.objects['左眼珠']
mat = bpy.data.materials.new('mat_eye')
color = (0, 0, 0, 1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
from mathutils import Color
bpy.data.objects['右眼珠'].select_set(True)
bpy.context.view_layer.objects.active = bpy.data.objects['右眼珠']
mat = bpy.data.materials.new('mat_eye')
color = (0, 0, 0, 1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
from mathutils import Color
bpy.data.objects['嘴'].select_set(True)
bpy.context.view_layer.objects.active = bpy.data.objects['嘴']
mat = bpy.data.materials.new('mat_eye')
color = (0.801,0.034,0.060,1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
from mathutils import Color
bpy.data.objects['左胳膊'].select_set(True)
bpy.context.view_layer.objects.active = bpy.data.objects['左胳膊']
mat = bpy.data.materials.new('mat_eye')
color = (1,0.894,0,1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
from mathutils import Color
bpy.data.objects['右胳膊'].select_set(True)
bpy.context.view_layer.objects.active = bpy.data.objects['右胳膊']
mat = bpy.data.materials.new('mat_eye')
color = (1,0.894,0,1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
from mathutils import Color
bpy.data.objects['左腿'].select_set(True)
bpy.context.view_layer.objects.active = bpy.data.objects['左腿']
mat = bpy.data.materials.new('mat_eye')
color = (1,0.912,0.522,1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
from mathutils import Color
bpy.data.objects['右腿'].select_set(True)
bpy.context.view_layer.objects.active = bpy.data.objects['右腿']
mat = bpy.data.materials.new('mat_eye')
color = (1,0.912,0.522,1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
from mathutils import Color
bpy.data.objects['左脚'].select_set(True)
bpy.context.view_layer.objects.active = bpy.data.objects['左脚']
mat = bpy.data.materials.new('mat_eye')
color = (0,0.045,0.707,1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
from mathutils import Color
bpy.data.objects['右脚'].select_set(True)
bpy.context.view_layer.objects.active = bpy.data.objects['右脚']
mat = bpy.data.materials.new('mat_eye')
color = (0,0.045,0.707,1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
camera = bpy.data.cameras.new('MyCamera')
camera_obj = bpy.data.objects.new('CameraObj', camera)
bpy.context.scene.collection.objects.link(camera_obj)
camera.lens = 50
camera.sensor_width = 36
camera.sensor_height = 24
camera_obj.location = (1, -25, 7.5)
camera_obj.rotation_euler = (-5, 0, 0)
bpy.ops.object.light_add(type='SPOT', radius=1)
bpy.context.object.data.energy = 10000
bpy.context.object.location = (18, -15, 10)
bpy.context.object.rotation_euler = (1.172,0,0.907)
bpy.context.scene.render.resolution_x = 640
bpy.context.scene.render.resolution_y = 480
bpy.context.scene.render.resolution_percentage = 50
#渲染?
bpy.context.scene.camera = camera_obj
# 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 = '/tmp/render2.png'
# Render the current view
bpy.ops.render.render(write_still=True)
import bpy
import math
# 删除默认场景中的所有对象
bpy.ops.object.select_all(action="SELECT")
bpy.ops.object.delete()
# 创建小鸟的身体
bpy.ops.mesh.primitive_cube_add(location=(0, 0, 0))
body = bpy.context.object
body.name = "Bird_Body"
body.scale = (1, 0.6, 0.5) # 调整尺寸以使其看起来更像小鸟身体
# 创建小鸟的头部并为其应用棕色材质
bpy.ops.mesh.primitive_uv_sphere_add(location=(0, 1, 1), radius=0.7)
head = bpy.context.object
head.name = "Bird_Head"
# 设置头部的材质和颜色
def assign_color(obj, color):
mat = bpy.data.materials.new(name="ColorMaterial")
mat.diffuse_color = color
if obj.data.materials:
obj.data.materials[0] = mat
else:
obj.data.materials.append(mat)
# 将头部设置为棕色
assign_color(head, (0.6, 0.4, 0.2, 1)) # 棕色
# 创建小鸟的眼睛并将其嵌入头部
bpy.ops.mesh.primitive_uv_sphere_add(location=(-0.3, 1.3, 1.5), radius=0.2)
eye_left = bpy.context.object
eye_left.name = "Eye_Left"
bpy.ops.mesh.primitive_uv_sphere_add(location=(0.3, 1.3, 1.5), radius=0.2)
eye_right = bpy.context.object
eye_right.name = "Eye_Right"
# 将眼睛设置为黑色
assign_color(eye_left, (0, 0, 0, 1)) # 黑色
assign_color(eye_right, (0, 0, 0, 1)) # 黑色
# 创建小鸟的耳朵并将其放在头上方
bpy.ops.mesh.primitive_cone_add(location=(0, 1.8, 1.2), radius1=0.1, radius2=0.5, depth=0.5)
ear_left = bpy.context.object
ear_left.name = "Ear_Left"
bpy.ops.mesh.primitive_cone_add(location=(0, 1.8, 1.2), radius1=0.1, radius2=0.5, depth=0.5)
ear_right = bpy.context.object
ear_right.name = "Ear_Right"
# 将耳朵设置为棕色
assign_color(ear_left, (0.8, 0.6, 0.4, 1)) # 棕色
assign_color(ear_right, (0.8, 0.6, 0.4, 1))
# 创建小鸟的尾巴
bpy.ops.mesh.primitive_cylinder_add(location=(0, -0.7, 0), radius=0.1, depth=1.5, rotation=(1.5708, 0, 0))
tail = bpy.context.object
tail.name = "Bird_Tail"
# 创建小鸟的腿,均匀分布在四个角的下方
leg_locations = [(-0.5, -0.6, 0.5), (0.5, -0.6, 0.5)]
legs = []
for loc in leg_locations:
bpy.ops.mesh.primitive_cylinder_add(location=loc, radius=0.1, depth=0.8, rotation=(1.5708, 0, 0))
leg = bpy.context.object
leg.name = "Leg_" + str(len(legs) + 1)
legs.append(leg)
# 设置其他部分的材质和颜色
# 小鸟身体颜色
assign_color(body, (0.6, 0.4, 0.2, 1)) # 棕色
# 小鸟尾巴颜色
assign_color(tail, (0.6, 0.4, 0.2, 1)) # 棕色
# 小鸟腿颜色
for leg in legs:
assign_color(leg, (0.6, 0.4, 0.2, 1)) # 棕色
# 创建翅膀
bpy.ops.mesh.primitive_plane_add(location=(-1.5, 0, 0), rotation=(0, 0, 0), size=1)
wing_left = bpy.context.object
wing_left.name = "Wing_Left"
bpy.ops.mesh.primitive_plane_add(location=(1.5, 0, 0), rotation=(0, 0, 3.14159), size=1)
wing_right = bpy.context.object
wing_right.name = "Wing_Right"
# 设置翅膀的颜色为黄色
assign_color(wing_left, (1, 1, 0, 1)) # 黄色
assign_color(wing_right, (1, 1, 0, 1)) # 黄色
# 添加地面
bpy.ops.mesh.primitive_plane_add(size=20, location=(0, 0, -2)) # 这里的size可以根据需要调整
# 设置地面类型为Shadow Catcher
ground = bpy.context.object
ground.name = "Ground"
ground.cycles.is_shadow_catcher = True
# 创建灯光
bpy.ops.object.light_add(type='POINT', radius=1, location=(0, 0, 5))
light = bpy.context.object
light.name = "Light"
light.data.energy = 3000 # 设置光照强度
# 创建摄影机
bpy.ops.object.camera_add(location=(2, 6, 3))
camera = bpy.context.object
camera.name = "Camera"
bpy.context.scene.camera = camera
# 设置摄影机坐标和旋转角度
camera.location = (6, -6, 5)
camera.rotation_euler = (math.radians(60), 0, math.radians(45))
# 渲染设置
bpy.context.scene.render.engine = 'CYCLES'
bpy.context.scene.render.filepath = "/tmp/render2.png" # 设置渲染结果保存路径
# 执行渲染
bpy.ops.render.render(write_still=True)
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"
head.location = (0,0,4)
head.scale = (1,1,1)
mat6 = bpy.data.materials.new('mat_head')
color6 = (1, 2, 1, 2)
mat6.diffuse_color = color6
bpy.context.object.data.materials.append(mat6)
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.2, 0.2, 0.2)
mat1 = bpy.data.materials.new('mat_eye')
color1 = (0, 0, 0, 1)
mat1.diffuse_color = color1
bpy.context.object.data.materials.append(mat1)
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.2, 0.2, 0.2)
bpy.context.object.data.materials.append(mat1)
bpy.context.object.parent = head
r_ear = bpy.ops.mesh.primitive_uv_sphere_add()
r_ear = bpy.context.object
r_ear.name = "r_ear"
r_ear.location = (0.3,0.8,0.1)
r_ear.scale = (0.2,0.2,0.3)
mat2 = bpy.data.materials.new('mat_ear')
color2 = (2, 1, 1, 1)
mat2.diffuse_color = color2
bpy.context.object.data.materials.append(mat2)
bpy.context.object.parent = head
l_ear = bpy.ops.mesh.primitive_uv_sphere_add()
l_ear = bpy.context.object
l_ear.name = "r_ear"
l_ear.location = (0.3,-0.8,0.1)
l_ear.scale = (0.2,0.2,0.3)
bpy.context.object.data.materials.append(mat2)
bpy.context.object.parent = head
nose = bpy.ops.mesh.primitive_cone_add()
nose = bpy.context.object
nose.name = "nose"
nose.location = (1,0,0.1)
nose.scale = (0.1,0.1,0.2)
mat3 = bpy.data.materials.new('mat_nose')
color3 = (1, 0, 0, 3)
mat3.diffuse_color = color3
bpy.context.object.data.materials.append(mat3)
bpy.context.object.parent = head
body = bpy.ops.mesh.primitive_cylinder_add()
body = bpy.context.object
body.name = "body"
body.location = (0,0,2)
body.scale = (1,1,1)
mat = bpy.data.materials.new('mat_body')
color = (0, 0, 1, 2)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
l_arm = bpy.ops.mesh.primitive_cylinder_add()
l_arm = bpy.context.object
l_arm.name = "l_arm"
l_arm.location = (0,-1,0)
l_arm.scale = (0.2,0.2,1)
mat4 = bpy.data.materials.new('mat_arm')
color4 = (1, 2, 0, 3)
mat4.diffuse_color = color4
bpy.context.object.data.materials.append(mat4)
bpy.context.object.parent = body
r_arm = bpy.ops.mesh.primitive_cylinder_add()
r_arm = bpy.context.object
r_arm.name = "r_arm"
r_arm.location = (0,1,0)
r_arm.scale = (0.2,0.2,1)
bpy.context.object.data.materials.append(mat4)
bpy.context.object.parent = body
l_leg = bpy.ops.mesh.primitive_cylinder_add()
l_leg = bpy.context.object
l_leg.name = "l_leg"
l_leg.location = (0,-0.6,-2)
l_leg.scale = (0.2,0.2,1)
mat5 = bpy.data.materials.new('mat_leg')
color5 = (5, 1, 0, 2)
mat5.diffuse_color = color5
bpy.context.object.data.materials.append(mat5)
bpy.context.object.parent = body
r_leg = bpy.ops.mesh.primitive_cylinder_add()
r_leg = bpy.context.object
r_leg.name = "r_leg"
r_leg.location = (0,0.6,-2)
r_leg.scale = (0.2,0.2,1)
bpy.context.object.data.materials.append(mat5)
bpy.context.object.parent = body
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 = (8, 2.236, 9.95) # X, Y, Z coordinates
camera_obj.rotation_euler = (-2.285,3.14,-1.165)
bpy.context.scene.camera = camera_obj
bpy.ops.object.light_add(type='SPOT', radius=1)
bpy.context.object.data.energy = 3000
bpy.context.object.location = (6.27,-3.4,5.62)
bpy.context.object.rotation_euler = (1.172,0,0.907)
bpy.context.scene.render.resolution_x = 640
bpy.context.scene.render.resolution_y = 480
bpy.context.scene.render.resolution_percentage = 50
bpy.context.scene.render.engine = 'CYCLES'
bpy.context.scene.render.filepath = '/tmp/render2.png'
bpy.ops.render.render(write_still=True)
import bpy
import random
# 清除现有对象
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete()
# 创建 pop_Mart 对象
pop_Mart = bpy.data.objects.new("pop_Mart", None)
bpy.data.collections["Collection"].objects.link(pop_Mart)
# 创建头部
bpy.ops.mesh.primitive_uv_sphere_add(radius=1.0, location=(0, 0, 1.5))
head = bpy.context.object
head.parent = pop_Mart
head.name = "Head"
# 创建身体
bpy.ops.mesh.primitive_cylinder_add(radius=0.75, depth=1.5, location=(0, 0, 0.5))
body = bpy.context.object
body.parent = pop_Mart
body.name = "Body"
# 创建左眼
bpy.ops.mesh.primitive_uv_sphere_add(radius=0.15, location=(-0.35, 0.9, 1.75))
left_eye = bpy.context.object
left_eye.parent = pop_Mart
left_eye.name = "left_eye"
# 创建右眼
bpy.ops.mesh.primitive_uv_sphere_add(radius=0.15, location=(0.35, 0.9, 1.75))
right_eye = bpy.context.object
right_eye.parent = pop_Mart
right_eye.name = "right_eye"
# 创建左臂
bpy.ops.mesh.primitive_cylinder_add(radius=0.15, depth=1.0, location=(-1.0, 0, 0.75))
left_arm = bpy.context.object
left_arm.parent = pop_Mart
left_arm.name = "left_arm"
# 创建右臂
bpy.ops.mesh.primitive_cylinder_add(radius=0.15, depth=1.0, location=(1.0, 0, 0.75))
right_arm = bpy.context.object
right_arm.parent = pop_Mart
right_arm.name = "right_arm"
# 创建左腿
bpy.ops.mesh.primitive_cylinder_add(radius=0.2, depth=1.0, location=(-0.4, 0, -0.5))
left_leg = bpy.context.object
left_leg.parent = pop_Mart
left_leg.name = "left_leg"
# 创建右腿
bpy.ops.mesh.primitive_cylinder_add(radius=0.2, depth=1.0, location=(0.4, 0, -0.5))
right_leg = bpy.context.object
right_leg.parent = pop_Mart
right_leg.name = "right_leg"
# 函数:为对象创建材质并应用随机颜色
def create_random_material(obj):
mat = bpy.data.materials.new(name=obj.name + "_Material")
red = random.random()
green = random.random()
blue = random.random()
alpha = 1.0
mat.diffuse_color = (red, green, blue, alpha)
obj.data.materials.append(mat)
# 应用随机材质和颜色
create_random_material(head)
create_random_material(body)
create_random_material(left_eye)
create_random_material(right_eye)
create_random_material(left_arm)
create_random_material(right_arm)
create_random_material(left_leg)
create_random_material(right_leg)
# 创建和设置摄影机
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 = (0, 10, 3) # 摄影机放置在模型的正前方
camera_obj.rotation_euler = (1.36, 0, 3.14) # 调整角度正对模型
bpy.context.scene.camera = camera_obj
# 创建和设置灯光
light_data = bpy.data.lights.new(name="Light", type='POINT')
light = bpy.data.objects.new(name="Light", object_data=light_data)
bpy.context.collection.objects.link(light)
light.location = (5, 5, 5)
light.data.energy = 1000 # 调整灯光强度
# 添加地面
bpy.ops.mesh.primitive_plane_add(size=20)
bpy.context.object.location = (0, 0, -1)
# 设置渲染参数
bpy.context.scene.render.resolution_x = 640
bpy.context.scene.render.resolution_y = 480
bpy.context.scene.render.resolution_percentage = 100
bpy.context.scene.render.engine = 'CYCLES' # 使用 Cycles 渲染引擎
bpy.context.scene.render.filepath = "/tmp/r.png" # 输出文件路径
# 渲染当前视图
bpy.ops.render.render(write_still=True)
import bpy
from math import pi
bpy.ops.object.select_all(action="SELECT")
bpy.ops.object.delete()
collection = bpy.data.collections["Collection"]
robot = bpy.data.objects.new("robot", None)
collection.objects.link(robot)
bpy.ops.mesh.primitive_cube_add(size=1.5, location=(0, 0, 5))
bpy.context.object.parent = robot
bpy.context.object.name = "head"
skin_material = bpy.data.materials.new('SkinMaterial')
color = (1, 0.7, 0.7, 1)
skin_material.diffuse_color = color
bpy.context.object.data.materials.append(skin_material)
bpy.ops.mesh.primitive_cone_add(scale = (0.8,0.8,2),location = (0,0,7.8))
bpy.context.object.parent = robot
bpy.context.object.name = "hat1"
hat1_material = bpy.data.materials.new('Hat1Material')
color = (1, 0.7, 0.2, 1)
hat1_material.diffuse_color = color
bpy.context.object.data.materials.append(hat1_material)
bpy.ops.mesh.primitive_torus_add(location=(0,0,6))
bpy.context.object.parent = robot
bpy.context.object.name = "hat2"
bpy.ops.mesh.primitive_uv_sphere_add(scale = (0.5,0.5,0.5),location = (0,0,7.5))
bpy.context.object.parent = robot
bpy.context.object.name = "hat3"
hat3_material = bpy.data.materials.new('Hat3Material')
color = (0.5, 0, 0.2, 1)
hat3_material.diffuse_color = color
bpy.context.object.data.materials.append(hat3_material)
bpy.ops.mesh.primitive_uv_sphere_add(scale = (0.5,0.5,0.5),location = (0,0,9.5))
bpy.context.object.parent = robot
bpy.context.object.name = "hat4"
hat4_material = bpy.data.materials.new('Hat4Material')
color = (0.5, 0, 0.2, 1)
hat4_material.diffuse_color = color
bpy.context.object.data.materials.append(hat4_material)
bpy.ops.mesh.primitive_cone_add(scale = (2,2,2),location = (0,0,3.5))
bpy.context.object.parent = robot
bpy.context.object.name = "body"
pink_material = bpy.data.materials.new('PinkMaterial')
color = (1, 0.5, 1, 1)
pink_material.diffuse_color = color
bpy.context.object.data.materials.append(pink_material)
bpy.ops.mesh.primitive_torus_add(location=(0,0,3))
bpy.context.object.parent = robot
bpy.context.object.name = "decorate1"
dec1_material = bpy.data.materials.new('Dec1Material')
color = (0, 0.2, 1, 1)
dec1_material.diffuse_color = color
bpy.context.object.data.materials.append(dec1_material)
bpy.ops.mesh.primitive_uv_sphere_add(scale = (0.35,0.35,0.35),location = (-1,1,2.5))
bpy.context.object.parent = robot
bpy.context.object.name = "decorate2"
dec2_material = bpy.data.materials.new('Dec2Material')
color = (0.2, 0, 0.7, 1)
dec2_material.diffuse_color = color
bpy.context.object.data.materials.append(dec2_material)
bpy.ops.mesh.primitive_uv_sphere_add(scale = (0.35,0.35,0.35),location = (1,1,2.5))
bpy.context.object.parent = robot
bpy.context.object.name = "decorate3"
dec3_material = bpy.data.materials.new('Dec3Material')
color = (0, 1, 0.5, 1)
dec3_material.diffuse_color = color
bpy.context.object.data.materials.append(dec3_material)
bpy.ops.mesh.primitive_cylinder_add(radius=0.3, depth=1.5, location=(-1.35, 0, 3.5))
bpy.context.object.rotation_euler[1] = pi / 6
bpy.context.object.parent = robot
bpy.context.object.name = "left_arm"
larm_material = bpy.data.materials.new('LarmMaterial')
color = (1, 0.3, 0.2, 1)
larm_material.diffuse_color = color
bpy.context.object.data.materials.append(larm_material)
bpy.ops.mesh.primitive_uv_sphere_add(scale=(0.35,0.35,0.35), location=(-1.35, 0, 3.5))
bpy.context.object.parent = robot
bpy.ops.mesh.primitive_cylinder_add(radius=0.3, depth=1.5, location=(1.75, 0, 3.75))
bpy.context.object.rotation_euler[1] = pi / 2
bpy.context.object.parent = robot
bpy.context.object.name = "right_arm"
rarm_material = bpy.data.materials.new('RarmMaterial')
color = (1, 0.3, 0.2, 1)
rarm_material.diffuse_color = color
bpy.context.object.data.materials.append(rarm_material)
bpy.ops.mesh.primitive_uv_sphere_add(scale=(0.35,0.35,0.35), location=(1.75, 0, 3.75))
bpy.context.object.parent = robot
bpy.ops.mesh.primitive_cylinder_add(radius=0.4, depth=2, location=(-0.5, 0, 1.5))
bpy.context.object.parent = robot
bpy.context.object.name = "left_leg"
yellow_material = bpy.data.materials.new('YellowMaterial')
color = (1, 0.5, 0.2, 1)
yellow_material.diffuse_color = color
bpy.context.object.data.materials.append(yellow_material)
bpy.ops.mesh.primitive_uv_sphere_add(scale=(0.45,0.45,0.45), location=(-0.5, 0, 0.5))
bpy.context.object.parent = robot
bpy.ops.mesh.primitive_cylinder_add(radius=0.4, depth=2, location=(0.5, 0, 1.5))
bpy.context.object.parent = robot
bpy.context.object.name = "right_leg"
yellow_material = bpy.data.materials.new('YellowMaterial')
color = (1, 1, 0, 1)
yellow_material.diffuse_color = color
bpy.context.object.data.materials.append(yellow_material)
bpy.ops.mesh.primitive_uv_sphere_add(scale=(0.45,0.45,0.45), location=(0.5, 0, 0.5))
bpy.context.object.parent = robot
bpy.ops.mesh.primitive_uv_sphere_add(radius=0.2, location=(-0.5, 0.75, 5.25))
bpy.context.object.parent = robot
bpy.context.object.name = "left_eye"
black_material = bpy.data.materials.new('BlackMaterial')
color = (0, 0, 0, 1)
black_material.diffuse_color = color
bpy.context.object.data.materials.append(black_material)
bpy.ops.mesh.primitive_uv_sphere_add(radius=0.2, location=(0.5, 0.75, 5.25))
bpy.context.object.parent = robot
bpy.context.object.name = "right_eye"
black_material = bpy.data.materials.new('BlackMaterial')
color = (0, 0, 0, 1)
black_material.diffuse_color = color
bpy.context.object.data.materials.append(black_material)
camera = bpy.data.cameras.new('MyCamera')
camera_obj = bpy.data.objects.new('CameraObj', camera)
bpy.context.scene.collection.objects.link(camera_obj)
camera_obj.location = (-12.36, 15.48, 12.76)
camera_obj.rotation_euler = (69 * pi / 180, 0, -133 * pi / 180)
bpy.ops.mesh.primitive_plane_add(size=50, location=(0, 0, 0))
bpy.context.scene.camera = camera_obj
bpy.context.scene.render.filepath = '/tmp/rendered_robot.png'
bpy.context.scene.render.image_settings.file_format = 'PNG'
bpy.ops.object.light_add(type='SPOT', radius=10, location=(-16.02, 10, 10))
spot_light = bpy.context.object
spot_light.data.energy = 8000
spot_light.data.spot_size = pi / 4
spot_light.data.spot_blend = 0.5
spot_light.rotation_euler = (-5*pi / 180, -58*pi / 180, -27*pi / 180)
bpy.context.scene.render.resolution_x = 640
bpy.context.scene.render.resolution_y = 480
bpy.context.scene.render.resolution_percentage = 50
bpy.context.scene.render.engine = 'CYCLES'
bpy.context.scene.render.filepath = '/tmp/1.png'
bpy.ops.render.render(write_still=True)
import bpy
bpy.ops.mesh.primitive_uv_sphere_add(radius=1, enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(2.5, 3, 2.5))
bpy.ops.object.shade_smooth()
obj = bpy.context.object
mat = bpy.data.materials.new(name="headear")
obj.data.materials.append(mat)
mat.diffuse_color = (0.800236, 0.535324, 0.328868, 1)
obj.name = "head"
bpy.ops.mesh.primitive_uv_sphere_add(radius=1, enter_editmode=False, align='WORLD', location=(0, 2, 2), scale=(0.7, 1, 0.7))
bpy.ops.object.shade_smooth()
obj = bpy.context.object
mat = bpy.data.materials.new(name="headear")
obj.data.materials.append(mat)
mat.diffuse_color = (0.800236, 0.535324, 0.328868, 1)
obj.name = "ear1"
bpy.ops.mesh.primitive_uv_sphere_add(radius=1, enter_editmode=False, align='WORLD', location=(0, -2, 2), scale=(0.7, 1, 0.7))
bpy.ops.object.shade_smooth()
obj = bpy.context.object
mat = bpy.data.materials.new(name="headear")
obj.data.materials.append(mat)
mat.diffuse_color = (0.800236, 0.535324, 0.328868, 1)
obj.name = "ear2"
bpy.ops.mesh.primitive_uv_sphere_add(radius=1, enter_editmode=False, align='WORLD', location=(1.9, 1, 1), scale=(0.25, 0.4, 0.3))
bpy.ops.object.shade_smooth()
obj = bpy.context.object
mat = bpy.data.materials.new(name="eyebrow")
obj.data.materials.append(mat)
mat.diffuse_color = (0.370, 0.250, 0.156, 1)
obj.name = "eyebrow1"
bpy.ops.mesh.primitive_uv_sphere_add(radius=1, enter_editmode=False, align='WORLD', location=(1.9, -1, 1), scale=(0.25, 0.4, 0.3))
bpy.ops.object.shade_smooth()
obj = bpy.context.object
mat = bpy.data.materials.new(name="eyebrow")
obj.data.materials.append(mat)
mat.diffuse_color = (0.370, 0.250, 0.156, 1)
obj.name = "eyebrow2"
bpy.ops.mesh.primitive_uv_sphere_add(radius=1, enter_editmode=False, align='WORLD', location=(2.25, -1, 0.6), scale=(0.25, 0.3, 0.35))
bpy.ops.object.shade_smooth()
obj = bpy.context.object
mat = bpy.data.materials.new(name="eye")
obj.data.materials.append(mat)
mat.diffuse_color = (0.204, 0.139, 0.088, 0.9)
obj.name = "eye1"
bpy.ops.mesh.primitive_uv_sphere_add(radius=1, enter_editmode=False, align='WORLD', location=(2.25, 1, 0.6), scale=(0.25, 0.3, 0.35))
bpy.ops.object.shade_smooth()
obj = bpy.context.object
mat = bpy.data.materials.new(name="eye")
obj.data.materials.append(mat)
mat.diffuse_color = (0.204, 0.139, 0.088, 0.9)
obj.name = "eye2"
bpy.ops.mesh.primitive_uv_sphere_add(radius=1, enter_editmode=False, align='WORLD', location=(2.4, 0, 0), scale=(0.16, 0.3, 0.2))
bpy.ops.object.shade_smooth()
obj = bpy.context.object
mat = bpy.data.materials.new(name="nose")
obj.data.materials.append(mat)
mat.diffuse_color = (0.071, 0.050, 0.033, 0.95)
obj.name = "nose"
bpy.ops.mesh.primitive_uv_sphere_add(radius=1, enter_editmode=False, align='WORLD', location=(2.25, 0, -0.7), scale=(0.16, 0.33, 0.28))
bpy.ops.object.shade_smooth()
obj = bpy.context.object
mat = bpy.data.materials.new(name="mouth")
obj.data.materials.append(mat)
mat.diffuse_color = (0.496, 0.167, 0.110, 0.9)
obj.name = "mouth"
camera_data = bpy.data.cameras.new('MyCamera')
camera_obj = bpy.data.objects.new('CameraObj', camera_data)
bpy.context.scene.collection.objects.link(camera_obj)
camera_data.lens = 40
camera_obj.location = (10, -9, 5.5)
camera_obj.rotation_euler = (1.21404, -0.10472, 0.919648)
bpy.context.scene.camera = camera_obj
bpy.ops.object.light_add(type='AREA', location=(5, 2, 3))
light = bpy.context.object
light.data.energy = 100
light.data.shadow_soft_size = 0.05
light.rotation_euler = (0.645, 0.524, 1.85)
bpy.context.view_layer.update()
scene = bpy.context.scene
scene.render.image_settings.file_format = 'PNG'
scene.render.filepath = '/tmp/output.png'
bpy.ops.render.render(write_still=True)
import bpy
bpy.ops.object.select_all(action="SELECT")
bpy.ops.object.delete()
bpy.ops.mesh.primitive_uv_sphere_add(radius=1, enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))
bpy.context.object.scale[0] = 2
bpy.context.object.scale[1] = 2
bpy.context.object.scale[2] = 2
bpy.ops.object.select_all(action='DESELECT')
bpy.context.object.select_set(True)
mat = bpy.data.materials.new(name="ColoredMaterial")
mat.diffuse_color = (0.135, 0.053, 0.027,1)
bpy.context.object.data.materials.append(mat)
bpy.ops.mesh.primitive_uv_sphere_add(enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))
bpy.context.object.location[2] = 2.5
bpy.context.object.scale[0] = 1.5
bpy.context.object.scale[1] = 1.5
bpy.context.object.scale[2] = 1.5
bpy.ops.object.select_all(action='DESELECT')
bpy.context.object.select_set(True)
mat = bpy.data.materials.new(name="ColoredMaterial")
mat.diffuse_color = (0.135, 0.053, 0.027,1)
bpy.context.object.data.materials.append(mat)
bpy.ops.mesh.primitive_uv_sphere_add(radius=1, enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))
bpy.context.object.location[2] = 3.8
bpy.context.object.location[1] = 1
bpy.context.object.scale[0] = 0.3
bpy.context.object.scale[1] = 0.5
bpy.context.object.scale[2] = 0.5
bpy.ops.object.select_all(action='DESELECT')
bpy.context.object.select_set(True)
mat = bpy.data.materials.new(name="ColoredMaterial")
mat.diffuse_color = (0.135, 0.053, 0.027,1)
bpy.context.object.data.materials.append(mat)
bpy.ops.mesh.primitive_uv_sphere_add(radius=1, enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))
bpy.context.object.location[2] = 3.8
bpy.context.object.location[1] = -1
bpy.context.object.scale[0] = 0.3
bpy.context.object.scale[1] = 0.5
bpy.context.object.scale[2] = 0.5
bpy.ops.object.select_all(action='DESELECT')
bpy.context.object.select_set(True)
mat = bpy.data.materials.new(name="ColoredMaterial")
mat.diffuse_color = (0.135, 0.053, 0.027,1)
bpy.context.object.data.materials.append(mat)
bpy.ops.mesh.primitive_uv_sphere_add(enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))
bpy.context.object.location[2] = 2.5
bpy.context.object.location[0] = 1
bpy.context.object.scale[0] = 0.7
bpy.context.object.scale[1] = 0.7
bpy.context.object.scale[2] = 0.7
bpy.ops.object.select_all(action='DESELECT')
bpy.context.object.select_set(True)
mat = bpy.data.materials.new(name="ColoredMaterial")
mat.diffuse_color = (0.051, 0.030, 0.016,1)
bpy.context.object.data.materials.append(mat)
bpy.ops.mesh.primitive_uv_sphere_add(enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))
bpy.context.object.location[2] = 2.7
bpy.context.object.location[0] = 1.6
bpy.context.object.scale[0] = 0.2
bpy.context.object.scale[1] = 0.3
bpy.context.object.scale[2] = 0.3
bpy.ops.object.select_all(action='DESELECT')
bpy.context.object.select_set(True)
mat = bpy.data.materials.new(name="ColoredMaterial")
mat.diffuse_color = (0.241, 0.146, 0.087,1)
bpy.context.object.data.materials.append(mat)
bpy.ops.mesh.primitive_uv_sphere_add(enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))
bpy.context.object.location[2] = 3.3
bpy.context.object.location[1] = 0.5
bpy.context.object.location[0] = 1.2
bpy.context.object.scale[0] = 0.15
bpy.context.object.scale[1] = 0.15
bpy.context.object.scale[2] = 0.15
bpy.ops.object.select_all(action='DESELECT')
bpy.context.object.select_set(True)
mat = bpy.data.materials.new(name="ColoredMaterial")
mat.diffuse_color = (0, 0, 0,1)
bpy.context.object.data.materials.append(mat)
bpy.ops.mesh.primitive_uv_sphere_add(enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))
bpy.context.object.location[2] = 3.3
bpy.context.object.location[1] = -0.5
bpy.context.object.location[0] = 1.2
bpy.context.object.scale[0] = 0.15
bpy.context.object.scale[1] = 0.15
bpy.context.object.scale[2] = 0.15
bpy.ops.object.select_all(action='DESELECT')
bpy.context.object.select_set(True)
mat = bpy.data.materials.new(name="ColoredMaterial")
mat.diffuse_color = (0, 0, 0,1)
bpy.context.object.data.materials.append(mat)
bpy.ops.mesh.primitive_cylinder_add(radius=1, depth=2, enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))
bpy.context.object.location[2] = -1.5
bpy.context.object.location[1] = 0.8
bpy.context.object.scale[0] = 0.9
bpy.context.object.scale[1] = 0.8
bpy.context.object.scale[2] = 0.9
bpy.ops.object.select_all(action='DESELECT')
bpy.context.object.select_set(True)
mat = bpy.data.materials.new(name="ColoredMaterial")
mat.diffuse_color = (0.135, 0.053, 0.027,1)
bpy.context.object.data.materials.append(mat)
bpy.ops.mesh.primitive_cylinder_add(radius=1, depth=2, enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))
bpy.context.object.location[2] = -1.5
bpy.context.object.location[1] = -0.8
bpy.context.object.scale[0] = 0.9
bpy.context.object.scale[1] = 0.8
bpy.context.object.scale[2] = 0.9
bpy.ops.object.select_all(action='DESELECT')
bpy.context.object.select_set(True)
mat = bpy.data.materials.new(name="ColoredMaterial")
mat.diffuse_color = (0.135, 0.053, 0.027,1)
bpy.context.object.data.materials.append(mat)
bpy.ops.mesh.primitive_uv_sphere_add(enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))
bpy.context.object.rotation_euler[0] = 0.785398
bpy.context.object.location[2] = 0.3
bpy.context.object.location[1] = 1.4
bpy.context.object.scale[0] = 0.5
bpy.context.object.scale[1] = 1
bpy.context.object.scale[2] = 1.5
bpy.ops.object.select_all(action='DESELECT')
bpy.context.object.select_set(True)
mat = bpy.data.materials.new(name="ColoredMaterial")
mat.diffuse_color = (0.135, 0.053, 0.027,1)
bpy.context.object.data.materials.append(mat)
bpy.ops.mesh.primitive_uv_sphere_add(enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))
bpy.context.object.rotation_euler[0] = -0.785398
bpy.context.object.location[2] = 0.3
bpy.context.object.location[1] = -1.4
bpy.context.object.scale[0] = 0.5
bpy.context.object.scale[1] = 1
bpy.context.object.scale[2] = 1.5
bpy.ops.object.select_all(action='DESELECT')
bpy.context.object.select_set(True)
mat = bpy.data.materials.new(name="ColoredMaterial")
mat.diffuse_color = (0.135, 0.053, 0.027,1)
bpy.context.object.data.materials.append(mat)
camera = bpy.data.cameras.new('MyCamera')
camera_obj = bpy.data.objects.new('CameraObj', camera)
bpy.context.collection.objects.link(camera_obj)
camera.lens = 80 # Focal length in millimeters
camera.sensor_width = 80 # Sensor width in millimeters
camera.sensor_height = 40 # Sensor height in millimeters
camera_obj.location = (10.6, 6, 10.5) # X, Y, Z coordinates
camera_obj.rotation_euler = (-128*0.0174444444,180*0.0174444444,-60*0.0174444444)
bpy.context.scene.camera = camera_obj
light_name = "MyLight"
if light_name not in bpy.data.objects:
light_data = bpy.data.lights.new(name=light_name + "_data", type='POINT')
light_object = bpy.data.objects.new(name=light_name, object_data=light_data)
bpy.context.collection.objects.link(light_object)
light = bpy.data.objects[light_name]
light.location = (14, 5, 8)
light.data.energy = 8000
light.data.color = (1, 1, 0.8)
scene = bpy.context.scene
scene.render.engine = 'CYCLES'
scene.render.resolution_x = 640
scene.render.resolution_y = 480
scene.render.filepath = "/tmp/rendered_image.png"
bpy.ops.render.render(write_still=True)
import bpy
bpy.ops.object.select_all(action="SELECT")
bpy.ops.object .delete ()
body = bpy.ops.mesh .primitive_uv_sphere_add()
body = bpy.context .object
bpy .context .object .name = "body"
mat = bpy.data.materials.new( 'mat_body')
color = (0, 1, 1, 1)
mat .diffuse_color = color
bpy.context.object.data.materials.append(mat)
r_hand = bpy.ops.mesh.primitive_cone_add ()
bpy .context .object .name = "r hand"
bpy. context.object. location = (0,0.9,0.65)
bpy.context.object. rotation_euler = (-0.5,0.4,0.6)
bpy. context.object.scale = (0.3,0.3,0.3)
mat = bpy. data.materials.new('mat_hand')
color = (0, 0, 0, 1)
mat .diffuse_color = color
bpy.context.object.data.materials.append(mat)
bpy.context.object.parent = body
l_hand =bpy.ops.mesh.primitive_cone_add()
bpy .context .object.name = "l_hand"
bpy.context.object. location = (0, -0.9,0.65)
bpy.context.object.rotation_euler = (0.5, -0.4,0.6)
bpy.context.object.scale = (0.3,0.3,0.3)
mat = bpy. data.materials.new ( 'mat_hand')
color = (0, 0, 0, 1)
mat. diffuse_color = color
bpy.context.object.data.materials.append(mat)
bpy.context.object.parent = body
head = bpy.ops.mesh.primitive_uv_sphere_add()
head = bpy. context.object
bpy. context .object .name = "head"
bpy. context .object. location = (0, 0, 1.5)
bpy. context.object.scale = (0.7, 0.7, 0.7)
mat = bpy.data.materials.new( 'mat head')
color = (0, 1, 1, 1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
r_eye = bpy.ops. mesh.primitive_uv_sphere_add()
bpy.context .object.name = "r_eye"
bpy. context. object. location = (1, 0.4, 0.2)
bpy. context. object. scale = (0.2, 0.2, 0.2)
mat = bpy.data.materials.new('mat_eye')
color = (0, 0, 0, 1)
mat.diffuse_color = 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 = (1, -0.4, 0.2)
bpy. context. object. scale = (0.2, 0.2, 0.2)
mat = bpy. data.materials.new( 'mat_eye')
color = (0, 0, 0, 1)
mat .diffuse_color = color
bpy.context.object.data.materials.append(mat)
bpy.context .object.parent = head
bpy.ops.mesh.primitive_cone_add ()
hat = bpy.context.object
hat .name = "nose"
hat. location = (1,0,0)
hat. scale = (0.3,0.3,0.3)
hat. rotation_euler=(1,1,1)
mat = bpy .data.materials .new( 'mat nose')
color = (0, 0, 0, 1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
bpy.context.object.parent = head
bpy.ops .mesh.primitive_cone_add()
hat = bpy.context. object
hat .name = "hat"
hat. location = (0,0,2.5)
hat. scale = (0.5,0.5,0.5)
mat = bpy. data.materials.new( 'mat _hat')
color = (1, 0, 0, 1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
character = bpy. data. objects .new("character", None)
bpy. data.collections ["Collection"].objects. link(character)
head.parent = character
body.parent = character
hat .parent = character
bpy.ops.mesh.primitive_plane_add(size=20)
bpy.context.object. location = (0,0,-1)
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_obj. location = (13.6, 5,10.5)
bpy.ops.object.light_add(type='SPOT', radius=1)
bpy.context.object.data.energy = 1000
bpy.context.object.location = (6.27,-3.4,2.83)
bpy.context.object.rotation_euler = (1.172,0,0.907)
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
bpy. context.scene. render. engine = 'CYCLES'
bpy. context. scene. render. filepath = '/tmp/render2.png'
bpy.ops.render.render(write_still=True)
- 雪人获得了女朋友
import bpy
bpy.ops.object.select_all(action="SELECT")
bpy.ops.object.delete()
def create_snow_man():
bpy.ops.mesh.primitive_uv_sphere_add()
head = bpy.context.object
bpy.context.object.name = "head"
mat = bpy.data.materials.new('mat_head')
color = (1, 0.7, 0.6, 1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
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.1, 0.3)
mat = bpy.data.materials.new('mat_eye')
color = (0, 0, 0, 1)
mat.diffuse_color = 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.1, 0.3)
mat = bpy.data.materials.new('mat_l_eye')
color = (0, 0, 0, 1)
mat.diffuse_color = color
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,-2.4)
body.scale = (2,2,2)
mat = bpy.data.materials.new('mat_body')
color = (0.005, 0.06, 0.003, 1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
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,-7.6)
def create_girl():
girl = bpy.data.objects.new("girl", None)
bpy.data.collections["Collection"].objects.link(girl)
bpy.ops.mesh.primitive_cone_add()
hat = bpy.context.object
hat.name = "hat"
hat.location = (-1.1,0,2)
hat.scale = (1,1,2)
bpy.context.object.rotation_euler[1] = 3.14 / -6
mat = bpy.data.materials.new('mat_hat')
color = (1, 0, 0, 1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
bpy.context.object.parent = girl
bpy.ops.mesh.primitive_torus_add()
bpy.context.object.name = "hat2"
bpy.context.object.location = (-0.2,0,0.4)
bpy.context.object.scale = (1, 1, 1)
bpy.context.object.rotation_euler[1] = 3.14 / -6
bpy.context.object.parent = girl
bpy.ops.mesh.primitive_uv_sphere_add()
bpy.context.object.name = "hat3"
bpy.context.object.location = (-2,0,3.5)
bpy.context.object.scale = (0.5,0.5,0.5)
bpy.context.object.parent = girl
bpy.ops.mesh.primitive_cylinder_add()
bpy.context.object.name = "l_leg"
bpy.context.object.location = (0,-0.5,-6)
bpy.context.object.scale = (0.3,0.3,1.5)
mat = bpy.data.materials.new('mat_l_leg')
color = (0.03, 0.01, 0, 1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
bpy.context.object.parent = girl
bpy.ops.mesh.primitive_cylinder_add()
bpy.context.object.name = "r_leg"
bpy.context.object.location = (0,0.5,-6)
bpy.context.object.scale = (0.3,0.3,1.5)
mat = bpy.data.materials.new('mat_r_leg')
color = (0.03, 0.01, 0, 1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
bpy.context.object.parent = girl
bpy.ops.mesh.primitive_torus_add()
bpy.context.object.name = "scarf"
bpy.context.object.location = (0,0,-1.2)
bpy.context.object.scale = (0.7, 0.7, 1)
bpy.context.object.parent = girl
bpy.ops.mesh.primitive_torus_add()
bpy.context.object.name = "body2"
bpy.context.object.location = (0,0,-4.3)
bpy.context.object.scale = (1.8, 1.8, 1.5)
mat = bpy.data.materials.new('mat_body2')
color = (1, 0, 0, 1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
bpy.context.object.parent = girl
bpy.ops.mesh.primitive_uv_sphere_add()
bpy.context.object.name = "body3"
bpy.context.object.location = (0.4,0,-2)
bpy.context.object.scale = (0.5,0.5,0.5)
mat = bpy.data.materials.new('mat_body3')
color = (1, 0, 0, 1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
bpy.context.object.parent = girl
bpy.ops.mesh.primitive_uv_sphere_add()
bpy.context.object.name = "l ear"
bpy.context.object.location = (0.2,-1,-0.08)
bpy.context.object.scale = (0.5,0.5,0.5)
mat = bpy.data.materials.new('mat_l ear')
color = (0.005, 0.06, 0.003, 1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
bpy.context.object.parent = girl
bpy.ops.mesh.primitive_uv_sphere_add()
bpy.context.object.name = "r ear"
bpy.context.object.location = (-0.2,1,-0.08)
bpy.context.object.scale = (0.5,0.5,0.5)
mat = bpy.data.materials.new('mat_r ear')
color = (0.005, 0.06, 0.003, 1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
bpy.context.object.parent = girl
bpy.ops.mesh.primitive_uv_sphere_add()
bpy.context.object.name = "body4"
bpy.context.object.location = (0.8,1,-3.2)
bpy.context.object.scale = (0.4,0.5,0.5)
bpy.context.object.parent = girl
bpy.ops.mesh.primitive_uv_sphere_add()
bpy.context.object.name = "body5"
bpy.context.object.location = (0.8,-1,-3.2)
bpy.context.object.scale = (0.4,0.5,0.5)
bpy.context.object.parent = girl
bpy.ops.mesh.primitive_uv_sphere_add()
bpy.context.object.name = "snow"
bpy.context.object.location = (-2,5.6,-4.5)
bpy.context.object.scale = (3,3,3)
bpy.context.object.parent = girl
bpy.ops.mesh.primitive_uv_sphere_add()
bpy.context.object.name = "snow2"
bpy.context.object.location = (-2,5.6,-0.3)
bpy.context.object.scale = (2,2,2)
bpy.context.object.parent = girl
bpy.ops.mesh.primitive_uv_sphere_add()
bpy.context.object.name = "snow3"
bpy.context.object.location = (-0.9,4.3,-0.36)
bpy.context.object.scale = (0.5,0.5,0.5)
mat = bpy.data.materials.new('mat_snow3')
color = (0.03, 0.01, 0, 1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
bpy.context.object.parent = girl
bpy.ops.mesh.primitive_uv_sphere_add()
bpy.context.object.name = "snow4"
bpy.context.object.location = (-0.289,5.5,-0.33)
bpy.context.object.scale = (0.5,0.5,0.5)
mat = bpy.data.materials.new('mat_snow4')
color = (0.03, 0.01, 0, 1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
bpy.context.object.parent = girl
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 # Focal length in millimeters
camera.sensor_width = 36 # Sensor width in millimeters
camera.sensor_height = 24 # Sensor height in millimeters
camera_obj.location = (23.3,5.9, 8.1) # X, Y, Z coordinates
camera_obj.rotation_euler = (1.172,0,1.8)
bpy.context.scene.camera = camera_obj
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)
bpy.context.scene.render.resolution_x = 640
bpy.context.scene.render.resolution_y = 480
bpy.context.scene.render.resolution_percentage = 50
def render():
bpy.context.scene.render.engine = 'CYCLES'
bpy.context.scene.render.filepath = '/tmp/render2.png'
bpy.ops.render.render(write_still=True)
create_snow_man()
create_girl()
init_camera()
init_light()
render()
import bpy
bpy.ops.object.select_all(action="SELECT") # 选择所有物体
bpy.ops.object.delete() # 删除选定的物体
body = bpy.ops.mesh.primitive_uv_sphere_add()
bpy.context.object.name = "body"
bpy.context.object.location = (0, 0, 0)
bpy.context.object.scale = (4.0, 4.0, 4.0)
mat = bpy.data.materials.new('mat_body')
color = (1, 0.619, 0.713, 1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
r_leg = bpy.ops.mesh.primitive_uv_sphere_add()
bpy.context.object.name = "r_leg"
bpy.context.object.location = (0.4, 3.2, 0)
bpy.context.object.scale = (1.5, 2.5, 1.5)
mat = bpy.data.materials.new('mat_leg')
color = (1, 0.619, 0.713, 1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
l_leg = bpy.ops.mesh.primitive_uv_sphere_add()
bpy.context.object.name = "l_leg"
bpy.context.object.location = (0.4, -3.2, 0)
bpy.context.object.scale = (1.5, 2.5, 1.5)
mat = bpy.data.materials.new('mat_leg')
color = (1, 0.619, 0.713, 1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
r_foot = bpy.ops.mesh.primitive_uv_sphere_add()
bpy.context.object.name = "r_foot"
bpy.context.object.location = (1.5, 2.5, -2.6)
bpy.context.object.rotation_euler[1] = 1
bpy.context.object.scale = (1.5, 1.5, 1.8)
mat = bpy.data.materials.new('mat_foot')
color = (0.886, 0.098, 0.309, 1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
l_foot = bpy.ops.mesh.primitive_uv_sphere_add()
bpy.context.object.name = "l_foot"
bpy.context.object.location = (1.5, -2.5, -2.6)
bpy.context.object.rotation_euler[1] = 1
bpy.context.object.scale = (1.5, 1.5, 1.8)
mat = bpy.data.materials.new('mat_foot')
color = (0.886, 0.098, 0.309, 1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
r_eye = bpy.ops.mesh.primitive_uv_sphere_add()
bpy.context.object.name = "r_eye"
bpy.context.object.location = (3.6, 1.0, 1.0)
bpy.context.object.scale = (0.4, 0.4, 1.0)
mat = bpy.data.materials.new('mat_eye')
color = (0, 0, 0, 1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
l_eye = bpy.ops.mesh.primitive_uv_sphere_add()
bpy.context.object.name = "l_eye"
bpy.context.object.location = (3.6, -1.0, 1.0)
bpy.context.object.scale = (0.4, 0.4, 1.0)
mat = bpy.data.materials.new('mat_eye')
color = (0, 0, 0, 1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
r_eyelittle = bpy.ops.mesh.primitive_uv_sphere_add()
bpy.context.object.name = "r_eyelittle"
bpy.context.object.location = (3.8, 1.0, 1.4)
bpy.context.object.scale = (0.25, 0.25, 0.5)
mat = bpy.data.materials.new('mat_eyelittle')
color = (1, 1, 1, 1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
l_eyelittle = bpy.ops.mesh.primitive_uv_sphere_add()
bpy.context.object.name = "l_eyelittle"
bpy.context.object.location = (3.8, -1.0, 1.4)
bpy.context.object.scale = (0.25, 0.25, 0.5)
mat = bpy.data.materials.new('mat_eyelittle')
color = (1, 1, 1, 1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
r_rouge = bpy.ops.mesh.primitive_uv_sphere_add()
bpy.context.object.name = "r_rouge"
bpy.context.object.location = (3.6, 1.8, 0)
bpy.context.object.scale = (0.3, 0.6, 0.4)
mat = bpy.data.materials.new('mat_rouge')
color = (0.933, 0.415, 0.509, 1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
l_rouge = bpy.ops.mesh.primitive_uv_sphere_add()
bpy.context.object.name = "l_rouge"
bpy.context.object.location = (3.6, -1.8, 0)
bpy.context.object.scale = (0.3, 0.6, 0.4)
mat = bpy.data.materials.new('mat_rouge')
color = (0.933, 0.415, 0.509, 1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
mouse = bpy.ops.mesh.primitive_uv_sphere_add()
bpy.context.object.name = "mouse"
bpy.context.object.location = (3.9, 0,-0.6)
bpy.context.object.scale = (0.3, 0.5, 0.4)
mat = bpy.data.materials.new('mat_mouse')
color = (1, 0.2, 0.3, 1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
r_bow = bpy.ops.mesh.primitive_uv_sphere_add()
bpy.context.object.name = "r_bow"
bpy.context.object.location = (-0.3, 1.5, 2.6)
bpy.context.object.rotation_euler[1] = 0.349
bpy.context.object.rotation_euler[2] = 1.4
bpy.context.object.scale = (1.5, 1.5, 3.0)
mat = bpy.data.materials.new('mat_row')
color = (0.98, 0.199, 0.199, 1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
l_bow = bpy.ops.mesh.primitive_uv_sphere_add()
bpy.context.object.name = "l_bow"
bpy.context.object.location = (-0.3, -1.5, 2.6)
bpy.context.object.rotation_euler[1] = 0.349
bpy.context.object.rotation_euler[2] = 4.8
bpy.context.object.scale = (1.5, 1.5, 3.0)
mat = bpy.data.materials.new('mat_row')
color = (0.98, 0.199, 0.199, 1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
m_bow = bpy.ops.mesh.primitive_uv_sphere_add()
bpy.context.object.name = "l_bow"
bpy.context.object.location = (0.0, 0.0, 3.9)
bpy.context.object.scale = (1.0, 1.0, 1.0)
mat = bpy.data.materials.new('mat_row')
color = (0.98, 0.199, 0.199, 1)
mat.diffuse_color = color
bpy.context.object.data.materials.append(mat)
# 添加地面
bpy.ops.mesh.primitive_plane_add(size=20, location=(0, 0, -4)) # 这里的size可以根据需要调整
# 设置地面类型为Shadow Catcher
ground = bpy.context.object
ground.name = "Ground"
ground.cycles.is_shadow_catcher = True
camera = bpy.data.cameras.new('MyCamera')
camera_obj = bpy.data.objects.new('CameraObj', camera)
bpy.context.scene.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 = (29.57, -3.37, 7.35) # X, Y, Z coordinates
camera_obj.rotation_euler = (1.38, 0.014, 1.44)
bpy.context.scene.camera = camera_obj
# 添加聚光灯
bpy.ops.object.light_add(type='SPOT', radius=3) # 添加聚光灯
spot_light = bpy.context.object # 获取新添加的聚光灯对象
spot_light.data.energy = 8000 # 设置聚光灯能量
spot_light.location = (13.5, -10, 12) # 设置聚光灯位(X、Y、Z坐标)
spot_light.rotation_euler = (0.675 ,0.749, 12.79) # 设置聚光灯旋转欧拉角
# 设置渲染分辨率
bpy.context.scene.render.resolution_x = 1280 # 渲染分辨率宽度
bpy.context.scene.render.resolution_y = 880 # 渲染分辨率高度
bpy.context.scene.render.resolution_percentage = 100 # 渲染分辨率百分比
# 设置渲染引擎(例如CYCLES、BLENDER_EEVEE)
bpy.context.scene.render.engine = 'CYCLES'
# 设置输出文件路径
bpy.context.scene.render.filepath = './tmp/my_render_output1.png'
# 渲染当前视图
bpy.ops.render.render(write_still=True)
- 我们下次再说!👋