From 6a3f2ee06c19c9f51827e05c1d71b8417806884d Mon Sep 17 00:00:00 2001 From: dddjef Date: Tue, 24 Apr 2018 17:00:30 +0200 Subject: [PATCH] Update __init__.py two changes in order to drive sprites with bones. The main idea is to use puppet rig as linked group in shots, and still have control on sprites slot index. Another change to update in realtime a slot index when a driving bone is used. Use at your own risk --- Blender/coa_tools/__init__.py | 60 +++++++++++++++++------------------ 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/Blender/coa_tools/__init__.py b/Blender/coa_tools/__init__.py index c416b98..1517150 100644 --- a/Blender/coa_tools/__init__.py +++ b/Blender/coa_tools/__init__.py @@ -201,12 +201,14 @@ def update_sprites(dummy): update_scene = False context = bpy.context - objects = [] + + ## fix to work with linked group. Objects inside a linked group is not the context.visible_objects list. + objects = [x for x in bpy.data.objects if x.is_visible(context.scene)] - if hasattr(context,"visible_objects"): - objects = context.visible_objects - else: - objects = bpy.data.objects + # if hasattr(context,"visible_objects"): + # objects = context.visible_objects + # else: + # objects = bpy.data.objects alpha_update_frequency = get_addon_prefs(context).alpha_update_frequency for obj in objects: @@ -235,11 +237,12 @@ def update_sprites(dummy): if update_scene: bpy.context.scene.update() - + ### animation wrap mode if hasattr(context,"active_object"): sprite_object = get_sprite_object(context.active_object) if sprite_object != None and sprite_object.coa_animation_loop: + print("active") if context.scene.frame_current > context.scene.frame_end: context.scene.frame_current = context.scene.frame_start if context.scene.frame_current == context.scene.coa_frame_last and context.scene.frame_current == context.scene.frame_start: @@ -253,33 +256,30 @@ def scene_update(dummy): global ticker ticker += 1 context = bpy.context - if hasattr(context,"visible_objects"): - objects = context.visible_objects - else: - objects = bpy.data.objects - - if hasattr(context,"window_manager"): - wm = bpy.context.window_manager - if wm.coa_update_uv: - for obj in objects: - if "coa_sprite" in obj and obj.animation_data != None and obj.type == "MESH": - if obj.coa_sprite_frame != obj.coa_sprite_frame_last: - update_uv(bpy.context,obj) - obj.coa_sprite_frame_last = obj.coa_sprite_frame - if obj.coa_slot_index != obj.coa_slot_index_last: - change_slot_mesh_data(context,obj) - obj.coa_slot_index_last = obj.coa_slot_index - if obj.coa_z_value != obj.coa_z_value_last: - set_z_value(context,obj,obj.coa_z_value) - obj.coa_z_value_last = obj.coa_z_value - if ticker%5 == 0: - if obj.coa_alpha != obj.coa_alpha_last: - set_alpha(obj,bpy.context,obj.coa_alpha) - obj.coa_alpha_last = obj.coa_alpha + actOb = context.active_object + # change to update only when a coa armature is moved. Handy for driver update. This function seemed to be deprecated + + if actOb.type == 'ARMATURE' and 'coa_hide' in actOb: + for obj in [x for x in bpy.data.objects if x.is_visible(context.scene)]: + if "coa_slot" in obj: + # if obj.coa_sprite_frame != obj.coa_sprite_frame_last: + # update_uv(bpy.context,obj) + # obj.coa_sprite_frame_last = obj.coa_sprite_frame + if obj.coa_slot_index != obj.coa_slot_index_last: + change_slot_mesh_data(context,obj) + obj.coa_slot_index_last = obj.coa_slot_index + if obj.coa_z_value != obj.coa_z_value_last: + set_z_value(context,obj,obj.coa_z_value) + obj.coa_z_value_last = obj.coa_z_value + # if ticker%5 == 0: + # if obj.coa_alpha != obj.coa_alpha_last: + # set_alpha(obj,bpy.context,obj.coa_alpha) + # obj.coa_alpha_last = obj.coa_alpha if hasattr(bpy.context,"active_object"): obj = bpy.context.active_object if obj != None and not obj.coa_sprite_updated and "coa_sprite" in obj: + print(obj) for thumb in preview_collections["coa_thumbs"]: preview_collections["coa_thumbs"][thumb].reload() obj.coa_sprite_updated = True @@ -339,4 +339,4 @@ def delete_thumb_previews(): thumb_dir_path = os.path.join(tempfile.gettempdir(),"coa_thumbs") if os.path.exists(thumb_dir_path): shutil.rmtree(thumb_dir_path, ignore_errors=True) -atexit.register(delete_thumb_previews) \ No newline at end of file +atexit.register(delete_thumb_previews)