From 3a475f11393ef19fab43c6a763214f78f3fb296e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20GABOLDE?= Date: Fri, 22 Nov 2024 23:40:44 +0100 Subject: [PATCH] blender exporter python addon + convex collision gn --- .../Meshes/STM_Rock_Flat_Einstein.blend | 4 +- .../Meshes/STM_Rock_Flat_Einstein_1m.fbx | 3 ++ .../Meshes/STM_Rock_Flat_Einstein_2m.fbx | 3 ++ .../Meshes/STM_Rock_Flat_Einstein_3m.fbx | 3 ++ AssetSources/Meshes/UnrealExporter.py | 47 ++++++++++++++++--- 5 files changed, 51 insertions(+), 9 deletions(-) create mode 100644 AssetSources/Meshes/STM_Rock_Flat_Einstein_1m.fbx create mode 100644 AssetSources/Meshes/STM_Rock_Flat_Einstein_2m.fbx create mode 100644 AssetSources/Meshes/STM_Rock_Flat_Einstein_3m.fbx diff --git a/AssetSources/Meshes/STM_Rock_Flat_Einstein.blend b/AssetSources/Meshes/STM_Rock_Flat_Einstein.blend index 0b06365..a028f51 100644 --- a/AssetSources/Meshes/STM_Rock_Flat_Einstein.blend +++ b/AssetSources/Meshes/STM_Rock_Flat_Einstein.blend @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:73ea6324f3f0a7d100586babd8e2e33ba48a7d3cbb572fc0e2542732c9ec3629 -size 1236274 +oid sha256:7a8bbf38c089f2f0d6956b9276b79bcfaf8e47d020e11eccbf78b7cf12fdbca2 +size 1169299 diff --git a/AssetSources/Meshes/STM_Rock_Flat_Einstein_1m.fbx b/AssetSources/Meshes/STM_Rock_Flat_Einstein_1m.fbx new file mode 100644 index 0000000..0d039d3 --- /dev/null +++ b/AssetSources/Meshes/STM_Rock_Flat_Einstein_1m.fbx @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5c442de0194466d38f3061643b1e8e4e1f45ef5b0875d29052dd96c08b52640d +size 222796 diff --git a/AssetSources/Meshes/STM_Rock_Flat_Einstein_2m.fbx b/AssetSources/Meshes/STM_Rock_Flat_Einstein_2m.fbx new file mode 100644 index 0000000..198a176 --- /dev/null +++ b/AssetSources/Meshes/STM_Rock_Flat_Einstein_2m.fbx @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a753c80d9780904ec166a26ef60fdc9ba429fe08f30d9d91eb57fc152d943771 +size 279068 diff --git a/AssetSources/Meshes/STM_Rock_Flat_Einstein_3m.fbx b/AssetSources/Meshes/STM_Rock_Flat_Einstein_3m.fbx new file mode 100644 index 0000000..2267018 --- /dev/null +++ b/AssetSources/Meshes/STM_Rock_Flat_Einstein_3m.fbx @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:04500f5ca2ad39685d66c3c02d86432543a7bb87a551cb96828c1eb6f7215bcf +size 308844 diff --git a/AssetSources/Meshes/UnrealExporter.py b/AssetSources/Meshes/UnrealExporter.py index c9352c7..c17c3f3 100644 --- a/AssetSources/Meshes/UnrealExporter.py +++ b/AssetSources/Meshes/UnrealExporter.py @@ -92,19 +92,38 @@ class OBJECT_OT_CombineExport(bpy.types.Operator): return {'FINISHED'} def SeparateExport(exportFolder): + #collection_collision_export = bpy.ops.collection.create("Collision.Export") + collection_collision_export = bpy.data.collections.new("Collision.Export") + bpy.context.scene.collection.children.link(collection_collision_export) objects = bpy.data.collections[bpy.context.scene.ue_exporter.source_collection].all_objects #for some absurd logic it works only if objects comes from the selection, no time to explain... - for object in objects: - object.select_set(True) - objects = bpy.context.selected_objects + #for object in objects: + # object.select_set(True) + #objects = bpy.context.selected_objects bpy.ops.object.select_all(action='DESELECT') - for object in objects: - object.select_set(True) + for object in list(objects): if object.type not in ['MESH']: continue + collision = bpy.data.objects['UCX_' + object.name] + export_collision = collision.copy() + export_collision.data = collision.data.copy() + export_collision.animation_data_clear() + bpy.context.collection.objects.link(export_collision) + #bpy.data.collections['Collision.Export'].objects.link(export_collision) + collection_collision_export.objects.link(export_collision) + export_collision.select_set(True) + bpy.context.view_layer.objects.active = export_collision + bpy.ops.object.modifier_apply(modifier='GeometryNodes') + bpy.ops.mesh.separate(type='LOOSE') + object.select_set(True) exportName = bpy.path.abspath(exportFolder) + object.name + '.fbx' - bpy.ops.export_scene.fbx(filepath=exportName, use_selection=True, mesh_smooth_type='FACE') - object.select_set(False) + bpy.ops.export_scene.fbx(filepath=exportName, use_selection=True, mesh_smooth_type='FACE') + bpy.ops.object.select_all(action='DESELECT') + objects = collection_collision_export.all_objects + for object in objects: + object.select_set(True) + bpy.ops.object.delete() + bpy.data.collections.remove(collection_collision_export) def CombineExport(exportFolder): objects = bpy.data.collections[bpy.context.scene.ue_exporter.source_collection].all_objects @@ -136,6 +155,20 @@ classes = ( UEExporterSettings ) +def apply_modifiers(obj): + ctx = bpy.context.copy() + ctx['object'] = obj + for _, m in enumerate(obj.modifiers): + try: + ctx['modifier'] = m + bpy.ops.object.modifier_apply(ctx, modifier=m.name) + except RuntimeError: + print(f"Error applying {m.name} to {obj.name}, removing it instead.") + obj.modifiers.remove(m) + + for m in obj.modifiers: + obj.modifiers.remove(m) + def register(): for c in classes: bpy.utils.register_class(c)