Refactor depth reference handling and cleanup
- Unified reference depth calculation to use a single implementation in common/depth.py. - Removed server-side reference depth computation and adjusted depth.json to only include image_size and intrinsics. - Updated depth texture handling to ignore transparent, invalid, and non-positive pixels when calculating reference depth. - Changed reference depth calculation to use the 95th percentile of valid depth values. - Adjusted depth direction fitting to return a flat direction when no samples are available. - Removed cleanup threshold parameters from Cutout and related nodes, simplifying the interface. - Updated tests to verify new reference depth logic and ensure compatibility with existing functionality.
This commit is contained in:
@@ -4,7 +4,12 @@ from enum import StrEnum
|
||||
|
||||
import bpy
|
||||
|
||||
from ...common.depth import camera_depth_values, depth_uniform_scale
|
||||
from ...common.coordinate import canonical_direction_to_symmetry_legacy
|
||||
from ...common.depth import (
|
||||
depth_uniform_scale,
|
||||
fit_symmetry_depth_direction,
|
||||
reference_depth,
|
||||
)
|
||||
from ...common.material import create_image_material
|
||||
from ...common.object import (
|
||||
blender_frame_rotation,
|
||||
@@ -13,19 +18,9 @@ from ...common.object import (
|
||||
set_modifier_input,
|
||||
)
|
||||
from ...common.node import load_node_group
|
||||
from .depth_calibration import (
|
||||
DEFAULT_DEPTH_BASELINE,
|
||||
DEFAULT_DEPTH_DIRECTION,
|
||||
depth_symmetry_projection_parameters,
|
||||
metric_depth_reference,
|
||||
use_adaptive_depth_calibration,
|
||||
)
|
||||
from .geometry import (
|
||||
CUTOUT_ALPHA_THRESHOLD,
|
||||
build_reference_mask,
|
||||
crop_plane_bounds,
|
||||
cutout_cleanup_value,
|
||||
selection_calibration,
|
||||
world_plane_metric,
|
||||
)
|
||||
from .shape import (
|
||||
BALLOON_ATTRIBUTE_NAME,
|
||||
@@ -80,12 +75,10 @@ def create_shape_object(
|
||||
context,
|
||||
source_object,
|
||||
shape,
|
||||
edge_length,
|
||||
content_values,
|
||||
content_bounds,
|
||||
base_shape,
|
||||
*,
|
||||
alpha_threshold=CUTOUT_ALPHA_THRESHOLD,
|
||||
depth_image=None,
|
||||
depth_metadata=None,
|
||||
normal_image=None,
|
||||
@@ -106,11 +99,6 @@ def create_shape_object(
|
||||
(bounds[0] + bounds[1]) * 0.5,
|
||||
(bounds[2] + bounds[3]) * 0.5,
|
||||
)
|
||||
world_metric, _world_z_scale = world_plane_metric(source_object.matrix_world)
|
||||
cleanup_value = cutout_cleanup_value(
|
||||
edge_length,
|
||||
world_metric,
|
||||
)
|
||||
material = None
|
||||
mesh = None
|
||||
mesh_object = None
|
||||
@@ -132,33 +120,25 @@ def create_shape_object(
|
||||
if shape in DEPTH_CUTOUT_SHAPES:
|
||||
if depth_image is None or depth_metadata is None:
|
||||
raise ValueError("Depth Shape requires a Depth texture and metadata")
|
||||
camera_depth, valid = camera_depth_values(depth_image)
|
||||
calibration_valid, transparent_fraction = selection_calibration(
|
||||
content_values, valid.shape, threshold=alpha_threshold
|
||||
model_reference = reference_depth(
|
||||
depth_image,
|
||||
build_reference_mask(content_values, depth_image.size),
|
||||
)
|
||||
calibration_valid &= valid
|
||||
uniform_scale = depth_uniform_scale(
|
||||
source_object,
|
||||
depth_metadata,
|
||||
model_reference,
|
||||
bounds,
|
||||
)
|
||||
if not use_adaptive_depth_calibration(transparent_fraction):
|
||||
depth_reference = DEFAULT_DEPTH_BASELINE
|
||||
if shape == "DEPTH_SYMMETRY":
|
||||
depth_direction = DEFAULT_DEPTH_DIRECTION
|
||||
elif shape == "DEPTH_SOLID":
|
||||
depth_reference = metric_depth_reference(
|
||||
camera_depth,
|
||||
calibration_valid,
|
||||
uniform_scale,
|
||||
)
|
||||
else:
|
||||
depth_reference, depth_direction = depth_symmetry_projection_parameters(
|
||||
base_shape.vertices,
|
||||
base_shape.uv,
|
||||
camera_depth,
|
||||
calibration_valid,
|
||||
uniform_scale,
|
||||
depth_reference = model_reference * uniform_scale
|
||||
if shape == "DEPTH_SYMMETRY":
|
||||
depth_direction = canonical_direction_to_symmetry_legacy(
|
||||
fit_symmetry_depth_direction(
|
||||
depth_image,
|
||||
base_shape.vertices,
|
||||
base_shape.uv,
|
||||
uniform_scale,
|
||||
)
|
||||
)
|
||||
|
||||
source_name = source_object.name
|
||||
@@ -195,22 +175,15 @@ def create_shape_object(
|
||||
modifier = mesh_object.modifiers.new(name=node_group.name, type="NODES")
|
||||
modifier.node_group = node_group
|
||||
modifier.show_group_selector = False
|
||||
for name, value in (
|
||||
("Cleanup Threshold", cleanup_value),
|
||||
(
|
||||
"Thickness",
|
||||
0.0 if shape in {"FLAT", "DEPTH_SYMMETRY"} else 1.0,
|
||||
),
|
||||
):
|
||||
if name == "Thickness" and shape == "DEPTH_SYMMETRY":
|
||||
continue
|
||||
if shape != "DEPTH_SYMMETRY":
|
||||
set_modifier_input(
|
||||
modifier,
|
||||
modifier_input_identifier(
|
||||
node_group, name,
|
||||
subtype="NONE" if name == "Thickness" and shape in DEPTH_CUTOUT_SHAPES else None,
|
||||
node_group,
|
||||
"Thickness",
|
||||
subtype="NONE" if shape in DEPTH_CUTOUT_SHAPES else None,
|
||||
),
|
||||
value,
|
||||
0.0 if shape == "FLAT" else 1.0,
|
||||
)
|
||||
if shape == "DEPTH_SOLID":
|
||||
set_modifier_input(
|
||||
|
||||
Reference in New Issue
Block a user