Merge pull request #8 from zignig/master
Automatic image generation of all the parts
27
render.py
Normal 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)
|
BIN
sturdy/render/cable_clip_AB.png
Normal file
After Width: | Height: | Size: 78 KiB |
BIN
sturdy/render/cable_clip_AD.png
Normal file
After Width: | Height: | Size: 78 KiB |
BIN
sturdy/render/cable_clip_CA.png
Normal file
After Width: | Height: | Size: 78 KiB |
BIN
sturdy/render/d_motor_bracket.png
Normal file
After Width: | Height: | Size: 79 KiB |
BIN
sturdy/render/d_motor_bracket_lid.png
Normal file
After Width: | Height: | Size: 73 KiB |
BIN
sturdy/render/d_shell.png
Normal file
After Width: | Height: | Size: 78 KiB |
BIN
sturdy/render/d_shell_lid.png
Normal file
After Width: | Height: | Size: 74 KiB |
BIN
sturdy/render/fan_guard.png
Normal file
After Width: | Height: | Size: 83 KiB |
BIN
sturdy/render/fixing_block.png
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
sturdy/render/pcb_spacer.png
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
sturdy/render/pulley.png
Normal file
After Width: | Height: | Size: 84 KiB |
BIN
sturdy/render/ribbon_clamp_12_33.png
Normal file
After Width: | Height: | Size: 76 KiB |
BIN
sturdy/render/ribbon_clamp_20_33.png
Normal file
After Width: | Height: | Size: 74 KiB |
BIN
sturdy/render/ribbon_clamp_20_40.png
Normal file
After Width: | Height: | Size: 74 KiB |
BIN
sturdy/render/ribbon_clamp_22_40.png
Normal file
After Width: | Height: | Size: 74 KiB |
BIN
sturdy/render/ribbon_clamp_22_44.png
Normal file
After Width: | Height: | Size: 73 KiB |
BIN
sturdy/render/wades_big_gear.png
Normal file
After Width: | Height: | Size: 79 KiB |
BIN
sturdy/render/wades_block.png
Normal file
After Width: | Height: | Size: 78 KiB |
BIN
sturdy/render/wades_gear_spacer.png
Normal file
After Width: | Height: | Size: 82 KiB |
BIN
sturdy/render/wades_idler_block.png
Normal file
After Width: | Height: | Size: 81 KiB |
BIN
sturdy/render/wades_small_gear.png
Normal file
After Width: | Height: | Size: 86 KiB |
BIN
sturdy/render/x_belt_clamp.png
Normal file
After Width: | Height: | Size: 81 KiB |
BIN
sturdy/render/x_belt_grip.png
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
sturdy/render/x_belt_tensioner.png
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
sturdy/render/x_carriage.png
Normal file
After Width: | Height: | Size: 82 KiB |
BIN
sturdy/render/x_idler_bracket.png
Normal file
After Width: | Height: | Size: 84 KiB |
BIN
sturdy/render/x_motor_bracket.png
Normal file
After Width: | Height: | Size: 81 KiB |
BIN
sturdy/render/y_bar_clamp.png
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
sturdy/render/y_bar_clamp_switch.png
Normal file
After Width: | Height: | Size: 82 KiB |
BIN
sturdy/render/y_bearing_mount.png
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
sturdy/render/y_bearing_mount_switch.png
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
sturdy/render/y_belt_anchor.png
Normal file
After Width: | Height: | Size: 83 KiB |
BIN
sturdy/render/y_belt_anchor_toothed.png
Normal file
After Width: | Height: | Size: 83 KiB |
BIN
sturdy/render/y_belt_clip.png
Normal file
After Width: | Height: | Size: 78 KiB |
BIN
sturdy/render/y_belt_clip_toothed.png
Normal file
After Width: | Height: | Size: 78 KiB |
BIN
sturdy/render/y_idler_bracket.png
Normal file
After Width: | Height: | Size: 82 KiB |
BIN
sturdy/render/y_motor_bracket.png
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
sturdy/render/z_bar_clamp.png
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
sturdy/render/z_bar_clamp_switch.png
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
sturdy/render/z_coupling.png
Normal file
After Width: | Height: | Size: 81 KiB |
BIN
sturdy/render/z_limit_switch_bracket.png
Normal file
After Width: | Height: | Size: 76 KiB |
BIN
sturdy/render/z_motor_bracket_lhs.png
Normal file
After Width: | Height: | Size: 81 KiB |
BIN
sturdy/render/z_motor_bracket_rhs.png
Normal file
After Width: | Height: | Size: 81 KiB |
BIN
sturdy/render/z_screw_pointer.png
Normal file
After Width: | Height: | Size: 79 KiB |
BIN
utils/render.blend
Normal file
67
utils/viz.py
Normal 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()
|