修正 mini_npz 深度数据职责

This commit is contained in:
2026-08-12 18:27:40 +08:00
parent c3a151ad2c
commit e3d023cac5
4 changed files with 32 additions and 119 deletions

View File

@@ -9,7 +9,6 @@ DEPTH_KEY_CANDIDATES = ("depth", "depths")
INTRINSICS_KEY_CANDIDATES = ("intrinsics", "ixts")
DISPLACEMENT_STRENGTH = 1.0
DISPLACEMENT_MIDLEVEL = 0.0
REFERENCE_DEPTH_KEY = "snapform_reference_depth"
ORIGINAL_DISPLACEMENT_STRENGTH = 1.0
ORIGINAL_DISPLACEMENT_MIDLEVEL = 0.0
BUMP_BASE_DISTANCE = 0.001
@@ -695,25 +694,6 @@ def extract_intrinsics_array(npz_path):
return intrinsics
def extract_reference_depth(npz_path):
try:
import numpy as np
except ImportError as error:
raise RuntimeError("Blender Python does not provide NumPy") from error
try:
with np.load(npz_path, allow_pickle=False) as archive:
if REFERENCE_DEPTH_KEY not in archive.files:
return None
reference_depth = float(archive[REFERENCE_DEPTH_KEY])
except OSError as error:
raise ValueError(f"Unable to read Mini NPZ: {npz_path}") from error
if not np.isfinite(reference_depth) or reference_depth <= 0.0:
raise ValueError("Mini NPZ has an invalid reference depth")
return reference_depth
def prepare_depth_values(depth):
import numpy as np
@@ -725,6 +705,13 @@ def prepare_depth_values(depth):
return values
def depth_displacement_values(depth):
"""Convert raw DA3 camera distance to positive outward displacement."""
import numpy as np
return 1.0 - np.asarray(depth, dtype=np.float32)
def camera_plane_bounds(
source_object,
depth,
@@ -1407,18 +1394,19 @@ def build_depth_plane(
depth_frames_directory=None,
):
source_name = source_object.name
depth_arrays = extract_depth_arrays(npz_path)
depth = depth_arrays[0]
raw_depth_arrays = extract_depth_arrays(npz_path)
raw_depth = raw_depth_arrays[0]
intrinsics = extract_intrinsics_array(npz_path)
stored_reference_depth = extract_reference_depth(npz_path)
depth_values = prepare_depth_values(depth)
raw_depth_values = prepare_depth_values(raw_depth)
bounds, reference_depth = camera_plane_bounds(
source_object,
depth_values,
raw_depth_values,
intrinsics,
DISPLACEMENT_STRENGTH,
reference_depth=stored_reference_depth,
)
depth_arrays = [
depth_displacement_values(frame) for frame in raw_depth_arrays
]
depth_name = depth_name or depth_data_name(source_object)
frame_count = len(depth_arrays)
foreground_image = (