Skip to content

Commit

Permalink
Support Curves
Browse files Browse the repository at this point in the history
  • Loading branch information
Weisl committed Jun 26, 2023
1 parent afbbd79 commit 483ced6
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 3 deletions.
4 changes: 3 additions & 1 deletion auto_Convex/add_bounding_auto_convex.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ def execute(self, context):
# skip if invalid object
if not self.is_valid_object(obj):
continue

if obj and obj.type == 'CURVE':
obj = self.curve_to_mesh(context, obj)

context.view_layer.objects.active = obj

if self.obj_mode == "EDIT":
Expand Down
2 changes: 2 additions & 0 deletions collider_conversion/conversion_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ def execute(self, context):
# skip if invalid object
if not self.is_valid_object(obj):
continue
if obj and obj.type == 'CURVE':
obj = self.curve_to_mesh(context, obj)

new_collider = obj.copy()
new_collider.data = obj.data.copy()
Expand Down
3 changes: 3 additions & 0 deletions collider_shapes/add_bounding_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ def execute(self, context):
if not self.is_valid_object(obj):
continue

if obj and obj.type == 'CURVE':
obj = self.curve_to_mesh(context, obj)

context.view_layer.objects.active = obj
bounding_box_data = {}

Expand Down
3 changes: 3 additions & 0 deletions collider_shapes/add_bounding_capsule.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ def execute(self, context):
if not self.is_valid_object(obj):
continue

if obj and obj.type == 'CURVE':
obj = self.curve_to_mesh(context, obj)

context.view_layer.objects.active = obj
bounding_capsule_data = {}

Expand Down
3 changes: 3 additions & 0 deletions collider_shapes/add_bounding_convex_hull.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ def execute(self, context):
if not self.is_valid_object(obj):
continue

if obj and obj.type == 'CURVE':
obj = self.curve_to_mesh(context, obj)

convex_collision_data = {}

if self.obj_mode == "EDIT":
Expand Down
3 changes: 3 additions & 0 deletions collider_shapes/add_bounding_cylinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ def execute(self, context):
if not self.is_valid_object(obj):
continue

if obj and obj.type == 'CURVE':
obj = self.curve_to_mesh(context, obj)

bounding_cylinder_data = {}

if self.obj_mode == 'EDIT':
Expand Down
16 changes: 14 additions & 2 deletions collider_shapes/add_bounding_primitive.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ def mesh_from_selection(obj, use_modifiers=False):
@staticmethod
def is_valid_object(obj):
"""Is the object valid to be used as a base mesh for collider generation"""
if obj is None or obj.type != "MESH":
if obj is None or obj.type not in ["MESH","CURVE"]:
return False
return True

Expand Down Expand Up @@ -854,6 +854,18 @@ def print_generation_time(shape, time):
print(shape)
print("Time elapsed: ", str(time))

def curve_to_mesh(self, context, curve):
deg = context.evaluated_depsgraph_get()
me = bpy.data.meshes.new_from_object(curve.evaluated_get(deg), depsgraph=deg)

new_obj = bpy.data.objects.new(curve.name + "_mesh", me)
context.collection.objects.link(new_obj)

new_obj.matrix_world = curve.matrix_world
context.view_layer.objects.active = new_obj

return new_obj

def primitive_postprocessing(self, context, bounding_object, base_object_collections):
colSettings = context.scene.collider_tools

Expand Down Expand Up @@ -1061,7 +1073,7 @@ def __init__(self):
def poll(cls, context):
count = 0
for obj in context.selected_objects:
if obj.type == 'MESH':
if obj.type in ['MESH','CURVE']:
count = count + 1
return count > 0

Expand Down
3 changes: 3 additions & 0 deletions collider_shapes/add_bounding_sphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ def execute(self, context):
if not self.is_valid_object(obj):
continue

if obj and obj.type == 'CURVE':
obj = self.curve_to_mesh(context, obj)

initial_mod_state = {}
context.view_layer.objects.active = obj
scene = context.scene
Expand Down
2 changes: 2 additions & 0 deletions collider_shapes/add_collision_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def execute(self, context):
# skip if invalid object
if not self.is_valid_object(obj):
continue
if obj and obj.type == 'CURVE':
obj = self.curve_to_mesh(context, obj)

mesh_collider_data = {}

Expand Down
2 changes: 2 additions & 0 deletions collider_shapes/add_minimum_bounding_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ def execute(self, context):
# skip if invalid object
if not self.is_valid_object(obj):
continue
if obj and obj.type == 'CURVE':
obj = self.curve_to_mesh(context, obj)

bounding_box_data = {}

Expand Down

0 comments on commit 483ced6

Please sign in to comment.