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

Merge pull request #8 from zignig/master

Automatic image generation of all the parts
This commit is contained in:
Chris
2012-03-16 12:23:48 -07:00
47 changed files with 94 additions and 0 deletions

27
render.py Normal file
View File

@@ -0,0 +1,27 @@
import os
import sys
import shutil
import commands
def render(machine):
render_dir = machine + os.sep + "render"
print render_dir
try:
os.stat(render_dir)
except:
os.mkdir(render_dir)
li = os.listdir(machine+os.sep+'stls')
stls = []
for i in li:
stls.append(i[:-4])
for i in stls:
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(command)
print commands.getstatusoutput(command)[1]
if __name__ == '__main__':
if len(sys.argv) > 1:
render(sys.argv[1])
else:
print "usage: bom [mendel|sturdy|your_machine]"
sys.exit(1)

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

BIN
sturdy/render/d_shell.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

BIN
sturdy/render/fan_guard.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
sturdy/render/pulley.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

BIN
utils/render.blend Normal file

Binary file not shown.

67
utils/viz.py Normal file
View File

@@ -0,0 +1,67 @@
import bpy
import sys
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()