1
0
mirror of https://github.com/nophead/Mendel90.git synced 2025-08-01 11:00:16 +02:00

auto renderer

This commit is contained in:
Simon Kirkby
2012-03-16 23:14:52 +08:00
parent aa42994a56
commit f8afc5987f
3 changed files with 69 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
import os
import sys
import shutil
import commands
def render(machine):
render_dir = machine + os.sep + "render"
@@ -14,8 +15,8 @@ def render(machine):
for i in li:
stls.append(i[:-4])
for i in stls:
command = 'blender utils'+os.sep+'render.blend -P utils'+os.sep+'viz.py -- '+machine+os.sep+'stls'+os.sep+i+'.stl '+machine+os.sep+'render'+os.sep+i+'.png'
print command
command = 'blender -b utils'+os.sep+'render.blend -P utils'+os.sep+'viz.py -- '+machine+os.sep+'stls'+os.sep+i+'.stl '+machine+os.sep+'render'+os.sep+i+'.png'
print commands.getstatusoutput(command)[1]
if __name__ == '__main__':
if len(sys.argv) > 1:

BIN
utils/render.blend Normal file

Binary file not shown.

View File

@@ -1,2 +1,67 @@
import bpy
import sys
# blender python script to place camera and render stls
global ob
global cam_target
mat = 'abs'
def load_stl(file_path):
global cam_target,ob
# load
bpy.ops.import_mesh.stl(filepath=file_path)
# select properly
ob = bpy.context.selected_objects[0]
print(ob)
bpy.ops.object.select_all(action='DESELECT')
ob.select = True
# remove doubles and clean
#py.ops.object.editmode_toggle()
#bpy.ops.mesh.select_all(action='TOGGLE')
#bpy.ops.mesh.remove_doubles(limit=0.0001)
#bpy.ops.mesh.normals_make_consistent(inside=False)
#bpy.ops.object.editmode_toggle()
bpy.ops.object.origin_set(type='GEOMETRY_ORIGIN', center='BOUNDS')
# place
z_dim = ob.dimensions[2]
print(z_dim)
bpy.ops.transform.translate(value=(0,0,z_dim/2.0))
cam_target = (0,0,z_dim/3.0)
# assign material
ob.material_slots.data.active_material = bpy.data.materials[mat]
def place_camera():
global cam_target
max_dim = 0
for i in ob.dimensions:
print(i)
if i > max_dim:
max_dim = i
print(max_dim)
bpy.data.objects['target'].location = cam_target
cam = bpy.data.objects['Camera'].location.x = max_dim*2.4
def render_thumb(image,gl=False,anim=False):
if gl:
if anim:
bpy.data.scenes['Scene'].render.filepath = "/tmp/"+ob.name+"#"
bpy.ops.render.opengl(animation=True)
else:
bpy.ops.render.opengl(write_still=True)
bpy.data.images['Render Result'].save_render(filepath=image)
else:
if anim:
bpy.data.scenes['Scene'].render.filepath = "/tmp/"+ob.name+"#"
bpy.ops.render.render(animation=True)
else:
bpy.ops.render.render(write_still=True)
bpy.data.images['Render Result'].save_render(filepath=image)
image = sys.argv[-1]
stl = sys.argv[-2]
print(stl)
print(image)
load_stl(stl)
place_camera()
render_thumb(image,gl=False)
#bpy.ops.object.delete()