feat: Implement weight cutout boundary smoothing for image depth cutout
- Added a new proposal for boundary smoothing in the weight cutout process, differentiating between Split edges and Outline smoothing requirements. - Introduced a new capability `cutout-boundary-smoothing` to control smoothing strength and default values. - Updated specifications to define the behavior of boundary-specific smoothing strength and default settings. - Created tasks to verify the implementation of boundary behavior and asset updates. - Developed comprehensive tests for depth symmetry and normal scaling to ensure expected behavior and performance. - Introduced new attributes for normal mapping to facilitate persistent face attributes sharing between depth symmetry and image materials. - Built a new node group for O Image Depth Symmetry, integrating the new smoothing capabilities and ensuring compatibility with existing workflows.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
"""Calibrate metric reference depth and the Depth Balloon base plane."""
|
||||
"""Calibrate metric reference depth and the Depth Symmetry base plane."""
|
||||
|
||||
PLANE_VARIANCE_FLOOR_RATIO = 0.025
|
||||
DEPTH_REFERENCE_PERCENTILE = 95.0
|
||||
@@ -122,7 +122,7 @@ def _stable_plane(coordinates, values):
|
||||
return plane
|
||||
|
||||
|
||||
def depth_balloon_projection_parameters(
|
||||
def depth_symmetry_projection_parameters(
|
||||
vertices,
|
||||
vertex_uv,
|
||||
camera_depth,
|
||||
@@ -135,15 +135,15 @@ def depth_balloon_projection_parameters(
|
||||
vertices = np.asarray(vertices, dtype=np.float32)
|
||||
uv = np.asarray(vertex_uv, dtype=np.float32)
|
||||
if vertices.ndim != 2 or vertices.shape[1] != 3:
|
||||
raise ValueError("Depth Balloon vertices must have three components")
|
||||
raise ValueError("Depth Symmetry vertices must have three components")
|
||||
if uv.shape != (len(vertices), 2):
|
||||
raise ValueError("Depth Balloon UV coordinates do not match its vertices")
|
||||
raise ValueError("Depth Symmetry UV coordinates do not match its vertices")
|
||||
camera_depth = np.asarray(camera_depth, dtype=np.float32)
|
||||
valid = np.asarray(valid, dtype=bool)
|
||||
if valid.shape != camera_depth.shape:
|
||||
raise ValueError("Depth Balloon depth and mask dimensions do not match")
|
||||
raise ValueError("Depth Symmetry depth and mask dimensions do not match")
|
||||
if not uniform_scale > 0.0:
|
||||
raise ValueError("Depth Balloon Uniform Scale must be positive")
|
||||
raise ValueError("Depth Symmetry Uniform Scale must be positive")
|
||||
height, width = camera_depth.shape
|
||||
sample_x = uv[:, 0] * max(width - 1, 0)
|
||||
sample_y = (1.0 - uv[:, 1]) * max(height - 1, 0)
|
||||
@@ -155,7 +155,7 @@ def depth_balloon_projection_parameters(
|
||||
sample_y,
|
||||
)
|
||||
if not usable.any():
|
||||
raise ValueError("MoGe-2 found no valid Depth Balloon samples")
|
||||
raise ValueError("MoGe-2 found no valid Depth Symmetry samples")
|
||||
local_coordinates = vertices[:, :2]
|
||||
metric_depth = sampled[usable] * float(uniform_scale)
|
||||
plane = _stable_plane(local_coordinates[usable], metric_depth)
|
||||
|
||||
@@ -6,7 +6,7 @@ from .shape import CUTOUT_SHAPE_LABELS
|
||||
CUTOUT_SHAPE_BUTTONS = (
|
||||
("FLAT", "MESH_GRID"),
|
||||
("SOLID", "MESH_UVSPHERE"),
|
||||
("DEPTH_BALLOON", "META_BALL"),
|
||||
("DEPTH_SYMMETRY", "META_BALL"),
|
||||
("DEPTH_SOLID", "SURFACE_NCURVE"),
|
||||
)
|
||||
|
||||
|
||||
@@ -5,10 +5,7 @@ from enum import StrEnum
|
||||
import bpy
|
||||
|
||||
from ...common.depth import camera_depth_values, depth_uniform_scale
|
||||
from ...common.material import (
|
||||
IMAGE_MATERIAL_NODE_GROUP_NAME,
|
||||
create_image_material,
|
||||
)
|
||||
from ...common.material import create_image_material
|
||||
from ...common.object import (
|
||||
finalize_object_result,
|
||||
modifier_input_identifier,
|
||||
@@ -18,7 +15,7 @@ from ...common.node import load_node_group
|
||||
from .depth_calibration import (
|
||||
DEFAULT_DEPTH_BASELINE,
|
||||
DEFAULT_DEPTH_DIRECTION,
|
||||
depth_balloon_projection_parameters,
|
||||
depth_symmetry_projection_parameters,
|
||||
metric_depth_reference,
|
||||
use_adaptive_depth_calibration,
|
||||
)
|
||||
@@ -31,7 +28,6 @@ from .geometry import (
|
||||
)
|
||||
from .shape import (
|
||||
BALLOON_ATTRIBUTE_NAME,
|
||||
NORMAL_SCALE_ATTRIBUTE_NAME,
|
||||
CUTOUT_NODE_GROUP_NAMES,
|
||||
DEPTH_CUTOUT_SHAPES,
|
||||
)
|
||||
@@ -75,24 +71,6 @@ def load_cutout_node_group(shape):
|
||||
return load_node_group(CUTOUT_NODE_GROUP_NAMES[shape])
|
||||
|
||||
|
||||
def _connect_cutout_normal_scale(material):
|
||||
nodes = material.node_tree.nodes
|
||||
image_layer = next(
|
||||
node
|
||||
for node in nodes
|
||||
if node.bl_idname == "ShaderNodeGroup"
|
||||
and node.node_tree is not None
|
||||
and node.node_tree.name == IMAGE_MATERIAL_NODE_GROUP_NAME
|
||||
)
|
||||
attribute = nodes.new("ShaderNodeAttribute")
|
||||
attribute.attribute_type = "GEOMETRY"
|
||||
attribute.attribute_name = NORMAL_SCALE_ATTRIBUTE_NAME
|
||||
attribute.location = (-550.0, -250.0)
|
||||
material.node_tree.links.new(
|
||||
attribute.outputs["Fac"], image_layer.inputs["Normal Scale"]
|
||||
)
|
||||
|
||||
|
||||
def create_shape_object(
|
||||
context,
|
||||
source_object,
|
||||
@@ -143,7 +121,6 @@ def create_shape_object(
|
||||
scene=context.scene,
|
||||
)
|
||||
depth_reference = None
|
||||
_connect_cutout_normal_scale(material)
|
||||
uniform_scale = None
|
||||
depth_direction = None
|
||||
if shape in DEPTH_CUTOUT_SHAPES:
|
||||
@@ -161,7 +138,7 @@ def create_shape_object(
|
||||
)
|
||||
if not use_adaptive_depth_calibration(transparent_fraction):
|
||||
depth_reference = DEFAULT_DEPTH_BASELINE
|
||||
if shape == "DEPTH_BALLOON":
|
||||
if shape == "DEPTH_SYMMETRY":
|
||||
depth_direction = DEFAULT_DEPTH_DIRECTION
|
||||
elif shape == "DEPTH_SOLID":
|
||||
depth_reference = metric_depth_reference(
|
||||
@@ -170,7 +147,7 @@ def create_shape_object(
|
||||
uniform_scale,
|
||||
)
|
||||
else:
|
||||
depth_reference, depth_direction = depth_balloon_projection_parameters(
|
||||
depth_reference, depth_direction = depth_symmetry_projection_parameters(
|
||||
base_shape.vertices,
|
||||
base_shape.uv,
|
||||
camera_depth,
|
||||
@@ -222,7 +199,7 @@ def create_shape_object(
|
||||
),
|
||||
value,
|
||||
)
|
||||
if shape in {"FLAT", "SOLID", "DEPTH_SOLID"} and gesture == "POLYLINE":
|
||||
if gesture == "POLYLINE" and shape != "DEPTH_SYMMETRY":
|
||||
set_modifier_input(
|
||||
modifier,
|
||||
modifier_input_identifier(node_group, "Mode"),
|
||||
@@ -246,7 +223,7 @@ def create_shape_object(
|
||||
modifier_input_identifier(node_group, name),
|
||||
value,
|
||||
)
|
||||
if shape == "DEPTH_BALLOON":
|
||||
if shape == "DEPTH_SYMMETRY":
|
||||
set_modifier_input(
|
||||
modifier,
|
||||
modifier_input_identifier(node_group, "Depth Direction"),
|
||||
|
||||
@@ -74,7 +74,7 @@ _HIDDEN = {"HIDDEN", "SKIP_SAVE"}
|
||||
def normal_mode_for_shape(shape, generate_normal):
|
||||
if shape == "DEPTH_SOLID":
|
||||
return NormalMode.OBJECT
|
||||
if shape == "DEPTH_BALLOON":
|
||||
if shape == "DEPTH_SYMMETRY":
|
||||
return NormalMode.TANGENT
|
||||
if not generate_normal:
|
||||
return NormalMode.NONE
|
||||
@@ -82,7 +82,7 @@ def normal_mode_for_shape(shape, generate_normal):
|
||||
|
||||
|
||||
def shape_uses_depth(shape):
|
||||
return shape in {"DEPTH_SOLID", "DEPTH_BALLOON"}
|
||||
return shape in {"DEPTH_SOLID", "DEPTH_SYMMETRY"}
|
||||
|
||||
|
||||
def create_cutout_shape(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""Cutout Shape identifiers shared by runtime and node-asset tools."""
|
||||
|
||||
BALLOON_ATTRIBUTE_NAME = "o_balloon"
|
||||
NORMAL_SCALE_ATTRIBUTE_NAME = "o_normal_scale"
|
||||
NORMAL_REDUCTION_ATTRIBUTE_NAME = "o_normal_reduction"
|
||||
CUTOUT_Z_TO_X = (
|
||||
(0.0, 0.0, -1.0, 0.0),
|
||||
(-1.0, 0.0, 0.0, 0.0),
|
||||
@@ -11,14 +11,14 @@ CUTOUT_Z_TO_X = (
|
||||
CUTOUT_NODE_GROUP_NAMES = {
|
||||
"FLAT": "O Image Cutout",
|
||||
"SOLID": "O Image Cutout",
|
||||
"DEPTH_BALLOON": "O Image Depth Balloon",
|
||||
"DEPTH_SYMMETRY": "O Image Depth Symmetry",
|
||||
"DEPTH_SOLID": "O Image Depth Cutout",
|
||||
}
|
||||
CUTOUT_SHAPE_LABELS = {
|
||||
"FLAT": "Flat",
|
||||
"SOLID": "Solid",
|
||||
"DEPTH_BALLOON": "Depth Balloon",
|
||||
"DEPTH_SYMMETRY": "Depth Symmetry",
|
||||
"DEPTH_SOLID": "Depth Solid",
|
||||
}
|
||||
CUTOUT_SHAPES = frozenset(CUTOUT_NODE_GROUP_NAMES)
|
||||
DEPTH_CUTOUT_SHAPES = frozenset({"DEPTH_BALLOON", "DEPTH_SOLID"})
|
||||
DEPTH_CUTOUT_SHAPES = frozenset({"DEPTH_SYMMETRY", "DEPTH_SOLID"})
|
||||
|
||||
Reference in New Issue
Block a user