blender exporter python addon + convex collision gn
This commit is contained in:
parent
a2b32c4481
commit
3a475f1139
BIN
AssetSources/Meshes/STM_Rock_Flat_Einstein.blend (Stored with Git LFS)
BIN
AssetSources/Meshes/STM_Rock_Flat_Einstein.blend (Stored with Git LFS)
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -92,19 +92,38 @@ class OBJECT_OT_CombineExport(bpy.types.Operator):
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
def SeparateExport(exportFolder):
|
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
|
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 some absurd logic it works only if objects comes from the selection, no time to explain...
|
||||||
for object in objects:
|
#for object in objects:
|
||||||
object.select_set(True)
|
# object.select_set(True)
|
||||||
objects = bpy.context.selected_objects
|
#objects = bpy.context.selected_objects
|
||||||
bpy.ops.object.select_all(action='DESELECT')
|
bpy.ops.object.select_all(action='DESELECT')
|
||||||
for object in objects:
|
for object in list(objects):
|
||||||
object.select_set(True)
|
|
||||||
if object.type not in ['MESH']:
|
if object.type not in ['MESH']:
|
||||||
continue
|
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'
|
exportName = bpy.path.abspath(exportFolder) + object.name + '.fbx'
|
||||||
bpy.ops.export_scene.fbx(filepath=exportName, use_selection=True, mesh_smooth_type='FACE')
|
bpy.ops.export_scene.fbx(filepath=exportName, use_selection=True, mesh_smooth_type='FACE')
|
||||||
object.select_set(False)
|
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):
|
def CombineExport(exportFolder):
|
||||||
objects = bpy.data.collections[bpy.context.scene.ue_exporter.source_collection].all_objects
|
objects = bpy.data.collections[bpy.context.scene.ue_exporter.source_collection].all_objects
|
||||||
|
@ -136,6 +155,20 @@ classes = (
|
||||||
UEExporterSettings
|
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():
|
def register():
|
||||||
for c in classes:
|
for c in classes:
|
||||||
bpy.utils.register_class(c)
|
bpy.utils.register_class(c)
|
||||||
|
|
Loading…
Reference in New Issue