Skip to content

Instantly share code, notes, and snippets.

@dirkk0

dirkk0/create.py

Last active Nov 5, 2016
Embed
What would you like to do?
Create scene in Blender and rotate the camera
import bpy
# delete default cube
candidate_list = [item.name for item in bpy.data.objects if item.type == "MESH"]
for object_name in candidate_list:
bpy.data.objects[object_name].select = True
bpy.ops.object.delete()
scale = 3
for i in range(5):
for j in range(5):
bpy.ops.mesh.primitive_uv_sphere_add(size=0.3,location=(i*scale,j*scale,+3))
bpy.ops.mesh.primitive_plane_add(view_align=False, enter_editmode=False, location=(0, 0, 0))
bpy.ops.transform.resize(value=(4,4,0))
bpy.ops.wm.save_as_mainfile(filepath="/tmp/save.blend")
# via
# https://news.ycombinator.com/item?id=8680733
# http://auxmem.com/2012/01/24/convert-3ds-files-to-obj-with-blender/
# simple obj export
# https://en.wikibooks.org/wiki/Blender_3D:_Noob_to_Pro/Advanced_Tutorials/Python_Scripting/Export_scripts
# simple obj import
# https://en.wikibooks.org/wiki/Blender_3D:_Noob_to_Pro/Advanced_Tutorials/Python_Scripting/Import_scripts
/Applications/Blender/blender.app/Contents/MacOS/blender -b -P create.py
/Applications/Blender/blender.app/Contents/MacOS/blender -b -P render.py
import bpy
from math import radians
bpy.ops.wm.open_mainfile(filepath="/tmp/save.blend")
obj_camera = bpy.context.scene.camera
# <Euler (x=1.1093, y=0.0108, z=0.8149), order='XYZ'>
print(obj_camera.rotation_euler)
# <Vector (7.4811, -6.5076, 5.3437)>
print(obj_camera.location)
# obj_camera.location = (0.0, 0.0, 0.0)
for a in [40,50,60,70,80,90]:
obj_camera.rotation_euler = (radians(a), 0.0108, 0.8149)
bpy.data.scenes['Scene'].render.filepath = '/tmp/image_'+str(a)+'.png'
bpy.ops.render.render(use_viewport = True, write_still=True)
obj_camera = bpy.context.scene.camera
# <Euler (x=1.1093, y=0.0108, z=0.8149), order='XYZ'>
print(obj_camera.rotation_euler)
# <Vector (7.4811, -6.5076, 5.3437)>
print(obj_camera.location)
# print(obj_camera.location)
fov = 90
pi = 3.14159265
obj_camera.data.angle = fov * pi/180
#obj_camera.location = (0.6, 0.0, 1.0)
obj_camera.rotation_euler = (radians(90), radians(0), radians(0))
print(obj_camera.rotation_euler)
# bpy.data.scenes['Scene'].render.filepath = '/tmp/image_N.png'
# bpy.data.scenes['Scene'].render.filepath = '/tmp/posz.png'
bpy.data.scenes['Scene'].render.filepath = d1 + '/back.png'
bpy.ops.render.render(use_viewport = False, write_still=True)
#obj_camera.location = (0.0, -0.6, 1.0)
obj_camera.rotation_euler = (radians(90), radians(0), radians(-90))
print(obj_camera.rotation_euler)
# bpy.data.scenes['Scene'].render.filepath = '/tmp/image_E.png'
# bpy.data.scenes['Scene'].render.filepath = '/tmp/posx.png'
bpy.data.scenes['Scene'].render.filepath = d1 + 'right.png'
bpy.ops.render.render(use_viewport = False, write_still=True)
#obj_camera.location = (-0.6, 0.0, 1.0)
obj_camera.rotation_euler = (radians(90), radians(0), radians(-180))ann Dich auch noc
# bpy.data.scenes['Scene'].render.filepath = '/tmp/image_S.png'
# bpy.data.scenes['Scene'].render.filepath = '/tmp/negz.png'
bpy.data.scenes['Scene'].render.filepath = d1 + 'front.png'
bpy.ops.render.render(use_viewport = True, write_still=True)
#obj_camera.location = (0.0, 0.6, 1.0)
obj_camera.rotation_euler = (radians(90), radians(0), radians(90))
# bpy.data.scenes['Scene'].render.filepath = '/tmp/image_W.png'
# bpy.data.scenes['Scene'].render.filepath = '/tmp/negx.png'
bpy.data.scenes['Scene'].render.filepath = d1 + 'left.png'
bpy.ops.render.render(use_viewport = True, write_still=True)
obj_camera.rotation_euler = (radians(180), radians(0), radians(0))
# bpy.data.scenes['Scene'].render.filepath = '/tmp/image_U.png'
# bpy.data.scenes['Scene'].render.filepath = '/tmp/posy.png'
bpy.data.scenes['Scene'].render.filepath = d1 + 'top.png'
bpy.ops.render.render(use_viewport = True, write_still=True)
obj_camera.rotation_euler = (radians(0), radians(0), radians(0))
# bpy.data.scenes['Scene'].render.filepath = '/tmp/image_D.png'
# bpy.data.scenes['Scene'].render.filepath = '/tmp/negy.png'
bpy.data.scenes['Scene'].render.filepath = d1 + 'bottom.png'
bpy.ops.render.render(use_viewport = True, write_still=True)
# # for a in [40,50,60,70,80,90]:
# # obj_camera.rotation_euler = (radians(a), 0.0108, 0.8149)
# # bpy.data.scenes['Scene'].render.filepath = '/tmp/image_'+str(a)+'.png'
# # bpy.ops.render.render(use_viewport = True, write_still=True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.