Page MenuHome

New Object and Image socket types
ClosedPublic

Authored by Jacques Lucke (JacquesLucke) on Apr 6 2020, 1:23 PM.

Details

Summary

This is part of T73324.

The main difficulty with adding these types is that they are the first sockets types
that reference ID data in their default_value. That means that I had to add some
new logic in a few places to deal with reference counting. I hope I found all the places...
It seems to work fine in my tests.

For now these socket types can only be created using a script like the one below:

import bpy

class MyCustomNode(bpy.types.Node):
    bl_idname = 'CustomNodeType'
    bl_label = "Custom Node"

    def init(self, context):
        self.inputs.new('NodeSocketObject', "Object")
        self.inputs.new('NodeSocketImage', "Image")

bpy.utils.register_class(MyCustomNode)

if len(bpy.data.simulations) == 0:
    bpy.data.simulations.new("Simulation")
    
sim = bpy.data.simulations[0]
sim.node_tree.nodes.new("CustomNodeType")

After running the script, go to the simulation editor and select the newly created simulation.


We might want to change readfile.c so that linked objects/images are only loaded,
when the socket is not connected. Otherwise it can be tricky to figure out why certain
id data blocks are still referenced by the node tree later on.

Diff Detail

Repository
rB Blender
Branch
image-and-object-socket-type (branched from master)
Build Status
Buildable 7515
Build 7515: arc lint + arc unit

Event Timeline

Uuuuhhhh... Did not check the patch in any detail, but... Adding that kind of change to an are which is already fairly severely broken regarding ID management does not make me really happy, to say the least...

See D6484 and linked reports, imho we should really fix this nest of issues before adding any more ID management complexity to nodetrees.

CC @Dalai Felinto (dfelinto) and @Brecht Van Lommel (brecht), since they recently told me that the nodetree issues were not urgent at all... ;)

I think D6484 is a separate issue. There is a design there, but this seems like regular user counting as already exists for node->id and sock->prop.

source/blender/nodes/intern/node_socket.c
338–346

At least for usage in node_templates.c (to replace a node with another node type while preserving the socket values), it should copy the value and increment the user count.

For the other usage in node_socket.c the pointer will be NULL since it comes from a socket template.

  • copy object/image pointer in node_socket_copy_default_value
  • fix user counting when freeing interface sockets
  • Merge branch 'embedded_simulation_node_tree' into image-and-object-socket-type
This revision is now accepted and ready to land.Apr 15 2020, 2:21 PM

It would be nice if the object socket color could follow the color of object icons in the outliner, making it orange. Similarly in future geometry nodes, geometry could use the same green.

These types of changes require balancing colors from various different types though, so this is the kind of thing that can be done in master by the UI designers.

Besides what I already noted above, could not spot anything wrong in ID management code here, so also good for me.