tkeskita / BVtkNodes

Create and execute VTK pipelines in Blender Node Editor
GNU General Public License v3.0
121 stars 20 forks source link

Color Ramp texture name is hard coded to node name, causes clash when using several node trees #69

Closed derekeden closed 2 years ago

derekeden commented 2 years ago

Hello,

I'm running into an issue when I make color ramp nodes in different node trees.

It seems that if I create multiple node trees, and have a color ramp node in each of those node trees, they are somehow linked together and always mirror eachother even if I have different settings for each color ramp node.

To reproduce, open an empty blend file and create two node trees. In each node tree, create a color ramp node. Now, edit the settings of one of them and go to the other node tree and you will see the settings have also been modified there.

See below images, note that the second color ramp does not match the preset value that was chosen, but instead is the same as the first color ramp:

image image

I cannot figure out how to have two different color ramp nodes in two different node trees.

Is this a bug or is there some way around this?

The only thing I can think of is having multiple color ramp nodes in each tree, where some don't get used.

Thanks! And once again, this add-on is amazing. Thank you.

derekeden commented 2 years ago

Of course after posting this I was able to figure it out..

I believe this is because of colormap.get_default_texture, which uses the node's name by default. Since color ramp nodes in separate node trees will have the same default name (Color Ramp), this means the textures keep being overwritten.

I was able to fix this by doing something like this when creating a color ramp node:

node = bpy.data.node_groups['NodeTree'].nodes.new(type="BVTK_Node_ColorRampType") #create
bpy.data.textures.remove(bpy.data.textures['Color Ramp']) #delete default named texture
node.name='test' #rename
node.my_texture='test' #rename
node.setup() #regen texture

I haven't tested further, some of those commands may not be necessary. But seems to work.

I might suggest having the color ramp node name increase by default? I.e. Color Ramp, Color Ramp.001, or Tree_Color Ramp, Tree_Color Ramp.001, etc...

This way by default textures will not be overwritten and this will work out of the box.

tkeskita commented 2 years ago

Hi,

a nice limitation bug you've found! Problem seems to be that get_texture() uses node name as-is for the texture name. Because different node trees may contain duplicate node names, you experience a clash when using several node trees.

One workaround would be to disallow same node names in different node trees as you suggested, but that would be against current Blender behavior (allows same node names between node trees). Instead I propose to fix this by generating texture names from node tree name + node name, and store it into a new StringProperty in the Color Ramp node. It would need to be stored, to keep reference to Blender textures correct.

You seem to be skilled with Python, would you be willing to try to make a patch to fix this?

BR, Tuomo

derekeden commented 2 years ago

hmm.. I will make an attempt ! I am skilled in python but the whole Blender add-on stuff confuses me a bit. This seems like a relatively simple fix though and might help me understand what's actually going on in the background! .. will get back to you

tkeskita commented 2 years ago

Hi, looks like this issue happens even within one Node Tree, after loading a saved BVTK node tree: Updating one color ramp will overwrite the other one too. If you don't mind, I'll try to solve this, as the bug is biting me now.