forked from nophead/Mendel90
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviz.py
67 lines (61 loc) · 1.91 KB
/
viz.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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()