MCPcopy
hub / github.com/ByteDance-Seed/Depth-Anything-3 / export_to_glb

Function export_to_glb

src/depth_anything_3/utils/export/glb.py:52–184  ·  view source on GitHub ↗

Generate a 3D point cloud and camera wireframes and export them as a ``.glb`` file. The function builds a point cloud from the predicted depth maps, aligns it to the first camera in glTF coordinates (X-right, Y-up, Z-backward), optionally draws camera wireframes, and writes the result t

(
    prediction: Prediction,
    export_dir: str,
    num_max_points: int = 1_000_000,
    conf_thresh: float = 1.05,
    filter_black_bg: bool = False,
    filter_white_bg: bool = False,
    conf_thresh_percentile: float = 40.0,
    ensure_thresh_percentile: float = 90.0,
    sky_depth_def: float = 98.0,
    show_cameras: bool = True,
    camera_size: float = 0.03,
    export_depth_vis: bool = True,
)

Source from the content-addressed store, hash-verified

50
51
52def export_to_glb(
53 prediction: Prediction,
54 export_dir: str,
55 num_max_points: int = 1_000_000,
56 conf_thresh: float = 1.05,
57 filter_black_bg: bool = False,
58 filter_white_bg: bool = False,
59 conf_thresh_percentile: float = 40.0,
60 ensure_thresh_percentile: float = 90.0,
61 sky_depth_def: float = 98.0,
62 show_cameras: bool = True,
63 camera_size: float = 0.03,
64 export_depth_vis: bool = True,
65) -> str:
66 """Generate a 3D point cloud and camera wireframes and export them as a ``.glb`` file.
67
68 The function builds a point cloud from the predicted depth maps, aligns it to the
69 first camera in glTF coordinates (X-right, Y-up, Z-backward), optionally draws
70 camera wireframes, and writes the result to ``scene.glb``. Auxiliary assets such as
71 depth visualizations can also be generated alongside the main export.
72
73 Args:
74 prediction: Model prediction containing depth, confidence, intrinsics, extrinsics,
75 and pre-processed images.
76 export_dir: Output directory where the glTF assets will be written.
77 num_max_points: Maximum number of points retained after downsampling.
78 conf_thresh: Base confidence threshold used before percentile adjustments.
79 filter_black_bg: Mark near-black background pixels for removal during confidence filtering.
80 filter_white_bg: Mark near-white background pixels for removal during confidence filtering.
81 conf_thresh_percentile: Lower percentile used when adapting the confidence threshold.
82 ensure_thresh_percentile: Upper percentile clamp for the adaptive threshold.
83 sky_depth_def: Percentile used to fill sky pixels with plausible depth values.
84 show_cameras: Whether to render camera wireframes in the exported scene.
85 camera_size: Relative camera wireframe scale as a fraction of the scene diagonal.
86 export_depth_vis: Whether to export raster depth visualisations alongside the glTF.
87
88 Returns:
89 Path to the exported ``scene.glb`` file.
90 """
91 # 1) Use prediction.processed_images, which is already processed image data
92 assert (
93 prediction.processed_images is not None
94 ), "Export to GLB: prediction.processed_images is required but not available"
95 assert (
96 prediction.depth is not None
97 ), "Export to GLB: prediction.depth is required but not available"
98 assert (
99 prediction.intrinsics is not None
100 ), "Export to GLB: prediction.intrinsics is required but not available"
101 assert (
102 prediction.extrinsics is not None
103 ), "Export to GLB: prediction.extrinsics is required but not available"
104 assert (
105 prediction.conf is not None
106 ), "Export to GLB: prediction.conf is required but not available"
107 logger.info(f"conf_thresh_percentile: {conf_thresh_percentile}")
108 logger.info(f"num max points: {num_max_points}")
109 logger.info(f"Exporting to GLB with num_max_points: {num_max_points}")

Callers 2

run_inferenceMethod · 0.90
exportFunction · 0.85

Calls 10

set_sky_depthFunction · 0.85
get_conf_threshFunction · 0.85
_filter_and_downsampleFunction · 0.85
_estimate_scene_scaleFunction · 0.85
_add_cameras_to_sceneFunction · 0.85
export_to_depth_visFunction · 0.85
infoMethod · 0.80
allMethod · 0.45

Tested by

no test coverage detected