forked from patmo141/odc_public
-
Notifications
You must be signed in to change notification settings - Fork 0
/
library_screenshots.py
186 lines (137 loc) · 5.02 KB
/
library_screenshots.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# Addon info
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
import bpy
import math
import time
bl_info = {
'name': "Scene Object Screenshot Generator",
'author': "Patrick R. Moore",
'version': (0,0,1),
'blender': (2, 6, 6),
'api': 53613,
'location': "3D View -> Tool Shelf",
'description': "Makes a tiled image of all objects in scene",
'warning': "",
'wiki_url': "",
'tracker_url': "",
'category': '3D View'}
#variables/arguments
#image size
#number of obejcts
#thumbnail size
#scene
def icon_mn_to_index(m,n,n_columns):
index = n*n_columns + m
return index
def icon_index_to_nm(i,n_columns):
m = math.floor(i/n_columns)
n = math.fmod(i,n_columns)
return [m,n]
def icon_index_to_pixel_array(index,thumb_x, thumb_y, sheex_x, n_columns):
'''
returns the pixel array indices as an array of lists
'''
if index != 0:
m = int(math.fmod(index,n_columns))
else:
m = 0
n = int(math.floor(index/n_columns))
#print('the m x n value is %s' % str([m,n]))
#the bottom left corner pixel...
#x = midpoint of first block + n*width of blocks -16 pixels, -1 for indexing?
#y = the number of blocks, - 1/2 a bloc, - 16 pixels + offset of
x = m*thumb_x
y = n*thumb_y
'''
#print('the x y value is %s' % str([x,y]))
img_width = 1204
img_array = [0]*32*32*4
for i in range(0,32):
start = 4*((y+i)*img_width + x)
end = start + 32*4
#print(start)
#print(end)
img_array[i*32*4:(i+1)*32*4] = icon_source.pixels[start:end]
return img_array
'''
def main(context, obj): #, thumbnail_size):
#object mode
if context.object.mode != 'OBJEECT':
bpy.ops.object.mode_set(mode = 'OBJECT')
#select object, unhide it, active
obj.hide = False
obj.select = True
context.scene.objects.active = obj
#hide everything else
for ob in bpy.data.objects:
if ob.name != obj.name:
ob.hide = True
#this makes it have to run from operator in 3d view
#cant run as script
region = context.region
space = context.space_data
#rv3d = space.region_3d
if not space.local_view:
bpy.ops.view3d.localview()
bpy.ops.view3d.view_selected()
bpy.ops.view3d.viewnumpad(type='TOP', align_active=True)
bpy.ops.view3d.view_orbit(type='ORBITDOWN')
bpy.ops.view3d.view_orbit(type='ORBITDOWN')
bpy.ops.view3d.view_orbit(type='ORBITLEFT')
#bpy.ops.render.opengl(animation=False, sequencer=False, write_still=False, view_context=True)
class SceneObjectThumbnails(bpy.types.Operator):
"""Takes a screen shot of every object in scene"""
bl_idname = "wm.scene_objects_thumbnails"
bl_label = "Scene Object Thumbnails"
_timer = None
def modal(self, context, event):
if event.type == 'ESC':
return self.cancel(context)
elif event.type == 'TIMER' and ((time.time()-self.time_point) > self.delta):
if context.space_data.local_view:
bpy.ops.view3d.localview()
ob = self.ob_list[self.iter]
main(context, ob)
self.iter += 1
self.time_point = time.time()
if self.iter < self.n_obs:
return {'RUNNING_MODAL'}
else:
context.window_manager.event_timer_remove(self._timer)
return {'FINISHED'}
return {'RUNNING_MODAL'}
def invoke(self, context, event):
self.ob_list = [ob for ob in context.scene.objects if ob.type not in {'CAMERA','EMPTY'}]
print(self.ob_list)
self.n_obs = len(self.ob_list)
self.iter = 0
self.time_point = time.time()
self.delta = 0.5
self._timer = context.window_manager.event_timer_add(10, context.window)
context.window_manager.modal_handler_add(self)
return {'RUNNING_MODAL'}
def cancel(self, context):
context.window_manager.event_timer_remove(self._timer)
return {'CANCELLED'}
def register():
bpy.utils.register_class(SceneObjectThumbnails)
def unregister():
bpy.utils.unregister_class(SceneObjectThumbnails)
if __name__ == "__main__":
register()