Improve exporter cache

This commit is contained in:
Lubos Lenco 2017-11-03 01:22:07 +01:00
parent 56eb968148
commit 014f301741
3 changed files with 26 additions and 9 deletions

View file

@ -1708,6 +1708,7 @@ class ArmoryExporter:
arm.utils.write_arm(fp, mesh_obj)
bobject.data.arm_cached = True
bobject.arm_cached = True
if bobject.type != 'FONT' and bobject.type != 'META':
bobject.data.arm_cached_verts = len(bobject.data.vertices)
bobject.data.arm_cached_edges = len(bobject.data.edges)
@ -1863,7 +1864,7 @@ class ArmoryExporter:
if hasattr(bobject.data, 'arm_sdfgen') and bobject.data.arm_sdfgen:
sdf_path = fp.replace('/mesh_', '/sdf_')
assets.add(sdf_path)
if self.object_is_cached(bobject) == True and os.path.exists(fp):
if self.is_mesh_cached(bobject) == True and os.path.exists(fp):
return
print('Exporting mesh ' + arm.utils.asset_name(bobject.data))
@ -1981,6 +1982,8 @@ class ArmoryExporter:
if hasattr(bobject.data, 'arm_aabb'):
bobject.data.arm_aabb = [abs(aabb_min[0]) + abs(aabb_max[0]), abs(aabb_min[1]) + abs(aabb_max[1]), abs(aabb_min[2]) + abs(aabb_max[2])]
break
# Not axis-aligned
# arm_aabb = [bobject.matrix_world * Vector(v) for v in bobject.bound_box]
# Restore the morph state
if shapeKeys:
@ -2848,13 +2851,15 @@ class ArmoryExporter:
return {'FINISHED'}
# Callbacks
def object_is_cached(self, bobject):
def is_mesh_cached(self, bobject):
if bobject.type == 'FONT' or bobject.type == 'META': # No verts
return bobject.data.arm_cached
if bobject.data.arm_cached_verts != len(bobject.data.vertices):
return False
if bobject.data.arm_cached_edges != len(bobject.data.edges):
return False
if not bobject.arm_cached:
return False
return bobject.data.arm_cached
def get_export_tangents(self, mesh):

View file

@ -177,11 +177,14 @@ def on_scene_update_post(context):
if hasattr(bpy.context, 'active_object'):
obj = bpy.context.active_object
if obj != None:
if obj.is_updated_data: # + data.is_updated
if obj.data != None and obj.data.is_updated:
recache(obj)
if obj.type == 'ARMATURE': # Newly parented objects needs to be recached
if len(ops) > 0 and ops[-1].bl_idname == 'OBJECT_OT_transform_apply':
recache(obj)
# New children need to be recached
if obj.type == 'ARMATURE':
for c in obj.children:
if c.is_updated_data:
if c.data != None and c.data.is_updated:
recache(c)
if hasattr(bpy.context, 'sculpt_object') and bpy.context.sculpt_object != None:
recache(bpy.context.sculpt_object)
@ -204,9 +207,14 @@ def on_scene_update_post(context):
if space != None:
space.node_tree.is_cached = False
def recache(edit_obj):
if hasattr(edit_obj.data, 'arm_cached'):
edit_obj.data.arm_cached = False
def recache(obj):
# Moving keyframes triggers is_updated_data..
if state.compileproc != None:
return
if obj.data == None:
return
if hasattr(obj.data, 'arm_cached'):
obj.data.arm_cached = False
def op_changed(op, obj):
# Recache mesh data
@ -215,7 +223,10 @@ def op_changed(op, obj):
op.bl_idname == 'OBJECT_OT_transform_apply' or \
op.bl_idname == 'OBJECT_OT_shade_smooth' or \
op.bl_idname == 'OBJECT_OT_shade_flat':
obj.data.arm_cached = False
# recache(obj)
# Note: Blender reverts object data when manipulating
# OBJECT_OT_transform_apply operator.. recache object flag instead
obj.arm_cached = False
appended_py_paths = []
@persistent

View file

@ -181,6 +181,7 @@ def init_properties():
bpy.types.Object.arm_proxy_sync_materials = bpy.props.BoolProperty(name="Materials", description="Keep materials synchronized with proxy object", default=True, update=proxy_sync_materials)
bpy.types.Object.arm_proxy_sync_modifiers = bpy.props.BoolProperty(name="Modifiers", description="Keep modifiers synchronized with proxy object", default=True, update=proxy_sync_modifiers)
bpy.types.Object.arm_proxy_sync_traits = bpy.props.BoolProperty(name="Traits", description="Keep traits synchronized with proxy object", default=True, update=proxy_sync_traits)
bpy.types.Object.arm_cached = bpy.props.BoolProperty(name="Object Cached", description="No need to reexport object data", default=True)
# For speakers
bpy.types.Speaker.arm_loop = bpy.props.BoolProperty(name="Loop", description="Loop this sound", default=False)
bpy.types.Speaker.arm_stream = bpy.props.BoolProperty(name="Stream", description="Stream this sound", default=False)