Skip to content

Commit

Permalink
plugin - cleanup matcol node tree more
Browse files Browse the repository at this point in the history
  • Loading branch information
HENDRIX-ZT2 committed Dec 23, 2023
1 parent 2a99f66 commit 80715a0
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 21 deletions.
42 changes: 39 additions & 3 deletions plugin/import_matcol.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os

from plugin.modules_import.material import get_group_node
from plugin.utils.node_arrange import nodes_iterate
from plugin.utils.node_arrange import nodes_iterate, get_input_nodes
from plugin.utils.node_util import load_tex_node, get_tree

from generated.formats.dinosaurmaterialvariants.compounds.DinoLayersHeader import DinoLayersHeader
Expand Down Expand Up @@ -146,6 +146,7 @@ def load(filepath=""):
normal_map.inputs["Strength"].default_value = 1.0

last_normal = normal_map
nodes = []
for i, (height_png, mask_png, lut) in enumerate(slots, start=1):
logging.info(f"Slot {i:02d}")

Expand Down Expand Up @@ -191,8 +192,8 @@ def load(filepath=""):
tile.update()
mask.update()
last_normal = height

if not slots:
nodes.append((tile, mask, height, transform))
if not nodes:
raise AttributeError(f"Could not find any layer textures - make sure the tile .fgm and .png files are in the same folder!")

diffuse_path = os.path.join(layers.base_dir, f"{layers.matname}.pbasediffusetexture.png")
Expand All @@ -219,4 +220,39 @@ def load(filepath=""):
tree.links.new(principled.outputs[0], output.inputs[0])

nodes_iterate(tree, output)
slots_arrange(tree, nodes)
return ()


def slots_arrange(tree, nodes):
if not nodes:
return
tile, mask, height, transform = nodes[0]
tile_y = tile.location.y
mask_y = mask.location.y
height_y = height.location.y
transform_y = transform.location.y
shift = abs(nodes[0][0].location.x - nodes[1][0].location.x)
# move the first node away from the rest of the main shader
delta = 2*shift

# realign each slot
for tile, mask, height, transform in reversed(nodes):
transform.location.x = height.location.x
tile.location.y = tile_y
mask.location.y = mask_y
height.location.y = height_y
transform.location.y = transform_y

tile.location.x -= delta
mask.location.x -= delta
height.location.x -= delta
transform.location.x -= delta
delta += shift

# just fix the input x
for node in get_input_nodes(height, "Normal"):
node.location.x -= delta
for child in get_input_nodes(node):
child.location.x -= delta

29 changes: 12 additions & 17 deletions plugin/utils/node_arrange.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,10 @@ def nodes_iterate(ntree, nodeoutput):
while a[level]:
a.append([])
# print ("level:",level)

for node in a[level]:
# print ("while: level:", level)
inputlist = [i for i in node.inputs if i.is_linked]
# print ("inputlist:", inputlist)
if inputlist:

for input in inputlist:
for nlinks in input.links:
# dont add parented nodes (inside frame) to list
# if not nlinks.from_node.parent:
node1 = nlinks.from_node
# print ("appending node:",node1)
a[level + 1].append(node1)

else:
pass
# print ("no inputlist at level:", level)

for input_node in get_input_nodes(node):
a[level + 1].append(input_node)
level += 1

# delete last empty list
Expand Down Expand Up @@ -78,6 +63,16 @@ def nodes_iterate(ntree, nodeoutput):
return None


def get_input_nodes(node, socket_id=""):
for node_socket in node.inputs:
if node_socket.is_linked:
# skip nodes that don't fit
if socket_id and socket_id not in node_socket.name:
continue
for node_link in node_socket.links:
yield node_link.from_node


def nodes_arrange(ntree, nodelist, level):
parents = []
for node in nodelist:
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
662b8cf7f - Sat Dec 23 11:13:34 2023 +0100
2a99f667e - Sat Dec 23 11:14:44 2023 +0100

0 comments on commit 80715a0

Please sign in to comment.