-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmark_assets.py
More file actions
233 lines (188 loc) · 8.34 KB
/
Copy pathmark_assets.py
File metadata and controls
233 lines (188 loc) · 8.34 KB
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# ##### 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.
#z
# 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 sys
#avoid creating backup files
bpy.context.preferences.filepaths.save_version = 0
argv = sys.argv
#argv = [
# 0:debug_mode
# 1:asset_type
# ]
argv = argv[argv.index("--") + 1:] # get all args after "--"
debug = True
if argv[0] == 'True':
debug = True
print(argv)
else:
debug = False
def process_assets(argv):
bpy.ops.wm.previews_clear()
# 1. store render engine and switch to EEVEE for preview creation
render_engine = bpy.context.scene.render.engine
bpy.context.scene.render.engine = 'BLENDER_EEVEE'
# 2. Lower the samples so the "complex shader" doesn't choke
# This ensures each thumbnail takes milliseconds, not minutes
render_samples = bpy.context.scene.eevee.taa_render_samples
bpy.context.scene.eevee.taa_render_samples = 1
#bpy.ops.wm.previews_batch_clear()
asset_type = argv[1].split()
if not debug:
print("asset_type: ", asset_type)
if 'mark_objects' in asset_type:
for ob in bpy.data.objects:
for i in bpy.data.scenes: #only mark objects that are linked to a scene
if ob.name in bpy.data.scenes[i.name].objects:
if ob.type == 'MESH':
if 'mark_mesh' in asset_type:
mark_assets(ob)
if 'clear_mesh' in asset_type:
clear_assets(ob)
if ob.type == 'SURFACE':
if 'mark_surface' in asset_type:
mark_assets(ob)
if 'clear_surface' in asset_type:
clear_assets(ob)
if ob.type == 'META':
if 'mark_meta' in asset_type:
mark_assets(ob)
if 'clear_meta' in asset_type:
clear_assets(ob)
if ob.type == 'CURVE':
if 'mark_curve' in asset_type:
mark_assets(ob)
if 'clear_curve' in asset_type:
clear_assets(ob)
if ob.type == 'FONT':
if 'mark_font' in asset_type:
mark_assets(ob)
if 'clear_font' in asset_type:
clear_assets(ob)
if ob.type == 'CURVES':
if 'mark_curves' in asset_type:
mark_assets(ob)
if 'clear_curves' in asset_type:
clear_assets(ob)
if ob.type == 'POINTCLOUD':
if 'mark_pointcloud' in asset_type:
mark_assets(ob)
if 'clear_pointcloud' in asset_type:
clear_assets(ob)
if ob.type == 'VOLUME':
if 'mark_volume' in asset_type:
mark_assets(ob)
if 'clear_volume' in asset_type:
clear_assets(ob)
if ob.type == 'GPENCIL':
if 'mark_greasepencil' in asset_type:
mark_assets(ob)
if 'clear_greasepencil' in asset_type:
clear_assets(ob)
if ob.type == 'ARMATURE':
if 'mark_armature' in asset_type:
mark_assets(ob)
if 'clear_armature' in asset_type:
clear_assets(ob)
if ob.type == 'LATTICE':
if 'mark_lattice' in asset_type:
mark_assets(ob)
if 'clear_lattice' in asset_type:
clear_assets(ob)
if ob.type == 'EMPTY':
if 'mark_empty' in asset_type:
mark_assets(ob)
if 'clear_empty' in asset_type:
clear_assets(ob)
if ob.type == 'LIGHT':
if 'mark_light' in asset_type:
mark_assets(ob)
if 'clear_light' in asset_type:
clear_assets(ob)
if ob.type == 'LIGHTPROBE':
if 'mark_lightprobe' in asset_type:
mark_assets(ob)
if 'clear_lightprobe' in asset_type:
clear_assets(ob)
if ob.type == 'CAMERA':
if 'mark_camera' in asset_type:
mark_assets(ob)
if 'clear_camera' in asset_type:
clear_assets(ob)
if ob.type == 'SPEAKER':
if 'mark_speaker' in asset_type:
mark_assets(ob)
if 'clear_speaker' in asset_type:
clear_assets(ob)
if 'clear_object' in asset_type:
for ob in bpy.data.objects:
clear_assets(ob)
for me in bpy.data.meshes:
clear_assets(me)
if 'mark_materials' in asset_type:
for mat in bpy.data.materials:
mark_assets(mat)
if 'clear_materials' in asset_type:
for mat in bpy.data.materials:
clear_assets(mat)
if 'mark_poses' in asset_type:
for pose in bpy.data.actions:
mark_assets(pose)
if 'clear_poses' in asset_type:
for pose in bpy.data.actions:
clear_assets(pose)
if 'mark_worlds' in asset_type:
for world in bpy.data.worlds:
mark_assets(world)
if 'clear_worlds' in asset_type:
for world in bpy.data.worlds:
clear_assets(world)
if 'mark_collections' in asset_type:
for collection in bpy.data.collections:
mark_assets(collection)
if 'clear_collections' in asset_type:
for collection in bpy.data.collections:
clear_assets(collection)
if 'mark_nodegroups' in asset_type:
for group in bpy.data.node_groups:
mark_assets(group)
if 'clear_nodegroups' in asset_type:
for group in bpy.data.node_groups:
clear_assets(group)
#restore render engine
bpy.context.scene.eevee.taa_render_samples = render_samples
bpy.context.scene.render.engine = render_engine
#save the blend file to store asset marks
print('save_mainfile')
bpy.ops.wm.save_mainfile()
def mark_assets(asset):
if asset.asset_data is None:
if debug:
print(' Mark as Asset: ', asset.name)
asset.asset_mark()
#bpy.ops.ed.lib_id_generate_preview_from_object()
asset.asset_generate_preview()
def clear_assets(asset):
if asset.asset_data is not None:
if debug:
print(' Clear Asset: ', asset.name)
asset.asset_clear()
asset.use_fake_user = True
process_assets(argv=argv)
'''
BLI_assert failed: C:\Repo\BlenderScripts\build_blender\BlenderGit\source\blender\windowmanager\intern\wm_window.c:2315, WM_opengl_context_create(), at 'BLI_thread_is_main()'
'''