feat: initial support for blender 4.0
It may inpact the userpresence, mesh bevel/crease attributes and shader node groups input/output socket
This commit is contained in:
parent
037be421cb
commit
0c26b9c6c4
@ -245,10 +245,8 @@ def dump_node_tree(node_tree: bpy.types.ShaderNodeTree) -> dict:
|
|||||||
'type': type(node_tree).__name__
|
'type': type(node_tree).__name__
|
||||||
}
|
}
|
||||||
|
|
||||||
for socket_id in ['inputs', 'outputs']:
|
sockets = [item for item in node_tree.interface.items_tree if item.item_type == 'SOCKET']
|
||||||
if hasattr(node_tree, socket_id):
|
node_tree_data['interface'] = dump_node_tree_sockets(sockets)
|
||||||
socket_collection = getattr(node_tree, socket_id)
|
|
||||||
node_tree_data[socket_id] = dump_node_tree_sockets(socket_collection)
|
|
||||||
|
|
||||||
return node_tree_data
|
return node_tree_data
|
||||||
|
|
||||||
@ -264,18 +262,18 @@ def dump_node_tree_sockets(sockets: bpy.types.Collection) -> dict:
|
|||||||
"""
|
"""
|
||||||
sockets_data = []
|
sockets_data = []
|
||||||
for socket in sockets:
|
for socket in sockets:
|
||||||
try:
|
sockets_data.append(
|
||||||
socket_uuid = socket['uuid']
|
(
|
||||||
except Exception:
|
socket.name,
|
||||||
socket_uuid = str(uuid4())
|
socket.socket_type,
|
||||||
socket['uuid'] = socket_uuid
|
socket.in_out
|
||||||
|
)
|
||||||
sockets_data.append((socket.name, socket.bl_socket_idname, socket_uuid))
|
)
|
||||||
|
|
||||||
return sockets_data
|
return sockets_data
|
||||||
|
|
||||||
|
|
||||||
def load_node_tree_sockets(sockets: bpy.types.Collection,
|
def load_node_tree_sockets(interface: bpy.types.NodeTreeInterface,
|
||||||
sockets_data: dict):
|
sockets_data: dict):
|
||||||
""" load sockets of a shader_node_tree
|
""" load sockets of a shader_node_tree
|
||||||
|
|
||||||
@ -286,20 +284,17 @@ def load_node_tree_sockets(sockets: bpy.types.Collection,
|
|||||||
:arg socket_data: dumped socket data
|
:arg socket_data: dumped socket data
|
||||||
:type socket_data: dict
|
:type socket_data: dict
|
||||||
"""
|
"""
|
||||||
# Check for removed sockets
|
# Remove old sockets
|
||||||
for socket in sockets:
|
interface.clear()
|
||||||
if not [s for s in sockets_data if 'uuid' in socket and socket['uuid'] == s[2]]:
|
|
||||||
sockets.remove(socket)
|
|
||||||
|
|
||||||
# Check for new sockets
|
# Check for new sockets
|
||||||
for idx, socket_data in enumerate(sockets_data):
|
for name, socket_type, in_out in sockets_data:
|
||||||
try:
|
socket = interface.new_socket(
|
||||||
checked_socket = sockets[idx]
|
name,
|
||||||
if checked_socket.name != socket_data[0]:
|
in_out=in_out,
|
||||||
checked_socket.name = socket_data[0]
|
socket_type=socket_type
|
||||||
except Exception:
|
)
|
||||||
s = sockets.new(socket_data[1], socket_data[0])
|
|
||||||
s['uuid'] = socket_data[2]
|
|
||||||
|
|
||||||
|
|
||||||
def load_node_tree(node_tree_data: dict, target_node_tree: bpy.types.ShaderNodeTree) -> dict:
|
def load_node_tree(node_tree_data: dict, target_node_tree: bpy.types.ShaderNodeTree) -> dict:
|
||||||
@ -316,13 +311,8 @@ def load_node_tree(node_tree_data: dict, target_node_tree: bpy.types.ShaderNodeT
|
|||||||
if not target_node_tree.is_property_readonly('name'):
|
if not target_node_tree.is_property_readonly('name'):
|
||||||
target_node_tree.name = node_tree_data['name']
|
target_node_tree.name = node_tree_data['name']
|
||||||
|
|
||||||
if 'inputs' in node_tree_data:
|
if 'interface' in node_tree_data:
|
||||||
socket_collection = getattr(target_node_tree, 'inputs')
|
load_node_tree_sockets(target_node_tree.interface, node_tree_data['interface'])
|
||||||
load_node_tree_sockets(socket_collection, node_tree_data['inputs'])
|
|
||||||
|
|
||||||
if 'outputs' in node_tree_data:
|
|
||||||
socket_collection = getattr(target_node_tree, 'outputs')
|
|
||||||
load_node_tree_sockets(socket_collection, node_tree_data['outputs'])
|
|
||||||
|
|
||||||
# Load nodes
|
# Load nodes
|
||||||
for node in node_tree_data["nodes"]:
|
for node in node_tree_data["nodes"]:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user