Add image selection refinement functionality with BEN2 integration

- Implemented viewport.py for handling 3D view projections, gestures, and overlay drawing.
- Created refine_image_selection.py to manage the refinement of gesture masks and output image bounds.
- Added selection module with refine_selection.py to process and crop images based on alpha channel visibility.
- Introduced __init__.py for selection module to expose refine_selection function.
This commit is contained in:
2026-08-31 22:10:05 +08:00
parent 14d63001d2
commit c97b4a3e41
76 changed files with 2127 additions and 1137 deletions

View File

@@ -4,14 +4,16 @@ from enum import StrEnum
import bpy
from ...common.image_data import (
from ...common.image import (
color_data_name,
image_rgba,
)
from ...common.depth_data import camera_depth_values, depth_uniform_scale
from ...common.object import (
from ...common.depth import camera_depth_values, depth_uniform_scale
from ...common.material import (
IMAGE_MATERIAL_NODE_GROUP_NAME,
create_image_material,
)
from ...common.object import (
finalize_object_result,
modifier_input_identifier,
set_modifier_input,
@@ -22,10 +24,10 @@ from .geometry import (
DEFAULT_DEPTH_DIRECTION,
crop_plane_bounds,
cutout_cleanup_value,
cutout_point_spacing,
cutout_sampling_spacing,
depth_balloon_projection_parameters,
metric_depth_reference,
region_calibration,
selection_calibration,
use_adaptive_depth_calibration,
world_plane_metric,
)
@@ -82,8 +84,8 @@ def _assign_float_point_attribute(mesh, name, values):
attribute.data.foreach_set("value", np.asarray(values, dtype=np.float32))
def _cropped_color_image(source_object, region_mask, source_rgba):
crop_bounds = region_mask.bounds
def _cropped_color_image(source_object, selection_mask, source_rgba):
crop_bounds = selection_mask.bounds
import numpy as np
source = source_object.data
@@ -149,7 +151,7 @@ def create_shape_object(
source_object,
shape,
mesh_resolution,
region_mask,
selection_mask,
base_shape,
*,
depth_image=None,
@@ -163,7 +165,7 @@ def create_shape_object(
normal_mode = NormalMode(normal_mode)
bounds = crop_plane_bounds(
source_object,
region_mask.bounds,
selection_mask.bounds,
tuple(source_object.data.size),
)
crop_center = (
@@ -172,12 +174,12 @@ def create_shape_object(
)
world_metric, _world_z_scale = world_plane_metric(source_object.matrix_world)
cleanup_value = cutout_cleanup_value(
cutout_point_spacing(source_object, mesh_resolution),
cutout_sampling_spacing(source_object, mesh_resolution),
world_metric,
)
color_image = _cropped_color_image(
source_object,
region_mask,
selection_mask,
image_rgba(source_object.data) if source_rgba is None else source_rgba,
)
material = None
@@ -206,8 +208,8 @@ def create_shape_object(
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 = region_calibration(
region_mask, valid.shape
calibration_valid, transparent_fraction = selection_calibration(
selection_mask, valid.shape
)
calibration_valid &= valid
uniform_scale = depth_uniform_scale(