Add Convex Functionality

This commit is contained in:
D4rkl1ght3r
2025-09-21 00:05:53 +02:00
parent 992465295d
commit 537c842904

View File

@@ -8,6 +8,7 @@ bl_info = {
"category": "Development",
}
import bmesh
import bpy
import re
@@ -158,6 +159,59 @@ class RenameChildObjectOperator(bpy.types.Operator):
self.report({'INFO'}, "Selected child objects renamed successfully")
return {'FINISHED'}
class OBJECT_OT_create_convex(bpy.types.Operator):
bl_idname = "object.create_convex"
bl_label = "Create Convex"
bl_description = "Delete faces and edges, then create a convex hull of the active object"
def execute(self, context):
obj = context.active_object
if not obj or obj.type != 'MESH':
self.report({'WARNING'}, "No active mesh object selected")
return {'CANCELLED'}
# Make object active and selected
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.select_all(action='DESELECT')
obj.select_set(True)
context.view_layer.objects.active = obj
# Enter edit mode
bpy.ops.object.mode_set(mode='EDIT')
mesh = bmesh.from_edit_mesh(obj.data)
# Delete all faces and edges
bmesh.ops.delete(mesh, geom=[f for f in mesh.faces] + [e for e in mesh.edges], context='EDGES_FACES')
bmesh.update_edit_mesh(obj.data)
# Exit edit mode
bpy.ops.object.mode_set(mode='OBJECT')
# Now, perform the convex hull operation on the vertices
# Create a new bmesh from the current mesh
bm = bmesh.new()
bm.from_mesh(obj.data)
# Perform convex hull
bmesh.ops.convex_hull(bm, input=bm.verts)
# Write back to the mesh
bm.to_mesh(obj.data)
bm.free()
self.report({'INFO'}, "Convex hull created")
return {'FINISHED'}
# Alternatively, directly run the convex hull operator:
bpy.ops.object.select_all(action='DESELECT')
obj.select_set(True)
context.view_layer.objects.active = obj
bpy.ops.object.convert(target='MESH')
bpy.ops.mesh.convex_hull()
self.report({'INFO'}, "Convex hull created")
return {'FINISHED'}
class LancerEditHelpersPanel(bpy.types.Panel):
bl_label = "LancerEdit Model Utility Plugin"
@@ -180,8 +234,13 @@ class LancerEditHelpersPanel(bpy.types.Panel):
# Section for renaming selected child object
layout.separator()
layout.label(text="Surface Creation Kit")
layout.label(text="Surface Creation Kit:")
# Button for creating Convex Hull Object
layout.operator("object.create_convex")
layout.separator()
# Input Dialogue for Sur Name
layout.prop(scene, "child_object_new_name")
# Button for Convert to Hull
layout.operator("object.rename_selected_child")
@@ -189,6 +248,7 @@ def register():
bpy.utils.register_class(LancerEditHelpersPanel)
bpy.utils.register_class(RenameObjectsAndMeshesOperator)
bpy.utils.register_class(RenameChildObjectOperator)
bpy.utils.register_class(OBJECT_OT_create_convex)
bpy.types.Scene.object_names = bpy.props.StringProperty(
name="Parent Name",
@@ -210,6 +270,7 @@ def unregister():
bpy.utils.unregister_class(LancerEditHelpersPanel)
bpy.utils.unregister_class(RenameObjectsAndMeshesOperator)
bpy.utils.unregister_class(RenameChildObjectOperator)
bpy.utils.unregister_class(OBJECT_OT_create_convex)
del bpy.types.Scene.object_names
del bpy.types.Scene.new_name
del bpy.types.Scene.child_object_new_name