Skip to content

Commit

Permalink
Fixes for 3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
greisane committed Dec 24, 2022
1 parent 740544f commit ba6dcf6
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 22 deletions.
17 changes: 8 additions & 9 deletions file/copybuffer_flatten.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down
6 changes: 2 additions & 4 deletions jobs/rig_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 21 additions & 7 deletions mesh/collision.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions mesh/extra_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]):
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ba6dcf6

Please sign in to comment.