Handler for objects in node
Created by: Durman
I have an idea how it is possible to track changes of objects in scene.
Instead of creating global event like "Some object have been changed" it is easier to bind such handler to a node in node tree. In particularly I suggest create additional button for objects in
node named like "track changes":
- When the button is pushed function tracking changes is added to handlers.
- Additional pushing on the button will remove function from handlers.
- Pushing on
get selection
button alse will remove function.
I think button for creating handler is most appropriate because it gives understanding that it is not cheap functionality. I already experimented with such handlers during working under alternative update system.
code
@persistent
def changes_of_objects_handler(scene):
select_objs = bpy.context.selected_objects
active_obj = scene.objects.active
if select_objs:
if select_objs[0].is_updated:
# this means object was moved move by user but setting new material also can pass this condition
debug('{} - is updated'.format([ob.name for ob in bpy.context.selected_objects]))
tree_updater.changed_object_in_scene.update(select_objs)
tree_updater.update(props='OBJECTS_UPDATE')
return
if active_obj:
if active_obj.is_updated_data:
# setting new vertex group, changing geometry and etc.
debug('{} - is updated data'.format(active_obj.name))
tree_updater.changed_object_in_scene.add(active_obj)
tree_updater.update(props='OBJECTS_UPDATE')
return
if active_obj.data.is_updated:
# setting new vertex group, changing geometry and etc.
debug('{} - DATA is updated'.format(active_obj.data.name))
tree_updater.changed_object_in_scene.add(active_obj)
tree_updater.update(props='OBJECTS_UPDATE')
return
if active_obj.data.is_updated_data:
# did not catch this trigger
debug('{} - DATA is updated data'.format(active_obj.data.name))
tree_updater.changed_object_in_scene.add(active_obj)
tree_updater.update(props='OBJECTS_UPDATE')
return
This function tracks changes of selected objects in scene but can be easily changed for tracking changes of named objects.
What benefits it can achieve.
- Firstly we can stop using animation during changing objects for getting updating node tree immediately.
- In second the function can call update from node event that is as fast as possible.
Problems: Main problem as I see is possibility to create loop in update events. For example, object from scene is gotten, next its matrix is changed and set to this object back that will rise update event again.
How can this be avoided.
I can suggest to add special mode for Sverchok called update. If Sverchok is in update mode
all other update events will be ignored.
So, anybody is interested in such feature for Sverchok?