Skip to content

Commit

Permalink
Use layer tree start node as default texcoord node and clean up some …
Browse files Browse the repository at this point in the history
…labels and node positions.
  • Loading branch information
ucupumar authored and Kareemov03 committed Sep 1, 2024
1 parent 1a69d15 commit ead7826
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 56 deletions.
8 changes: 4 additions & 4 deletions Layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4898,8 +4898,8 @@ class YLayerChannel(bpy.types.PropertyGroup):
update = update_blend_type)

intensity_value : FloatProperty(
name = 'Channel Intensity Factor',
description = 'Channel Intensity Factor',
name = 'Layer Channel Opacity',
description = 'Layer channel opacity',
default=1.0, min=0.0, max=1.0, subtype='FACTOR', precision=3)

# Modifiers
Expand Down Expand Up @@ -5345,8 +5345,8 @@ class YLayer(bpy.types.PropertyGroup):
default = 'IMAGE')

intensity_value : FloatProperty(
name = 'Layer Intensity Factor',
description = 'Layer Intensity Factor',
name = 'Layer Opacity',
description = 'Layer opacity',
default=1.0, min=0.0, max=1.0, subtype='FACTOR', precision=3)

color_shortcut : BoolProperty(
Expand Down
4 changes: 2 additions & 2 deletions Mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -1737,8 +1737,8 @@ class YLayerMask(bpy.types.PropertyGroup):
update = update_mask_blend_type)

intensity_value : FloatProperty(
name = 'Mask Intensity Factor',
description = 'Mask Intensity Factor',
name = 'Mask Opacity',
description = 'Mask opacity',
default=1.0, min=0.0, max=1.0, subtype='FACTOR', precision=3)

# Transform
Expand Down
28 changes: 19 additions & 9 deletions node_arrangements.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,11 +624,18 @@ def rearrange_layer_nodes(layer, tree=None):
#flip_bump = bump_ch.transition_bump_flip
chain = min(len(layer.masks), bump_ch.transition_bump_chain)

#start_x = 350
#loc = Vector((350, 0))

# Back to source nodes
loc = Vector((0, 0))
start_x = -350
loc = Vector((start_x, 0))

# Start node
check_set_node_loc(tree, TREE_START, loc)

start = tree.nodes.get(TREE_START)
check_set_node_width(start, 250)

loc.x -= start_x
loc.y = -(len(start.outputs) * 40)

# Arrange pack unpack height group
if layer.type == 'GROUP':
Expand Down Expand Up @@ -778,6 +785,9 @@ def rearrange_layer_nodes(layer, tree=None):
if check_set_node_loc(tree, layer.texcoord, loc):
loc.y -= 240

#if check_set_node_loc(tree, TREE_START, loc):
# loc.y -= 240

if check_set_node_loc(tree, layer.bump_process, loc):
loc.y -= 300

Expand Down Expand Up @@ -1221,13 +1231,13 @@ def rearrange_layer_nodes(layer, tree=None):
loc.y = 0

# Start node
check_set_node_loc(tree, TREE_START, loc)
#check_set_node_loc(tree, TREE_START, loc)

start = tree.nodes.get(TREE_START)
check_set_node_width(start, 250)
#start = tree.nodes.get(TREE_START)
#check_set_node_width(start, 250)

loc.x += 300
loc.y = 0
#loc.x += 300
#loc.y = 0

#bookmark_x = loc.x

Expand Down
78 changes: 39 additions & 39 deletions node_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -1759,13 +1759,13 @@ def reconnect_layer_nodes(layer, ch_idx=-1, merge_mask=False):
flip_y = nodes.get(layer.flip_y)

# Get tangent and bitangent
layer_tangent = texcoord.outputs.get(layer.uv_name + io_suffix['TANGENT'])
layer_bitangent = texcoord.outputs.get(layer.uv_name + io_suffix['BITANGENT'])
layer_tangent = start.outputs.get(layer.uv_name + io_suffix['TANGENT'])
layer_bitangent = start.outputs.get(layer.uv_name + io_suffix['BITANGENT'])

height_root_ch = get_root_height_channel(yp)
if height_root_ch and height_root_ch.main_uv != '':
tangent = texcoord.outputs.get(height_root_ch.main_uv + io_suffix['TANGENT'])
bitangent = texcoord.outputs.get(height_root_ch.main_uv + io_suffix['BITANGENT'])
tangent = start.outputs.get(height_root_ch.main_uv + io_suffix['TANGENT'])
bitangent = start.outputs.get(height_root_ch.main_uv + io_suffix['BITANGENT'])
else:
tangent = layer_tangent
bitangent = layer_bitangent
Expand All @@ -1774,24 +1774,24 @@ def reconnect_layer_nodes(layer, ch_idx=-1, merge_mask=False):
bump_process = nodes.get(layer.bump_process)
if bump_process and height_root_ch:

prev_normal = texcoord.outputs.get(height_root_ch.name)
prev_height = texcoord.outputs.get(height_root_ch.name + io_suffix['HEIGHT'])
prev_max_height = texcoord.outputs.get(height_root_ch.name + io_suffix['MAX_HEIGHT'])
prev_normal = start.outputs.get(height_root_ch.name)
prev_height = start.outputs.get(height_root_ch.name + io_suffix['HEIGHT'])
prev_max_height = start.outputs.get(height_root_ch.name + io_suffix['MAX_HEIGHT'])

if prev_height and 'Height' in bump_process.inputs: create_link(tree, prev_height, bump_process.inputs['Height'])
if prev_max_height and 'Max Height' in bump_process.inputs: create_link(tree, prev_max_height, bump_process.inputs['Max Height'])

if height_root_ch.enable_smooth_bump:
#prev_height_ons = texcoord.outputs.get(height_root_ch.name + io_suffix['HEIGHT_ONS'])
#prev_height_ew = texcoord.outputs.get(height_root_ch.name + io_suffix['HEIGHT_EW'])
#prev_height_ons = start.outputs.get(height_root_ch.name + io_suffix['HEIGHT_ONS'])
#prev_height_ew = start.outputs.get(height_root_ch.name + io_suffix['HEIGHT_EW'])

#if prev_height_ons and 'Height ONS' in bump_process.inputs: create_link(tree, prev_height_ons, bump_process.inputs['Height ONS'])
#if prev_height_ew and 'Height EW' in bump_process.inputs: create_link(tree, prev_height_ew, bump_process.inputs['Height EW'])

prev_height_n = texcoord.outputs.get(height_root_ch.name + io_suffix['HEIGHT_N'])
prev_height_s = texcoord.outputs.get(height_root_ch.name + io_suffix['HEIGHT_S'])
prev_height_e = texcoord.outputs.get(height_root_ch.name + io_suffix['HEIGHT_E'])
prev_height_w = texcoord.outputs.get(height_root_ch.name + io_suffix['HEIGHT_W'])
prev_height_n = start.outputs.get(height_root_ch.name + io_suffix['HEIGHT_N'])
prev_height_s = start.outputs.get(height_root_ch.name + io_suffix['HEIGHT_S'])
prev_height_e = start.outputs.get(height_root_ch.name + io_suffix['HEIGHT_E'])
prev_height_w = start.outputs.get(height_root_ch.name + io_suffix['HEIGHT_W'])

if prev_height_n and 'Height N' in bump_process.inputs: create_link(tree, prev_height_n, bump_process.inputs['Height N'])
if prev_height_s and 'Height S' in bump_process.inputs: create_link(tree, prev_height_s, bump_process.inputs['Height S'])
Expand All @@ -1815,13 +1815,13 @@ def reconnect_layer_nodes(layer, ch_idx=-1, merge_mask=False):
#if layer.type not in {'VCOL', 'BACKGROUND', 'COLOR', 'GROUP', 'HEMI', 'OBJECT_INDEX'} or using_vector:
if is_layer_using_vector(layer):
if layer.texcoord_type == 'UV':
vector = texcoord.outputs.get(layer.uv_name + io_suffix['UV'])
else: vector = texcoord.outputs.get(io_names[layer.texcoord_type])
vector = start.outputs.get(layer.uv_name + io_suffix['UV'])
else: vector = start.outputs.get(io_names[layer.texcoord_type])

if vector and blur_vector:
vector = create_link(tree, vector, blur_vector.inputs[1])[0]

layer_blur_factor = texcoord.outputs.get(get_entity_input_name(layer, 'blur_vector_factor'))
layer_blur_factor = start.outputs.get(get_entity_input_name(layer, 'blur_vector_factor'))
if layer_blur_factor: create_link(tree, layer_blur_factor, blur_vector.inputs[0])

if vector and mapping:
Expand Down Expand Up @@ -1944,7 +1944,7 @@ def reconnect_layer_nodes(layer, ch_idx=-1, merge_mask=False):
if height_blend: compare_alpha = height_blend.outputs.get('Normal Alpha')

# UV Neighbor multiplier
bump_smooth_multiplier_value = texcoord.outputs.get(get_entity_input_name(height_ch, 'bump_smooth_multiplier'))
bump_smooth_multiplier_value = start.outputs.get(get_entity_input_name(height_ch, 'bump_smooth_multiplier'))
if bump_smooth_multiplier_value:

if uv_neighbor and 'Multiplier' in uv_neighbor.inputs:
Expand All @@ -1962,8 +1962,8 @@ def reconnect_layer_nodes(layer, ch_idx=-1, merge_mask=False):
#else:
chain = min(len(layer.masks), trans_bump_ch.transition_bump_chain)

tb_value = texcoord.outputs.get(get_entity_input_name(trans_bump_ch, 'transition_bump_value'))
tb_second_value = texcoord.outputs.get(get_entity_input_name(trans_bump_ch, 'transition_bump_second_edge_value'))
tb_value = start.outputs.get(get_entity_input_name(trans_bump_ch, 'transition_bump_value'))
tb_second_value = start.outputs.get(get_entity_input_name(trans_bump_ch, 'transition_bump_second_edge_value'))

# Root mask value for merging mask
root_mask_val = get_essential_node(tree, ONE_VALUE)[0]
Expand Down Expand Up @@ -2023,7 +2023,7 @@ def reconnect_layer_nodes(layer, ch_idx=-1, merge_mask=False):

# Color ID related
if mask.type == 'COLOR_ID':
color_id_val = texcoord.outputs.get(get_entity_input_name(mask, 'color_id'))
color_id_val = start.outputs.get(get_entity_input_name(mask, 'color_id'))
if color_id_val and 'Color ID' in mask_source.inputs:
create_link(tree, color_id_val, mask_source.inputs['Color ID'])

Expand All @@ -2039,19 +2039,19 @@ def reconnect_layer_nodes(layer, ch_idx=-1, merge_mask=False):
mask_source_e = nodes.get(mask.source_e)
mask_source_w = nodes.get(mask.source_w)

# Mask texcoord
# Mask start
mask_vector = None
mask_uv_name = mask.uv_name if not mask.use_baked or mask.baked_uv_name == '' else mask.baked_uv_name
if mask.use_baked or mask.type not in {'VCOL', 'HEMI', 'OBJECT_INDEX', 'COLOR_ID', 'BACKFACE', 'EDGE_DETECT'}:
if mask.use_baked or mask.texcoord_type == 'UV':
mask_vector = texcoord.outputs.get(mask_uv_name + io_suffix['UV'])
mask_vector = start.outputs.get(mask_uv_name + io_suffix['UV'])
else:
mask_vector = texcoord.outputs.get(io_names[mask.texcoord_type])
mask_vector = start.outputs.get(io_names[mask.texcoord_type])

if mask_vector:

if not mask.use_baked:
mask_blur_factor = texcoord.outputs.get(get_entity_input_name(mask, 'blur_vector_factor'))
mask_blur_factor = start.outputs.get(get_entity_input_name(mask, 'blur_vector_factor'))
if mask_blur_factor: create_link(tree, mask_blur_factor, mask_blur_vector.inputs[0])

if mask_blur_vector:
Expand Down Expand Up @@ -2087,8 +2087,8 @@ def reconnect_layer_nodes(layer, ch_idx=-1, merge_mask=False):
create_link(tree, bump_smooth_multiplier_value, mask_uv_neighbor.inputs['Multiplier'])

# Mask tangent
mask_tangent = texcoord.outputs.get(mask_uv_name + io_suffix['TANGENT'])
mask_bitangent = texcoord.outputs.get(mask_uv_name + io_suffix['BITANGENT'])
mask_tangent = start.outputs.get(mask_uv_name + io_suffix['TANGENT'])
mask_bitangent = start.outputs.get(mask_uv_name + io_suffix['BITANGENT'])

if 'Tangent' in mask_uv_neighbor.inputs:
if tangent: create_link(tree, tangent, mask_uv_neighbor.inputs['Tangent'])
Expand All @@ -2110,7 +2110,7 @@ def reconnect_layer_nodes(layer, ch_idx=-1, merge_mask=False):
create_link(tree, mask_val, mmix.inputs[mixcol1])

# Mask intensity
mask_intensity = texcoord.outputs.get(get_entity_input_name(mask, 'intensity_value'))
mask_intensity = start.outputs.get(get_entity_input_name(mask, 'intensity_value'))

# Mask channels
for j, c in enumerate(mask.channels):
Expand Down Expand Up @@ -2291,10 +2291,10 @@ def reconnect_layer_nodes(layer, ch_idx=-1, merge_mask=False):
else:
if ch.override_type == 'DEFAULT':
if root_ch.type == 'VALUE':
ch_override_value = texcoord.outputs.get(get_entity_input_name(ch, 'override_value'))
ch_override_value = start.outputs.get(get_entity_input_name(ch, 'override_value'))
if ch_override_value: rgb = ch_override_value
else:
ch_override_color = texcoord.outputs.get(get_entity_input_name(ch, 'override_color'))
ch_override_color = start.outputs.get(get_entity_input_name(ch, 'override_color'))
if ch_override_color: rgb = ch_override_color
else:
ch_source = nodes.get(ch.source)
Expand Down Expand Up @@ -2362,7 +2362,7 @@ def reconnect_layer_nodes(layer, ch_idx=-1, merge_mask=False):
normal = rgb_before_override
if root_ch.type == 'NORMAL' and ch.override_1:
if ch.override_1_type == 'DEFAULT':
ch_override_1_color = texcoord.outputs.get(get_entity_input_name(ch, 'override_1_color'))
ch_override_1_color = start.outputs.get(get_entity_input_name(ch, 'override_1_color'))
if ch_override_1_color:
normal = ch_override_1_color
else:
Expand Down Expand Up @@ -2390,7 +2390,7 @@ def reconnect_layer_nodes(layer, ch_idx=-1, merge_mask=False):
if root_ch.type == 'NORMAL' and ch.normal_map_type == 'NORMAL_MAP':
rgb = normal

ch_tb_fac = texcoord.outputs.get(get_entity_input_name(ch, 'transition_bump_fac'))
ch_tb_fac = start.outputs.get(get_entity_input_name(ch, 'transition_bump_fac'))

if intensity_multiplier and ch != trans_bump_ch:
if trans_bump_flip:
Expand Down Expand Up @@ -2707,7 +2707,7 @@ def reconnect_layer_nodes(layer, ch_idx=-1, merge_mask=False):
tb_falloff = nodes.get(ch.tb_falloff)

if tb_falloff:
tb_emulated_curve_fac = texcoord.outputs.get(get_entity_input_name(ch, 'transition_bump_falloff_emulated_curve_fac'))
tb_emulated_curve_fac = start.outputs.get(get_entity_input_name(ch, 'transition_bump_falloff_emulated_curve_fac'))
if tb_emulated_curve_fac:
if 'Fac' in tb_falloff.inputs:
create_link(tree, tb_emulated_curve_fac, tb_falloff.inputs['Fac'])
Expand Down Expand Up @@ -2886,7 +2886,7 @@ def reconnect_layer_nodes(layer, ch_idx=-1, merge_mask=False):
if rgb_e and 'Height e' in height_proc.inputs: create_link(tree, rgb_e, height_proc.inputs['Height e'])
if rgb_w and 'Height w' in height_proc.inputs: create_link(tree, rgb_w, height_proc.inputs['Height w'])
else:
prev_normal = texcoord.outputs.get(root_ch.name)
prev_normal = start.outputs.get(root_ch.name)
if prev_normal and normal_proc and 'Normal' in normal_proc.inputs:
create_link(tree, prev_normal, normal_proc.inputs['Normal'])

Expand Down Expand Up @@ -3294,19 +3294,19 @@ def reconnect_layer_nodes(layer, ch_idx=-1, merge_mask=False):
if layer_intensity_value and 'Intensity Layer' in tao.inputs:
create_link(tree, layer_intensity_value, tao.inputs['Intensity Layer'])

tao_intensity = texcoord.outputs.get(get_entity_input_name(ch, 'transition_ao_intensity'))
tao_intensity = start.outputs.get(get_entity_input_name(ch, 'transition_ao_intensity'))
if tao_intensity:
create_link(tree, tao_intensity, tao.inputs['Intensity'])

tao_power = texcoord.outputs.get(get_entity_input_name(ch, 'transition_ao_power'))
tao_power = start.outputs.get(get_entity_input_name(ch, 'transition_ao_power'))
if tao_power:
create_link(tree, tao_power, tao.inputs['Power'])

tao_color = texcoord.outputs.get(get_entity_input_name(ch, 'transition_ao_color'))
tao_color = start.outputs.get(get_entity_input_name(ch, 'transition_ao_color'))
if tao_color:
create_link(tree, tao_color, tao.inputs['AO Color'])

tao_inside_intensity = texcoord.outputs.get(get_entity_input_name(ch, 'transition_ao_inside_intensity'))
tao_inside_intensity = start.outputs.get(get_entity_input_name(ch, 'transition_ao_inside_intensity'))
if tao_inside_intensity:
create_link(tree, tao_inside_intensity, tao.inputs['Inside Intensity'])

Expand Down Expand Up @@ -3364,8 +3364,8 @@ def reconnect_layer_nodes(layer, ch_idx=-1, merge_mask=False):
if tr_ramp and root_ch.type in {'RGB', 'VALUE'} and ch.enable_transition_ramp:

tr_ramp_blend = nodes.get(ch.tr_ramp_blend)
tr_intensity_value = texcoord.outputs.get(get_entity_input_name(ch, 'transition_ramp_intensity_value'))
tb_second_fac = texcoord.outputs.get(get_entity_input_name(ch, 'transition_bump_second_fac'))
tr_intensity_value = start.outputs.get(get_entity_input_name(ch, 'transition_ramp_intensity_value'))
tb_second_fac = start.outputs.get(get_entity_input_name(ch, 'transition_bump_second_fac'))

create_link(tree, transition_input, tr_ramp.inputs['Transition'])

Expand Down
4 changes: 2 additions & 2 deletions subtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -2237,7 +2237,7 @@ def check_blend_type_nodes(root_ch, layer, ch):
if channel_enabled:
layer_intensity = tree.nodes.get(ch.layer_intensity)
if not layer_intensity:
layer_intensity = new_node(tree, ch, 'layer_intensity', 'ShaderNodeMath', 'Layer Intensity')
layer_intensity = new_node(tree, ch, 'layer_intensity', 'ShaderNodeMath', 'Layer Opacity')
layer_intensity.operation = 'MULTIPLY'
else:
if remove_node(tree, ch, 'layer_intensity'): need_reconnect = True
Expand Down Expand Up @@ -2290,7 +2290,7 @@ def check_blend_type_nodes(root_ch, layer, ch):
# Intensity nodes
intensity = tree.nodes.get(ch.intensity)
if not intensity:
intensity = new_node(tree, ch, 'intensity', 'ShaderNodeMath', 'Intensity')
intensity = new_node(tree, ch, 'intensity', 'ShaderNodeMath', 'Channel Opacity')
intensity.operation = 'MULTIPLY'

# Channel intensity
Expand Down

0 comments on commit ead7826

Please sign in to comment.