From 57fe9480593a1cdb97414ff1642410105fd8d039 Mon Sep 17 00:00:00 2001 From: Matthias Patscheider Date: Mon, 26 Jun 2023 11:37:38 +0300 Subject: [PATCH] #71 Support Meta, Surface, Text --- auto_Convex/add_bounding_auto_convex.py | 6 +++--- collider_conversion/conversion_operators.py | 4 ++-- collider_shapes/add_bounding_box.py | 5 +++-- collider_shapes/add_bounding_capsule.py | 4 ++-- collider_shapes/add_bounding_convex_hull.py | 4 ++-- collider_shapes/add_bounding_cylinder.py | 4 ++-- collider_shapes/add_bounding_primitive.py | 17 +++++++++-------- collider_shapes/add_bounding_sphere.py | 4 ++-- collider_shapes/add_collision_mesh.py | 4 ++-- collider_shapes/add_minimum_bounding_box.py | 4 ++-- 10 files changed, 29 insertions(+), 27 deletions(-) diff --git a/auto_Convex/add_bounding_auto_convex.py b/auto_Convex/add_bounding_auto_convex.py index 681377a..9d3f078 100644 --- a/auto_Convex/add_bounding_auto_convex.py +++ b/auto_Convex/add_bounding_auto_convex.py @@ -144,9 +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) - + if obj and obj.type in self.valid_object_types: + obj = self.convert_to_mesh(context, obj) + context.view_layer.objects.active = obj if self.obj_mode == "EDIT": diff --git a/collider_conversion/conversion_operators.py b/collider_conversion/conversion_operators.py index a47c536..8c02eba 100644 --- a/collider_conversion/conversion_operators.py +++ b/collider_conversion/conversion_operators.py @@ -129,8 +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) + if obj and obj.type in self.valid_object_types: + obj = self.convert_to_mesh(context, obj) new_collider = obj.copy() new_collider.data = obj.data.copy() diff --git a/collider_shapes/add_bounding_box.py b/collider_shapes/add_bounding_box.py index 93b6470..8505fde 100644 --- a/collider_shapes/add_bounding_box.py +++ b/collider_shapes/add_bounding_box.py @@ -127,8 +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) + if obj and obj.type in self.valid_object_types: + print('ZZZZZZZZZZZZZZZZZZZZZZZZZ') + obj = self.convert_to_mesh(context, obj) context.view_layer.objects.active = obj bounding_box_data = {} diff --git a/collider_shapes/add_bounding_capsule.py b/collider_shapes/add_bounding_capsule.py index a03eefb..5959f2d 100644 --- a/collider_shapes/add_bounding_capsule.py +++ b/collider_shapes/add_bounding_capsule.py @@ -87,8 +87,8 @@ 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) + if obj and obj.type in self.valid_object_types: + obj = self.convert_to_mesh(context, obj) context.view_layer.objects.active = obj bounding_capsule_data = {} diff --git a/collider_shapes/add_bounding_convex_hull.py b/collider_shapes/add_bounding_convex_hull.py index ec83f65..99d6007 100644 --- a/collider_shapes/add_bounding_convex_hull.py +++ b/collider_shapes/add_bounding_convex_hull.py @@ -55,8 +55,8 @@ 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) + if obj and obj.type in self.valid_object_types: + obj = self.convert_to_mesh(context, obj) convex_collision_data = {} diff --git a/collider_shapes/add_bounding_cylinder.py b/collider_shapes/add_bounding_cylinder.py index c54aa61..02f0c11 100644 --- a/collider_shapes/add_bounding_cylinder.py +++ b/collider_shapes/add_bounding_cylinder.py @@ -264,8 +264,8 @@ 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) + if obj and obj.type in self.valid_object_types: + obj = self.convert_to_mesh(context, obj) bounding_cylinder_data = {} diff --git a/collider_shapes/add_bounding_primitive.py b/collider_shapes/add_bounding_primitive.py index 7f19f96..6e68670 100644 --- a/collider_shapes/add_bounding_primitive.py +++ b/collider_shapes/add_bounding_primitive.py @@ -779,10 +779,9 @@ def mesh_from_selection(obj, use_modifiers=False): return mesh - @staticmethod - def is_valid_object(obj): + def is_valid_object(self, obj): """Is the object valid to be used as a base mesh for collider generation""" - if obj is None or obj.type not in ["MESH","CURVE"]: + if obj is None or obj.type not in self.valid_object_types: return False return True @@ -854,14 +853,14 @@ def print_generation_time(shape, time): print(shape) print("Time elapsed: ", str(time)) - def curve_to_mesh(self, context, curve): + def convert_to_mesh(self, context, object): deg = context.evaluated_depsgraph_get() - me = bpy.data.meshes.new_from_object(curve.evaluated_get(deg), depsgraph=deg) + me = bpy.data.meshes.new_from_object(object.evaluated_get(deg), depsgraph=deg) - new_obj = bpy.data.objects.new(curve.name + "_mesh", me) + new_obj = bpy.data.objects.new(object.name + "_mesh", me) context.collection.objects.link(new_obj) - new_obj.matrix_world = curve.matrix_world + new_obj.matrix_world = object.matrix_world context.view_layer.objects.active = new_obj return new_obj @@ -1069,11 +1068,13 @@ def __init__(self): self.use_recenter_origin = False self.use_custom_rotation = False + self.valid_object_types = ['CURVE', 'SURFACE', 'FONT', 'META'] + @classmethod def poll(cls, context): count = 0 for obj in context.selected_objects: - if obj.type in ['MESH','CURVE']: + if obj.type in ['MESH', 'CURVE', 'SURFACE', 'FONT', 'META']: count = count + 1 return count > 0 diff --git a/collider_shapes/add_bounding_sphere.py b/collider_shapes/add_bounding_sphere.py index 502305e..09f4544 100644 --- a/collider_shapes/add_bounding_sphere.py +++ b/collider_shapes/add_bounding_sphere.py @@ -174,8 +174,8 @@ 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) + if obj and obj.type in self.valid_object_types: + obj = self.convert_to_mesh(context, obj) initial_mod_state = {} context.view_layer.objects.active = obj diff --git a/collider_shapes/add_collision_mesh.py b/collider_shapes/add_collision_mesh.py index 1432e9b..000a163 100644 --- a/collider_shapes/add_collision_mesh.py +++ b/collider_shapes/add_collision_mesh.py @@ -59,8 +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) + if obj and obj.type in self.valid_object_types: + obj = self.convert_to_mesh(context, obj) mesh_collider_data = {} diff --git a/collider_shapes/add_minimum_bounding_box.py b/collider_shapes/add_minimum_bounding_box.py index 86e3dc4..aa0861a 100644 --- a/collider_shapes/add_minimum_bounding_box.py +++ b/collider_shapes/add_minimum_bounding_box.py @@ -153,8 +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) + if obj and obj.type in self.valid_object_types: + obj = self.convert_to_mesh(context, obj) bounding_box_data = {}