3
3
# https://github.com/RenaudRohlinger/blender_gltf_scripts
4
4
5
5
import os
6
+
7
+
8
+ if "bpy" in locals ():
9
+ import importlib
10
+ importlib .reload (apply_all )
11
+ else :
12
+ from . import apply_all
13
+
6
14
import bpy
7
- from bpy_extras .io_utils import ExportHelper
8
15
9
16
bl_info = {
10
17
"name" : "GLTF Scripts" ,
20
27
21
28
loading = False
22
29
23
-
24
30
def main_instance (self , context ):
25
31
bpy .context .window .cursor_set ("WAIT" )
26
32
loading = True
27
33
bpy .ops .object .select_all (action = "DESELECT" )
28
34
29
35
# prevent the undo to not work
30
- collections = bpy .data .collections
31
- for collection in collections :
32
- if collection .users_dupli_group :
33
- for obj in collection .all_objects :
34
- obj .select_set (True )
36
+ objects = [ob for ob in bpy .context .view_layer .objects if ob .visible_get ()]
37
+
38
+ mesh = [m for m in objects if m .type == 'MESH' ]
39
+
40
+ for obj in mesh :
41
+ obj .select_set (True )
35
42
36
43
# name of the glb generated based on the name of the .blend file
37
44
basedir = os .path .dirname (bpy .data .filepath )
@@ -94,6 +101,86 @@ def main_instance(self, context):
94
101
pass
95
102
96
103
104
+
105
+
106
+ def export_collider (self , context ):
107
+ bpy .context .window .cursor_set ("WAIT" )
108
+ loading = True
109
+ bpy .ops .object .select_all (action = "SELECT" )
110
+
111
+ # prevent the undo to not work
112
+ # collections = bpy.data.collections
113
+ # for collection in collections:
114
+ # for obj in collection.all_objects:
115
+ # obj.select_set(True)
116
+
117
+
118
+
119
+ bpy .ops .object .select_all (action = 'DESELECT' )
120
+
121
+ objects = [ob for ob in bpy .context .view_layer .objects if ob .visible_get ()]
122
+
123
+ mesh = [m for m in objects if m .type == 'MESH' ]
124
+
125
+ for obj in mesh :
126
+ obj .select_set (state = True )
127
+
128
+ bpy .context .view_layer .objects .active = obj
129
+
130
+ apply_all .apply_all_modifier (self , context )
131
+
132
+ bpy .ops .object .join ()
133
+
134
+ # name of the glb generated based on the name of the .blend file
135
+ basedir = os .path .dirname (bpy .data .filepath )
136
+
137
+ # add user basedir path if available
138
+ if context .scene .dir_path :
139
+ basedir = bpy .path .abspath (context .scene .dir_path )
140
+
141
+ name = os .path .splitext (os .path .basename (bpy .data .filepath ))[0 ]
142
+
143
+ if context .scene .filename_path :
144
+ name = context .scene .filename_path
145
+
146
+ if not name :
147
+ context .scene .filename_path = "scene"
148
+ name = "scene"
149
+
150
+ fn = os .path .join (basedir , name ) + "_physic.glb"
151
+
152
+ wm = bpy .types .WindowManager
153
+ props = wm .operator_properties_last ("export_scene.gltf" )
154
+ dic = {}
155
+ for k , v in props .items ():
156
+ dic [k ] = v
157
+
158
+ if context .scene .advanced_mode :
159
+ if props :
160
+ fn = dic ["filepath" ][:- 4 ] + "_physic.glb"
161
+
162
+ bpy .ops .export_scene .gltf (
163
+ filepath = fn ,
164
+ check_existing = True ,
165
+ export_format = "GLB" ,
166
+ ui_tab = "GENERAL" ,
167
+ use_selection = True ,
168
+ export_materials = "NONE" ,
169
+ export_colors = False ,
170
+ export_apply = True ,
171
+ export_normals = False ,
172
+ export_texcoords = False ,
173
+ export_draco_mesh_compression_level = context .scene .draco_level ,
174
+ export_draco_mesh_compression_enable = False ,
175
+ )
176
+ self .report ({"INFO" }, "GLTF Export completed" )
177
+
178
+ bpy .context .window .cursor_set ("DEFAULT" )
179
+ loading = False
180
+ pass
181
+
182
+
183
+
97
184
def main (self , context ):
98
185
bpy .context .window .cursor_set ("WAIT" )
99
186
loading = True
@@ -252,6 +339,25 @@ def main_gltf(self, context):
252
339
pass
253
340
254
341
342
+ class GLTF_Collider (bpy .types .Operator ):
343
+ bl_idname = "object.gltf_collider"
344
+ bl_label = "Collider Export"
345
+
346
+ def execute (self , context ):
347
+ try :
348
+ self .report (
349
+ {"INFO" }, "----- ----- ----- GLTF Scripts ----- ----- -----" )
350
+ self .report ({"INFO" }, "Collider merge processing" )
351
+ bpy .ops .ed .undo_push (message = "Collider Export" )
352
+ export_collider (self , context )
353
+ bpy .ops .ed .undo ()
354
+ return {"FINISHED" }
355
+ except Exception as e :
356
+ print ("Something went wrong" )
357
+ self .report ({"ERROR" }, "Something went wrong" )
358
+ # raise the exception again
359
+ raise e
360
+
255
361
class SimpleGLTF (bpy .types .Operator ):
256
362
bl_idname = "object.simple_gltf"
257
363
bl_label = "Quick Scene Export"
@@ -264,7 +370,7 @@ def execute(self, context):
264
370
bpy .context .window .cursor_set ("WAIT" )
265
371
# loading = True
266
372
main_gltf (self , context )
267
- # bpy.ops.ed.undo()
373
+ bpy .ops .ed .undo ()
268
374
bpy .context .window .cursor_set ("DEFAULT" )
269
375
# loading = False
270
376
return {"FINISHED" }
@@ -274,7 +380,6 @@ def execute(self, context):
274
380
# raise the exception again
275
381
raise e
276
382
277
-
278
383
class BakeCamera (bpy .types .Operator ):
279
384
bl_idname = "object.simple_operator"
280
385
bl_label = "Camera Bake Export"
@@ -476,11 +581,13 @@ def draw(self, context):
476
581
)
477
582
layout .operator ("object.simple_gltf" ,
478
583
icon = "SHADERFX" , depress = loading )
584
+ layout .operator ("object.gltf_collider" ,
585
+ icon = "MOD_BUILD" , depress = loading )
479
586
layout .operator ("object.curves_export" ,
480
587
icon = "FORCE_CURVE" , depress = loading )
481
588
482
589
483
- blender_classes = [BakeCamera , SimpleGLTF ,
590
+ blender_classes = [BakeCamera , SimpleGLTF , GLTF_Collider ,
484
591
GLTF_PT_Panel , GLTF_Instance , Curves_Export ]
485
592
486
593
0 commit comments