@@ -125,6 +125,99 @@ def dks_ue_get_texture_file(texture_path,mesh_name,mat_name,texture_name,texture
125125 else :
126126 return ""
127127
128+ def dks_ue_create_bjd (self , context ):
129+
130+ global _preferences
131+
132+ blender_data = {}
133+
134+ blender_data ['path' ]= dks_ue_get_export_sub ().replace ("\\ " ,"/" )
135+
136+ blender_data ['options' ] = {}
137+
138+ blender_data ['options' ]['ImportMesh' ]= bpy .context .preferences .addons [__package__ ].preferences .ue_ImportMesh ;
139+ blender_data ['options' ]['ImportMaterials' ]= bpy .context .preferences .addons [__package__ ].preferences .ue_ImportMaterials ;
140+ blender_data ['options' ]['ImportAnimations' ]= bpy .context .preferences .addons [__package__ ].preferences .ue_ImportAnimations ;
141+ blender_data ['options' ]['CreatePhysicsAsset' ]= bpy .context .preferences .addons [__package__ ].preferences .ue_CreatePhysicsAsset ;
142+ blender_data ['options' ]['AutoComputeLodDistances' ]= bpy .context .preferences .addons [__package__ ].preferences .ue_AutoComputeLodDistances ;
143+
144+ blender_data ['options' ]['static_mesh' ]= {}
145+ blender_data ['options' ]['static_mesh' ]['NormalImportMethod' ]= bpy .context .preferences .addons [__package__ ].preferences .ue_static_mesh_NormalImportMethod ;
146+ blender_data ['options' ]['static_mesh' ]['ImportMeshLODs' ]= bpy .context .preferences .addons [__package__ ].preferences .ue_static_mesh_ImportMeshLODs ;
147+ blender_data ['options' ]['static_mesh' ]['CombineMeshes' ]= bpy .context .preferences .addons [__package__ ].preferences .ue_static_mesh_CombineMeshes ;
148+ blender_data ['options' ]['static_mesh' ]['AutoGenerateCollision' ]= bpy .context .preferences .addons [__package__ ].preferences .ue_static_mesh_AutoGenerateCollision ;
149+
150+ blender_data ['options' ]['skeletal_mesh' ]= {}
151+ blender_data ['options' ]['skeletal_mesh' ]['NormalImportMethod' ]= bpy .context .preferences .addons [__package__ ].preferences .ue_skeletal_mesh_NormalImportMethod ;
152+ blender_data ['options' ]['skeletal_mesh' ]['ImportMeshLODs' ]= bpy .context .preferences .addons [__package__ ].preferences .ue_skeletal_mesh_ImportMeshLODs ;
153+ blender_data ['options' ]['skeletal_mesh' ]['UseT0AsRefPose' ]= bpy .context .preferences .addons [__package__ ].preferences .ue_skeletal_mesh_UseT0AsRefPose ;
154+ blender_data ['options' ]['skeletal_mesh' ]['PreserveSmoothingGroups' ]= bpy .context .preferences .addons [__package__ ].preferences .ue_skeletal_mesh_PreserveSmoothingGroups ;
155+ blender_data ['options' ]['skeletal_mesh' ]['ImportMorphTargets' ]= bpy .context .preferences .addons [__package__ ].preferences .ue_skeletal_mesh_ImportMorphTargets ;
156+
157+ blender_data ['options' ]['animation' ]= {}
158+ blender_data ['options' ]['animation' ]['animation_length' ]= bpy .context .preferences .addons [__package__ ].preferences .ue_animation_animation_length ;
159+ blender_data ['options' ]['animation' ]['frame_range_min' ]= bpy .context .preferences .addons [__package__ ].preferences .ue_animation_frame_range_min ;
160+ blender_data ['options' ]['animation' ]['frame_range_max' ]= bpy .context .preferences .addons [__package__ ].preferences .ue_animation_frame_range_max ;
161+ blender_data ['options' ]['animation' ]['ImportMeshesInBoneHierarchy' ]= bpy .context .preferences .addons [__package__ ].preferences .ue_animation_ImportMeshesInBoneHierarchy ;
162+ blender_data ['options' ]['animation' ]['UseDefaultSampleRate' ]= bpy .context .preferences .addons [__package__ ].preferences .ue_animation_UseDefaultSampleRate ;
163+ blender_data ['options' ]['animation' ]['CustomSampleRate' ]= bpy .context .preferences .addons [__package__ ].preferences .ue_animation_CustomSampleRate ;
164+ blender_data ['options' ]['animation' ]['ConvertScene' ]= bpy .context .preferences .addons [__package__ ].preferences .ue_animation_ConvertScene ;
165+
166+ blender_data ['materials' ] = []
167+
168+ if _preferences ["option_copy_textures" ]:
169+
170+ _objects = bpy .context .scene .objects
171+ _texture_ext = "png"
172+
173+ _path_textures_from = bpy .path .abspath ('//' ) + _preferences ["option_textures_folder" ] + sep
174+ _path_textures_to = dks_ue_get_export_path () + _preferences ["option_textures_folder" ] + sep
175+
176+ for _obj in _objects :
177+
178+ if _obj .type == 'MESH' :
179+
180+ _obj_name = _obj .name
181+
182+ _materials = _obj .data .materials
183+
184+ for _material in _materials :
185+
186+ _material_name = _material .name
187+
188+ _material_data = {}
189+ _material_data ["name" ]= _material_name
190+
191+ _file_Base_Color = dks_ue_get_texture_file (_path_textures_from ,_obj_name ,_material_name ,'Base_Color' ,_texture_ext )
192+ if _file_Base_Color == "" :
193+ _file_Base_Color = dks_ue_get_texture_file (_path_textures_from ,_obj_name ,_material_name ,'BaseColor' ,_texture_ext )
194+ _file_Ambient_occlusion = dks_ue_get_texture_file (_path_textures_from ,_obj_name ,_material_name ,'Ambient_occlusion' ,_texture_ext )
195+ _file_Metallic = dks_ue_get_texture_file (_path_textures_from ,_obj_name ,_material_name ,'Metallic' ,_texture_ext )
196+ _file_Roughness = dks_ue_get_texture_file (_path_textures_from ,_obj_name ,_material_name ,'Roughness' ,_texture_ext )
197+ _file_ORM = dks_ue_get_texture_file (_path_textures_from ,_obj_name ,_material_name ,'OcclusionRoughnessMetallic' ,_texture_ext )
198+ _file_Opacity = dks_ue_get_texture_file (_path_textures_from ,_obj_name ,_material_name ,'Opacity' ,_texture_ext )
199+ _file_Normal = dks_ue_get_texture_file (_path_textures_from ,_obj_name ,_material_name ,'Normal' ,_texture_ext )
200+ if _file_Normal == "" :
201+ _file_Normal = dks_ue_get_texture_file (_path_textures_from ,_obj_name ,_material_name ,'Normal_OpenGL' ,_texture_ext )
202+ _file_Emissive = dks_ue_get_texture_file (_path_textures_from ,_obj_name ,_material_name ,'Emissive' ,_texture_ext )
203+
204+ _material_data ['base_color' ]= _file_Base_Color [len (bpy .path .abspath ('//' )):].replace ("\\ " ,"/" ).replace ("." + _texture_ext ,"" )
205+ _material_data ['normal' ]= _file_Normal [len (bpy .path .abspath ('//' )):].replace ("\\ " ,"/" ).replace ("." + _texture_ext ,"" )
206+ _material_data ['orm' ]= _file_ORM [len (bpy .path .abspath ('//' )):].replace ("\\ " ,"/" ).replace ("." + _texture_ext ,"" )
207+ _material_data ['opacity' ]= _file_Opacity [len (bpy .path .abspath ('//' )):].replace ("\\ " ,"/" ).replace ("." + _texture_ext ,"" )
208+ _material_data ['ambient_occlusion' ]= _file_Ambient_occlusion [len (bpy .path .abspath ('//' )):].replace ("\\ " ,"/" ).replace ("." + _texture_ext ,"" )
209+ _material_data ['metallic' ]= _file_Metallic [len (bpy .path .abspath ('//' )):].replace ("\\ " ,"/" ).replace ("." + _texture_ext ,"" )
210+ _material_data ['roughness' ]= _file_Roughness [len (bpy .path .abspath ('//' )):].replace ("\\ " ,"/" ).replace ("." + _texture_ext ,"" )
211+ _material_data ['emissive' ]= _file_Emissive [len (bpy .path .abspath ('//' )):].replace ("\\ " ,"/" ).replace ("." + _texture_ext ,"" )
212+
213+ blender_data ['materials' ].append (_material_data )
214+
215+ json_data = json .dumps (blender_data , sort_keys = False , indent = 3 )
216+ json_data_filename = dks_ue_filename ().replace (".fbx" ,".bjd" )
217+
218+ with open (json_data_filename , 'w' ) as f :
219+ json .dump (blender_data , f )
220+
128221class dks_ue_export (bpy .types .Operator ):
129222
130223 bl_idname = "dks_ue.export"
@@ -217,63 +310,9 @@ def execute(self, context):
217310 if path .exists (_path_textures_from ):
218311 dir_util .copy_tree (_path_textures_from , _path_textures_to )
219312
220- blender_data = {}
221- blender_data ['path' ]= dks_ue_get_export_sub ().replace ("\\ " ,"/" )
222- blender_data ['options' ] = {}
223-
224- blender_data ['options' ]['ImportMaterials' ]= True ;
225- blender_data ['options' ]['ImportAnimations' ]= True ;
226- blender_data ['options' ]['CreatePhysicsAsset' ]= True ;
227-
228- blender_data ['materials' ] = []
229-
230- _objects = bpy .context .scene .objects
231- _texture_ext = "png"
232-
233- for _obj in _objects :
234-
235- if _obj .type == 'MESH' :
236-
237- _obj_name = _obj .name
238-
239- _materials = _obj .data .materials
240-
241- for _material in _materials :
242-
243- _material_name = _material .name
244-
245- _material_data = {}
246- _material_data ["name" ]= _material_name
247-
248- _file_Base_Color = dks_ue_get_texture_file (_path_textures_from ,_obj_name ,_material_name ,'Base_Color' ,_texture_ext )
249- if _file_Base_Color == "" :
250- _file_Base_Color = dks_ue_get_texture_file (_path_textures_from ,_obj_name ,_material_name ,'BaseColor' ,_texture_ext )
251- _file_Ambient_occlusion = dks_ue_get_texture_file (_path_textures_from ,_obj_name ,_material_name ,'Ambient_occlusion' ,_texture_ext )
252- _file_Metallic = dks_ue_get_texture_file (_path_textures_from ,_obj_name ,_material_name ,'Metallic' ,_texture_ext )
253- _file_Roughness = dks_ue_get_texture_file (_path_textures_from ,_obj_name ,_material_name ,'Roughness' ,_texture_ext )
254- _file_ORM = dks_ue_get_texture_file (_path_textures_from ,_obj_name ,_material_name ,'OcclusionRoughnessMetallic' ,_texture_ext )
255- _file_Opacity = dks_ue_get_texture_file (_path_textures_from ,_obj_name ,_material_name ,'Opacity' ,_texture_ext )
256- _file_Normal = dks_ue_get_texture_file (_path_textures_from ,_obj_name ,_material_name ,'Normal' ,_texture_ext )
257- if _file_Normal == "" :
258- _file_Normal = dks_ue_get_texture_file (_path_textures_from ,_obj_name ,_material_name ,'Normal_OpenGL' ,_texture_ext )
259- _file_Emissive = dks_ue_get_texture_file (_path_textures_from ,_obj_name ,_material_name ,'Emissive' ,_texture_ext )
260-
261- _material_data ['base_color' ]= _file_Base_Color [len (bpy .path .abspath ('//' )):].replace ("\\ " ,"/" ).replace ("." + _texture_ext ,"" )
262- _material_data ['normal' ]= _file_Normal [len (bpy .path .abspath ('//' )):].replace ("\\ " ,"/" ).replace ("." + _texture_ext ,"" )
263- _material_data ['orm' ]= _file_ORM [len (bpy .path .abspath ('//' )):].replace ("\\ " ,"/" ).replace ("." + _texture_ext ,"" )
264- _material_data ['opacity' ]= _file_Opacity [len (bpy .path .abspath ('//' )):].replace ("\\ " ,"/" ).replace ("." + _texture_ext ,"" )
265- _material_data ['ambient_occlusion' ]= _file_Ambient_occlusion [len (bpy .path .abspath ('//' )):].replace ("\\ " ,"/" ).replace ("." + _texture_ext ,"" )
266- _material_data ['metallic' ]= _file_Metallic [len (bpy .path .abspath ('//' )):].replace ("\\ " ,"/" ).replace ("." + _texture_ext ,"" )
267- _material_data ['roughness' ]= _file_Roughness [len (bpy .path .abspath ('//' )):].replace ("\\ " ,"/" ).replace ("." + _texture_ext ,"" )
268- _material_data ['emissive' ]= _file_Emissive [len (bpy .path .abspath ('//' )):].replace ("\\ " ,"/" ).replace ("." + _texture_ext ,"" )
269-
270- blender_data ['materials' ].append (_material_data )
271-
272- json_data = json .dumps (blender_data , sort_keys = False , indent = 3 )
273- json_data_filename = dks_ue_filename ().replace (".fbx" ,".bjd" )
274-
275- with open (json_data_filename , 'w' ) as f :
276- json .dump (blender_data , f )
313+ if _preferences ["option_ue_json" ]:
314+
315+ dks_ue_create_bjd (self , context )
277316
278317 return {'FINISHED' }
279318
0 commit comments