Implement arrangement framework for node groups
- Introduced `frames.py` to manage field complex calculations and their arrangement within node groups. - Added functionality to create and remove field frames based on node arrangements. - Developed `passages.py` to find unobstructed paths for connections around calculation frames. - Implemented `references.py` to route shared results on peripheral tracks, ensuring efficient distribution of outputs. - Created `sections.py` to reserve space for field calculations adjacent to geometry consumers. - Added `sources.py` to position shared calculation sources effectively beside their distribution channels. - Enhanced outline smoothing with `outline_smoothing.py` to adapt camera depth along original outlines.
This commit is contained in:
@@ -4,7 +4,8 @@ from mathutils import Matrix
|
||||
from anyimage.operators.cutout_tool.shape import CUTOUT_Z_TO_X, NORMAL_SCALE_ATTRIBUTE_NAME
|
||||
from ..common.nodes import interface_socket, group_input, math_node, float_input, menu_switch, read_float_attribute, store_float_attribute, prepare_node_group, sample_field, evaluate_field
|
||||
from ..common.smoothing import expand_smooth
|
||||
from ..common.boundary_smoothing import smooth_boundary_camera, smooth_cut_boundary
|
||||
from ..common.boundary_smoothing import smooth_cut_boundary
|
||||
from ..common.outline_smoothing import smooth_outline_camera
|
||||
from ..common.cutout import _island_cleanup, _position_field, _remove_zero_thickness, _shade_output
|
||||
from ..common.depth_surface import _math, project_depth_surface, build_surface_camera, split_depth_surface, sample_face_camera, thicken_depth_surface
|
||||
from ..common.smoothing import edge_boundary_field
|
||||
@@ -72,83 +73,33 @@ def build_volume_fields(group):
|
||||
return {"rim": rim, "center": center, "thickness": thickness}
|
||||
|
||||
|
||||
def build_volume_rounding(group, geometry, fields, uniform, normal_weight=1):
|
||||
links = group.links
|
||||
|
||||
control = group.nodes.new("NodeGroupInput")
|
||||
profile = group.nodes.new("GeometryNodeInputNamedAttribute")
|
||||
profile.data_type = "FLOAT"
|
||||
profile.inputs["Name"].default_value = "o_balloon"
|
||||
balloon = profile.outputs["Attribute"]
|
||||
maximum = group.nodes.new("GeometryNodeAttributeStatistic")
|
||||
maximum.data_type, maximum.domain = "FLOAT", "POINT"
|
||||
links.new(geometry, maximum.inputs["Geometry"])
|
||||
links.new(balloon, maximum.inputs["Attribute"])
|
||||
limit = _math(group, "MAXIMUM", maximum.outputs["Max"], 1e-8)
|
||||
falloff = group.nodes.new("ShaderNodeMapRange")
|
||||
falloff.interpolation_type = "SMOOTHERSTEP"
|
||||
falloff.inputs["To Min"].default_value = 1
|
||||
falloff.inputs["To Max"].default_value = 0
|
||||
links.new(balloon, falloff.inputs["Value"])
|
||||
links.new(limit, falloff.inputs["From Max"])
|
||||
weight = _math(group, "MULTIPLY", falloff.outputs[0], control.outputs["Edge Round"])
|
||||
center = fields["center"]
|
||||
position = group.nodes.new("GeometryNodeInputPosition")
|
||||
axes = group.nodes.new("ShaderNodeSeparateXYZ")
|
||||
def build_shell_fields(group, geometry, fields, uniform, normal_weight=1):
|
||||
"""Evaluate rear directions on the center surface and select shell thickness."""
|
||||
nodes, links = group.nodes, group.links
|
||||
position = nodes.new("GeometryNodeInputPosition")
|
||||
axes = nodes.new("ShaderNodeSeparateXYZ")
|
||||
links.new(position.outputs[0], axes.inputs[0])
|
||||
target = _math(group, "ADD", center, balloon)
|
||||
delta = _math(group, "SUBTRACT", target, axes.outputs["Z"])
|
||||
delta = _math(group, "MULTIPLY", delta, weight)
|
||||
enabled = _math(group, "MINIMUM", control.outputs["Thickness"], 1)
|
||||
enabled = _math(group, "MAXIMUM", enabled, 0)
|
||||
delta = _math(group, "MULTIPLY", delta, enabled)
|
||||
rear = _math(group, "MULTIPLY", balloon, weight)
|
||||
rear = _math(group, "MULTIPLY", rear, control.outputs["Thickness"])
|
||||
thickness = fields["thickness"]
|
||||
total = _math(group, "ADD", thickness, delta)
|
||||
total = _math(group, "ADD", total, rear)
|
||||
|
||||
# Evaluate normals on a separate center surface with identical point indices.
|
||||
center_position = group.nodes.new("ShaderNodeCombineXYZ")
|
||||
center_position = nodes.new("ShaderNodeCombineXYZ")
|
||||
for axis in ("X", "Y"):
|
||||
links.new(axes.outputs[axis], center_position.inputs[axis])
|
||||
links.new(center, center_position.inputs["Z"])
|
||||
surface = group.nodes.new("GeometryNodeSetPosition")
|
||||
links.new(fields["center"], center_position.inputs["Z"])
|
||||
surface = nodes.new("GeometryNodeSetPosition")
|
||||
links.new(geometry, surface.inputs["Geometry"])
|
||||
links.new(center_position.outputs[0], surface.inputs["Position"])
|
||||
normal = group.nodes.new("GeometryNodeInputNormal")
|
||||
blur = group.nodes.new("GeometryNodeBlurAttribute")
|
||||
normal = nodes.new("GeometryNodeInputNormal")
|
||||
blur = nodes.new("GeometryNodeBlurAttribute")
|
||||
blur.data_type = "FLOAT_VECTOR"
|
||||
blur.inputs["Iterations"].default_value = 100
|
||||
links.new(normal.outputs[0], blur.inputs["Value"])
|
||||
local = group.nodes.new("NodeGroupInput")
|
||||
links.new(local.outputs["Normal Smooth"], blur.inputs["Iterations"])
|
||||
normalized = blend_normal(group, normal.outputs[0], blur.outputs[0], normal_weight)
|
||||
index = group.nodes.new("GeometryNodeInputIndex")
|
||||
sample = group.nodes.new("GeometryNodeSampleIndex")
|
||||
sample.data_type, sample.domain = "FLOAT_VECTOR", "POINT"
|
||||
links.new(surface.outputs[0], sample.inputs["Geometry"])
|
||||
links.new(normalized, sample.inputs["Value"])
|
||||
links.new(index.outputs[0], sample.inputs["Index"])
|
||||
thickness = group.nodes.new("GeometryNodeSwitch")
|
||||
rear_normal = sample_field(group, surface.outputs[0], normalized, "FLOAT_VECTOR")
|
||||
control = group_input(nodes, {"Uniform Thickness"})
|
||||
thickness = nodes.new("GeometryNodeSwitch")
|
||||
thickness.input_type = "FLOAT"
|
||||
links.new(uniform, thickness.inputs["Switch"])
|
||||
links.new(total, thickness.inputs["False"])
|
||||
links.new(fields["thickness"], thickness.inputs["False"])
|
||||
links.new(control.outputs["Uniform Thickness"], thickness.inputs["True"])
|
||||
rounding = {
|
||||
"edge_weight": weight, "front_delta": delta,
|
||||
"thickness": thickness.outputs[0], "normal": sample.outputs[0],
|
||||
}
|
||||
displacement = group.nodes.new("ShaderNodeCombineXYZ")
|
||||
links.new(delta, displacement.inputs["Z"])
|
||||
front = group.nodes.new("GeometryNodeSetPosition")
|
||||
links.new(geometry, front.inputs["Geometry"])
|
||||
links.new(displacement.outputs[0], front.inputs["Offset"])
|
||||
choose = group.nodes.new("GeometryNodeSwitch")
|
||||
choose.input_type = "GEOMETRY"
|
||||
links.new(uniform, choose.inputs["Switch"])
|
||||
links.new(front.outputs[0], choose.inputs["False"])
|
||||
links.new(geometry, choose.inputs["True"])
|
||||
return choose.outputs[0], rounding
|
||||
return {"thickness": thickness.outputs[0], "normal": rear_normal}
|
||||
|
||||
|
||||
def build_front_fields(group, rim, front_normal, normal_weight=1):
|
||||
@@ -186,14 +137,10 @@ def build_front_fields(group, rim, front_normal, normal_weight=1):
|
||||
structure = _math(group, "MAXIMUM", structure, 0)
|
||||
|
||||
normal = front_normal
|
||||
controls = group.nodes.new("NodeGroupInput")
|
||||
# Keep the accepted broad front-direction filter at the default of 50;
|
||||
# zero disables both this filter and the initial front/back normal filters.
|
||||
spread = _math(group, "MULTIPLY", controls.outputs["Normal Smooth"], 256 / 50)
|
||||
smooth = group.nodes.new("GeometryNodeBlurAttribute")
|
||||
smooth.data_type = "FLOAT_VECTOR"
|
||||
links.new(normal, smooth.inputs["Value"])
|
||||
links.new(spread, smooth.inputs["Iterations"])
|
||||
smooth.inputs["Iterations"].default_value = 512
|
||||
normalized = blend_normal(group, normal, smooth.outputs[0], normal_weight)
|
||||
return {"structure": structure, "inflation_normal": normalized}
|
||||
|
||||
@@ -247,17 +194,21 @@ def build_inflation_position(group, position, distance, uniform, fields):
|
||||
result.operation = "ADD"
|
||||
links.new(position, result.inputs[0])
|
||||
links.new(offset.outputs[0], result.inputs[1])
|
||||
return result.outputs[0]
|
||||
enabled = group.nodes.new("GeometryNodeSwitch")
|
||||
enabled.input_type = "VECTOR"
|
||||
links.new(control.outputs["Front Inflation"], enabled.inputs["Switch"])
|
||||
links.new(position, enabled.inputs["False"])
|
||||
links.new(result.outputs[0], enabled.inputs["True"])
|
||||
return enabled.outputs[0]
|
||||
|
||||
|
||||
def build_front_normal(group, normal_weight):
|
||||
links = group.links
|
||||
normal = group.nodes.new("GeometryNodeInputNormal")
|
||||
control = group.nodes.new("NodeGroupInput")
|
||||
blur = group.nodes.new("GeometryNodeBlurAttribute")
|
||||
blur.data_type = "FLOAT_VECTOR"
|
||||
links.new(normal.outputs[0], blur.inputs["Value"])
|
||||
links.new(control.outputs["Normal Smooth"], blur.inputs["Iterations"])
|
||||
blur.inputs["Iterations"].default_value = 100
|
||||
normalized = blend_normal(group, normal.outputs[0], blur.outputs[0], normal_weight)
|
||||
return evaluate_field(group, normalized, "FLOAT_VECTOR", "POINT")
|
||||
|
||||
@@ -291,35 +242,14 @@ def build_shell_position(group, position, front, uniform, fields):
|
||||
thin_offset = vector("SCALE", normal, distance)
|
||||
uniform_position = vector("ADD", front, thin_offset)
|
||||
|
||||
# R = t * (front_z - center) + (1 - t) * front_delta, with t clamped.
|
||||
# This avoids division by Thickness and removes the old zero-thickness drift.
|
||||
control = group.nodes.new("NodeGroupInput")
|
||||
control = group_input(group.nodes, {"Thickness"})
|
||||
clamp = group.nodes.new("ShaderNodeClamp")
|
||||
links.new(control.outputs["Thickness"], clamp.inputs["Value"])
|
||||
t = clamp.outputs[0]
|
||||
center = fields["center"]
|
||||
delta = fields["front_delta"]
|
||||
radius = _math(group, "SUBTRACT", front_z, center)
|
||||
radius = _math(group, "MULTIPLY", radius, t)
|
||||
remaining = _math(group, "SUBTRACT", 1, t)
|
||||
remainder = _math(group, "MULTIPLY", remaining, delta)
|
||||
radius = _math(group, "ADD", radius, remainder)
|
||||
|
||||
# Front and rear use the same edge field, evaluated on their own caps.
|
||||
edge = fields["edge_weight"]
|
||||
mask = read_float_attribute(group, "o_normal_scale")
|
||||
remaining = _math(group, "SUBTRACT", 1, edge)
|
||||
remaining = _math(group, "MULTIPLY", remaining, mask)
|
||||
weight = _math(group, "SUBTRACT", 1, remaining)
|
||||
difference = _math(group, "SUBTRACT", weight, edge)
|
||||
base = _math(group, "MULTIPLY", difference, radius)
|
||||
layer = _math(group, "MULTIPLY", weight, distance)
|
||||
rear_radius = _math(group, "ADD", base, layer)
|
||||
front_radius = _math(group, "MULTIPLY", edge, radius)
|
||||
normal = fields["normal"]
|
||||
direction = vector("SUBTRACT", normal, (0, 0, 1))
|
||||
front_shift = vector("SCALE", direction, front_radius)
|
||||
front_position = vector("ADD", front, front_shift)
|
||||
radius = _math(group, "MULTIPLY", _math(group, "SUBTRACT", front_z, fields["center"]), t)
|
||||
rear = _math(group, "SUBTRACT", 1, read_float_attribute(group, "o_normal_scale"))
|
||||
rear_radius = _math(group, "MULTIPLY", rear, _math(group, "ADD", radius, distance))
|
||||
direction = vector("SUBTRACT", fields["normal"], (0, 0, 1))
|
||||
rear_shift = vector("SCALE", direction, rear_radius)
|
||||
axis_offset = group.nodes.new("ShaderNodeCombineXYZ")
|
||||
links.new(distance, axis_offset.inputs["Z"])
|
||||
@@ -334,7 +264,7 @@ def build_shell_position(group, position, front, uniform, fields):
|
||||
links.new(transition.outputs[0], mix.inputs[0])
|
||||
links.new(thin_offset, mix.inputs[4])
|
||||
links.new(full_offset, mix.inputs[5])
|
||||
balloon_position = vector("ADD", front_position, mix.outputs["Result"])
|
||||
balloon_position = vector("ADD", front, mix.outputs["Result"])
|
||||
choose = group.nodes.new("GeometryNodeSwitch")
|
||||
choose.input_type = "VECTOR"
|
||||
links.new(uniform, choose.inputs["Switch"])
|
||||
@@ -351,11 +281,11 @@ def _build_depth_surface(group, geometry, controls):
|
||||
scale = controls.outputs["Uniform Scale"]
|
||||
original = geometry
|
||||
geometry, corner_camera, cut_vertex = split_depth_surface(
|
||||
group, geometry, sample_face_camera(group, image), split, scale, triangles=True,
|
||||
group, geometry, sample_face_camera(group, image), split, controls.outputs["Reference Depth"], triangles=True,
|
||||
)
|
||||
geometry = remove_boundary_triangles(group, geometry)
|
||||
camera = build_surface_camera(group, _position_field(group, image), corner_camera, cut_vertex, split)
|
||||
camera = smooth_boundary_camera(group, camera)
|
||||
camera = smooth_outline_camera(group, original, geometry, camera, scale)
|
||||
projection = project_depth_surface(
|
||||
group, geometry, camera, scale, controls.outputs["Reference Depth"], controls.outputs["Depth Scale"], split,
|
||||
)
|
||||
@@ -370,10 +300,10 @@ def _build_depth_surface(group, geometry, controls):
|
||||
normal_weight = build_normal_weight(group, uniform)
|
||||
normal = build_front_normal(group, normal_weight)
|
||||
front = build_front_fields(group, volume["rim"], normal, normal_weight)
|
||||
rounded, rounding = build_volume_rounding(group, projection, volume, uniform, normal_weight)
|
||||
thickness = sample_field(group, projection, rounding["thickness"], "FLOAT")
|
||||
shell_fields = build_shell_fields(group, projection, volume, uniform, normal_weight)
|
||||
thickness = sample_field(group, projection, shell_fields["thickness"], "FLOAT")
|
||||
shell = thicken_depth_surface(
|
||||
group, rounded, thickness, back_mask=NORMAL_SCALE_ATTRIBUTE_NAME, weld_zero_thickness=True,
|
||||
group, projection, thickness, back_mask=NORMAL_SCALE_ATTRIBUTE_NAME, weld_zero_thickness=True,
|
||||
)
|
||||
fields = {
|
||||
name: sample_field(group, projection, value, data_type, index=shell["source_index"])
|
||||
@@ -385,7 +315,7 @@ def _build_depth_surface(group, geometry, controls):
|
||||
fields.update({
|
||||
name: sample_field(group, projection, value, "FLOAT_VECTOR" if name == "normal" else "FLOAT",
|
||||
index=shell["source_index"])
|
||||
for name, value in rounding.items()
|
||||
for name, value in shell_fields.items()
|
||||
})
|
||||
oriented = build_shell_position(group, shell["position"], shell["front"], uniform, fields)
|
||||
links.new(oriented, shell["position_input"])
|
||||
@@ -405,7 +335,7 @@ def build_image_depth_cutout_group():
|
||||
group = bpy.data.node_groups.new(name, 'GeometryNodeTree')
|
||||
group.is_modifier, group.use_fake_user = (True, True)
|
||||
group.color_tag = 'GEOMETRY'
|
||||
group['anyimage_asset_revision'] = 18
|
||||
group['anyimage_asset_revision'] = 23
|
||||
interface_socket(group, 'Geometry', 'INPUT', 'NodeSocketGeometry')
|
||||
interface_socket(group, 'Mode', 'INPUT', 'NodeSocketMenu')
|
||||
float_input(group, 'Thickness', 1.0).description = 'Balloon profile multiplier; zero returns the sheet'
|
||||
@@ -416,17 +346,16 @@ def build_image_depth_cutout_group():
|
||||
iterations.default_value = 0
|
||||
iterations.min_value, iterations.max_value = (0, 20)
|
||||
options = group.interface.new_panel(name='Options', default_closed=True)
|
||||
boundary_smooth = interface_socket(group, 'Boundary Smooth', 'INPUT', 'NodeSocketInt', options)
|
||||
boundary_smooth.default_value, boundary_smooth.min_value, boundary_smooth.max_value = 5, 0, 20
|
||||
boundary_smooth.description = 'Smooth boundary depth and geometry along the original outline and split edges'
|
||||
float_input(group, 'Cleanup Threshold', 0.0, parent=options)
|
||||
float_input(group, 'Reference Depth', 1.0, subtype='DISTANCE', parent=options)
|
||||
float_input(group, 'Edge Round', 0.2, maximum=1, subtype='FACTOR', parent=options)
|
||||
float_input(group, 'Front Inflation', 1.0, maximum=32, parent=options)
|
||||
normal_iterations = interface_socket(group, 'Normal Smooth', 'INPUT', 'NodeSocketInt', options)
|
||||
normal_iterations.default_value = 50
|
||||
normal_iterations.min_value, normal_iterations.max_value = (0, 50)
|
||||
float_input(group, 'Smooth Weight', 1.0, maximum=1, subtype='FACTOR', parent=options)
|
||||
float_input(group, 'Reference Depth', 1.0, subtype='DISTANCE', parent=options)
|
||||
boundary_smooth = interface_socket(group, 'Boundary Smooth', 'INPUT', 'NodeSocketInt', options)
|
||||
boundary_smooth.default_value, boundary_smooth.min_value, boundary_smooth.max_value = 2, 1, 20
|
||||
boundary_smooth.description = 'Boundary geometry iterations and depth blur steps per outline smoothing round'
|
||||
outline_smooth = interface_socket(group, 'Outline Depth Fix', 'INPUT', 'NodeSocketInt', options)
|
||||
outline_smooth.default_value, outline_smooth.min_value, outline_smooth.max_value = 16, 0, 200
|
||||
outline_smooth.description = 'Adaptive ray-distance smoothing rounds around the original outline; preserves split boundary distance'
|
||||
float_input(group, 'Front Inflation', 0.0, maximum=1, subtype='FACTOR', parent=options)
|
||||
data = group.interface.new_panel(name='Data', default_closed=True)
|
||||
interface_socket(group, 'Inward Axis', 'INPUT', 'NodeSocketMenu', data).hide_in_modifier = True
|
||||
float_input(group, 'Uniform Scale', 1.0, parent=data).hide_in_modifier = True
|
||||
|
||||
Reference in New Issue
Block a user