Support datablocks used as default values in nodes
Follow pointers of input sockets of nodes that can reference ID datablocks.
This commit is contained in:
@@ -72,6 +72,23 @@ IDP_DOUBLE = 8
|
||||
IDP_IDPARRAY = 9
|
||||
IDP_NUMTYPES = 10
|
||||
|
||||
# DNA_node_types.h
|
||||
SOCK_CUSTOM = -1 # socket has no integer type
|
||||
SOCK_FLOAT = 0
|
||||
SOCK_VECTOR = 1
|
||||
SOCK_RGBA = 2
|
||||
SOCK_SHADER = 3
|
||||
SOCK_BOOLEAN = 4
|
||||
SOCK_MESH = 5 # deprecated
|
||||
SOCK_INT = 6
|
||||
SOCK_STRING = 7
|
||||
SOCK_OBJECT = 8
|
||||
SOCK_IMAGE = 9
|
||||
SOCK_GEOMETRY = 10
|
||||
SOCK_COLLECTION = 11
|
||||
SOCK_TEXTURE = 12
|
||||
SOCK_MATERIAL = 13
|
||||
|
||||
# BKE_pointcache.h
|
||||
PTCACHE_FILE_PTCACHE = 0
|
||||
PTCACHE_FILE_OPENVDB = 1
|
||||
|
||||
@@ -93,15 +93,35 @@ def _expand_generic_nodetree(block: blendfile.BlendFileBlock):
|
||||
assert block.dna_type.dna_type_id == b"bNodeTree"
|
||||
|
||||
nodes = block.get_pointer((b"nodes", b"first"))
|
||||
|
||||
# See DNA_node_types.h
|
||||
socket_types_with_value_pointer = {
|
||||
cdefs.SOCK_OBJECT, # bNodeSocketValueObject
|
||||
cdefs.SOCK_IMAGE, # bNodeSocketValueImage
|
||||
cdefs.SOCK_COLLECTION, # bNodeSocketValueCollection
|
||||
cdefs.SOCK_TEXTURE, # bNodeSocketValueTexture
|
||||
cdefs.SOCK_MATERIAL, # bNodeSocketValueMaterial
|
||||
}
|
||||
|
||||
for node in iterators.listbase(nodes):
|
||||
if node[b"type"] == cdefs.CMP_NODE_R_LAYERS:
|
||||
continue
|
||||
yield node
|
||||
|
||||
# The 'id' property points to whatever is used by the node
|
||||
# (like the image in an image texture node).
|
||||
yield node.get_pointer(b"id")
|
||||
|
||||
# Default values of inputs can also point to ID datablocks.
|
||||
inputs = node.get_pointer((b"inputs", b"first"))
|
||||
for input in iterators.listbase(inputs):
|
||||
if input[b"type"] not in socket_types_with_value_pointer:
|
||||
continue
|
||||
value_container = input.get_pointer(b"default_value")
|
||||
if not value_container:
|
||||
continue
|
||||
value = value_container.get_pointer(b"value")
|
||||
yield value
|
||||
|
||||
|
||||
def _expand_generic_idprops(block: blendfile.BlendFileBlock):
|
||||
"""Yield ID datablocks and their libraries referenced from ID properties."""
|
||||
|
||||
Reference in New Issue
Block a user