Linking Custom Node Tree to DataBlock

提供: wiki
移動先: 案内検索

Introduction

Unfortunately, at the moment there is no easy way (using python) to implement the linking of custom node trees to datablocks. In turn, native node trees, such as material nodes, composite nodes, texture nodes are "used" by mesh, scene, texture respectively. The custom node tree condition without links generates some problems for the developers who use them.

Issue

For me as a Blend4Web developer, there are two main problems:

  • correct linking (through low-level pointer with reference-counting)
  • set edit node tree in the node editor depending on the current context

Problem in Addons

  • Blend4Web

In version 15.8, we introduced our users to a node-based logic editor. It allows you to add interactivity to your application without programming. At the moment, we have a logic tree type of "for the scene", so we "link" the node tree to the scene with the help of Python. Linking is done through the identifier (name) of the tree. But this method is inconvenient since it is not possible to track the name change. There is also difficulty controlling the number of node tree users, more specifically with its reduction, since it is impossible to know the previous value of this property in the update callback properties. As a result, I would like to be able to link the tree to the scene via a low-level pointer and using the true approach with reference-counting. In the future, we may need to link to the object/camera/lamp/.. specific for this datablock type node logic.

  • LuxRender

See luxrender.add_material_nodetree operator. The same problem with renaming + overly complicated interface and imminent unlinking if you rename the material.

  • Sverchok

Problems of setting current edit tree in node editor after editing another type of trees.

Maybe there are other Addons whose developers have similar difficulties. In all cases, the developers set a 'Fake User' for the node tree, because it is impossible to properly manage the references and it is the only stable solution.

Proposal

  • Making it possible to link custom node trees to datablock, such as Scene, Object, Camera, Lamp, Material etc. This can be implemented similarly to AnimData. To implement a Python API for linking/unlinking. Example:
obj.custom_nodetrees_link_set.add(bpy.data.node_groups["NodeTree"])
# obj.custom_nodetrees_link_set["NodeTree"] now stores a pointer to bpy.data.node_groups[tree_name].
# The add method will overwrite the link to the tree with the same bl_idname.
# So only one link for the custom tree type, which is bl_idname, is allowed.
  • Implementing the custom node tree linking general approach through the blender user interface.

This requires a mechanism for selecting the datablock to which we want to link the tree. This can be done, for example, through the Outliner, or by adding a new node editor panel that lists datablocks of types "ordered" by custom node tree.

P. S. Maybe this new feature will help BGE developers in transition to the node editor.

Useful links

Python ID Property for pointer proposal [1]

Datablock ID Properties [2]