Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blender 4.3 + NodeGroup + NodeFrame support #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions scripts/export-geometry-nodes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import bpy, json, uuid, mathutils
from bpy import context
from pathlib import Path
from bpy_types import bpy_types
import bpy

import builtins as __builtin__

Expand Down Expand Up @@ -69,7 +69,7 @@ def convert_complex_type_to_json_format(default_value):
if isinstance(default_value, float):
return "{}".format(default_value)

if isinstance(default_value, bpy_types.bpy_prop_array):
if isinstance(default_value, bpy.types.bpy_prop_array):
socket_array = []
for socket_value in default_value:
socket_array.append("{}".format(socket_value))
Expand All @@ -95,16 +95,20 @@ def handle_node_group(node_group):
# Loop through the nodes
for node in node_group.nodes:
#print("Node", node.keys())
#print("Node props", dir(node))
node["uuid"] = str(uuid.uuid4())
#print("Node props", dir(node))
if not "uuid" in node:
node["uuid"] = str(uuid.uuid4())

if any(node.bl_idname == item for item in ["GeometryNodeGroup", "ShaderNodeGroup", "CompositorNodeGroup", "TextureNodeGroup"]):
handle_node_group(node.node_tree)

# Store any necessary node data
node_output = {
"uuid": node["uuid"],
"type": node.type,
"bl_idname": node.bl_idname,
"location": convert_vector_to_obj(node.location),
"width": node.width,
"width_hidden": node.width_hidden,
"height": node.height,
"dimensions": convert_vector_to_obj(node.dimensions),
"name": node.name,
Expand All @@ -114,7 +118,6 @@ def handle_node_group(node_group):
#"inputs": node.inputs,
#"outputs": node.outputs,
#"internal_links": node.internal_links,
"parent": node.parent,
"use_custom_color": node.use_custom_color,
"color": convert_color_to_obj(node.color),
"select": node.select,
Expand All @@ -123,6 +126,11 @@ def handle_node_group(node_group):
"hide": node.hide,
"mute": node.mute,
}

if node.parent:
if not "uuid" in node.parent:
node.parent["uuid"] = str(uuid.uuid4())
node_output["parent"] = node.parent["uuid"]

# Loop through inputs and outputs and add those
for input in node.inputs:
Expand Down Expand Up @@ -152,15 +160,15 @@ def handle_node_group(node_group):

# Check if it has a default value - this is the user input node data
if hasattr(input, "default_value"):
print("input default_value", input.default_value)
#print("input default_value", input.default_value)
input_data["default_value"] = convert_complex_type_to_json_format(input.default_value)

# Add data to node inputs
node_output["inputs"].append(input_data)


for output in node.outputs:
print("[OUTPUT]:", dir(output))
#print("[OUTPUT]:", dir(output))
# Store the input data
output_data = {
"description": output.description,
Expand All @@ -187,7 +195,7 @@ def handle_node_group(node_group):

# Check if it has a default value - this is the user input node data
if hasattr(output, "default_value"):
print("output default_value", output.default_value)
#print("output default_value", output.default_value)
output_data["default_value"] = convert_complex_type_to_json_format(output.default_value)

# Add data to node inputs
Expand Down Expand Up @@ -217,14 +225,14 @@ def handle_node_group(node_group):
# FROM_SOCKET
# We check if the default value exists (some slots don't have - like Geometry)
if hasattr(link.from_socket, "default_value"):
print("[FROM SOCKET] type:", type(link.from_socket.default_value))
#print("[FROM SOCKET] type:", type(link.from_socket.default_value))
socket_value = convert_complex_type_to_json_format(link.from_socket.default_value)
if socket_value:
link_data["from_socket"]["default_value"] = socket_value

# TO_SOCKET
if hasattr(link.to_socket, "default_value"):
print("[TO SOCKET] type:", type(link.to_socket.default_value))
#print("[TO SOCKET] type:", type(link.to_socket.default_value))
socket_value = convert_complex_type_to_json_format(link.to_socket.default_value)
if socket_value:
link_data["to_socket"]["default_value"] = socket_value
Expand All @@ -237,14 +245,14 @@ def handle_node_group(node_group):
# Grab the file name
blend_file_name = blend_path.with_suffix("").name;
# The template for the final JSON filename
name_template = "{}-nodes-{}"
name_template = "{}-nodes-{}-{}"

# Check if file exists - increment if so
while blend_path.with_name(name_template.format(blend_file_name, file_index)).with_suffix(".json").exists():
while blend_path.with_name(name_template.format(blend_file_name, node_group.name, file_index)).with_suffix(".json").exists():
file_index += 1

# Create a file name with a number appended (e.g. your-file-01)
blend_versioned_name = name_template.format(blend_file_name, file_index)
blend_versioned_name = name_template.format(blend_file_name, node_group.name, file_index)
# Creates a JSON path using current filename + location
json_path = blend_path.with_name(blend_versioned_name).with_suffix(".json")

Expand Down