From ba6dcf65f293d1a83e7e14253bc91798785abf3f Mon Sep 17 00:00:00 2001 From: greisane Date: Fri, 23 Dec 2022 21:26:29 -0300 Subject: [PATCH] Fixes for 3.4 --- file/copybuffer_flatten.py | 17 ++++++++--------- helpers.py | 8 ++++++++ jobs/rig_export.py | 6 ++---- mesh/collision.py | 28 +++++++++++++++++++++------- mesh/extra_objects.py | 3 +-- 5 files changed, 40 insertions(+), 22 deletions(-) diff --git a/file/copybuffer_flatten.py b/file/copybuffer_flatten.py index f5438ae..e140fd2 100644 --- a/file/copybuffer_flatten.py +++ b/file/copybuffer_flatten.py @@ -1,6 +1,13 @@ import bpy import re -from ..helpers import get_context, select_only, load_selection, save_selection, swap_object_names +from ..helpers import ( + get_context, + load_selection, + save_selection, + select_only, + swap_object_names, + try_call, +) # TODO # - Make flattening optional and rename to Copy Advanced @@ -20,14 +27,6 @@ def clear_pointers(obj): if getattr(obj, prop_id) != my_data: setattr(obj, prop_id, None) -def try_call(f, *args, **kwargs): - try: - f(*args, **kwargs) - return True - except RuntimeError: - pass - return False - class GRET_OT_copybuffer_flatten(bpy.types.Operator): #tooltip """Selected objects alone are copied to the clipboard, even if they reference other objects. diff --git a/helpers.py b/helpers.py index 7ea07e9..47ff80e 100644 --- a/helpers.py +++ b/helpers.py @@ -441,6 +441,14 @@ def wrapper(*args, **kwargs): else: return decorator(_func) +def try_call(f, *args, **kwargs): + try: + f(*args, **kwargs) + return True + except RuntimeError: + pass + return False + def get_export_path(path, fields): """Returns an absolute path from an export path.""" diff --git a/jobs/rig_export.py b/jobs/rig_export.py index 87bb283..95dcad5 100644 --- a/jobs/rig_export.py +++ b/jobs/rig_export.py @@ -299,11 +299,9 @@ def should_apply_modifier(modifier): obj.data.name = job.export_collection.name job.export_collection.objects.link(obj) context.scene.collection.objects.unlink(obj) - # Disable features on output meshes for performance + # Auto-smooth has a noticeable impact in performance while animating, + # disable unless the user explicitly enabled it back in the previous build result obj.data.use_auto_smooth = use_auto_smooth - obj.data.use_customdata_vertex_bevel = False - obj.data.use_customdata_edge_bevel = False - obj.data.use_customdata_edge_crease = False # Don't delete this self.new_objs.discard(obj) self.new_meshes.discard(obj.data) diff --git a/mesh/collision.py b/mesh/collision.py index 3eb0755..a40c40b 100644 --- a/mesh/collision.py +++ b/mesh/collision.py @@ -11,7 +11,7 @@ get_point_dist_to_line_sq, get_range_pct, ) -from ..helpers import get_collection, TempModifier +from ..helpers import try_call, get_context, get_collection, TempModifier # make_collision TODO: # - Non-axis aligned boxes @@ -34,19 +34,33 @@ def find_free_col_name(prefix, name): break return col_name +def clear_customdata(obj, sculpt_mask_data=True, skin_data=True, custom_split_normals=True, + edge_bevel_weight=True, vertex_bevel_weight=True, edge_crease=True, vertex_crease=True): + ctx = get_context(obj) + if sculpt_mask_data: + try_call(bpy.ops.mesh.customdata_mask_clear, ctx) + if skin_data: + try_call(bpy.ops.mesh.customdata_skin_clear, ctx) + if custom_split_normals: + try_call(bpy.ops.mesh.customdata_custom_splitnormals_clear, ctx) + if edge_bevel_weight: + try_call(bpy.ops.mesh.customdata_bevel_weight_edge_clear, ctx) + if vertex_bevel_weight: + try_call(bpy.ops.mesh.customdata_bevel_weight_vertex_clear, ctx) + if edge_crease: + try_call(bpy.ops.mesh.customdata_crease_edge_clear, ctx) + if vertex_crease: + try_call(bpy.ops.mesh.customdata_crease_vertex_clear, ctx) + def remove_extra_data(obj): assert obj.type == 'MESH' obj.vertex_groups.clear() obj.shape_key_clear() + clear_customdata(obj) mesh = obj.data - mesh.use_customdata_vertex_bevel = False - mesh.use_customdata_edge_bevel = False - mesh.use_customdata_edge_crease = False - - # mesh.materials.clear() seems to crash - while mesh.materials: + while mesh.materials: # mesh.materials.clear() seems to crash mesh.materials.pop() while mesh.uv_layers.active: mesh.uv_layers.remove(mesh.uv_layers.active) diff --git a/mesh/extra_objects.py b/mesh/extra_objects.py index 05890b4..b6b29da 100644 --- a/mesh/extra_objects.py +++ b/mesh/extra_objects.py @@ -284,7 +284,6 @@ def execute(self, context): mesh.from_pydata(vertices, [], faces) for face in mesh.polygons: face.use_smooth = self.use_smooth_shade - mesh.use_customdata_edge_crease = True mesh.use_auto_smooth = True mesh.auto_smooth_angle = pi for edge in (mesh.edges[4], mesh.edges[8]): @@ -318,7 +317,7 @@ def execute(self, context): mod.deform_axis = 'Z' mod = obj.modifiers.new(type='ARRAY', name="") - mod.count = self.number_of_rows + mod.count = self.rows mod.relative_offset_displace = [0.0, 0.0, 1.0] mod.use_merge_vertices = True mod.merge_threshold = 1e-5