blender exporter python addon + convex collision gn

This commit is contained in:
Jérémie GABOLDE 2024-11-22 23:40:44 +01:00
parent a2b32c4481
commit 3a475f1139
5 changed files with 51 additions and 9 deletions

Binary file not shown.

BIN
AssetSources/Meshes/STM_Rock_Flat_Einstein_1m.fbx (Stored with Git LFS) Normal file

Binary file not shown.

BIN
AssetSources/Meshes/STM_Rock_Flat_Einstein_2m.fbx (Stored with Git LFS) Normal file

Binary file not shown.

BIN
AssetSources/Meshes/STM_Rock_Flat_Einstein_3m.fbx (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -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)