Refactor geometry node groups for image depth processing

- Introduced new utility functions in common nodes for evaluating fields and capturing attributes.
- Simplified volume field calculations in image depth cutout and panorama groups by utilizing new utility functions.
- Enhanced readability and maintainability of the image depth cutout and panorama node groups by removing redundant code and improving function usage.
- Adjusted default values for thickness and depth scale in image relief plane group for better user experience.
- Improved handling of geometry attributes and connections in image depth plane group to streamline processing.
This commit is contained in:
2026-09-10 16:46:19 +08:00
parent 489003c2cc
commit 8ae3c1d5b7
20 changed files with 553 additions and 473 deletions

View File

@@ -2,112 +2,44 @@
import bpy
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
from ..common.nodes import interface_socket, group_input, math_node, float_input, menu_switch, read_float_attribute, store_float_attribute, prepare_node_group, capture_fields, evaluate_field
from ..common.smoothing import expand_smooth
from ..common.cutout import _island_cleanup, _position_field, _remove_zero_thickness, _shade_output
from ..common.depth_surface import project_depth_surface, store_surface_camera, remove_surface_attributes, split_depth_surface, sample_face_camera, thicken_depth_surface
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
NODE_GROUP_NAME = "O Image Depth Cutout"
def build_volume_fields(group, geometry):
boundary = edge_boundary_field(group.nodes, group.links)
store = group.nodes.new("GeometryNodeStoreNamedAttribute")
store.domain, store.data_type = "POINT", "FLOAT"
store.inputs["Name"].default_value = "o_balloon_surface_rim"
group.links.new(geometry, store.inputs["Geometry"])
group.links.new(boundary, store.inputs["Value"])
profile = group.nodes.new("GeometryNodeInputNamedAttribute")
profile.data_type = "FLOAT"
profile.inputs["Name"].default_value = "o_balloon"
def build_volume_fields(group):
"""Evaluate the center and thickness on the original front surface."""
links = group.links
def math(operation, a, b):
result = group.nodes.new("ShaderNodeMath")
result.operation = operation
for index, value in enumerate((a, b)):
if isinstance(value, (int, float)):
result.inputs[index].default_value = value
else:
links.new(value, result.inputs[index])
return result.outputs[0]
rim = evaluate_field(group, edge_boundary_field(group.nodes, links), "FLOAT", "POINT")
profile = read_float_attribute(group, "o_balloon")
position = group.nodes.new("GeometryNodeInputPosition")
axes = group.nodes.new("ShaderNodeSeparateXYZ")
links.new(position.outputs[0], axes.inputs[0])
seed = math("SUBTRACT", axes.outputs["Z"], profile.outputs["Attribute"])
center = group.nodes.new("GeometryNodeStoreNamedAttribute")
center.domain, center.data_type = "POINT", "FLOAT"
center.inputs["Name"].default_value = "o_balloon_surface_center"
links.new(store.outputs["Geometry"], center.inputs["Geometry"])
links.new(seed, center.inputs["Value"])
current = group.nodes.new("GeometryNodeInputNamedAttribute")
current.data_type = "FLOAT"
current.inputs["Name"].default_value = "o_balloon_surface_center"
rim = group.nodes.new("GeometryNodeInputNamedAttribute")
rim.data_type = "FLOAT"
rim.inputs["Name"].default_value = "o_balloon_surface_rim"
interior = math("SUBTRACT", 1, rim.outputs["Attribute"])
seed = _math(group, "SUBTRACT", axes.outputs["Z"], profile)
interior = _math(group, "SUBTRACT", 1, rim)
blur = group.nodes.new("GeometryNodeBlurAttribute")
blur.data_type = "FLOAT"
blur.inputs["Iterations"].default_value = 256
links.new(current.outputs["Attribute"], blur.inputs["Value"])
links.new(seed, blur.inputs["Value"])
links.new(interior, blur.inputs["Weight"])
update = group.nodes.new("GeometryNodeStoreNamedAttribute")
update.domain, update.data_type = "POINT", "FLOAT"
update.inputs["Name"].default_value = "o_balloon_surface_center"
links.new(center.outputs["Geometry"], update.inputs["Geometry"])
links.new(blur.outputs[0], update.inputs["Value"])
baseline = group.nodes.new("GeometryNodeInputNamedAttribute")
baseline.data_type = "FLOAT"
baseline.inputs["Name"].default_value = "o_balloon_surface_center"
profile_end = group.nodes.new("GeometryNodeInputNamedAttribute")
profile_end.data_type = "FLOAT"
profile_end.inputs["Name"].default_value = "o_balloon"
position_end = group.nodes.new("GeometryNodeInputPosition")
axes_end = group.nodes.new("ShaderNodeSeparateXYZ")
links.new(position_end.outputs[0], axes_end.inputs[0])
residual = math("SUBTRACT", axes_end.outputs["Z"], baseline.outputs["Attribute"])
full = math("ADD", residual, profile_end.outputs["Attribute"])
minimum = math("MULTIPLY", profile_end.outputs["Attribute"], 0.05)
positive = math("MAXIMUM", full, minimum)
control = group.nodes.new("NodeGroupInput")
scaled = math("MULTIPLY", positive, control.outputs["Thickness"])
thickness = group.nodes.new("GeometryNodeStoreNamedAttribute")
thickness.domain, thickness.data_type = "POINT", "FLOAT"
thickness.inputs["Name"].default_value = "o_balloon_surface_thickness"
group.links.new(update.outputs["Geometry"], thickness.inputs["Geometry"])
group.links.new(scaled, thickness.inputs["Value"])
return thickness.outputs["Geometry"]
center = blur.outputs[0]
residual = _math(group, "SUBTRACT", axes.outputs["Z"], center)
full = _math(group, "ADD", residual, profile)
minimum = _math(group, "MULTIPLY", profile, 0.05)
positive = _math(group, "MAXIMUM", full, minimum)
control = group_input(group.nodes, {"Thickness"})
thickness = _math(group, "MULTIPLY", positive, control.outputs["Thickness"])
return {"rim": rim, "center": center, "thickness": thickness}
def build_volume_rounding(group, volume):
def build_volume_rounding(group, geometry, fields, uniform):
links = group.links
def math(operation, a, b):
result = group.nodes.new("ShaderNodeMath")
result.operation = operation
for index, value in enumerate((a, b)):
if isinstance(value, (int, float)):
result.inputs[index].default_value = value
else:
links.new(value, result.inputs[index])
return result.outputs[0]
def read(name, kind="FLOAT"):
result = group.nodes.new("GeometryNodeInputNamedAttribute")
result.data_type = kind
result.inputs["Name"].default_value = "o_balloon_surface_" + name
return result.outputs["Attribute"]
def store(geometry, name, value, kind="FLOAT"):
result = group.nodes.new("GeometryNodeStoreNamedAttribute")
result.data_type, result.domain = kind, "POINT"
result.inputs["Name"].default_value = "o_balloon_surface_" + name
links.new(geometry, result.inputs["Geometry"])
links.new(value, result.inputs["Value"])
return result.outputs["Geometry"]
control = group.nodes.new("NodeGroupInput")
profile = group.nodes.new("GeometryNodeInputNamedAttribute")
profile.data_type = "FLOAT"
@@ -115,34 +47,31 @@ def build_volume_rounding(group, volume):
balloon = profile.outputs["Attribute"]
maximum = group.nodes.new("GeometryNodeAttributeStatistic")
maximum.data_type, maximum.domain = "FLOAT", "POINT"
links.new(volume, maximum.inputs["Geometry"])
links.new(geometry, maximum.inputs["Geometry"])
links.new(balloon, maximum.inputs["Attribute"])
limit = math("MAXIMUM", maximum.outputs["Max"], 1e-8)
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("MULTIPLY", falloff.outputs[0], control.outputs["Edge Round"])
center = read("center")
weight = _math(group, "MULTIPLY", falloff.outputs[0], control.outputs["Edge Round"])
center = fields["center"]
position = group.nodes.new("GeometryNodeInputPosition")
axes = group.nodes.new("ShaderNodeSeparateXYZ")
links.new(position.outputs[0], axes.inputs[0])
target = math("ADD", center, balloon)
delta = math("SUBTRACT", target, axes.outputs["Z"])
delta = math("MULTIPLY", delta, weight)
enabled = math("MINIMUM", control.outputs["Thickness"], 1)
enabled = math("MAXIMUM", enabled, 0)
delta = math("MULTIPLY", delta, enabled)
carrier = store(volume, "edge_weight", weight)
carrier = store(carrier, "front_delta", delta)
rear = math("MULTIPLY", balloon, weight)
rear = math("MULTIPLY", rear, control.outputs["Thickness"])
thickness = read("thickness")
total = math("ADD", thickness, delta)
total = math("ADD", total, rear)
carrier = store(carrier, "thickness", total)
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")
@@ -150,7 +79,7 @@ def build_volume_rounding(group, volume):
links.new(axes.outputs[axis], center_position.inputs[axis])
links.new(center, center_position.inputs["Z"])
surface = group.nodes.new("GeometryNodeSetPosition")
links.new(volume, surface.inputs["Geometry"])
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")
@@ -167,44 +96,30 @@ def build_volume_rounding(group, volume):
links.new(surface.outputs[0], sample.inputs["Geometry"])
links.new(normalize.outputs[0], sample.inputs["Value"])
links.new(index.outputs[0], sample.inputs["Index"])
carrier = store(carrier, "normal", sample.outputs[0], "FLOAT_VECTOR")
captured = read("front_delta")
thickness = group.nodes.new("GeometryNodeSwitch")
thickness.input_type = "FLOAT"
links.new(uniform, thickness.inputs["Switch"])
links.new(total, thickness.inputs["False"])
links.new(control.outputs["Uniform Thickness"], thickness.inputs["True"])
carrier, captured = capture_fields(
group, geometry, "POINT",
edge_weight=("FLOAT", weight), front_delta=("FLOAT", delta),
thickness=("FLOAT", thickness.outputs[0]), normal=("VECTOR", sample.outputs[0]),
)
displacement = group.nodes.new("ShaderNodeCombineXYZ")
links.new(captured, displacement.inputs["Z"])
links.new(captured["front_delta"], displacement.inputs["Z"])
front = group.nodes.new("GeometryNodeSetPosition")
links.new(carrier, front.inputs["Geometry"])
links.new(displacement.outputs[0], front.inputs["Offset"])
return front.outputs[0]
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(carrier, choose.inputs["True"])
return choose.outputs[0], captured
def _inflation_math(group, operation, a, b):
result = group.nodes.new("ShaderNodeMath")
result.operation = operation
for index, value in enumerate((a, b)):
if hasattr(value, "node"):
group.links.new(value, result.inputs[index])
else:
result.inputs[index].default_value = value
return result.outputs[0]
def _inflation_read(group, name, kind="FLOAT"):
result = group.nodes.new("GeometryNodeInputNamedAttribute")
result.data_type = kind
result.inputs["Name"].default_value = "o_balloon_surface_" + name
return result.outputs["Attribute"]
def _inflation_store(group, geometry, name, value, kind="FLOAT"):
result = group.nodes.new("GeometryNodeStoreNamedAttribute")
result.data_type, result.domain = kind, "POINT"
result.inputs["Name"].default_value = "o_balloon_surface_" + name
group.links.new(geometry, result.inputs["Geometry"])
group.links.new(value, result.inputs["Value"])
return result.outputs["Geometry"]
def build_front_fields(group, geometry):
def build_front_fields(group, rim, front_normal):
"""Fit structural amplitude over neighbouring points before creating the shell."""
links = group.links
@@ -221,30 +136,28 @@ def build_front_fields(group, geometry):
profile_node.data_type = "FLOAT"
profile_node.inputs["Name"].default_value = "o_balloon"
profile = profile_node.outputs["Attribute"]
rim = _inflation_read(group, "rim")
interior = _inflation_math(group, "SUBTRACT", 1, rim)
interior = _math(group, "SUBTRACT", 1, rim)
position = group.nodes.new("GeometryNodeInputPosition")
axes = group.nodes.new("ShaderNodeSeparateXYZ")
links.new(position.outputs[0], axes.inputs[0])
depth = axes.outputs["Z"]
depth_slow = blur(depth, interior)
profile_slow = blur(profile, interior)
depth_bump = _inflation_math(group, "SUBTRACT", depth, depth_slow)
profile_bump = _inflation_math(group, "SUBTRACT", profile, profile_slow)
numerator = _inflation_math(group, "MULTIPLY", depth_bump, profile_bump)
denominator = _inflation_math(group, "MULTIPLY", profile_bump, profile_bump)
depth_bump = _math(group, "SUBTRACT", depth, depth_slow)
profile_bump = _math(group, "SUBTRACT", profile, profile_slow)
numerator = _math(group, "MULTIPLY", depth_bump, profile_bump)
denominator = _math(group, "MULTIPLY", profile_bump, profile_bump)
numerator = blur(numerator)
denominator = blur(denominator)
denominator = _inflation_math(group, "MAXIMUM", denominator, 1e-10)
structure = _inflation_math(group, "DIVIDE", numerator, denominator)
structure = _inflation_math(group, "MAXIMUM", structure, 0)
carrier = _inflation_store(group, geometry, "structure", structure)
denominator = _math(group, "MAXIMUM", denominator, 1e-10)
structure = _math(group, "DIVIDE", numerator, denominator)
structure = _math(group, "MAXIMUM", structure, 0)
normal = _inflation_read(group, "front_normal", "FLOAT_VECTOR")
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 = _inflation_math(group, "MULTIPLY", controls.outputs["Normal Smooth"], 256 / 50)
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"])
@@ -252,52 +165,50 @@ def build_front_fields(group, geometry):
normalize = group.nodes.new("ShaderNodeVectorMath")
normalize.operation = "NORMALIZE"
links.new(smooth.outputs[0], normalize.inputs[0])
carrier = _inflation_store(group, carrier, "inflation_normal", normalize.outputs[0], "FLOAT_VECTOR")
return carrier
return {"structure": structure, "inflation_normal": normalize.outputs[0]}
def build_inflation_position(group, position, distance, uniform):
def build_inflation_position(group, position, distance, uniform, fields):
"""Grow both modes continuously while leaving the rear cap in place."""
links = group.links
structure = _inflation_read(group, "structure")
structure = fields["structure"]
control = group.nodes.new("NodeGroupInput")
a = _inflation_math(group, "MULTIPLY", control.outputs["Thickness"], control.outputs["Front Inflation"])
a = _math(group, "MULTIPLY", control.outputs["Thickness"], control.outputs["Front Inflation"])
# A shifted cubic blend preserves continuous growth and height order.
shifted = _inflation_math(group, "ADD", a, 0.75)
quadratic = _inflation_math(group, "MULTIPLY", a, shifted)
quadratic = _inflation_math(group, "ADD", quadratic, 0.1875)
q = _inflation_math(group, "MULTIPLY", a, quadratic)
k = _inflation_math(group, "ADD", structure, 0.25)
square = _inflation_math(group, "MULTIPLY", k, k)
cube = _inflation_math(group, "MULTIPLY", square, k)
total = _inflation_math(group, "ADD", cube, q)
root = _inflation_math(group, "POWER", total, 1 / 3)
root_square = _inflation_math(group, "MULTIPLY", root, root)
product = _inflation_math(group, "MULTIPLY", root, k)
denominator = _inflation_math(group, "ADD", root_square, product)
denominator = _inflation_math(group, "ADD", denominator, square)
response = _inflation_math(group, "DIVIDE", q, denominator)
shifted = _math(group, "ADD", a, 0.75)
quadratic = _math(group, "MULTIPLY", a, shifted)
quadratic = _math(group, "ADD", quadratic, 0.1875)
q = _math(group, "MULTIPLY", a, quadratic)
k = _math(group, "ADD", structure, 0.25)
square = _math(group, "MULTIPLY", k, k)
cube = _math(group, "MULTIPLY", square, k)
total = _math(group, "ADD", cube, q)
root = _math(group, "POWER", total, 1 / 3)
root_square = _math(group, "MULTIPLY", root, root)
product = _math(group, "MULTIPLY", root, k)
denominator = _math(group, "ADD", root_square, product)
denominator = _math(group, "ADD", denominator, square)
response = _math(group, "DIVIDE", q, denominator)
profile = group.nodes.new("GeometryNodeInputNamedAttribute")
profile.data_type = "FLOAT"
profile.inputs["Name"].default_value = "o_balloon"
balloon = _inflation_math(group, "MULTIPLY", profile.outputs["Attribute"], response)
balloon = _math(group, "MULTIPLY", profile.outputs["Attribute"], response)
uniform_control = group.nodes.new("NodeGroupInput")
uniform_amount = _inflation_math(group, "MULTIPLY", uniform_control.outputs["Uniform Thickness"], uniform_control.outputs["Front Inflation"])
uniform_amount = _math(group, "MULTIPLY", uniform_control.outputs["Uniform Thickness"], uniform_control.outputs["Front Inflation"])
selected = group.nodes.new("GeometryNodeSwitch")
selected.input_type = "FLOAT"
links.new(uniform, selected.inputs["Switch"])
links.new(balloon, selected.inputs["False"])
links.new(uniform_amount, selected.inputs["True"])
displacement = selected.outputs[0]
height = _inflation_read(group, "thickness")
layer = _inflation_math(group, "DIVIDE", distance, height)
layer = _inflation_math(group, "ADD", 1, layer)
layer = _inflation_math(group, "MAXIMUM", layer, 0)
layer = _inflation_math(group, "MINIMUM", layer, 1)
displacement = _inflation_math(group, "MULTIPLY", displacement, layer)
normal = _inflation_read(group, "inflation_normal", "FLOAT_VECTOR")
height = fields["thickness"]
layer = _math(group, "DIVIDE", distance, height)
layer = _math(group, "ADD", 1, layer)
layer = _math(group, "MAXIMUM", layer, 0)
layer = _math(group, "MINIMUM", layer, 1)
displacement = _math(group, "MULTIPLY", displacement, layer)
normal = fields["inflation_normal"]
offset = group.nodes.new("ShaderNodeVectorMath")
offset.operation = "SCALE"
links.new(normal, offset.inputs[0])
@@ -309,7 +220,7 @@ def build_inflation_position(group, position, distance, uniform):
return result.outputs[0]
def build_front_normals(group, geometry):
def build_front_normal(group):
links = group.links
normal = group.nodes.new("GeometryNodeInputNormal")
control = group.nodes.new("NodeGroupInput")
@@ -320,15 +231,10 @@ def build_front_normals(group, geometry):
normalize = group.nodes.new("ShaderNodeVectorMath")
normalize.operation = "NORMALIZE"
links.new(blur.outputs[0], normalize.inputs[0])
store = group.nodes.new("GeometryNodeStoreNamedAttribute")
store.data_type, store.domain = "FLOAT_VECTOR", "POINT"
store.inputs["Name"].default_value = "o_balloon_surface_front_normal"
links.new(geometry, store.inputs["Geometry"])
links.new(normalize.outputs[0], store.inputs["Value"])
return store.outputs[0]
return evaluate_field(group, normalize.outputs[0], "FLOAT_VECTOR", "POINT")
def build_shell_position(group, position, uniform):
def build_shell_position(group, position, front, uniform, fields):
links = group.links
def connect(value, target):
@@ -337,13 +243,6 @@ def build_shell_position(group, position, uniform):
else:
target.default_value = value
def math(operation, a, b):
result = group.nodes.new("ShaderNodeMath")
result.operation = operation
connect(a, result.inputs[0])
connect(b, result.inputs[1])
return result.outputs[0]
def vector(operation, a, b):
result = group.nodes.new("ShaderNodeVectorMath")
result.operation = operation
@@ -351,23 +250,16 @@ def build_shell_position(group, position, uniform):
connect(b, result.inputs[3 if operation == "SCALE" else 1])
return result.outputs[0]
def read(name, kind="FLOAT"):
result = group.nodes.new("GeometryNodeInputNamedAttribute")
result.data_type = kind
result.inputs["Name"].default_value = name
return result.outputs["Attribute"]
def z(value):
result = group.nodes.new("ShaderNodeSeparateXYZ")
links.new(value, result.inputs[0])
return result.outputs["Z"]
# Uniform and the thin end of Balloon share the actual front normal.
front = read("o_depth_surface_position", "FLOAT_VECTOR")
front_z = z(front)
raw_z = z(position)
distance = math("SUBTRACT", raw_z, front_z)
normal = read("o_balloon_surface_front_normal", "FLOAT_VECTOR")
distance = _math(group, "SUBTRACT", raw_z, front_z)
normal = fields["front_normal"]
thin_offset = vector("SCALE", normal, distance)
uniform_position = vector("ADD", front, thin_offset)
@@ -377,26 +269,26 @@ def build_shell_position(group, position, uniform):
clamp = group.nodes.new("ShaderNodeClamp")
links.new(control.outputs["Thickness"], clamp.inputs["Value"])
t = clamp.outputs[0]
center = read("o_balloon_surface_center")
delta = read("o_balloon_surface_front_delta")
radius = math("SUBTRACT", front_z, center)
radius = math("MULTIPLY", radius, t)
remaining = math("SUBTRACT", 1, t)
remainder = math("MULTIPLY", remaining, delta)
radius = math("ADD", radius, remainder)
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 = read("o_balloon_surface_edge_weight")
mask = read("o_normal_scale")
remaining = math("SUBTRACT", 1, edge)
remaining = math("MULTIPLY", remaining, mask)
weight = math("SUBTRACT", 1, remaining)
difference = math("SUBTRACT", weight, edge)
base = math("MULTIPLY", difference, radius)
layer = math("MULTIPLY", weight, distance)
rear_radius = math("ADD", base, layer)
front_radius = math("MULTIPLY", edge, radius)
normal = read("o_balloon_surface_normal", "FLOAT_VECTOR")
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)
@@ -420,87 +312,48 @@ def build_shell_position(group, position, uniform):
links.new(uniform, choose.inputs["Switch"])
links.new(balloon_position, choose.inputs["False"])
links.new(uniform_position, choose.inputs["True"])
return build_inflation_position(group, choose.outputs[0], distance, uniform)
return build_inflation_position(group, choose.outputs[0], distance, uniform, fields)
def _build_depth_surface(
group,
geometry,
thickness,
depth_scale,
split,
uniform_scale,
reference_depth,
depth_image,
):
nodes = group.nodes
def _build_depth_surface(group, geometry, controls):
"""Project the cleaned mesh, capture surface fields, and connect the shell."""
links = group.links
geometry = split_depth_surface(
group, geometry, sample_face_camera(group, depth_image), split, uniform_scale, triangles=True
split = controls.outputs["Split Threshold"]
image = controls.outputs["Depth Image"]
scale = controls.outputs["Uniform Scale"]
geometry, corner_camera, cut_vertex = split_depth_surface(
group, geometry, sample_face_camera(group, image), split, scale, triangles=True,
)
original_camera = _position_field(group, depth_image)
geometry, camera_position = store_surface_camera(
group, geometry, original_camera, split
camera = build_surface_camera(group, _position_field(group, image), corner_camera, cut_vertex, split)
projection = project_depth_surface(
group, geometry, camera, scale, controls.outputs["Reference Depth"], controls.outputs["Depth Scale"],
)
geometry = project_depth_surface(
group, geometry, camera_position, uniform_scale, reference_depth, depth_scale
# The mode field is shared by the geometry and thickness choices.
mode = menu_switch(group, "Mode", ("Balloon", "Uniform"), "BOOLEAN")
mode.inputs["Balloon"].default_value = False
mode.inputs["Uniform"].default_value = True
uniform = mode.outputs[0]
volume = build_volume_fields(group)
normal = build_front_normal(group)
front = build_front_fields(group, volume["rim"], normal)
shared, fields = capture_fields(
group, projection, "POINT",
center=("FLOAT", volume["center"]), front_normal=("VECTOR", normal),
structure=("FLOAT", front["structure"]), inflation_normal=("VECTOR", front["inflation_normal"]),
)
shaped = thicken_depth_surface(group, geometry, thickness)
geometry = _remove_zero_thickness(
group, geometry, shaped, thickness
rounded, rounding = build_volume_rounding(group, shared, {**volume, **fields}, uniform)
fields.update(rounding)
shell = thicken_depth_surface(
group, rounded, fields["thickness"], back_mask=NORMAL_SCALE_ATTRIBUTE_NAME, weld_zero_thickness=True,
)
return remove_surface_attributes(group, geometry)
def _depth_volume(group):
"""Insert the volume field ahead of identity-based shell construction."""
links = group.links
nodes = group.nodes
projection = nodes["Set Position"].outputs["Geometry"]
shell_input = nodes["Store Named Attribute.005"].inputs["Geometry"]
projection = build_front_normals(group, projection)
volume = build_volume_fields(group, projection)
shared = build_front_fields(group, volume.node.inputs["Geometry"].links[0].from_socket)
links.new(shared, volume.node.inputs["Geometry"])
uniform_control = group_input(group.nodes, {"Uniform Thickness"})
uniform = store_float_attribute(group, shared, "o_balloon_surface_thickness", uniform_control.outputs["Uniform Thickness"])
choose = menu_switch(group, "Mode", ("Balloon", "Uniform"), "GEOMETRY")
links.new(volume, choose.inputs["Balloon"])
links.new(uniform, choose.inputs["Uniform"])
links.new(choose.outputs[0], shell_input)
thickness = read_float_attribute(group, "o_balloon_surface_thickness")
links.new(thickness, nodes["Math.018"].inputs[1])
control = group_input(group.nodes, {"Thickness", "Uniform Thickness"})
amount = menu_switch(group, "Mode", ("Balloon", "Uniform"), "FLOAT")
links.new(control.outputs["Thickness"], amount.inputs["Balloon"])
links.new(control.outputs["Uniform Thickness"], amount.inputs["Uniform"])
links.new(amount.outputs[0], nodes["Math.019"].inputs[0])
identity_thickness = read_float_attribute(group, "o_balloon_surface_thickness")
positive = math_node(group.nodes, "GREATER_THAN")
positive.inputs[1].default_value = 1e-12
links.new(identity_thickness, positive.inputs[0])
layer = math_node(group.nodes, "MULTIPLY")
links.new(positive.outputs[0], layer.inputs[0])
links.new(nodes["Separate XYZ.006"].outputs["Z"], layer.inputs[1])
links.new(layer.outputs[0], nodes["Combine XYZ.002"].inputs["Z"])
for name in ("Flip Faces", "Flip Faces.001"):
source = nodes[name].outputs["Mesh"]
outgoing = [link for link in links if link.from_socket == source]
targets = [link.to_socket for link in outgoing]
for link in outgoing:
links.remove(link)
masked = store_float_attribute(group, source, NORMAL_SCALE_ATTRIBUTE_NAME, 0.0, domain="FACE")
for target in targets:
links.new(masked, target)
rounded = build_volume_rounding(group, volume)
links.new(rounded, choose.inputs["Balloon"])
restored = nodes["Vector Math.004"].outputs[0]
targets = [link.to_socket for link in restored.links]
uniform_mode = choose.outputs[0].node.inputs["Switch"].links[0].from_socket
oriented = build_shell_position(group, restored, uniform_mode)
for target in targets:
links.new(oriented, target)
oriented = build_shell_position(group, shell["position"], shell["front"], uniform, fields)
links.new(oriented, shell["position_input"])
amount = group.nodes.new("GeometryNodeSwitch")
amount.input_type = "FLOAT"
links.new(uniform, amount.inputs["Switch"])
links.new(controls.outputs["Thickness"], amount.inputs["False"])
links.new(controls.outputs["Uniform Thickness"], amount.inputs["True"])
return _remove_zero_thickness(group, projection, shell["geometry"], amount.outputs[0])
def build_image_depth_cutout_group():
@@ -535,24 +388,15 @@ def build_image_depth_cutout_group():
float_input(group, 'Uniform Scale', 1.0, parent=data).hide_in_modifier = True
interface_socket(group, 'Depth Image', 'INPUT', 'NodeSocketImage', data).hide_in_modifier = True
interface_socket(group, 'Geometry', 'OUTPUT', 'NodeSocketGeometry')
controls = group_input(group.nodes, set())
geometry = _build_depth_surface(group, controls.outputs['Geometry'], controls.outputs['Thickness'], controls.outputs['Depth Scale'], controls.outputs['Split Threshold'], controls.outputs['Uniform Scale'], controls.outputs['Reference Depth'], controls.outputs['Depth Image'])
_depth_volume(group)
planar_inputs = [link.to_socket for link in group.links if link.from_node.bl_idname == 'NodeGroupInput' and link.from_socket.name == 'Geometry']
base = group_input(group.nodes, {'Geometry', 'Cleanup Threshold'})
area = math_node(group.nodes, 'MULTIPLY')
area.inputs[1].default_value = 0.01
group.links.new(base.outputs['Cleanup Threshold'], area.inputs[0])
cleaned = _island_cleanup(group, base.outputs['Geometry'], area.outputs[0])
cleaned = store_float_attribute(group, cleaned, NORMAL_SCALE_ATTRIBUTE_NAME, 1.0, domain='FACE')
for target in planar_inputs:
group.links.new(cleaned, target)
controls = group_input(group.nodes, set())
geometry = _build_depth_surface(group, cleaned, controls)
geometry = expand_smooth(group, geometry, iterations_name='Smooth', weight_name='Smooth Weight')
remove = group.nodes.new('GeometryNodeRemoveAttribute')
remove.pattern_mode = 'WILDCARD'
remove.inputs['Name'].default_value = 'o_balloon_surface_*'
group.links.new(geometry, remove.inputs['Geometry'])
geometry = remove.outputs[0]
orient = group.nodes.new('GeometryNodeTransform')
orient.inputs['Rotation'].default_value = Matrix(CUTOUT_Z_TO_X).to_euler()
group.links.new(geometry, orient.inputs['Geometry'])
@@ -560,8 +404,6 @@ def build_image_depth_cutout_group():
group.links.new(geometry, axis.inputs['-Z'])
group.links.new(orient.outputs[0], axis.inputs['+X'])
_shade_output(group, axis.outputs[0])
projection = next((node.outputs['Geometry'] for node in group.nodes if node.bl_idname == 'GeometryNodeStoreNamedAttribute' and node.inputs['Name'].default_value == 'o_balloon_surface_front_normal'))
group.links.new(projection, group.nodes['Switch.002'].inputs['True'])
prepare_node_group(group)
for item in group.interface.items_tree:
if item.item_type != 'SOCKET' or item.in_out != 'INPUT':