33# https://github.com/RenaudRohlinger/blender_gltf_scripts
44
55import os
6+
7+
8+ if "bpy" in locals ():
9+ import importlib
10+ importlib .reload (apply_all )
11+ else :
12+ from . import apply_all
13+
614import bpy
7- from bpy_extras .io_utils import ExportHelper
815
916bl_info = {
1017 "name" : "GLTF Scripts" ,
2027
2128loading = False
2229
23-
2430def main_instance (self , context ):
2531 bpy .context .window .cursor_set ("WAIT" )
2632 loading = True
2733 bpy .ops .object .select_all (action = "DESELECT" )
2834
2935 # 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 )
3542
3643 # name of the glb generated based on the name of the .blend file
3744 basedir = os .path .dirname (bpy .data .filepath )
@@ -94,6 +101,86 @@ def main_instance(self, context):
94101 pass
95102
96103
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+
97184def main (self , context ):
98185 bpy .context .window .cursor_set ("WAIT" )
99186 loading = True
@@ -252,6 +339,25 @@ def main_gltf(self, context):
252339 pass
253340
254341
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+
255361class SimpleGLTF (bpy .types .Operator ):
256362 bl_idname = "object.simple_gltf"
257363 bl_label = "Quick Scene Export"
@@ -264,7 +370,7 @@ def execute(self, context):
264370 bpy .context .window .cursor_set ("WAIT" )
265371 # loading = True
266372 main_gltf (self , context )
267- # bpy.ops.ed.undo()
373+ bpy .ops .ed .undo ()
268374 bpy .context .window .cursor_set ("DEFAULT" )
269375 # loading = False
270376 return {"FINISHED" }
@@ -274,7 +380,6 @@ def execute(self, context):
274380 # raise the exception again
275381 raise e
276382
277-
278383class BakeCamera (bpy .types .Operator ):
279384 bl_idname = "object.simple_operator"
280385 bl_label = "Camera Bake Export"
@@ -476,11 +581,13 @@ def draw(self, context):
476581 )
477582 layout .operator ("object.simple_gltf" ,
478583 icon = "SHADERFX" , depress = loading )
584+ layout .operator ("object.gltf_collider" ,
585+ icon = "MOD_BUILD" , depress = loading )
479586 layout .operator ("object.curves_export" ,
480587 icon = "FORCE_CURVE" , depress = loading )
481588
482589
483- blender_classes = [BakeCamera , SimpleGLTF ,
590+ blender_classes = [BakeCamera , SimpleGLTF , GLTF_Collider ,
484591 GLTF_PT_Panel , GLTF_Instance , Curves_Export ]
485592
486593
0 commit comments