Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update system - explanation #2770

Closed
Durman opened this issue Dec 26, 2019 · 5 comments · Fixed by #3706
Closed

Update system - explanation #2770

Durman opened this issue Dec 26, 2019 · 5 comments · Fixed by #3706

Comments

@Durman
Copy link
Collaborator

Durman commented Dec 26, 2019

Will try to describe what is going on:

Blender update events:

  • depsgraph_update_pre handler
  • frame_change_post/post handler
  • node_tree.update method
  • node.update method
  • property.update method

Sverchok update events:

  • process_from_node function
  • process_from_nodes function

Triggers of depsgraph_update_pre handler:

  • swithch editor type
  • add object in scene
  • moving object in scene ❗️
  • switch edit / object modes
  • moving parts of mesh ❗️
  • select parts of mesh
  • apply mesh operators
  • change of any property
  • open close panels
  • and so on

Reaction upon manipulation in node tree:

events depsgraph_update_pre node_tree.update node.update order
Add new node ✔️ ✔️ ✔️ nodes, tree, handler
Copy node ✔️ ✔️ nodes, tree
Dellite node ✔️ ✔️ other nodes, tree
Rename tree ✔️
Add link ✔️ ✔️ nodes, tree
Remove link ✔️ ✔️ current node, nodes, tree
Add socket to a node ✔️
Remove socket ✔️
Rename socket ✔️
Rename node ✔️
@Durman
Copy link
Collaborator Author

Durman commented Dec 26, 2019

Sverchok tree properties:

  • sv_process (bool) - for switching off process tree manually, mainly
  • skip_tree_update (bool) - for temporary ignoring tree.update events
  • has_changed (bool) - only True if tree.update event and not skip_tree_update
  • sv_animate (bool) - process tree upon frame change events if True and sv_process is True
  • configuring_new_node (bool) - True during initialization of new node.
  • is_frozen (bool) - does not process tree if True, but sockets data will be reseted anyway

Calling Sverchok update events:

  • depsgraph_update_pre handler - looks it can't call any update events because has_changed property is always False during of work of this handler.
  • frame_change_post/post handler - Looks like it updates all tree if sv_process and sv_animate.
  • node_tree.update method - Looks like it updates all tree if sv_process and not skip_tree_update and not configuring_new_node and not is frozen.
  • node.update method - is not used by default.
  • property.update method - looks like it updates tree from current node which property has updateNode function if not tree.is_frozen

@Durman
Copy link
Collaborator Author

Durman commented Mar 29, 2020

Being notified when subparts of a mesh change (vertices, faces, shape keys, etc)
brecht - This information is not tracked by Blender, so it’s also not available in the Python API.

https://devtalk.blender.org/t/being-notified-when-subparts-of-a-mesh-change-vertices-faces-shape-keys-etc/12373

@Durman
Copy link
Collaborator Author

Durman commented Nov 8, 2020

What is going on if during update event cause another update event:

class MyCustomTree(NodeTree):
    bl_idname = 'CustomTreeType'
    bl_label = "Custom Node Tree"
    bl_icon = 'NODETREE'
    
    def update(self):
        print('TREE UPDATE')


class TestNode(Node):
    bl_idname = 'TestNode'
    bl_label = 'Test node'
    
    def init(self, context):
        print(f'INIT NODE "{self.name}"')
        print('ADD ANOTHER NODE FROM INIT')
        self.id_data.nodes.new('TestNode2')
        print('RETURN INIT METHOD AGAIN')
ADD FIRST NODE INTO TREE
INIT NODE "Test node"
ADD ANOTHER NODE FROM INIT
TREE UPDATE
RETURN INTO INIT METHOD AGAIN
TREE UPDATE

It proves that our freezing method of the tree is redundant.

whole code
import bpy
from bpy.types import NodeTree, Node, NodeSocket


class MyCustomTree(NodeTree):
    bl_idname = 'CustomTreeType'
    bl_label = "Custom Node Tree"
    bl_icon = 'NODETREE'
    
    def update(self):
        print('UPDATE')


class TestNode(Node):
    bl_idname = 'TestNode'
    bl_label = 'Test node'
    
    def init(self, context):
        print(f'INIT NODE "{self.name}"')
        print('ADD ANOTHER NODE FROM INIT')
        self.id_data.nodes.new('TestNode2')
        print('RETURN INIT METHOD AGAIN')


class TestNode2(Node):
    bl_idname = 'TestNode2'
    bl_label = 'Test node 2'


def register():
    [bpy.utils.register_class(c) for c in [MyCustomTree, TestNode, TestNode2]]


def unregister():
    for cls_str in ['MyCustomTree', 'TestNode', 'TestNode2']:
        cls = bpy.types.NodeGroup.bl_rna_get_subclass_py(cls_str)
        if cls:
            unregister_class(cls)


if __name__ == "__main__":
    unregister()
    register()
    [bpy.data.node_groups.remove(t) for t in bpy.data.node_groups if t.bl_idname == 'CustomTreeType']
    tree = bpy.data.node_groups.new('Test', 'CustomTreeType')
    bpy.data.screens['Layout'].areas[3].type = 'NODE_EDITOR'
    bpy.data.screens['Layout'].areas[3].spaces[0].node_tree = tree
    print('ADD FIRST NODE INTO TREE')
    tree.nodes.new('TestNode')    

@Durman
Copy link
Collaborator Author

Durman commented Nov 8, 2020

2020-11-08_13-05-00

@Durman
Copy link
Collaborator Author

Durman commented Nov 8, 2020

Creating new sockets will trigger redundant tree updates if

  • they are creating inside init method.
  • they are creating inside a property update

Creating them in other places will trigger nothing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant