Spaces:
Runtime error
Runtime error
Upload 26 files
Browse files- .gitattributes +11 -0
- wheels/TRELLIS.2/o-voxels/build/lib.linux-x86_64-cpython-310/o_voxel/_C.cpython-310-x86_64-linux-gnu.so +3 -0
- wheels/TRELLIS.2/o-voxels/build/lib.linux-x86_64-cpython-310/o_voxel/__init__.py +7 -0
- wheels/TRELLIS.2/o-voxels/build/lib.linux-x86_64-cpython-310/o_voxel/convert/__init__.py +2 -0
- wheels/TRELLIS.2/o-voxels/build/lib.linux-x86_64-cpython-310/o_voxel/convert/flexible_dual_grid.py +283 -0
- wheels/TRELLIS.2/o-voxels/build/lib.linux-x86_64-cpython-310/o_voxel/convert/volumetic_attr.py +583 -0
- wheels/TRELLIS.2/o-voxels/build/lib.linux-x86_64-cpython-310/o_voxel/io/__init__.py +45 -0
- wheels/TRELLIS.2/o-voxels/build/lib.linux-x86_64-cpython-310/o_voxel/io/npz.py +43 -0
- wheels/TRELLIS.2/o-voxels/build/lib.linux-x86_64-cpython-310/o_voxel/io/ply.py +72 -0
- wheels/TRELLIS.2/o-voxels/build/lib.linux-x86_64-cpython-310/o_voxel/io/vxz.py +365 -0
- wheels/TRELLIS.2/o-voxels/build/lib.linux-x86_64-cpython-310/o_voxel/postprocess.py +331 -0
- wheels/TRELLIS.2/o-voxels/build/lib.linux-x86_64-cpython-310/o_voxel/rasterize.py +111 -0
- wheels/TRELLIS.2/o-voxels/build/lib.linux-x86_64-cpython-310/o_voxel/serialize.py +68 -0
- wheels/TRELLIS.2/o-voxels/build/temp.linux-x86_64-cpython-310/.ninja_deps +3 -0
- wheels/TRELLIS.2/o-voxels/build/temp.linux-x86_64-cpython-310/.ninja_log +23 -0
- wheels/TRELLIS.2/o-voxels/build/temp.linux-x86_64-cpython-310/build.ninja +47 -0
- wheels/TRELLIS.2/o-voxels/build/temp.linux-x86_64-cpython-310/src/convert/flexible_dual_grid.o +3 -0
- wheels/TRELLIS.2/o-voxels/build/temp.linux-x86_64-cpython-310/src/convert/volumetic_attr.o +3 -0
- wheels/TRELLIS.2/o-voxels/build/temp.linux-x86_64-cpython-310/src/ext.o +3 -0
- wheels/TRELLIS.2/o-voxels/build/temp.linux-x86_64-cpython-310/src/hash/hash.o +3 -0
- wheels/TRELLIS.2/o-voxels/build/temp.linux-x86_64-cpython-310/src/io/filter_neighbor.o +3 -0
- wheels/TRELLIS.2/o-voxels/build/temp.linux-x86_64-cpython-310/src/io/filter_parent.o +3 -0
- wheels/TRELLIS.2/o-voxels/build/temp.linux-x86_64-cpython-310/src/io/svo.o +3 -0
- wheels/TRELLIS.2/o-voxels/build/temp.linux-x86_64-cpython-310/src/rasterize/rasterize.o +3 -0
- wheels/TRELLIS.2/o-voxels/build/temp.linux-x86_64-cpython-310/src/serialize/api.o +3 -0
- wheels/TRELLIS.2/o-voxels/build/temp.linux-x86_64-cpython-310/src/serialize/hilbert.o +0 -0
- wheels/TRELLIS.2/o-voxels/build/temp.linux-x86_64-cpython-310/src/serialize/z_order.o +0 -0
.gitattributes
CHANGED
|
@@ -76,3 +76,14 @@ assets/hdri/night.exr filter=lfs diff=lfs merge=lfs -text
|
|
| 76 |
assets/hdri/sunrise.exr filter=lfs diff=lfs merge=lfs -text
|
| 77 |
assets/hdri/sunset.exr filter=lfs diff=lfs merge=lfs -text
|
| 78 |
wheels/TRELLIS.2/o-voxels/assets/overview.webp filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
assets/hdri/sunrise.exr filter=lfs diff=lfs merge=lfs -text
|
| 77 |
assets/hdri/sunset.exr filter=lfs diff=lfs merge=lfs -text
|
| 78 |
wheels/TRELLIS.2/o-voxels/assets/overview.webp filter=lfs diff=lfs merge=lfs -text
|
| 79 |
+
wheels/TRELLIS.2/o-voxels/build/lib.linux-x86_64-cpython-310/o_voxel/_C.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 80 |
+
wheels/TRELLIS.2/o-voxels/build/temp.linux-x86_64-cpython-310/.ninja_deps filter=lfs diff=lfs merge=lfs -text
|
| 81 |
+
wheels/TRELLIS.2/o-voxels/build/temp.linux-x86_64-cpython-310/src/convert/flexible_dual_grid.o filter=lfs diff=lfs merge=lfs -text
|
| 82 |
+
wheels/TRELLIS.2/o-voxels/build/temp.linux-x86_64-cpython-310/src/convert/volumetic_attr.o filter=lfs diff=lfs merge=lfs -text
|
| 83 |
+
wheels/TRELLIS.2/o-voxels/build/temp.linux-x86_64-cpython-310/src/ext.o filter=lfs diff=lfs merge=lfs -text
|
| 84 |
+
wheels/TRELLIS.2/o-voxels/build/temp.linux-x86_64-cpython-310/src/hash/hash.o filter=lfs diff=lfs merge=lfs -text
|
| 85 |
+
wheels/TRELLIS.2/o-voxels/build/temp.linux-x86_64-cpython-310/src/io/filter_neighbor.o filter=lfs diff=lfs merge=lfs -text
|
| 86 |
+
wheels/TRELLIS.2/o-voxels/build/temp.linux-x86_64-cpython-310/src/io/filter_parent.o filter=lfs diff=lfs merge=lfs -text
|
| 87 |
+
wheels/TRELLIS.2/o-voxels/build/temp.linux-x86_64-cpython-310/src/io/svo.o filter=lfs diff=lfs merge=lfs -text
|
| 88 |
+
wheels/TRELLIS.2/o-voxels/build/temp.linux-x86_64-cpython-310/src/rasterize/rasterize.o filter=lfs diff=lfs merge=lfs -text
|
| 89 |
+
wheels/TRELLIS.2/o-voxels/build/temp.linux-x86_64-cpython-310/src/serialize/api.o filter=lfs diff=lfs merge=lfs -text
|
wheels/TRELLIS.2/o-voxels/build/lib.linux-x86_64-cpython-310/o_voxel/_C.cpython-310-x86_64-linux-gnu.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6814a3a5ae8b1d084e0fa27fdf4a9dcea775d3f4c77efc368b3a448dcf9237b4
|
| 3 |
+
size 747376
|
wheels/TRELLIS.2/o-voxels/build/lib.linux-x86_64-cpython-310/o_voxel/__init__.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from . import (
|
| 2 |
+
convert,
|
| 3 |
+
io,
|
| 4 |
+
postprocess,
|
| 5 |
+
rasterize,
|
| 6 |
+
serialize
|
| 7 |
+
)
|
wheels/TRELLIS.2/o-voxels/build/lib.linux-x86_64-cpython-310/o_voxel/convert/__init__.py
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .flexible_dual_grid import *
|
| 2 |
+
from .volumetic_attr import *
|
wheels/TRELLIS.2/o-voxels/build/lib.linux-x86_64-cpython-310/o_voxel/convert/flexible_dual_grid.py
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import *
|
| 2 |
+
import numpy as np
|
| 3 |
+
import torch
|
| 4 |
+
from .. import _C
|
| 5 |
+
|
| 6 |
+
__all__ = [
|
| 7 |
+
"mesh_to_flexible_dual_grid",
|
| 8 |
+
"flexible_dual_grid_to_mesh",
|
| 9 |
+
]
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def _init_hashmap(grid_size, capacity, device):
|
| 13 |
+
VOL = (grid_size[0] * grid_size[1] * grid_size[2]).item()
|
| 14 |
+
|
| 15 |
+
# If the number of elements in the tensor is less than 2^32, use uint32 as the hashmap type, otherwise use uint64.
|
| 16 |
+
if VOL < 2**32:
|
| 17 |
+
hashmap_keys = torch.full((capacity,), torch.iinfo(torch.uint32).max, dtype=torch.uint32, device=device)
|
| 18 |
+
elif VOL < 2**64:
|
| 19 |
+
hashmap_keys = torch.full((capacity,), torch.iinfo(torch.uint64).max, dtype=torch.uint64, device=device)
|
| 20 |
+
else:
|
| 21 |
+
raise ValueError(f"The spatial size is too large to fit in a hashmap. Get volumn {VOL} > 2^64.")
|
| 22 |
+
|
| 23 |
+
hashmap_vals = torch.empty((capacity,), dtype=torch.uint32, device=device)
|
| 24 |
+
|
| 25 |
+
return hashmap_keys, hashmap_vals
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
@torch.no_grad()
|
| 29 |
+
def mesh_to_flexible_dual_grid(
|
| 30 |
+
vertices: torch.Tensor,
|
| 31 |
+
faces: torch.Tensor,
|
| 32 |
+
voxel_size: Union[float, list, tuple, np.ndarray, torch.Tensor] = None,
|
| 33 |
+
grid_size: Union[int, list, tuple, np.ndarray, torch.Tensor] = None,
|
| 34 |
+
aabb: Union[list, tuple, np.ndarray, torch.Tensor] = None,
|
| 35 |
+
face_weight: float = 1.0,
|
| 36 |
+
boundary_weight: float = 1.0,
|
| 37 |
+
regularization_weight: float = 0.1,
|
| 38 |
+
timing: bool = False,
|
| 39 |
+
) -> Union[torch.Tensor, torch.Tensor, torch.Tensor]:
|
| 40 |
+
"""
|
| 41 |
+
Voxelize a mesh into a sparse voxel grid.
|
| 42 |
+
|
| 43 |
+
Args:
|
| 44 |
+
vertices (torch.Tensor): The vertices of the mesh.
|
| 45 |
+
faces (torch.Tensor): The faces of the mesh.
|
| 46 |
+
voxel_size (float, list, tuple, np.ndarray, torch.Tensor): The size of each voxel.
|
| 47 |
+
grid_size (int, list, tuple, np.ndarray, torch.Tensor): The size of the grid.
|
| 48 |
+
NOTE: One of voxel_size and grid_size must be provided.
|
| 49 |
+
aabb (list, tuple, np.ndarray, torch.Tensor): The axis-aligned bounding box of the mesh.
|
| 50 |
+
If not provided, it will be computed automatically.
|
| 51 |
+
face_weight (float): The weight of the face term in the QEF when solving the dual vertices.
|
| 52 |
+
boundary_weight (float): The weight of the boundary term in the QEF when solving the dual vertices.
|
| 53 |
+
regularization_weight (float): The weight of the regularization term in the QEF when solving the dual vertices.
|
| 54 |
+
timing (bool): Whether to time the voxelization process.
|
| 55 |
+
|
| 56 |
+
Returns:
|
| 57 |
+
torch.Tensor: The indices of the voxels that are occupied by the mesh.
|
| 58 |
+
The shape of the tensor is (N, 3), where N is the number of occupied voxels.
|
| 59 |
+
torch.Tensor: The dual vertices of the mesh.
|
| 60 |
+
torch.Tensor: The intersected flag of each voxel.
|
| 61 |
+
"""
|
| 62 |
+
|
| 63 |
+
# Load mesh
|
| 64 |
+
vertices = vertices.float()
|
| 65 |
+
faces = faces.int()
|
| 66 |
+
|
| 67 |
+
# Voxelize settings
|
| 68 |
+
assert voxel_size is not None or grid_size is not None, "Either voxel_size or grid_size must be provided"
|
| 69 |
+
|
| 70 |
+
if voxel_size is not None:
|
| 71 |
+
if isinstance(voxel_size, float):
|
| 72 |
+
voxel_size = [voxel_size, voxel_size, voxel_size]
|
| 73 |
+
if isinstance(voxel_size, (list, tuple)):
|
| 74 |
+
voxel_size = np.array(voxel_size)
|
| 75 |
+
if isinstance(voxel_size, np.ndarray):
|
| 76 |
+
voxel_size = torch.tensor(voxel_size, dtype=torch.float32)
|
| 77 |
+
assert isinstance(voxel_size, torch.Tensor), f"voxel_size must be a float, list, tuple, np.ndarray, or torch.Tensor, but got {type(voxel_size)}"
|
| 78 |
+
assert voxel_size.dim() == 1, f"voxel_size must be a 1D tensor, but got {voxel_size.shape}"
|
| 79 |
+
assert voxel_size.size(0) == 3, f"voxel_size must have 3 elements, but got {voxel_size.size(0)}"
|
| 80 |
+
|
| 81 |
+
if grid_size is not None:
|
| 82 |
+
if isinstance(grid_size, int):
|
| 83 |
+
grid_size = [grid_size, grid_size, grid_size]
|
| 84 |
+
if isinstance(grid_size, (list, tuple)):
|
| 85 |
+
grid_size = np.array(grid_size)
|
| 86 |
+
if isinstance(grid_size, np.ndarray):
|
| 87 |
+
grid_size = torch.tensor(grid_size, dtype=torch.int32)
|
| 88 |
+
assert isinstance(grid_size, torch.Tensor), f"grid_size must be an int, list, tuple, np.ndarray, or torch.Tensor, but got {type(grid_size)}"
|
| 89 |
+
assert grid_size.dim() == 1, f"grid_size must be a 1D tensor, but got {grid_size.shape}"
|
| 90 |
+
assert grid_size.size(0) == 3, f"grid_size must have 3 elements, but got {grid_size.size(0)}"
|
| 91 |
+
|
| 92 |
+
if aabb is not None:
|
| 93 |
+
if isinstance(aabb, (list, tuple)):
|
| 94 |
+
aabb = np.array(aabb)
|
| 95 |
+
if isinstance(aabb, np.ndarray):
|
| 96 |
+
aabb = torch.tensor(aabb, dtype=torch.float32)
|
| 97 |
+
assert isinstance(aabb, torch.Tensor), f"aabb must be a list, tuple, np.ndarray, or torch.Tensor, but got {type(aabb)}"
|
| 98 |
+
assert aabb.dim() == 2, f"aabb must be a 2D tensor, but got {aabb.shape}"
|
| 99 |
+
assert aabb.size(0) == 2, f"aabb must have 2 rows, but got {aabb.size(0)}"
|
| 100 |
+
assert aabb.size(1) == 3, f"aabb must have 3 columns, but got {aabb.size(1)}"
|
| 101 |
+
|
| 102 |
+
# Auto adjust aabb
|
| 103 |
+
if aabb is None:
|
| 104 |
+
min_xyz = vertices.min(dim=0).values
|
| 105 |
+
max_xyz = vertices.max(dim=0).values
|
| 106 |
+
|
| 107 |
+
if voxel_size is not None:
|
| 108 |
+
padding = torch.ceil((max_xyz - min_xyz) / voxel_size) * voxel_size - (max_xyz - min_xyz)
|
| 109 |
+
min_xyz -= padding * 0.5
|
| 110 |
+
max_xyz += padding * 0.5
|
| 111 |
+
if grid_size is not None:
|
| 112 |
+
padding = (max_xyz - min_xyz) / (grid_size - 1)
|
| 113 |
+
min_xyz -= padding * 0.5
|
| 114 |
+
max_xyz += padding * 0.5
|
| 115 |
+
|
| 116 |
+
aabb = torch.stack([min_xyz, max_xyz], dim=0).float().cuda()
|
| 117 |
+
|
| 118 |
+
# Fill voxel size or grid size
|
| 119 |
+
if voxel_size is None:
|
| 120 |
+
voxel_size = (aabb[1] - aabb[0]) / grid_size
|
| 121 |
+
if grid_size is None:
|
| 122 |
+
grid_size = ((aabb[1] - aabb[0]) / voxel_size).round().int()
|
| 123 |
+
|
| 124 |
+
# subdivide mesh
|
| 125 |
+
vertices = vertices - aabb[0].reshape(1, 3)
|
| 126 |
+
grid_range = torch.stack([torch.zeros_like(grid_size), grid_size], dim=0).int()
|
| 127 |
+
|
| 128 |
+
ret = _C.mesh_to_flexible_dual_grid_cpu(
|
| 129 |
+
vertices,
|
| 130 |
+
faces,
|
| 131 |
+
voxel_size,
|
| 132 |
+
grid_range,
|
| 133 |
+
face_weight,
|
| 134 |
+
boundary_weight,
|
| 135 |
+
regularization_weight,
|
| 136 |
+
timing,
|
| 137 |
+
)
|
| 138 |
+
|
| 139 |
+
return ret
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def flexible_dual_grid_to_mesh(
|
| 143 |
+
coords: torch.Tensor,
|
| 144 |
+
dual_vertices: torch.Tensor,
|
| 145 |
+
intersected_flag: torch.Tensor,
|
| 146 |
+
split_weight: Union[torch.Tensor, None],
|
| 147 |
+
aabb: Union[list, tuple, np.ndarray, torch.Tensor],
|
| 148 |
+
voxel_size: Union[float, list, tuple, np.ndarray, torch.Tensor] = None,
|
| 149 |
+
grid_size: Union[int, list, tuple, np.ndarray, torch.Tensor] = None,
|
| 150 |
+
train: bool = False,
|
| 151 |
+
):
|
| 152 |
+
"""
|
| 153 |
+
Extract mesh from sparse voxel structures using flexible dual grid.
|
| 154 |
+
|
| 155 |
+
Args:
|
| 156 |
+
coords (torch.Tensor): The coordinates of the voxels.
|
| 157 |
+
dual_vertices (torch.Tensor): The dual vertices.
|
| 158 |
+
intersected_flag (torch.Tensor): The intersected flag.
|
| 159 |
+
split_weight (torch.Tensor): The split weight of each dual quad. If None, the algorithm
|
| 160 |
+
will split based on minimum angle.
|
| 161 |
+
aabb (list, tuple, np.ndarray, torch.Tensor): The axis-aligned bounding box of the mesh.
|
| 162 |
+
voxel_size (float, list, tuple, np.ndarray, torch.Tensor): The size of each voxel.
|
| 163 |
+
grid_size (int, list, tuple, np.ndarray, torch.Tensor): The size of the grid.
|
| 164 |
+
NOTE: One of voxel_size and grid_size must be provided.
|
| 165 |
+
train (bool): Whether to use training mode.
|
| 166 |
+
|
| 167 |
+
Returns:
|
| 168 |
+
vertices (torch.Tensor): The vertices of the mesh.
|
| 169 |
+
faces (torch.Tensor): The faces of the mesh.
|
| 170 |
+
"""
|
| 171 |
+
# Static variables
|
| 172 |
+
if not hasattr(flexible_dual_grid_to_mesh, "edge_neighbor_voxel_offset"):
|
| 173 |
+
flexible_dual_grid_to_mesh.edge_neighbor_voxel_offset = torch.tensor([
|
| 174 |
+
[[0, 0, 0], [0, 0, 1], [0, 1, 1], [0, 1, 0]], # x-axis
|
| 175 |
+
[[0, 0, 0], [1, 0, 0], [1, 0, 1], [0, 0, 1]], # y-axis
|
| 176 |
+
[[0, 0, 0], [0, 1, 0], [1, 1, 0], [1, 0, 0]], # z-axis
|
| 177 |
+
], dtype=torch.int, device=coords.device).unsqueeze(0)
|
| 178 |
+
if not hasattr(flexible_dual_grid_to_mesh, "quad_split_1"):
|
| 179 |
+
flexible_dual_grid_to_mesh.quad_split_1 = torch.tensor([0, 1, 2, 0, 2, 3], dtype=torch.long, device=coords.device, requires_grad=False)
|
| 180 |
+
if not hasattr(flexible_dual_grid_to_mesh, "quad_split_2"):
|
| 181 |
+
flexible_dual_grid_to_mesh.quad_split_2 = torch.tensor([0, 1, 3, 3, 1, 2], dtype=torch.long, device=coords.device, requires_grad=False)
|
| 182 |
+
if not hasattr(flexible_dual_grid_to_mesh, "quad_split_train"):
|
| 183 |
+
flexible_dual_grid_to_mesh.quad_split_train = torch.tensor([0, 1, 4, 1, 2, 4, 2, 3, 4, 3, 0, 4], dtype=torch.long, device=coords.device, requires_grad=False)
|
| 184 |
+
|
| 185 |
+
# AABB
|
| 186 |
+
if isinstance(aabb, (list, tuple)):
|
| 187 |
+
aabb = np.array(aabb)
|
| 188 |
+
if isinstance(aabb, np.ndarray):
|
| 189 |
+
aabb = torch.tensor(aabb, dtype=torch.float32, device=coords.device)
|
| 190 |
+
assert isinstance(aabb, torch.Tensor), f"aabb must be a list, tuple, np.ndarray, or torch.Tensor, but got {type(aabb)}"
|
| 191 |
+
assert aabb.dim() == 2, f"aabb must be a 2D tensor, but got {aabb.shape}"
|
| 192 |
+
assert aabb.size(0) == 2, f"aabb must have 2 rows, but got {aabb.size(0)}"
|
| 193 |
+
assert aabb.size(1) == 3, f"aabb must have 3 columns, but got {aabb.size(1)}"
|
| 194 |
+
|
| 195 |
+
# Voxel size
|
| 196 |
+
if voxel_size is not None:
|
| 197 |
+
if isinstance(voxel_size, float):
|
| 198 |
+
voxel_size = [voxel_size, voxel_size, voxel_size]
|
| 199 |
+
if isinstance(voxel_size, (list, tuple)):
|
| 200 |
+
voxel_size = np.array(voxel_size)
|
| 201 |
+
if isinstance(voxel_size, np.ndarray):
|
| 202 |
+
voxel_size = torch.tensor(voxel_size, dtype=torch.float32, device=coords.device)
|
| 203 |
+
grid_size = ((aabb[1] - aabb[0]) / voxel_size).round().int()
|
| 204 |
+
else:
|
| 205 |
+
assert grid_size is not None, "Either voxel_size or grid_size must be provided"
|
| 206 |
+
if isinstance(grid_size, int):
|
| 207 |
+
grid_size = [grid_size, grid_size, grid_size]
|
| 208 |
+
if isinstance(grid_size, (list, tuple)):
|
| 209 |
+
grid_size = np.array(grid_size)
|
| 210 |
+
if isinstance(grid_size, np.ndarray):
|
| 211 |
+
grid_size = torch.tensor(grid_size, dtype=torch.int32, device=coords.device)
|
| 212 |
+
voxel_size = (aabb[1] - aabb[0]) / grid_size
|
| 213 |
+
assert isinstance(voxel_size, torch.Tensor), f"voxel_size must be a float, list, tuple, np.ndarray, or torch.Tensor, but got {type(voxel_size)}"
|
| 214 |
+
assert voxel_size.dim() == 1, f"voxel_size must be a 1D tensor, but got {voxel_size.shape}"
|
| 215 |
+
assert voxel_size.size(0) == 3, f"voxel_size must have 3 elements, but got {voxel_size.size(0)}"
|
| 216 |
+
assert isinstance(grid_size, torch.Tensor), f"grid_size must be an int, list, tuple, np.ndarray, or torch.Tensor, but got {type(grid_size)}"
|
| 217 |
+
assert grid_size.dim() == 1, f"grid_size must be a 1D tensor, but got {grid_size.shape}"
|
| 218 |
+
assert grid_size.size(0) == 3, f"grid_size must have 3 elements, but got {grid_size.size(0)}"
|
| 219 |
+
|
| 220 |
+
# Extract mesh
|
| 221 |
+
N = dual_vertices.shape[0]
|
| 222 |
+
mesh_vertices = (coords.float() + dual_vertices) / (2 * N) - 0.5
|
| 223 |
+
|
| 224 |
+
# Store active voxels into hashmap
|
| 225 |
+
hashmap = _init_hashmap(grid_size, 2 * N, device=coords.device)
|
| 226 |
+
_C.hashmap_insert_3d_idx_as_val_cuda(*hashmap, torch.cat([torch.zeros_like(coords[:, :1]), coords], dim=-1), *grid_size.tolist())
|
| 227 |
+
|
| 228 |
+
# Find connected voxels
|
| 229 |
+
edge_neighbor_voxel = coords.reshape(N, 1, 1, 3) + flexible_dual_grid_to_mesh.edge_neighbor_voxel_offset # (N, 3, 4, 3)
|
| 230 |
+
connected_voxel = edge_neighbor_voxel[intersected_flag] # (M, 4, 3)
|
| 231 |
+
M = connected_voxel.shape[0]
|
| 232 |
+
connected_voxel_hash_key = torch.cat([
|
| 233 |
+
torch.zeros((M * 4, 1), dtype=torch.int, device=coords.device),
|
| 234 |
+
connected_voxel.reshape(-1, 3)
|
| 235 |
+
], dim=1)
|
| 236 |
+
connected_voxel_indices = _C.hashmap_lookup_3d_cuda(*hashmap, connected_voxel_hash_key, *grid_size.tolist()).reshape(M, 4).int()
|
| 237 |
+
connected_voxel_valid = (connected_voxel_indices != 0xffffffff).all(dim=1)
|
| 238 |
+
quad_indices = connected_voxel_indices[connected_voxel_valid].int() # (L, 4)
|
| 239 |
+
L = quad_indices.shape[0]
|
| 240 |
+
|
| 241 |
+
# Construct triangles
|
| 242 |
+
if not train:
|
| 243 |
+
mesh_vertices = (coords.float() + dual_vertices) * voxel_size + aabb[0].reshape(1, 3)
|
| 244 |
+
if split_weight is None:
|
| 245 |
+
# if split 1
|
| 246 |
+
atempt_triangles_0 = quad_indices[:, flexible_dual_grid_to_mesh.quad_split_1]
|
| 247 |
+
normals0 = torch.cross(mesh_vertices[atempt_triangles_0[:, 1]] - mesh_vertices[atempt_triangles_0[:, 0]], mesh_vertices[atempt_triangles_0[:, 2]] - mesh_vertices[atempt_triangles_0[:, 0]])
|
| 248 |
+
normals1 = torch.cross(mesh_vertices[atempt_triangles_0[:, 2]] - mesh_vertices[atempt_triangles_0[:, 1]], mesh_vertices[atempt_triangles_0[:, 3]] - mesh_vertices[atempt_triangles_0[:, 1]])
|
| 249 |
+
align0 = (normals0 * normals1).sum(dim=1, keepdim=True).abs()
|
| 250 |
+
# if split 2
|
| 251 |
+
atempt_triangles_1 = quad_indices[:, flexible_dual_grid_to_mesh.quad_split_2]
|
| 252 |
+
normals0 = torch.cross(mesh_vertices[atempt_triangles_1[:, 1]] - mesh_vertices[atempt_triangles_1[:, 0]], mesh_vertices[atempt_triangles_1[:, 2]] - mesh_vertices[atempt_triangles_1[:, 0]])
|
| 253 |
+
normals1 = torch.cross(mesh_vertices[atempt_triangles_1[:, 2]] - mesh_vertices[atempt_triangles_1[:, 1]], mesh_vertices[atempt_triangles_1[:, 3]] - mesh_vertices[atempt_triangles_1[:, 1]])
|
| 254 |
+
align1 = (normals0 * normals1).sum(dim=1, keepdim=True).abs()
|
| 255 |
+
# select split
|
| 256 |
+
mesh_triangles = torch.where(align0 > align1, atempt_triangles_0, atempt_triangles_1).reshape(-1, 3)
|
| 257 |
+
else:
|
| 258 |
+
split_weight_ws = split_weight[quad_indices]
|
| 259 |
+
split_weight_ws_02 = split_weight_ws[:, 0] * split_weight_ws[:, 2]
|
| 260 |
+
split_weight_ws_13 = split_weight_ws[:, 1] * split_weight_ws[:, 3]
|
| 261 |
+
mesh_triangles = torch.where(
|
| 262 |
+
split_weight_ws_02 > split_weight_ws_13,
|
| 263 |
+
quad_indices[:, flexible_dual_grid_to_mesh.quad_split_1],
|
| 264 |
+
quad_indices[:, flexible_dual_grid_to_mesh.quad_split_2]
|
| 265 |
+
).reshape(-1, 3)
|
| 266 |
+
else:
|
| 267 |
+
assert split_weight is not None, "split_weight must be provided in training mode"
|
| 268 |
+
mesh_vertices = (coords.float() + dual_vertices) * voxel_size + aabb[0].reshape(1, 3)
|
| 269 |
+
quad_vs = mesh_vertices[quad_indices]
|
| 270 |
+
mean_v02 = (quad_vs[:, 0] + quad_vs[:, 2]) / 2
|
| 271 |
+
mean_v13 = (quad_vs[:, 1] + quad_vs[:, 3]) / 2
|
| 272 |
+
split_weight_ws = split_weight[quad_indices]
|
| 273 |
+
split_weight_ws_02 = split_weight_ws[:, 0] * split_weight_ws[:, 2]
|
| 274 |
+
split_weight_ws_13 = split_weight_ws[:, 1] * split_weight_ws[:, 3]
|
| 275 |
+
mid_vertices = (
|
| 276 |
+
split_weight_ws_02 * mean_v02 +
|
| 277 |
+
split_weight_ws_13 * mean_v13
|
| 278 |
+
) / (split_weight_ws_02 + split_weight_ws_13)
|
| 279 |
+
mesh_vertices = torch.cat([mesh_vertices, mid_vertices], dim=0)
|
| 280 |
+
quad_indices = torch.cat([quad_indices, torch.arange(N, N + L, device='cuda').unsqueeze(1)], dim=1)
|
| 281 |
+
mesh_triangles = quad_indices[:, flexible_dual_grid_to_mesh.quad_split_train].reshape(-1, 3)
|
| 282 |
+
|
| 283 |
+
return mesh_vertices, mesh_triangles
|
wheels/TRELLIS.2/o-voxels/build/lib.linux-x86_64-cpython-310/o_voxel/convert/volumetic_attr.py
ADDED
|
@@ -0,0 +1,583 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import *
|
| 2 |
+
import io
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import torch
|
| 5 |
+
import numpy as np
|
| 6 |
+
from tqdm import tqdm
|
| 7 |
+
import trimesh
|
| 8 |
+
import trimesh.visual
|
| 9 |
+
|
| 10 |
+
from .. import _C
|
| 11 |
+
|
| 12 |
+
__all__ = [
|
| 13 |
+
"textured_mesh_to_volumetric_attr",
|
| 14 |
+
"blender_dump_to_volumetric_attr"
|
| 15 |
+
]
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
ALPHA_MODE_ENUM = {
|
| 19 |
+
"OPAQUE": 0,
|
| 20 |
+
"MASK": 1,
|
| 21 |
+
"BLEND": 2,
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def is_power_of_two(n: int) -> bool:
|
| 26 |
+
return n > 0 and (n & (n - 1)) == 0
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def nearest_power_of_two(n: int) -> int:
|
| 30 |
+
if n < 1:
|
| 31 |
+
raise ValueError("n must be >= 1")
|
| 32 |
+
if is_power_of_two(n):
|
| 33 |
+
return n
|
| 34 |
+
lower = 2 ** (n.bit_length() - 1)
|
| 35 |
+
upper = 2 ** n.bit_length()
|
| 36 |
+
if n - lower < upper - n:
|
| 37 |
+
return lower
|
| 38 |
+
else:
|
| 39 |
+
return upper
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def textured_mesh_to_volumetric_attr(
|
| 43 |
+
mesh: Union[trimesh.Scene, trimesh.Trimesh, str],
|
| 44 |
+
voxel_size: Union[float, list, tuple, np.ndarray, torch.Tensor] = None,
|
| 45 |
+
grid_size: Union[int, list, tuple, np.ndarray, torch.Tensor] = None,
|
| 46 |
+
aabb: Union[list, tuple, np.ndarray, torch.Tensor] = None,
|
| 47 |
+
mip_level_offset: float = 0.0,
|
| 48 |
+
verbose: bool = False,
|
| 49 |
+
timing: bool = False,
|
| 50 |
+
) -> Union[torch.Tensor, Dict[str, torch.Tensor]]:
|
| 51 |
+
"""
|
| 52 |
+
Voxelize a mesh into a sparse voxel grid with PBR properties.
|
| 53 |
+
|
| 54 |
+
Args:
|
| 55 |
+
mesh (trimesh.Scene, trimesh.Trimesh, str): The input mesh.
|
| 56 |
+
If a string is provided, it will be loaded as a mesh using trimesh.load().
|
| 57 |
+
voxel_size (float, list, tuple, np.ndarray, torch.Tensor): The size of each voxel.
|
| 58 |
+
grid_size (int, list, tuple, np.ndarray, torch.Tensor): The size of the grid.
|
| 59 |
+
NOTE: One of voxel_size and grid_size must be provided.
|
| 60 |
+
aabb (list, tuple, np.ndarray, torch.Tensor): The axis-aligned bounding box of the mesh.
|
| 61 |
+
If not provided, it will be computed automatically.
|
| 62 |
+
tile_size (int): The size of the tiles used for each individual voxelization.
|
| 63 |
+
mip_level_offset (float): The mip level offset for texture mip level selection.
|
| 64 |
+
verbose (bool): Whether to print the settings.
|
| 65 |
+
timing (bool): Whether to print the timing information.
|
| 66 |
+
|
| 67 |
+
Returns:
|
| 68 |
+
torch.Tensor: The indices of the voxels that are occupied by the mesh.
|
| 69 |
+
Dict[str, torch.Tensor]: A dictionary containing the following keys:
|
| 70 |
+
- "base_color": The base color of the occupied voxels.
|
| 71 |
+
- "metallic": The metallic value of the occupied voxels.
|
| 72 |
+
- "roughness": The roughness value of the occupied voxels.
|
| 73 |
+
- "emissive": The emissive value of the occupied voxels.
|
| 74 |
+
- "alpha": The alpha value of the occupied voxels.
|
| 75 |
+
- "normal": The normal of the occupied voxels.
|
| 76 |
+
"""
|
| 77 |
+
|
| 78 |
+
# Load mesh
|
| 79 |
+
if isinstance(mesh, str):
|
| 80 |
+
mesh = trimesh.load(mesh)
|
| 81 |
+
if isinstance(mesh, trimesh.Scene):
|
| 82 |
+
groups = mesh.dump()
|
| 83 |
+
if isinstance(mesh, trimesh.Trimesh):
|
| 84 |
+
groups = [mesh]
|
| 85 |
+
scene = trimesh.Scene(groups)
|
| 86 |
+
|
| 87 |
+
# Voxelize settings
|
| 88 |
+
assert voxel_size is not None or grid_size is not None, "Either voxel_size or grid_size must be provided"
|
| 89 |
+
|
| 90 |
+
if voxel_size is not None:
|
| 91 |
+
if isinstance(voxel_size, float):
|
| 92 |
+
voxel_size = [voxel_size, voxel_size, voxel_size]
|
| 93 |
+
if isinstance(voxel_size, (list, tuple)):
|
| 94 |
+
voxel_size = np.array(voxel_size)
|
| 95 |
+
if isinstance(voxel_size, np.ndarray):
|
| 96 |
+
voxel_size = torch.tensor(voxel_size, dtype=torch.float32)
|
| 97 |
+
assert isinstance(voxel_size, torch.Tensor), f"voxel_size must be a float, list, tuple, np.ndarray, or torch.Tensor, but got {type(voxel_size)}"
|
| 98 |
+
assert voxel_size.dim() == 1, f"voxel_size must be a 1D tensor, but got {voxel_size.shape}"
|
| 99 |
+
assert voxel_size.size(0) == 3, f"voxel_size must have 3 elements, but got {voxel_size.size(0)}"
|
| 100 |
+
|
| 101 |
+
if grid_size is not None:
|
| 102 |
+
if isinstance(grid_size, int):
|
| 103 |
+
grid_size = [grid_size, grid_size, grid_size]
|
| 104 |
+
if isinstance(grid_size, (list, tuple)):
|
| 105 |
+
grid_size = np.array(grid_size)
|
| 106 |
+
if isinstance(grid_size, np.ndarray):
|
| 107 |
+
grid_size = torch.tensor(grid_size, dtype=torch.int32)
|
| 108 |
+
assert isinstance(grid_size, torch.Tensor), f"grid_size must be an int, list, tuple, np.ndarray, or torch.Tensor, but got {type(grid_size)}"
|
| 109 |
+
assert grid_size.dim() == 1, f"grid_size must be a 1D tensor, but got {grid_size.shape}"
|
| 110 |
+
assert grid_size.size(0) == 3, f"grid_size must have 3 elements, but got {grid_size.size(0)}"
|
| 111 |
+
|
| 112 |
+
if aabb is not None:
|
| 113 |
+
if isinstance(aabb, (list, tuple)):
|
| 114 |
+
aabb = np.array(aabb)
|
| 115 |
+
if isinstance(aabb, np.ndarray):
|
| 116 |
+
aabb = torch.tensor(aabb, dtype=torch.float32)
|
| 117 |
+
assert isinstance(aabb, torch.Tensor), f"aabb must be a list, tuple, np.ndarray, or torch.Tensor, but got {type(aabb)}"
|
| 118 |
+
assert aabb.dim() == 2, f"aabb must be a 2D tensor, but got {aabb.shape}"
|
| 119 |
+
assert aabb.size(0) == 2, f"aabb must have 2 rows, but got {aabb.size(0)}"
|
| 120 |
+
assert aabb.size(1) == 3, f"aabb must have 3 columns, but got {aabb.size(1)}"
|
| 121 |
+
|
| 122 |
+
# Auto adjust aabb
|
| 123 |
+
if aabb is None:
|
| 124 |
+
aabb = scene.bounds
|
| 125 |
+
min_xyz = aabb[0]
|
| 126 |
+
max_xyz = aabb[1]
|
| 127 |
+
|
| 128 |
+
if voxel_size is not None:
|
| 129 |
+
padding = torch.ceil((max_xyz - min_xyz) / voxel_size) * voxel_size - (max_xyz - min_xyz)
|
| 130 |
+
min_xyz -= padding * 0.5
|
| 131 |
+
max_xyz += padding * 0.5
|
| 132 |
+
if grid_size is not None:
|
| 133 |
+
padding = (max_xyz - min_xyz) / (grid_size - 1)
|
| 134 |
+
min_xyz -= padding * 0.5
|
| 135 |
+
max_xyz += padding * 0.5
|
| 136 |
+
|
| 137 |
+
aabb = torch.stack([min_xyz, max_xyz], dim=0).float()
|
| 138 |
+
|
| 139 |
+
# Fill voxel size or grid size
|
| 140 |
+
if voxel_size is None:
|
| 141 |
+
voxel_size = (aabb[1] - aabb[0]) / grid_size
|
| 142 |
+
if grid_size is None:
|
| 143 |
+
grid_size = ((aabb[1] - aabb[0]) / voxel_size).round().int()
|
| 144 |
+
|
| 145 |
+
grid_range = torch.stack([torch.zeros_like(grid_size), grid_size], dim=0).int()
|
| 146 |
+
|
| 147 |
+
# Print settings
|
| 148 |
+
if verbose:
|
| 149 |
+
print(f"Voxelize settings:")
|
| 150 |
+
print(f" Voxel size: {voxel_size}")
|
| 151 |
+
print(f" Grid size: {grid_size}")
|
| 152 |
+
print(f" AABB: {aabb}")
|
| 153 |
+
|
| 154 |
+
# Load Scene
|
| 155 |
+
scene_buffers = {
|
| 156 |
+
'triangles': [],
|
| 157 |
+
'normals': [],
|
| 158 |
+
'uvs': [],
|
| 159 |
+
'material_ids': [],
|
| 160 |
+
'base_color_factor': [],
|
| 161 |
+
'base_color_texture': [],
|
| 162 |
+
'metallic_factor': [],
|
| 163 |
+
'metallic_texture': [],
|
| 164 |
+
'roughness_factor': [],
|
| 165 |
+
'roughness_texture': [],
|
| 166 |
+
'emissive_factor': [],
|
| 167 |
+
'emissive_texture': [],
|
| 168 |
+
'alpha_mode': [],
|
| 169 |
+
'alpha_cutoff': [],
|
| 170 |
+
'alpha_factor': [],
|
| 171 |
+
'alpha_texture': [],
|
| 172 |
+
'normal_texture': [],
|
| 173 |
+
}
|
| 174 |
+
for sid, (name, g) in tqdm(enumerate(scene.geometry.items()), total=len(scene.geometry), desc="Loading Scene", disable=not verbose):
|
| 175 |
+
if verbose:
|
| 176 |
+
print(f"Geometry: {name}")
|
| 177 |
+
print(f" Visual: {g.visual}")
|
| 178 |
+
print(f" Triangles: {g.triangles.shape[0]}")
|
| 179 |
+
print(f" Vertices: {g.vertices.shape[0]}")
|
| 180 |
+
print(f" Normals: {g.vertex_normals.shape[0]}")
|
| 181 |
+
if g.visual.material.baseColorFactor is not None:
|
| 182 |
+
print(f" Base color factor: {g.visual.material.baseColorFactor}")
|
| 183 |
+
if g.visual.material.baseColorTexture is not None:
|
| 184 |
+
print(f" Base color texture: {g.visual.material.baseColorTexture.size} {g.visual.material.baseColorTexture.mode}")
|
| 185 |
+
if g.visual.material.metallicFactor is not None:
|
| 186 |
+
print(f" Metallic factor: {g.visual.material.metallicFactor}")
|
| 187 |
+
if g.visual.material.roughnessFactor is not None:
|
| 188 |
+
print(f" Roughness factor: {g.visual.material.roughnessFactor}")
|
| 189 |
+
if g.visual.material.metallicRoughnessTexture is not None:
|
| 190 |
+
print(f" Metallic roughness texture: {g.visual.material.metallicRoughnessTexture.size} {g.visual.material.metallicRoughnessTexture.mode}")
|
| 191 |
+
if g.visual.material.emissiveFactor is not None:
|
| 192 |
+
print(f" Emissive factor: {g.visual.material.emissiveFactor}")
|
| 193 |
+
if g.visual.material.emissiveTexture is not None:
|
| 194 |
+
print(f" Emissive texture: {g.visual.material.emissiveTexture.size} {g.visual.material.emissiveTexture.mode}")
|
| 195 |
+
if g.visual.material.alphaMode is not None:
|
| 196 |
+
print(f" Alpha mode: {g.visual.material.alphaMode}")
|
| 197 |
+
if g.visual.material.alphaCutoff is not None:
|
| 198 |
+
print(f" Alpha cutoff: {g.visual.material.alphaCutoff}")
|
| 199 |
+
if g.visual.material.normalTexture is not None:
|
| 200 |
+
print(f" Normal texture: {g.visual.material.normalTexture.size} {g.visual.material.normalTexture.mode}")
|
| 201 |
+
|
| 202 |
+
assert isinstance(g, trimesh.Trimesh), f"Only trimesh.Trimesh is supported, but got {type(g)}"
|
| 203 |
+
assert isinstance(g.visual, trimesh.visual.TextureVisuals), f"Only trimesh.visual.TextureVisuals is supported, but got {type(g.visual)}"
|
| 204 |
+
assert isinstance(g.visual.material, trimesh.visual.material.PBRMaterial), f"Only trimesh.visual.material.PBRMaterial is supported, but got {type(g.visual.material)}"
|
| 205 |
+
triangles = torch.tensor(g.triangles, dtype=torch.float32) - aabb[0].reshape(1, 1, 3) # [N, 3, 3]
|
| 206 |
+
normals = torch.tensor(g.vertex_normals[g.faces], dtype=torch.float32) # [N, 3, 3]
|
| 207 |
+
uvs = torch.tensor(g.visual.uv[g.faces], dtype=torch.float32) if g.visual.uv is not None \
|
| 208 |
+
else torch.zeros(g.triangles.shape[0], 3, 2, dtype=torch.float32) # [N, 3, 2]
|
| 209 |
+
baseColorFactor = torch.tensor(g.visual.material.baseColorFactor / 255, dtype=torch.float32) if g.visual.material.baseColorFactor is not None \
|
| 210 |
+
else torch.ones(3, dtype=torch.float32) # [3]
|
| 211 |
+
baseColorTexture = torch.tensor(np.array(g.visual.material.baseColorTexture.convert('RGBA'))[..., :3], dtype=torch.uint8) if g.visual.material.baseColorTexture is not None \
|
| 212 |
+
else torch.tensor([]) # [H, W, 3]
|
| 213 |
+
metallicFactor = g.visual.material.metallicFactor if g.visual.material.metallicFactor is not None else 1.0
|
| 214 |
+
metallicTexture = torch.tensor(np.array(g.visual.material.metallicRoughnessTexture.convert('RGB'))[..., 2], dtype=torch.uint8) if g.visual.material.metallicRoughnessTexture is not None \
|
| 215 |
+
else torch.tensor([]) # [H, W]
|
| 216 |
+
roughnessFactor = g.visual.material.roughnessFactor if g.visual.material.roughnessFactor is not None else 1.0
|
| 217 |
+
roughnessTexture = torch.tensor(np.array(g.visual.material.metallicRoughnessTexture.convert('RGB'))[..., 1], dtype=torch.uint8) if g.visual.material.metallicRoughnessTexture is not None \
|
| 218 |
+
else torch.tensor([]) # [H, W]
|
| 219 |
+
emissiveFactor = torch.tensor(g.visual.material.emissiveFactor, dtype=torch.float32) if g.visual.material.emissiveFactor is not None \
|
| 220 |
+
else torch.zeros(3, dtype=torch.float32) # [3]
|
| 221 |
+
emissiveTexture = torch.tensor(np.array(g.visual.material.emissiveTexture.convert('RGB'))[..., :3], dtype=torch.uint8) if g.visual.material.emissiveTexture is not None \
|
| 222 |
+
else torch.tensor([]) # [H, W, 3]
|
| 223 |
+
alphaMode = ALPHA_MODE_ENUM[g.visual.material.alphaMode] if g.visual.material.alphaMode in ALPHA_MODE_ENUM else 0
|
| 224 |
+
alphaCutoff = g.visual.material.alphaCutoff if g.visual.material.alphaCutoff is not None else 0.5
|
| 225 |
+
alphaFactor = g.visual.material.baseColorFactor[3] / 255 if g.visual.material.baseColorFactor is not None else 1.0
|
| 226 |
+
alphaTexture = torch.tensor(np.array(g.visual.material.baseColorTexture.convert('RGBA'))[..., 3], dtype=torch.uint8) if g.visual.material.baseColorTexture is not None and alphaMode != 0 \
|
| 227 |
+
else torch.tensor([]) # [H, W]
|
| 228 |
+
normalTexture = torch.tensor(np.array(g.visual.material.normalTexture.convert('RGB'))[..., :3], dtype=torch.uint8) if g.visual.material.normalTexture is not None \
|
| 229 |
+
else torch.tensor([]) # [H, W, 3]
|
| 230 |
+
|
| 231 |
+
scene_buffers['triangles'].append(triangles)
|
| 232 |
+
scene_buffers['normals'].append(normals)
|
| 233 |
+
scene_buffers['uvs'].append(uvs)
|
| 234 |
+
scene_buffers['material_ids'].append(torch.full((triangles.shape[0],), sid, dtype=torch.int32))
|
| 235 |
+
scene_buffers['base_color_factor'].append(baseColorFactor)
|
| 236 |
+
scene_buffers['base_color_texture'].append(baseColorTexture)
|
| 237 |
+
scene_buffers['metallic_factor'].append(metallicFactor)
|
| 238 |
+
scene_buffers['metallic_texture'].append(metallicTexture)
|
| 239 |
+
scene_buffers['roughness_factor'].append(roughnessFactor)
|
| 240 |
+
scene_buffers['roughness_texture'].append(roughnessTexture)
|
| 241 |
+
scene_buffers['emissive_factor'].append(emissiveFactor)
|
| 242 |
+
scene_buffers['emissive_texture'].append(emissiveTexture)
|
| 243 |
+
scene_buffers['alpha_mode'].append(alphaMode)
|
| 244 |
+
scene_buffers['alpha_cutoff'].append(alphaCutoff)
|
| 245 |
+
scene_buffers['alpha_factor'].append(alphaFactor)
|
| 246 |
+
scene_buffers['alpha_texture'].append(alphaTexture)
|
| 247 |
+
scene_buffers['normal_texture'].append(normalTexture)
|
| 248 |
+
|
| 249 |
+
scene_buffers['triangles'] = torch.cat(scene_buffers['triangles'], dim=0) # [N, 3, 3]
|
| 250 |
+
scene_buffers['normals'] = torch.cat(scene_buffers['normals'], dim=0) # [N, 3, 3]
|
| 251 |
+
scene_buffers['uvs'] = torch.cat(scene_buffers['uvs'], dim=0) # [N, 3, 2]
|
| 252 |
+
scene_buffers['material_ids'] = torch.cat(scene_buffers['material_ids'], dim=0) # [N]
|
| 253 |
+
|
| 254 |
+
# Voxelize
|
| 255 |
+
out_tuple = _C.textured_mesh_to_volumetric_attr_cpu(
|
| 256 |
+
voxel_size,
|
| 257 |
+
grid_range,
|
| 258 |
+
scene_buffers["triangles"],
|
| 259 |
+
scene_buffers["normals"],
|
| 260 |
+
scene_buffers["uvs"],
|
| 261 |
+
scene_buffers["material_ids"],
|
| 262 |
+
scene_buffers["base_color_factor"],
|
| 263 |
+
scene_buffers["base_color_texture"],
|
| 264 |
+
[1] * len(scene_buffers["base_color_texture"]),
|
| 265 |
+
[0] * len(scene_buffers["base_color_texture"]),
|
| 266 |
+
scene_buffers["metallic_factor"],
|
| 267 |
+
scene_buffers["metallic_texture"],
|
| 268 |
+
[1] * len(scene_buffers["metallic_texture"]),
|
| 269 |
+
[0] * len(scene_buffers["metallic_texture"]),
|
| 270 |
+
scene_buffers["roughness_factor"],
|
| 271 |
+
scene_buffers["roughness_texture"],
|
| 272 |
+
[1] * len(scene_buffers["roughness_texture"]),
|
| 273 |
+
[0] * len(scene_buffers["roughness_texture"]),
|
| 274 |
+
scene_buffers["emissive_factor"],
|
| 275 |
+
scene_buffers["emissive_texture"],
|
| 276 |
+
[1] * len(scene_buffers["emissive_texture"]),
|
| 277 |
+
[0] * len(scene_buffers["emissive_texture"]),
|
| 278 |
+
scene_buffers["alpha_mode"],
|
| 279 |
+
scene_buffers["alpha_cutoff"],
|
| 280 |
+
scene_buffers["alpha_factor"],
|
| 281 |
+
scene_buffers["alpha_texture"],
|
| 282 |
+
[1] * len(scene_buffers["alpha_texture"]),
|
| 283 |
+
[0] * len(scene_buffers["alpha_texture"]),
|
| 284 |
+
scene_buffers["normal_texture"],
|
| 285 |
+
[1] * len(scene_buffers["normal_texture"]),
|
| 286 |
+
[0] * len(scene_buffers["normal_texture"]),
|
| 287 |
+
mip_level_offset,
|
| 288 |
+
timing,
|
| 289 |
+
)
|
| 290 |
+
|
| 291 |
+
# Post process
|
| 292 |
+
coord = out_tuple[0]
|
| 293 |
+
attr = {
|
| 294 |
+
"base_color": torch.clamp(out_tuple[1] * 255, 0, 255).byte().reshape(-1, 3),
|
| 295 |
+
"metallic": torch.clamp(out_tuple[2] * 255, 0, 255).byte().reshape(-1, 1),
|
| 296 |
+
"roughness": torch.clamp(out_tuple[3] * 255, 0, 255).byte().reshape(-1, 1),
|
| 297 |
+
"emissive": torch.clamp(out_tuple[4] * 255, 0, 255).byte().reshape(-1, 3),
|
| 298 |
+
"alpha": torch.clamp(out_tuple[5] * 255, 0, 255).byte().reshape(-1, 1),
|
| 299 |
+
"normal": torch.clamp((out_tuple[6] * 0.5 + 0.5) * 255, 0, 255).byte().reshape(-1, 3),
|
| 300 |
+
}
|
| 301 |
+
|
| 302 |
+
return coord, attr
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
def blender_dump_to_volumetric_attr(
|
| 306 |
+
dump: Dict[str, Any],
|
| 307 |
+
voxel_size: Union[float, list, tuple, np.ndarray, torch.Tensor] = None,
|
| 308 |
+
grid_size: Union[int, list, tuple, np.ndarray, torch.Tensor] = None,
|
| 309 |
+
aabb: Union[list, tuple, np.ndarray, torch.Tensor] = None,
|
| 310 |
+
mip_level_offset: float = 0.0,
|
| 311 |
+
verbose: bool = False,
|
| 312 |
+
timing: bool = False,
|
| 313 |
+
) -> Union[torch.Tensor, Dict[str, torch.Tensor]]:
|
| 314 |
+
"""
|
| 315 |
+
Voxelize a mesh into a sparse voxel grid with PBR properties.
|
| 316 |
+
|
| 317 |
+
Args:
|
| 318 |
+
dump (Dict[str, Any]): Dumped data from a blender scene.
|
| 319 |
+
voxel_size (float, list, tuple, np.ndarray, torch.Tensor): The size of each voxel.
|
| 320 |
+
grid_size (int, list, tuple, np.ndarray, torch.Tensor): The size of the grid.
|
| 321 |
+
NOTE: One of voxel_size and grid_size must be provided.
|
| 322 |
+
aabb (list, tuple, np.ndarray, torch.Tensor): The axis-aligned bounding box of the mesh.
|
| 323 |
+
If not provided, it will be computed automatically.
|
| 324 |
+
mip_level_offset (float): The mip level offset for texture mip level selection.
|
| 325 |
+
verbose (bool): Whether to print the settings.
|
| 326 |
+
timing (bool): Whether to print the timing information.
|
| 327 |
+
|
| 328 |
+
Returns:
|
| 329 |
+
torch.Tensor: The indices of the voxels that are occupied by the mesh.
|
| 330 |
+
Dict[str, torch.Tensor]: A dictionary containing the following keys:
|
| 331 |
+
- "base_color": The base color of the occupied voxels.
|
| 332 |
+
- "metallic": The metallic value of the occupied voxels.
|
| 333 |
+
- "roughness": The roughness value of the occupied voxels.
|
| 334 |
+
- "emissive": The emissive value of the occupied voxels.
|
| 335 |
+
- "alpha": The alpha value of the occupied voxels.
|
| 336 |
+
- "normal": The normal of the occupied voxels.
|
| 337 |
+
"""
|
| 338 |
+
# Voxelize settings
|
| 339 |
+
assert voxel_size is not None or grid_size is not None, "Either voxel_size or grid_size must be provided"
|
| 340 |
+
|
| 341 |
+
if voxel_size is not None:
|
| 342 |
+
if isinstance(voxel_size, float):
|
| 343 |
+
voxel_size = [voxel_size, voxel_size, voxel_size]
|
| 344 |
+
if isinstance(voxel_size, (list, tuple)):
|
| 345 |
+
voxel_size = np.array(voxel_size)
|
| 346 |
+
if isinstance(voxel_size, np.ndarray):
|
| 347 |
+
voxel_size = torch.tensor(voxel_size, dtype=torch.float32)
|
| 348 |
+
assert isinstance(voxel_size, torch.Tensor), f"voxel_size must be a float, list, tuple, np.ndarray, or torch.Tensor, but got {type(voxel_size)}"
|
| 349 |
+
assert voxel_size.dim() == 1, f"voxel_size must be a 1D tensor, but got {voxel_size.shape}"
|
| 350 |
+
assert voxel_size.size(0) == 3, f"voxel_size must have 3 elements, but got {voxel_size.size(0)}"
|
| 351 |
+
|
| 352 |
+
if grid_size is not None:
|
| 353 |
+
if isinstance(grid_size, int):
|
| 354 |
+
grid_size = [grid_size, grid_size, grid_size]
|
| 355 |
+
if isinstance(grid_size, (list, tuple)):
|
| 356 |
+
grid_size = np.array(grid_size)
|
| 357 |
+
if isinstance(grid_size, np.ndarray):
|
| 358 |
+
grid_size = torch.tensor(grid_size, dtype=torch.int32)
|
| 359 |
+
assert isinstance(grid_size, torch.Tensor), f"grid_size must be an int, list, tuple, np.ndarray, or torch.Tensor, but got {type(grid_size)}"
|
| 360 |
+
assert grid_size.dim() == 1, f"grid_size must be a 1D tensor, but got {grid_size.shape}"
|
| 361 |
+
assert grid_size.size(0) == 3, f"grid_size must have 3 elements, but got {grid_size.size(0)}"
|
| 362 |
+
|
| 363 |
+
if aabb is not None:
|
| 364 |
+
if isinstance(aabb, (list, tuple)):
|
| 365 |
+
aabb = np.array(aabb)
|
| 366 |
+
if isinstance(aabb, np.ndarray):
|
| 367 |
+
aabb = torch.tensor(aabb, dtype=torch.float32)
|
| 368 |
+
assert isinstance(aabb, torch.Tensor), f"aabb must be a list, tuple, np.ndarray, or torch.Tensor, but got {type(aabb)}"
|
| 369 |
+
assert aabb.dim() == 2, f"aabb must be a 2D tensor, but got {aabb.shape}"
|
| 370 |
+
assert aabb.size(0) == 2, f"aabb must have 2 rows, but got {aabb.size(0)}"
|
| 371 |
+
assert aabb.size(1) == 3, f"aabb must have 3 columns, but got {aabb.size(1)}"
|
| 372 |
+
|
| 373 |
+
# Auto adjust aabb
|
| 374 |
+
if aabb is None:
|
| 375 |
+
min_xyz = np.min([
|
| 376 |
+
object['vertices'].min(axis=0)
|
| 377 |
+
for object in dump['objects']
|
| 378 |
+
], axis=0)
|
| 379 |
+
max_xyz = np.max([
|
| 380 |
+
object['vertices'].max(axis=0)
|
| 381 |
+
for object in dump['objects']
|
| 382 |
+
], axis=0)
|
| 383 |
+
|
| 384 |
+
if voxel_size is not None:
|
| 385 |
+
padding = torch.ceil((max_xyz - min_xyz) / voxel_size) * voxel_size - (max_xyz - min_xyz)
|
| 386 |
+
min_xyz -= padding * 0.5
|
| 387 |
+
max_xyz += padding * 0.5
|
| 388 |
+
if grid_size is not None:
|
| 389 |
+
padding = (max_xyz - min_xyz) / (grid_size - 1)
|
| 390 |
+
min_xyz -= padding * 0.5
|
| 391 |
+
max_xyz += padding * 0.5
|
| 392 |
+
|
| 393 |
+
aabb = torch.stack([min_xyz, max_xyz], dim=0).float()
|
| 394 |
+
|
| 395 |
+
# Fill voxel size or grid size
|
| 396 |
+
if voxel_size is None:
|
| 397 |
+
voxel_size = (aabb[1] - aabb[0]) / grid_size
|
| 398 |
+
if grid_size is None:
|
| 399 |
+
grid_size = ((aabb[1] - aabb[0]) / voxel_size).round().int()
|
| 400 |
+
|
| 401 |
+
grid_range = torch.stack([torch.zeros_like(grid_size), grid_size], dim=0).int()
|
| 402 |
+
|
| 403 |
+
# Print settings
|
| 404 |
+
if verbose:
|
| 405 |
+
print(f"Voxelize settings:")
|
| 406 |
+
print(f" Voxel size: {voxel_size}")
|
| 407 |
+
print(f" Grid size: {grid_size}")
|
| 408 |
+
print(f" AABB: {aabb}")
|
| 409 |
+
|
| 410 |
+
# Load Scene
|
| 411 |
+
scene_buffers = {
|
| 412 |
+
'triangles': [],
|
| 413 |
+
'normals': [],
|
| 414 |
+
'uvs': [],
|
| 415 |
+
'material_ids': [],
|
| 416 |
+
'base_color_factor': [],
|
| 417 |
+
'base_color_texture': [],
|
| 418 |
+
'base_color_texture_filter': [],
|
| 419 |
+
'base_color_texture_wrap': [],
|
| 420 |
+
'metallic_factor': [],
|
| 421 |
+
'metallic_texture': [],
|
| 422 |
+
'metallic_texture_filter': [],
|
| 423 |
+
'metallic_texture_wrap': [],
|
| 424 |
+
'roughness_factor': [],
|
| 425 |
+
'roughness_texture': [],
|
| 426 |
+
'roughness_texture_filter': [],
|
| 427 |
+
'roughness_texture_wrap': [],
|
| 428 |
+
'alpha_mode': [],
|
| 429 |
+
'alpha_cutoff': [],
|
| 430 |
+
'alpha_factor': [],
|
| 431 |
+
'alpha_texture': [],
|
| 432 |
+
'alpha_texture_filter': [],
|
| 433 |
+
'alpha_texture_wrap': [],
|
| 434 |
+
}
|
| 435 |
+
|
| 436 |
+
def load_texture(pack):
|
| 437 |
+
png_bytes = pack['image']
|
| 438 |
+
image = Image.open(io.BytesIO(png_bytes))
|
| 439 |
+
if image.width != image.height or not is_power_of_two(image.width):
|
| 440 |
+
size = nearest_power_of_two(max(image.width, image.height))
|
| 441 |
+
image = image.resize((size, size), Image.LANCZOS)
|
| 442 |
+
texture = torch.tensor(np.array(image), dtype=torch.uint8)
|
| 443 |
+
filter_mode = {
|
| 444 |
+
'Linear': 1,
|
| 445 |
+
'Closest': 0,
|
| 446 |
+
'Cubic': 1,
|
| 447 |
+
'Smart': 1,
|
| 448 |
+
}[pack['interpolation']]
|
| 449 |
+
wrap_mode = {
|
| 450 |
+
'REPEAT': 0,
|
| 451 |
+
'EXTEND': 1,
|
| 452 |
+
'CLIP': 1,
|
| 453 |
+
'MIRROR': 2,
|
| 454 |
+
}[pack['extension']]
|
| 455 |
+
return texture, filter_mode, wrap_mode
|
| 456 |
+
|
| 457 |
+
for material in dump['materials']:
|
| 458 |
+
baseColorFactor = torch.tensor(material['baseColorFactor'][:3], dtype=torch.float32)
|
| 459 |
+
if material['baseColorTexture'] is not None:
|
| 460 |
+
baseColorTexture, baseColorTextureFilter, baseColorTextureWrap = \
|
| 461 |
+
load_texture(material['baseColorTexture'])
|
| 462 |
+
assert baseColorTexture.shape[2] == 3, f"Base color texture must have 3 channels, but got {baseColorTexture.shape[2]}"
|
| 463 |
+
else:
|
| 464 |
+
baseColorTexture = torch.tensor([])
|
| 465 |
+
baseColorTextureFilter = 0
|
| 466 |
+
baseColorTextureWrap = 0
|
| 467 |
+
scene_buffers['base_color_factor'].append(baseColorFactor)
|
| 468 |
+
scene_buffers['base_color_texture'].append(baseColorTexture)
|
| 469 |
+
scene_buffers['base_color_texture_filter'].append(baseColorTextureFilter)
|
| 470 |
+
scene_buffers['base_color_texture_wrap'].append(baseColorTextureWrap)
|
| 471 |
+
|
| 472 |
+
metallicFactor = material['metallicFactor']
|
| 473 |
+
if material['metallicTexture'] is not None:
|
| 474 |
+
metallicTexture, metallicTextureFilter, metallicTextureWrap = \
|
| 475 |
+
load_texture(material['metallicTexture'])
|
| 476 |
+
assert metallicTexture.dim() == 2, f"Metallic roughness texture must have 2 dimensions, but got {metallicTexture.dim()}"
|
| 477 |
+
else:
|
| 478 |
+
metallicTexture = torch.tensor([])
|
| 479 |
+
metallicTextureFilter = 0
|
| 480 |
+
metallicTextureWrap = 0
|
| 481 |
+
scene_buffers['metallic_factor'].append(metallicFactor)
|
| 482 |
+
scene_buffers['metallic_texture'].append(metallicTexture)
|
| 483 |
+
scene_buffers['metallic_texture_filter'].append(metallicTextureFilter)
|
| 484 |
+
scene_buffers['metallic_texture_wrap'].append(metallicTextureWrap)
|
| 485 |
+
|
| 486 |
+
roughnessFactor = material['roughnessFactor']
|
| 487 |
+
if material['roughnessTexture'] is not None:
|
| 488 |
+
roughnessTexture, roughnessTextureFilter, roughnessTextureWrap = \
|
| 489 |
+
load_texture(material['roughnessTexture'])
|
| 490 |
+
assert roughnessTexture.dim() == 2, f"Metallic roughness texture must have 2 dimensions, but got {roughnessTexture.dim()}"
|
| 491 |
+
else:
|
| 492 |
+
roughnessTexture = torch.tensor([])
|
| 493 |
+
roughnessTextureFilter = 0
|
| 494 |
+
roughnessTextureWrap = 0
|
| 495 |
+
scene_buffers['roughness_factor'].append(roughnessFactor)
|
| 496 |
+
scene_buffers['roughness_texture'].append(roughnessTexture)
|
| 497 |
+
scene_buffers['roughness_texture_filter'].append(roughnessTextureFilter)
|
| 498 |
+
scene_buffers['roughness_texture_wrap'].append(roughnessTextureWrap)
|
| 499 |
+
|
| 500 |
+
alphaMode = ALPHA_MODE_ENUM[material['alphaMode']]
|
| 501 |
+
alphaCutoff = material['alphaCutoff']
|
| 502 |
+
alphaFactor = material['alphaFactor']
|
| 503 |
+
if material['alphaTexture'] is not None:
|
| 504 |
+
alphaTexture, alphaTextureFilter, alphaTextureWrap = \
|
| 505 |
+
load_texture(material['alphaTexture'])
|
| 506 |
+
assert alphaTexture.dim() == 2, f"Alpha texture must have 2 dimensions, but got {alphaTexture.dim()}"
|
| 507 |
+
else:
|
| 508 |
+
alphaTexture = torch.tensor([])
|
| 509 |
+
alphaTextureFilter = 0
|
| 510 |
+
alphaTextureWrap = 0
|
| 511 |
+
scene_buffers['alpha_mode'].append(alphaMode)
|
| 512 |
+
scene_buffers['alpha_cutoff'].append(alphaCutoff)
|
| 513 |
+
scene_buffers['alpha_factor'].append(alphaFactor)
|
| 514 |
+
scene_buffers['alpha_texture'].append(alphaTexture)
|
| 515 |
+
scene_buffers['alpha_texture_filter'].append(alphaTextureFilter)
|
| 516 |
+
scene_buffers['alpha_texture_wrap'].append(alphaTextureWrap)
|
| 517 |
+
|
| 518 |
+
for object in dump['objects']:
|
| 519 |
+
triangles = torch.tensor(object['vertices'][object['faces']], dtype=torch.float32).reshape(-1, 3, 3) - aabb[0].reshape(1, 1, 3)
|
| 520 |
+
normails = torch.tensor(object['normals'], dtype=torch.float32)
|
| 521 |
+
uvs = torch.tensor(object['uvs'], dtype=torch.float32) if object['uvs'] is not None else torch.zeros(triangles.shape[0], 3, 2, dtype=torch.float32)
|
| 522 |
+
material_id = torch.tensor(object['mat_ids'], dtype=torch.int32)
|
| 523 |
+
scene_buffers['triangles'].append(triangles)
|
| 524 |
+
scene_buffers['normals'].append(normails)
|
| 525 |
+
scene_buffers['uvs'].append(uvs)
|
| 526 |
+
scene_buffers['material_ids'].append(material_id)
|
| 527 |
+
|
| 528 |
+
scene_buffers['triangles'] = torch.cat(scene_buffers['triangles'], dim=0) # [N, 3, 3]
|
| 529 |
+
scene_buffers['normals'] = torch.cat(scene_buffers['normals'], dim=0) # [N, 3, 3]
|
| 530 |
+
scene_buffers['uvs'] = torch.cat(scene_buffers['uvs'], dim=0) # [N, 3, 2]
|
| 531 |
+
scene_buffers['material_ids'] = torch.cat(scene_buffers['material_ids'], dim=0) # [N]
|
| 532 |
+
|
| 533 |
+
scene_buffers['uvs'][:, :, 1] = 1 - scene_buffers['uvs'][:, :, 1] # Flip v coordinate
|
| 534 |
+
|
| 535 |
+
# Voxelize
|
| 536 |
+
out_tuple = _C.textured_mesh_to_volumetric_attr_cpu(
|
| 537 |
+
voxel_size,
|
| 538 |
+
grid_range,
|
| 539 |
+
scene_buffers["triangles"],
|
| 540 |
+
scene_buffers["normals"],
|
| 541 |
+
scene_buffers["uvs"],
|
| 542 |
+
scene_buffers["material_ids"],
|
| 543 |
+
scene_buffers["base_color_factor"],
|
| 544 |
+
scene_buffers["base_color_texture"],
|
| 545 |
+
scene_buffers["base_color_texture_filter"],
|
| 546 |
+
scene_buffers["base_color_texture_wrap"],
|
| 547 |
+
scene_buffers["metallic_factor"],
|
| 548 |
+
scene_buffers["metallic_texture"],
|
| 549 |
+
scene_buffers["metallic_texture_filter"],
|
| 550 |
+
scene_buffers["metallic_texture_wrap"],
|
| 551 |
+
scene_buffers["roughness_factor"],
|
| 552 |
+
scene_buffers["roughness_texture"],
|
| 553 |
+
scene_buffers["roughness_texture_filter"],
|
| 554 |
+
scene_buffers["roughness_texture_wrap"],
|
| 555 |
+
[torch.zeros(3, dtype=torch.float32) for _ in range(len(scene_buffers["base_color_texture"]))],
|
| 556 |
+
[torch.tensor([]) for _ in range(len(scene_buffers["base_color_texture"]))],
|
| 557 |
+
[0] * len(scene_buffers["base_color_texture"]),
|
| 558 |
+
[0] * len(scene_buffers["base_color_texture"]),
|
| 559 |
+
scene_buffers["alpha_mode"],
|
| 560 |
+
scene_buffers["alpha_cutoff"],
|
| 561 |
+
scene_buffers["alpha_factor"],
|
| 562 |
+
scene_buffers["alpha_texture"],
|
| 563 |
+
scene_buffers["alpha_texture_filter"],
|
| 564 |
+
scene_buffers["alpha_texture_wrap"],
|
| 565 |
+
[torch.tensor([]) for _ in range(len(scene_buffers["base_color_texture"]))],
|
| 566 |
+
[0] * len(scene_buffers["base_color_texture"]),
|
| 567 |
+
[0] * len(scene_buffers["base_color_texture"]),
|
| 568 |
+
mip_level_offset,
|
| 569 |
+
timing,
|
| 570 |
+
)
|
| 571 |
+
|
| 572 |
+
# Post process
|
| 573 |
+
coord = out_tuple[0]
|
| 574 |
+
attr = {
|
| 575 |
+
"base_color": torch.clamp(out_tuple[1] * 255, 0, 255).byte().reshape(-1, 3),
|
| 576 |
+
"metallic": torch.clamp(out_tuple[2] * 255, 0, 255).byte().reshape(-1, 1),
|
| 577 |
+
"roughness": torch.clamp(out_tuple[3] * 255, 0, 255).byte().reshape(-1, 1),
|
| 578 |
+
"emissive": torch.clamp(out_tuple[4] * 255, 0, 255).byte().reshape(-1, 3),
|
| 579 |
+
"alpha": torch.clamp(out_tuple[5] * 255, 0, 255).byte().reshape(-1, 1),
|
| 580 |
+
"normal": torch.clamp((out_tuple[6] * 0.5 + 0.5) * 255, 0, 255).byte().reshape(-1, 3),
|
| 581 |
+
}
|
| 582 |
+
|
| 583 |
+
return coord, attr
|
wheels/TRELLIS.2/o-voxels/build/lib.linux-x86_64-cpython-310/o_voxel/io/__init__.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Dict, Union
|
| 2 |
+
import torch
|
| 3 |
+
from .ply import *
|
| 4 |
+
from .npz import *
|
| 5 |
+
from .vxz import *
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def read(file_path: str) -> Union[torch.Tensor, Dict[str, torch.Tensor]]:
|
| 9 |
+
"""
|
| 10 |
+
Read a file containing voxels.
|
| 11 |
+
|
| 12 |
+
Args:
|
| 13 |
+
file_path: Path to the file.
|
| 14 |
+
|
| 15 |
+
Returns:
|
| 16 |
+
torch.Tensor: the coordinates of the voxels.
|
| 17 |
+
Dict[str, torch.Tensor]: the attributes of the voxels.
|
| 18 |
+
"""
|
| 19 |
+
if file_path.endswith('.npz'):
|
| 20 |
+
return read_npz(file_path)
|
| 21 |
+
elif file_path.endswith('.ply'):
|
| 22 |
+
return read_ply(file_path)
|
| 23 |
+
elif file_path.endswith('.vxz'):
|
| 24 |
+
return read_vxz(file_path)
|
| 25 |
+
else:
|
| 26 |
+
raise ValueError(f"Unsupported file type {file_path}")
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def write(file_path: str, coord: torch.Tensor, attr: Dict[str, torch.Tensor], **kwargs):
|
| 30 |
+
"""
|
| 31 |
+
Write a file containing voxels.
|
| 32 |
+
|
| 33 |
+
Args:
|
| 34 |
+
file_path: Path to the file.
|
| 35 |
+
coord: the coordinates of the voxels.
|
| 36 |
+
attr: the attributes of the voxels.
|
| 37 |
+
"""
|
| 38 |
+
if file_path.endswith('.npz'):
|
| 39 |
+
write_npz(file_path, coord, attr, **kwargs)
|
| 40 |
+
elif file_path.endswith('.ply'):
|
| 41 |
+
write_ply(file_path, coord, attr, **kwargs)
|
| 42 |
+
elif file_path.endswith('.vxz'):
|
| 43 |
+
write_vxz(file_path, coord, attr, **kwargs)
|
| 44 |
+
else:
|
| 45 |
+
raise ValueError(f"Unsupported file type {file_path}")
|
wheels/TRELLIS.2/o-voxels/build/lib.linux-x86_64-cpython-310/o_voxel/io/npz.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import *
|
| 2 |
+
import torch
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
__all__ = [
|
| 7 |
+
"read_npz",
|
| 8 |
+
"write_npz",
|
| 9 |
+
]
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def read_npz(file) -> Union[torch.Tensor, Dict[str, torch.Tensor]]:
|
| 13 |
+
"""
|
| 14 |
+
Read a NPZ file containing voxels.
|
| 15 |
+
|
| 16 |
+
Args:
|
| 17 |
+
file_path: Path or file object from which to read the NPZ file.
|
| 18 |
+
|
| 19 |
+
Returns:
|
| 20 |
+
torch.Tensor: the coordinates of the voxels.
|
| 21 |
+
Dict[str, torch.Tensor]: the attributes of the voxels.
|
| 22 |
+
"""
|
| 23 |
+
data = np.load(file)
|
| 24 |
+
coord = torch.from_numpy(data['coord']).int()
|
| 25 |
+
attr = {k: torch.from_numpy(v) for k, v in data.items() if k!= 'coord'}
|
| 26 |
+
return coord, attr
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def write_npz(file, coord: torch.Tensor, attr: Dict[str, torch.Tensor], compress=True):
|
| 30 |
+
"""
|
| 31 |
+
Write a NPZ file containing voxels.
|
| 32 |
+
|
| 33 |
+
Args:
|
| 34 |
+
file_path: Path or file object to which to write the NPZ file.
|
| 35 |
+
coord: the coordinates of the voxels.
|
| 36 |
+
attr: the attributes of the voxels.
|
| 37 |
+
"""
|
| 38 |
+
data = {'coord': coord.cpu().numpy().astype(np.uint16)}
|
| 39 |
+
data.update({k: v.cpu().numpy() for k, v in attr.items()})
|
| 40 |
+
if compress:
|
| 41 |
+
np.savez_compressed(file, **data)
|
| 42 |
+
else:
|
| 43 |
+
np.savez(file, **data)
|
wheels/TRELLIS.2/o-voxels/build/lib.linux-x86_64-cpython-310/o_voxel/io/ply.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import *
|
| 2 |
+
import io
|
| 3 |
+
import torch
|
| 4 |
+
import numpy as np
|
| 5 |
+
import plyfile
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
__all__ = [
|
| 9 |
+
"read_ply",
|
| 10 |
+
"write_ply",
|
| 11 |
+
]
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
DTYPE_MAP = {
|
| 15 |
+
torch.uint8: 'u1',
|
| 16 |
+
torch.uint16: 'u2',
|
| 17 |
+
torch.uint32: 'u4',
|
| 18 |
+
torch.int8: 'i1',
|
| 19 |
+
torch.int16: 'i2',
|
| 20 |
+
torch.int32: 'i4',
|
| 21 |
+
torch.float32: 'f4',
|
| 22 |
+
torch.float64: 'f8'
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def read_ply(file) -> Union[torch.Tensor, Dict[str, torch.Tensor]]:
|
| 27 |
+
"""
|
| 28 |
+
Read a PLY file containing voxels.
|
| 29 |
+
|
| 30 |
+
Args:
|
| 31 |
+
file: Path or file-like object of the PLY file.
|
| 32 |
+
|
| 33 |
+
Returns:
|
| 34 |
+
torch.Tensor: the coordinates of the voxels.
|
| 35 |
+
Dict[str, torch.Tensor]: the attributes of the voxels.
|
| 36 |
+
"""
|
| 37 |
+
plydata = plyfile.PlyData.read(file)
|
| 38 |
+
xyz = np.stack([plydata.elements[0][k] for k in ['x', 'y', 'z']], axis=1)
|
| 39 |
+
coord = np.round(xyz).astype(int)
|
| 40 |
+
coord = torch.from_numpy(coord)
|
| 41 |
+
|
| 42 |
+
attr_keys = [k for k in plydata.elements[0].data.dtype.names if k not in ['x', 'y', 'z']]
|
| 43 |
+
attr_names = ['_'.join(k.split('_')[:-1]) for k in attr_keys]
|
| 44 |
+
attr_chs = [sum([1 for k in attr_keys if k.startswith(f'{name}_')]) for name in attr_names]
|
| 45 |
+
|
| 46 |
+
attr = {}
|
| 47 |
+
for i, name in enumerate(attr_names):
|
| 48 |
+
attr[name] = np.stack([plydata.elements[0][f'{name}_{j}'] for j in range(attr_chs[i])], axis=1)
|
| 49 |
+
attr = {k: torch.from_numpy(v) for k, v in attr.items()}
|
| 50 |
+
|
| 51 |
+
return coord, attr
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def write_ply(file, coord: torch.Tensor, attr: Dict[str, torch.Tensor]):
|
| 55 |
+
"""
|
| 56 |
+
Write a PLY file containing voxels.
|
| 57 |
+
|
| 58 |
+
Args:
|
| 59 |
+
file: Path or file-like object of the PLY file.
|
| 60 |
+
coord: the coordinates of the voxels.
|
| 61 |
+
attr: the attributes of the voxels.
|
| 62 |
+
"""
|
| 63 |
+
dtypes = [('x', 'f4'), ('y', 'f4'), ('z', 'f4')]
|
| 64 |
+
for k, v in attr.items():
|
| 65 |
+
for j in range(v.shape[-1]):
|
| 66 |
+
assert v.dtype in DTYPE_MAP, f"Unsupported data type {v.dtype} for attribute {k}"
|
| 67 |
+
dtypes.append((f'{k}_{j}', DTYPE_MAP[v.dtype]))
|
| 68 |
+
data = np.empty(len(coord), dtype=dtypes)
|
| 69 |
+
all_chs = np.concatenate([coord.cpu().numpy().astype(np.float32)] + [v.cpu().numpy() for v in attr.values()], axis=1)
|
| 70 |
+
data[:] = list(map(tuple, all_chs))
|
| 71 |
+
plyfile.PlyData([plyfile.PlyElement.describe(data, 'vertex')]).write(file)
|
| 72 |
+
|
wheels/TRELLIS.2/o-voxels/build/lib.linux-x86_64-cpython-310/o_voxel/io/vxz.py
ADDED
|
@@ -0,0 +1,365 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import *
|
| 2 |
+
import os
|
| 3 |
+
import json
|
| 4 |
+
import struct
|
| 5 |
+
import torch
|
| 6 |
+
import numpy as np
|
| 7 |
+
import zlib
|
| 8 |
+
import lzma
|
| 9 |
+
import zstandard
|
| 10 |
+
from concurrent.futures import ThreadPoolExecutor
|
| 11 |
+
from ..serialize import encode_seq, decode_seq
|
| 12 |
+
from .. import _C
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
__all__ = [
|
| 16 |
+
"read_vxz",
|
| 17 |
+
"read_vxz_info",
|
| 18 |
+
"write_vxz",
|
| 19 |
+
]
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
"""
|
| 23 |
+
VXZ format
|
| 24 |
+
|
| 25 |
+
Header:
|
| 26 |
+
- file type (3 bytes) - 'VXZ'
|
| 27 |
+
- version (1 byte) - 0
|
| 28 |
+
- binary start offset (4 bytes)
|
| 29 |
+
- structure (json) -
|
| 30 |
+
{
|
| 31 |
+
"num_voxel": int,
|
| 32 |
+
"chunk_size": int,
|
| 33 |
+
"filter": str,
|
| 34 |
+
"compression": str,
|
| 35 |
+
"compression_level": int,
|
| 36 |
+
"raw_size": int,
|
| 37 |
+
"compressed_size": int,
|
| 38 |
+
"compress_ratio": float,
|
| 39 |
+
"attr_interleave": str,
|
| 40 |
+
"attr": [
|
| 41 |
+
{"name": str, "chs": int},
|
| 42 |
+
...
|
| 43 |
+
]
|
| 44 |
+
"chunks": [
|
| 45 |
+
{
|
| 46 |
+
"ptr": [offset, length], # offset from global binary start
|
| 47 |
+
"svo": [offset, length], # offset from this chunk start
|
| 48 |
+
"attr": [offset, length], # offset from this chunk start
|
| 49 |
+
},
|
| 50 |
+
...
|
| 51 |
+
]
|
| 52 |
+
}
|
| 53 |
+
- binary data
|
| 54 |
+
"""
|
| 55 |
+
|
| 56 |
+
DEFAULT_COMPRESION_LEVEL = {
|
| 57 |
+
'none': 0,
|
| 58 |
+
'deflate': 9,
|
| 59 |
+
'lzma': 9,
|
| 60 |
+
'zstd': 22,
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def _compress(data: bytes, algo: Literal['none', 'deflate', 'lzma', 'zstd'], level: int) -> bytes:
|
| 65 |
+
if algo == 'none':
|
| 66 |
+
return data
|
| 67 |
+
if level is None:
|
| 68 |
+
level = DEFAULT_COMPRESION_LEVEL[algo]
|
| 69 |
+
if algo == 'deflate':
|
| 70 |
+
compresser = zlib.compressobj(level, wbits=-15)
|
| 71 |
+
return compresser.compress(data) + compresser.flush()
|
| 72 |
+
if algo == 'lzma':
|
| 73 |
+
compresser = lzma.LZMACompressor(format=lzma.FORMAT_RAW, filters=[{'id': lzma.FILTER_LZMA2, 'preset': level}])
|
| 74 |
+
return compresser.compress(data) + compresser.flush()
|
| 75 |
+
if algo == 'zstd':
|
| 76 |
+
compresser = zstandard.ZstdCompressor(level=level, write_checksum=False, write_content_size=True, threads=-1)
|
| 77 |
+
return compresser.compress(data)
|
| 78 |
+
raise ValueError(f"Invalid compression algorithm: {algo}")
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def _decompress(data: bytes, algo: Literal['none', 'deflate', 'lzma', 'zstd'], level: int) -> bytes:
|
| 82 |
+
if algo == 'none':
|
| 83 |
+
return data
|
| 84 |
+
if level is None:
|
| 85 |
+
level = DEFAULT_COMPRESION_LEVEL[algo]
|
| 86 |
+
if algo == 'deflate':
|
| 87 |
+
decompresser = zlib.decompressobj(wbits=-15)
|
| 88 |
+
return decompresser.decompress(data) + decompresser.flush()
|
| 89 |
+
if algo == 'lzma':
|
| 90 |
+
decompresser = lzma.LZMADecompressor(format=lzma.FORMAT_RAW, filters=[{'id': lzma.FILTER_LZMA2, 'preset': level}])
|
| 91 |
+
return decompresser.decompress(data)
|
| 92 |
+
if algo == 'zstd':
|
| 93 |
+
decompresser = zstandard.ZstdDecompressor(format=zstandard.FORMAT_ZSTD1)
|
| 94 |
+
return decompresser.decompress(data)
|
| 95 |
+
raise ValueError(f"Invalid compression algorithm: {algo}")
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
def read_vxz_info(file) -> Dict:
|
| 99 |
+
"""
|
| 100 |
+
Read the header of a VXZ file without decompressing the binary data.
|
| 101 |
+
|
| 102 |
+
Args:
|
| 103 |
+
file_path: Path or file-like object to the VXZ file.
|
| 104 |
+
|
| 105 |
+
Returns:
|
| 106 |
+
Dict: the header of the VXZ file.
|
| 107 |
+
"""
|
| 108 |
+
if isinstance(file, str):
|
| 109 |
+
with open(file, 'rb') as f:
|
| 110 |
+
file_data = f.read()
|
| 111 |
+
else:
|
| 112 |
+
file_data = file.read()
|
| 113 |
+
|
| 114 |
+
assert file_data[:3] == b'VXZ', "Invalid file type"
|
| 115 |
+
version = file_data[3]
|
| 116 |
+
assert version == 0, "Invalid file version"
|
| 117 |
+
|
| 118 |
+
bin_start = struct.unpack('>I', file_data[4:8])[0]
|
| 119 |
+
structure_data = json.loads(file_data[8:bin_start].decode())
|
| 120 |
+
return structure_data
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
def read_vxz(file, num_threads: int = -1) -> Union[torch.Tensor, Dict[str, torch.Tensor]]:
|
| 124 |
+
"""
|
| 125 |
+
Read a VXZ file containing voxels.
|
| 126 |
+
|
| 127 |
+
Args:
|
| 128 |
+
file_path: Path or file-like object to the VXZ file.
|
| 129 |
+
num_threads: the number of threads to use for reading the file.
|
| 130 |
+
|
| 131 |
+
Returns:
|
| 132 |
+
torch.Tensor: the coordinates of the voxels.
|
| 133 |
+
Dict[str, torch.Tensor]: the attributes of the voxels.
|
| 134 |
+
"""
|
| 135 |
+
if isinstance(file, str):
|
| 136 |
+
with open(file, 'rb') as f:
|
| 137 |
+
file_data = f.read()
|
| 138 |
+
else:
|
| 139 |
+
file_data = file.read()
|
| 140 |
+
|
| 141 |
+
num_threads = num_threads if num_threads > 0 else os.cpu_count()
|
| 142 |
+
|
| 143 |
+
# Parse header
|
| 144 |
+
assert file_data[:3] == b'VXZ', "Invalid file type"
|
| 145 |
+
version = file_data[3]
|
| 146 |
+
assert version == 0, "Invalid file version"
|
| 147 |
+
|
| 148 |
+
bin_start = struct.unpack('>I', file_data[4:8])[0]
|
| 149 |
+
structure_data = json.loads(file_data[8:bin_start].decode())
|
| 150 |
+
bin_data = file_data[bin_start:]
|
| 151 |
+
|
| 152 |
+
# Decode chunks
|
| 153 |
+
chunk_size = structure_data['chunk_size']
|
| 154 |
+
chunk_depth = np.log2(chunk_size)
|
| 155 |
+
assert chunk_depth.is_integer(), f"Chunk size must be a power of 2, got {chunk_size}"
|
| 156 |
+
chunk_depth = int(chunk_depth)
|
| 157 |
+
|
| 158 |
+
def worker(chunk_info):
|
| 159 |
+
decompressed = {}
|
| 160 |
+
chunk_data = bin_data[chunk_info['ptr'][0]:chunk_info['ptr'][0]+chunk_info['ptr'][1]]
|
| 161 |
+
for k, v in chunk_info.items():
|
| 162 |
+
if k in ['ptr', 'idx']:
|
| 163 |
+
continue
|
| 164 |
+
decompressed[k] = np.frombuffer(_decompress(chunk_data[v[0]:v[0]+v[1]], structure_data['compression'], structure_data['compression_level']), dtype=np.uint8)
|
| 165 |
+
svo = torch.tensor(np.frombuffer(decompressed['svo'], dtype=np.uint8))
|
| 166 |
+
morton_code = _C.decode_sparse_voxel_octree_cpu(svo, chunk_depth)
|
| 167 |
+
coord = decode_seq(morton_code.int()).cpu()
|
| 168 |
+
|
| 169 |
+
# deinterleave attributes
|
| 170 |
+
if structure_data['attr_interleave'] == 'none':
|
| 171 |
+
all_attr = []
|
| 172 |
+
for k, chs in structure_data['attr']:
|
| 173 |
+
for i in range(chs):
|
| 174 |
+
all_attr.append(torch.tensor(decompressed[f'{k}_{i}']))
|
| 175 |
+
all_attr = torch.stack(all_attr, dim=1)
|
| 176 |
+
elif structure_data['attr_interleave'] == 'as_is':
|
| 177 |
+
all_attr = []
|
| 178 |
+
for k, chs in structure_data['attr']:
|
| 179 |
+
all_attr.append(torch.tensor(decompressed[k].reshape(-1, chs)))
|
| 180 |
+
all_attr = torch.cat(all_attr, dim=1)
|
| 181 |
+
elif structure_data['attr_interleave'] == 'all':
|
| 182 |
+
all_chs = sum(chs for k, chs in structure_data['attr'])
|
| 183 |
+
all_attr = decompressed['attr'].reshape(-1, all_chs)
|
| 184 |
+
|
| 185 |
+
# unfilter
|
| 186 |
+
if structure_data['filter'] == 'none':
|
| 187 |
+
pass
|
| 188 |
+
elif structure_data['filter'] == 'parent':
|
| 189 |
+
all_attr = _C.decode_sparse_voxel_octree_attr_parent_cpu(svo, chunk_depth, all_attr)
|
| 190 |
+
elif structure_data['filter'] == 'neighbor':
|
| 191 |
+
all_attr = _C.decode_sparse_voxel_octree_attr_neighbor_cpu(coord, chunk_size, all_attr)
|
| 192 |
+
|
| 193 |
+
# final
|
| 194 |
+
attr = {}
|
| 195 |
+
ch = 0
|
| 196 |
+
for k, chs in structure_data['attr']:
|
| 197 |
+
attr[k] = all_attr[:, ch:ch+chs]
|
| 198 |
+
ch += chs
|
| 199 |
+
return {
|
| 200 |
+
'coord': coord,
|
| 201 |
+
'attr': attr,
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
if num_threads == 1:
|
| 205 |
+
chunks = [worker(info) for info in structure_data['chunks']]
|
| 206 |
+
else:
|
| 207 |
+
with ThreadPoolExecutor(max_workers=num_threads) as executor:
|
| 208 |
+
chunks = list(executor.map(worker, structure_data['chunks']))
|
| 209 |
+
|
| 210 |
+
# Combine chunks
|
| 211 |
+
coord = []
|
| 212 |
+
attr = {k: [] for k, _ in structure_data['attr']}
|
| 213 |
+
for info, chunk in zip(structure_data['chunks'], chunks):
|
| 214 |
+
coord.append(chunk['coord'] + torch.tensor([[info['idx'][0] * chunk_size, info['idx'][1] * chunk_size, info['idx'][2] * chunk_size]]).int())
|
| 215 |
+
for k, v in chunk['attr'].items():
|
| 216 |
+
attr[k].append(v)
|
| 217 |
+
coord = torch.cat(coord, dim=0)
|
| 218 |
+
for k, v in attr.items():
|
| 219 |
+
attr[k] = torch.cat(v, dim=0)
|
| 220 |
+
return coord, attr
|
| 221 |
+
|
| 222 |
+
|
| 223 |
+
def write_vxz(
|
| 224 |
+
file,
|
| 225 |
+
coord: torch.Tensor,
|
| 226 |
+
attr: Dict[str, torch.Tensor],
|
| 227 |
+
chunk_size: int = 256,
|
| 228 |
+
filter: Literal['none', 'parent', 'neighbor'] = 'none',
|
| 229 |
+
compression: Literal['none', 'deflate', 'lzma', 'zstd'] = 'lzma',
|
| 230 |
+
compression_level: Optional[int] = None,
|
| 231 |
+
attr_interleave: Literal['none', 'as_is', 'all'] = 'as_is',
|
| 232 |
+
num_threads: int = -1,
|
| 233 |
+
):
|
| 234 |
+
"""
|
| 235 |
+
Write a VXZ file containing voxels.
|
| 236 |
+
|
| 237 |
+
Args:
|
| 238 |
+
file: Path or file-like object to the VXZ file.
|
| 239 |
+
coord: the coordinates of the voxels.
|
| 240 |
+
attr: the attributes of the voxels.
|
| 241 |
+
chunk_size: the size of each chunk.
|
| 242 |
+
filter: the filter to apply to the voxels.
|
| 243 |
+
compression: the compression algorithm to use.
|
| 244 |
+
compression_level: the level of compression.
|
| 245 |
+
attr_interleave: how to interleave the attributes.
|
| 246 |
+
num_threads: the number of threads to use for compression.
|
| 247 |
+
"""
|
| 248 |
+
# Check
|
| 249 |
+
for k, v in attr.items():
|
| 250 |
+
assert coord.shape[0] == v.shape[0], f"Number of coordinates and attributes do not match for key {k}"
|
| 251 |
+
assert v.dtype == torch.uint8, f"Attributes must be uint8, got {v.dtype} for key {k}"
|
| 252 |
+
assert attr_interleave in ['none', 'as_is', 'all'], f"Invalid attr_interleave value: {attr_interleave}"
|
| 253 |
+
|
| 254 |
+
compression_level = compression_level or DEFAULT_COMPRESION_LEVEL[compression]
|
| 255 |
+
num_threads = num_threads if num_threads > 0 else os.cpu_count()
|
| 256 |
+
|
| 257 |
+
file_info = {
|
| 258 |
+
'num_voxel': coord.shape[0],
|
| 259 |
+
'chunk_size': chunk_size,
|
| 260 |
+
'filter': filter,
|
| 261 |
+
'compression': compression,
|
| 262 |
+
'compression_level': compression_level,
|
| 263 |
+
'raw_size': sum([coord.numel() * 4] + [v.numel() for v in attr.values()]),
|
| 264 |
+
'compressed_size': 0,
|
| 265 |
+
'compress_ratio': 0.0,
|
| 266 |
+
'attr_interleave': attr_interleave,
|
| 267 |
+
'attr': [[k, v.shape[1]] for k, v in attr.items()],
|
| 268 |
+
'chunks': [],
|
| 269 |
+
}
|
| 270 |
+
bin_data = b''
|
| 271 |
+
|
| 272 |
+
# Split into chunks
|
| 273 |
+
chunk_depth = np.log2(chunk_size)
|
| 274 |
+
assert chunk_depth.is_integer(), f"Chunk size must be a power of 2, got {chunk_size}"
|
| 275 |
+
chunk_depth = int(chunk_depth)
|
| 276 |
+
|
| 277 |
+
chunk_coord = coord // chunk_size
|
| 278 |
+
coord = coord % chunk_size
|
| 279 |
+
unique_chunk_coord, inverse = torch.unique(chunk_coord, dim=0, return_inverse=True)
|
| 280 |
+
|
| 281 |
+
chunks = []
|
| 282 |
+
for idx, chunk_xyz in enumerate(unique_chunk_coord.tolist()):
|
| 283 |
+
chunk_mask = (inverse == idx)
|
| 284 |
+
chunks.append({
|
| 285 |
+
'idx': chunk_xyz,
|
| 286 |
+
'coord': coord[chunk_mask],
|
| 287 |
+
'attr': {k: v[chunk_mask] for k, v in attr.items()},
|
| 288 |
+
})
|
| 289 |
+
|
| 290 |
+
# Compress each chunk
|
| 291 |
+
with ThreadPoolExecutor(max_workers=num_threads) as executor:
|
| 292 |
+
def worker(chunk):
|
| 293 |
+
## compress to binary
|
| 294 |
+
coord = chunk['coord']
|
| 295 |
+
morton_code = encode_seq(coord)
|
| 296 |
+
sorted_idx = morton_code.argsort().cpu()
|
| 297 |
+
coord = coord.cpu()[sorted_idx]
|
| 298 |
+
morton_code = morton_code.cpu()[sorted_idx]
|
| 299 |
+
attr = torch.cat([v.cpu()[sorted_idx] for v in chunk['attr'].values()], dim=1)
|
| 300 |
+
svo = _C.encode_sparse_voxel_octree_cpu(morton_code, chunk_depth)
|
| 301 |
+
svo_bytes = _compress(svo.numpy().tobytes(), compression, compression_level)
|
| 302 |
+
|
| 303 |
+
# filter
|
| 304 |
+
if filter == 'none':
|
| 305 |
+
attr = attr.numpy()
|
| 306 |
+
elif filter == 'parent':
|
| 307 |
+
attr = _C.encode_sparse_voxel_octree_attr_parent_cpu(svo, chunk_depth, attr).numpy()
|
| 308 |
+
elif filter == 'neighbor':
|
| 309 |
+
attr = _C.encode_sparse_voxel_octree_attr_neighbor_cpu(coord, chunk_size, attr).numpy()
|
| 310 |
+
|
| 311 |
+
# interleave attributes
|
| 312 |
+
attr_bytes = {}
|
| 313 |
+
if attr_interleave == 'none':
|
| 314 |
+
ch = 0
|
| 315 |
+
for k, chs in file_info['attr']:
|
| 316 |
+
for i in range(chs):
|
| 317 |
+
attr_bytes[f'{k}_{i}'] = _compress(attr[:, ch].tobytes(), compression, compression_level)
|
| 318 |
+
ch += 1
|
| 319 |
+
elif attr_interleave == 'as_is':
|
| 320 |
+
ch = 0
|
| 321 |
+
for k, chs in file_info['attr']:
|
| 322 |
+
attr_bytes[k] = _compress(attr[:, ch:ch+chs].tobytes(), compression, compression_level)
|
| 323 |
+
ch += chs
|
| 324 |
+
elif attr_interleave == 'all':
|
| 325 |
+
attr_bytes['attr'] = _compress(attr.tobytes(), compression, compression_level)
|
| 326 |
+
|
| 327 |
+
## buffer for each chunk
|
| 328 |
+
chunk_info = {'idx': chunk['idx']}
|
| 329 |
+
bin_data = b''
|
| 330 |
+
|
| 331 |
+
### svo
|
| 332 |
+
chunk_info['svo'] = [len(bin_data), len(svo_bytes)]
|
| 333 |
+
bin_data += svo_bytes
|
| 334 |
+
|
| 335 |
+
### attr
|
| 336 |
+
for k, v in attr_bytes.items():
|
| 337 |
+
chunk_info[k] = [len(bin_data), len(v)]
|
| 338 |
+
bin_data += v
|
| 339 |
+
|
| 340 |
+
return chunk_info, bin_data
|
| 341 |
+
|
| 342 |
+
chunks = list(executor.map(worker, chunks))
|
| 343 |
+
|
| 344 |
+
for chunk_info, chunk_data in chunks:
|
| 345 |
+
chunk_info['ptr'] = [len(bin_data), len(chunk_data)]
|
| 346 |
+
bin_data += chunk_data
|
| 347 |
+
file_info['chunks'].append(chunk_info)
|
| 348 |
+
|
| 349 |
+
file_info['compressed_size'] = len(bin_data)
|
| 350 |
+
file_info['compress_ratio'] = file_info['raw_size'] / file_info['compressed_size']
|
| 351 |
+
|
| 352 |
+
# File parts
|
| 353 |
+
structure_data = json.dumps(file_info).encode()
|
| 354 |
+
header = b'VXZ\x00' + struct.pack('>I', len(structure_data) + 8)
|
| 355 |
+
|
| 356 |
+
# Write to file
|
| 357 |
+
if isinstance(file, str):
|
| 358 |
+
with open(file, 'wb') as f:
|
| 359 |
+
f.write(header)
|
| 360 |
+
f.write(structure_data)
|
| 361 |
+
f.write(bin_data)
|
| 362 |
+
else:
|
| 363 |
+
file.write(header)
|
| 364 |
+
file.write(structure_data)
|
| 365 |
+
file.write(bin_data)
|
wheels/TRELLIS.2/o-voxels/build/lib.linux-x86_64-cpython-310/o_voxel/postprocess.py
ADDED
|
@@ -0,0 +1,331 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import *
|
| 2 |
+
from tqdm import tqdm
|
| 3 |
+
import numpy as np
|
| 4 |
+
import torch
|
| 5 |
+
import cv2
|
| 6 |
+
from PIL import Image
|
| 7 |
+
import trimesh
|
| 8 |
+
import trimesh.visual
|
| 9 |
+
from flex_gemm.ops.grid_sample import grid_sample_3d
|
| 10 |
+
import nvdiffrast.torch as dr
|
| 11 |
+
import cumesh
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def to_glb(
|
| 15 |
+
vertices: torch.Tensor,
|
| 16 |
+
faces: torch.Tensor,
|
| 17 |
+
attr_volume: torch.Tensor,
|
| 18 |
+
coords: torch.Tensor,
|
| 19 |
+
attr_layout: Dict[str, slice],
|
| 20 |
+
aabb: Union[list, tuple, np.ndarray, torch.Tensor],
|
| 21 |
+
voxel_size: Union[float, list, tuple, np.ndarray, torch.Tensor] = None,
|
| 22 |
+
grid_size: Union[int, list, tuple, np.ndarray, torch.Tensor] = None,
|
| 23 |
+
decimation_target: int = 1000000,
|
| 24 |
+
texture_size: int = 2048,
|
| 25 |
+
remesh: bool = False,
|
| 26 |
+
remesh_band: float = 1,
|
| 27 |
+
remesh_project: float = 0.9,
|
| 28 |
+
mesh_cluster_threshold_cone_half_angle_rad=np.radians(90.0),
|
| 29 |
+
mesh_cluster_refine_iterations=0,
|
| 30 |
+
mesh_cluster_global_iterations=1,
|
| 31 |
+
mesh_cluster_smooth_strength=1,
|
| 32 |
+
verbose: bool = False,
|
| 33 |
+
use_tqdm: bool = False,
|
| 34 |
+
):
|
| 35 |
+
"""
|
| 36 |
+
Convert an extracted mesh to a GLB file.
|
| 37 |
+
Performs cleaning, optional remeshing, UV unwrapping, and texture baking from a volume.
|
| 38 |
+
|
| 39 |
+
Args:
|
| 40 |
+
vertices: (N, 3) tensor of vertex positions
|
| 41 |
+
faces: (M, 3) tensor of vertex indices
|
| 42 |
+
attr_volume: (L, C) features of a sprase tensor for attribute interpolation
|
| 43 |
+
coords: (L, 3) tensor of coordinates for each voxel
|
| 44 |
+
attr_layout: dictionary of slice objects for each attribute
|
| 45 |
+
aabb: (2, 3) tensor of minimum and maximum coordinates of the volume
|
| 46 |
+
voxel_size: (3,) tensor of size of each voxel
|
| 47 |
+
grid_size: (3,) tensor of number of voxels in each dimension
|
| 48 |
+
decimation_target: target number of vertices for mesh simplification
|
| 49 |
+
texture_size: size of the texture for baking
|
| 50 |
+
remesh: whether to perform remeshing
|
| 51 |
+
remesh_band: size of the remeshing band
|
| 52 |
+
remesh_project: projection factor for remeshing
|
| 53 |
+
mesh_cluster_threshold_cone_half_angle_rad: threshold for cone-based clustering in uv unwrapping
|
| 54 |
+
mesh_cluster_refine_iterations: number of iterations for refining clusters in uv unwrapping
|
| 55 |
+
mesh_cluster_global_iterations: number of global iterations for clustering in uv unwrapping
|
| 56 |
+
mesh_cluster_smooth_strength: strength of smoothing for clustering in uv unwrapping
|
| 57 |
+
verbose: whether to print verbose messages
|
| 58 |
+
use_tqdm: whether to use tqdm to display progress bar
|
| 59 |
+
"""
|
| 60 |
+
# --- Input Normalization (AABB, Voxel Size, Grid Size) ---
|
| 61 |
+
if isinstance(aabb, (list, tuple)):
|
| 62 |
+
aabb = np.array(aabb)
|
| 63 |
+
if isinstance(aabb, np.ndarray):
|
| 64 |
+
aabb = torch.tensor(aabb, dtype=torch.float32, device=coords.device)
|
| 65 |
+
assert isinstance(aabb, torch.Tensor), f"aabb must be a list, tuple, np.ndarray, or torch.Tensor, but got {type(aabb)}"
|
| 66 |
+
assert aabb.dim() == 2, f"aabb must be a 2D tensor, but got {aabb.shape}"
|
| 67 |
+
assert aabb.size(0) == 2, f"aabb must have 2 rows, but got {aabb.size(0)}"
|
| 68 |
+
assert aabb.size(1) == 3, f"aabb must have 3 columns, but got {aabb.size(1)}"
|
| 69 |
+
|
| 70 |
+
# Calculate grid dimensions based on AABB and voxel size
|
| 71 |
+
if voxel_size is not None:
|
| 72 |
+
if isinstance(voxel_size, float):
|
| 73 |
+
voxel_size = [voxel_size, voxel_size, voxel_size]
|
| 74 |
+
if isinstance(voxel_size, (list, tuple)):
|
| 75 |
+
voxel_size = np.array(voxel_size)
|
| 76 |
+
if isinstance(voxel_size, np.ndarray):
|
| 77 |
+
voxel_size = torch.tensor(voxel_size, dtype=torch.float32, device=coords.device)
|
| 78 |
+
grid_size = ((aabb[1] - aabb[0]) / voxel_size).round().int()
|
| 79 |
+
else:
|
| 80 |
+
assert grid_size is not None, "Either voxel_size or grid_size must be provided"
|
| 81 |
+
if isinstance(grid_size, int):
|
| 82 |
+
grid_size = [grid_size, grid_size, grid_size]
|
| 83 |
+
if isinstance(grid_size, (list, tuple)):
|
| 84 |
+
grid_size = np.array(grid_size)
|
| 85 |
+
if isinstance(grid_size, np.ndarray):
|
| 86 |
+
grid_size = torch.tensor(grid_size, dtype=torch.int32, device=coords.device)
|
| 87 |
+
voxel_size = (aabb[1] - aabb[0]) / grid_size
|
| 88 |
+
|
| 89 |
+
# Assertions for dimensions
|
| 90 |
+
assert isinstance(voxel_size, torch.Tensor)
|
| 91 |
+
assert voxel_size.dim() == 1 and voxel_size.size(0) == 3
|
| 92 |
+
assert isinstance(grid_size, torch.Tensor)
|
| 93 |
+
assert grid_size.dim() == 1 and grid_size.size(0) == 3
|
| 94 |
+
|
| 95 |
+
if use_tqdm:
|
| 96 |
+
pbar = tqdm(total=6, desc="Extracting GLB")
|
| 97 |
+
if verbose:
|
| 98 |
+
print(f"Original mesh: {vertices.shape[0]} vertices, {faces.shape[0]} faces")
|
| 99 |
+
|
| 100 |
+
# Move data to GPU
|
| 101 |
+
vertices = vertices.cuda()
|
| 102 |
+
faces = faces.cuda()
|
| 103 |
+
|
| 104 |
+
# Initialize CUDA mesh handler
|
| 105 |
+
mesh = cumesh.CuMesh()
|
| 106 |
+
mesh.init(vertices, faces)
|
| 107 |
+
|
| 108 |
+
# --- Initial Mesh Cleaning ---
|
| 109 |
+
# Fills holes as much as we can before processing
|
| 110 |
+
mesh.fill_holes(max_hole_perimeter=3e-2)
|
| 111 |
+
if verbose:
|
| 112 |
+
print(f"After filling holes: {mesh.num_vertices} vertices, {mesh.num_faces} faces")
|
| 113 |
+
vertices, faces = mesh.read()
|
| 114 |
+
if use_tqdm:
|
| 115 |
+
pbar.update(1)
|
| 116 |
+
|
| 117 |
+
# Build BVH for the current mesh to guide remeshing
|
| 118 |
+
if use_tqdm:
|
| 119 |
+
pbar.set_description("Building BVH")
|
| 120 |
+
if verbose:
|
| 121 |
+
print(f"Building BVH for current mesh...", end='', flush=True)
|
| 122 |
+
bvh = cumesh.cuBVH(vertices, faces)
|
| 123 |
+
if use_tqdm:
|
| 124 |
+
pbar.update(1)
|
| 125 |
+
if verbose:
|
| 126 |
+
print("Done")
|
| 127 |
+
|
| 128 |
+
if use_tqdm:
|
| 129 |
+
pbar.set_description("Cleaning mesh")
|
| 130 |
+
if verbose:
|
| 131 |
+
print("Cleaning mesh...")
|
| 132 |
+
|
| 133 |
+
# --- Branch 1: Standard Pipeline (Simplification & Cleaning) ---
|
| 134 |
+
if not remesh:
|
| 135 |
+
# Step 1: Aggressive simplification (3x target)
|
| 136 |
+
mesh.simplify(decimation_target * 3, verbose=verbose)
|
| 137 |
+
if verbose:
|
| 138 |
+
print(f"After inital simplification: {mesh.num_vertices} vertices, {mesh.num_faces} faces")
|
| 139 |
+
|
| 140 |
+
# Step 2: Clean up topology (duplicates, non-manifolds, isolated parts)
|
| 141 |
+
mesh.remove_duplicate_faces()
|
| 142 |
+
mesh.repair_non_manifold_edges()
|
| 143 |
+
mesh.remove_small_connected_components(1e-5)
|
| 144 |
+
mesh.fill_holes(max_hole_perimeter=3e-2)
|
| 145 |
+
if verbose:
|
| 146 |
+
print(f"After initial cleanup: {mesh.num_vertices} vertices, {mesh.num_faces} faces")
|
| 147 |
+
|
| 148 |
+
# Step 3: Final simplification to target count
|
| 149 |
+
mesh.simplify(decimation_target, verbose=verbose)
|
| 150 |
+
if verbose:
|
| 151 |
+
print(f"After final simplification: {mesh.num_vertices} vertices, {mesh.num_faces} faces")
|
| 152 |
+
|
| 153 |
+
# Step 4: Final Cleanup loop
|
| 154 |
+
mesh.remove_duplicate_faces()
|
| 155 |
+
mesh.repair_non_manifold_edges()
|
| 156 |
+
mesh.remove_small_connected_components(1e-5)
|
| 157 |
+
mesh.fill_holes(max_hole_perimeter=3e-2)
|
| 158 |
+
if verbose:
|
| 159 |
+
print(f"After final cleanup: {mesh.num_vertices} vertices, {mesh.num_faces} faces")
|
| 160 |
+
|
| 161 |
+
# Step 5: Unify face orientations
|
| 162 |
+
mesh.unify_face_orientations()
|
| 163 |
+
|
| 164 |
+
# --- Branch 2: Remeshing Pipeline ---
|
| 165 |
+
else:
|
| 166 |
+
center = aabb.mean(dim=0)
|
| 167 |
+
scale = (aabb[1] - aabb[0]).max().item()
|
| 168 |
+
resolution = grid_size.max().item()
|
| 169 |
+
|
| 170 |
+
# Perform Dual Contouring remeshing (rebuilds topology)
|
| 171 |
+
mesh.init(*cumesh.remeshing.remesh_narrow_band_dc(
|
| 172 |
+
vertices, faces,
|
| 173 |
+
center = center,
|
| 174 |
+
scale = (resolution + 3 * remesh_band) / resolution * scale,
|
| 175 |
+
resolution = resolution,
|
| 176 |
+
band = remesh_band,
|
| 177 |
+
project_back = remesh_project, # Snaps vertices back to original surface
|
| 178 |
+
verbose = verbose,
|
| 179 |
+
bvh = bvh,
|
| 180 |
+
))
|
| 181 |
+
if verbose:
|
| 182 |
+
print(f"After remeshing: {mesh.num_vertices} vertices, {mesh.num_faces} faces")
|
| 183 |
+
|
| 184 |
+
# Simplify and clean the remeshed result (similar logic to above)
|
| 185 |
+
mesh.simplify(decimation_target, verbose=verbose)
|
| 186 |
+
if verbose:
|
| 187 |
+
print(f"After simplifying: {mesh.num_vertices} vertices, {mesh.num_faces} faces")
|
| 188 |
+
|
| 189 |
+
if use_tqdm:
|
| 190 |
+
pbar.update(1)
|
| 191 |
+
if verbose:
|
| 192 |
+
print("Done")
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
# --- UV Parameterization ---
|
| 196 |
+
if use_tqdm:
|
| 197 |
+
pbar.set_description("Parameterizing new mesh")
|
| 198 |
+
if verbose:
|
| 199 |
+
print("Parameterizing new mesh...")
|
| 200 |
+
|
| 201 |
+
out_vertices, out_faces, out_uvs, out_vmaps = mesh.uv_unwrap(
|
| 202 |
+
compute_charts_kwargs={
|
| 203 |
+
"threshold_cone_half_angle_rad": mesh_cluster_threshold_cone_half_angle_rad,
|
| 204 |
+
"refine_iterations": mesh_cluster_refine_iterations,
|
| 205 |
+
"global_iterations": mesh_cluster_global_iterations,
|
| 206 |
+
"smooth_strength": mesh_cluster_smooth_strength,
|
| 207 |
+
},
|
| 208 |
+
return_vmaps=True,
|
| 209 |
+
verbose=verbose,
|
| 210 |
+
)
|
| 211 |
+
out_vertices = out_vertices.cuda()
|
| 212 |
+
out_faces = out_faces.cuda()
|
| 213 |
+
out_uvs = out_uvs.cuda()
|
| 214 |
+
out_vmaps = out_vmaps.cuda()
|
| 215 |
+
mesh.compute_vertex_normals()
|
| 216 |
+
out_normals = mesh.read_vertex_normals()[out_vmaps]
|
| 217 |
+
|
| 218 |
+
if use_tqdm:
|
| 219 |
+
pbar.update(1)
|
| 220 |
+
if verbose:
|
| 221 |
+
print("Done")
|
| 222 |
+
|
| 223 |
+
# --- Texture Baking (Attribute Sampling) ---
|
| 224 |
+
if use_tqdm:
|
| 225 |
+
pbar.set_description("Sampling attributes")
|
| 226 |
+
if verbose:
|
| 227 |
+
print("Sampling attributes...", end='', flush=True)
|
| 228 |
+
|
| 229 |
+
# Setup differentiable rasterizer context
|
| 230 |
+
ctx = dr.RasterizeCudaContext()
|
| 231 |
+
# Prepare UV coordinates for rasterization (rendering in UV space)
|
| 232 |
+
uvs_rast = torch.cat([out_uvs * 2 - 1, torch.zeros_like(out_uvs[:, :1]), torch.ones_like(out_uvs[:, :1])], dim=-1).unsqueeze(0)
|
| 233 |
+
rast = torch.zeros((1, texture_size, texture_size, 4), device='cuda', dtype=torch.float32)
|
| 234 |
+
|
| 235 |
+
# Rasterize in chunks to save memory
|
| 236 |
+
for i in range(0, out_faces.shape[0], 100000):
|
| 237 |
+
rast_chunk, _ = dr.rasterize(
|
| 238 |
+
ctx, uvs_rast, out_faces[i:i+100000],
|
| 239 |
+
resolution=[texture_size, texture_size],
|
| 240 |
+
)
|
| 241 |
+
mask_chunk = rast_chunk[..., 3:4] > 0
|
| 242 |
+
rast_chunk[..., 3:4] += i # Store face ID in alpha channel
|
| 243 |
+
rast = torch.where(mask_chunk, rast_chunk, rast)
|
| 244 |
+
|
| 245 |
+
# Mask of valid pixels in texture
|
| 246 |
+
mask = rast[0, ..., 3] > 0
|
| 247 |
+
|
| 248 |
+
# Interpolate 3D positions in UV space (finding 3D coord for every texel)
|
| 249 |
+
pos = dr.interpolate(out_vertices.unsqueeze(0), rast, out_faces)[0][0]
|
| 250 |
+
valid_pos = pos[mask]
|
| 251 |
+
|
| 252 |
+
# Map these positions back to the *original* high-res mesh to get accurate attributes
|
| 253 |
+
# This corrects geometric errors introduced by simplification/remeshing
|
| 254 |
+
_, face_id, uvw = bvh.unsigned_distance(valid_pos, return_uvw=True)
|
| 255 |
+
orig_tri_verts = vertices[faces[face_id.long()]] # (N_new, 3, 3)
|
| 256 |
+
valid_pos = (orig_tri_verts * uvw.unsqueeze(-1)).sum(dim=1)
|
| 257 |
+
|
| 258 |
+
# Trilinear sampling from the attribute volume (Color, Material props)
|
| 259 |
+
attrs = torch.zeros(texture_size, texture_size, attr_volume.shape[1], device='cuda')
|
| 260 |
+
attrs[mask] = grid_sample_3d(
|
| 261 |
+
attr_volume,
|
| 262 |
+
torch.cat([torch.zeros_like(coords[:, :1]), coords], dim=-1),
|
| 263 |
+
shape=torch.Size([1, attr_volume.shape[1], *grid_size.tolist()]),
|
| 264 |
+
grid=((valid_pos - aabb[0]) / voxel_size).reshape(1, -1, 3),
|
| 265 |
+
mode='trilinear',
|
| 266 |
+
)
|
| 267 |
+
if use_tqdm:
|
| 268 |
+
pbar.update(1)
|
| 269 |
+
if verbose:
|
| 270 |
+
print("Done")
|
| 271 |
+
|
| 272 |
+
# --- Texture Post-Processing & Material Construction ---
|
| 273 |
+
if use_tqdm:
|
| 274 |
+
pbar.set_description("Finalizing mesh")
|
| 275 |
+
if verbose:
|
| 276 |
+
print("Finalizing mesh...", end='', flush=True)
|
| 277 |
+
|
| 278 |
+
mask = mask.cpu().numpy()
|
| 279 |
+
|
| 280 |
+
# Extract channels based on layout (BaseColor, Metallic, Roughness, Alpha)
|
| 281 |
+
base_color = np.clip(attrs[..., attr_layout['base_color']].cpu().numpy() * 255, 0, 255).astype(np.uint8)
|
| 282 |
+
metallic = np.clip(attrs[..., attr_layout['metallic']].cpu().numpy() * 255, 0, 255).astype(np.uint8)
|
| 283 |
+
roughness = np.clip(attrs[..., attr_layout['roughness']].cpu().numpy() * 255, 0, 255).astype(np.uint8)
|
| 284 |
+
alpha = np.clip(attrs[..., attr_layout['alpha']].cpu().numpy() * 255, 0, 255).astype(np.uint8)
|
| 285 |
+
alpha_mode = 'OPAQUE'
|
| 286 |
+
|
| 287 |
+
# Inpainting: fill gaps (dilation) to prevent black seams at UV boundaries
|
| 288 |
+
mask_inv = (~mask).astype(np.uint8)
|
| 289 |
+
base_color = cv2.inpaint(base_color, mask_inv, 3, cv2.INPAINT_TELEA)
|
| 290 |
+
metallic = cv2.inpaint(metallic, mask_inv, 1, cv2.INPAINT_TELEA)[..., None]
|
| 291 |
+
roughness = cv2.inpaint(roughness, mask_inv, 1, cv2.INPAINT_TELEA)[..., None]
|
| 292 |
+
alpha = cv2.inpaint(alpha, mask_inv, 1, cv2.INPAINT_TELEA)[..., None]
|
| 293 |
+
|
| 294 |
+
# Create PBR material
|
| 295 |
+
# Standard PBR packs Metallic and Roughness into Blue and Green channels
|
| 296 |
+
material = trimesh.visual.material.PBRMaterial(
|
| 297 |
+
baseColorTexture=Image.fromarray(np.concatenate([base_color, alpha], axis=-1)),
|
| 298 |
+
baseColorFactor=np.array([255, 255, 255, 255], dtype=np.uint8),
|
| 299 |
+
metallicRoughnessTexture=Image.fromarray(np.concatenate([np.zeros_like(metallic), roughness, metallic], axis=-1)),
|
| 300 |
+
metallicFactor=1.0,
|
| 301 |
+
roughnessFactor=1.0,
|
| 302 |
+
alphaMode=alpha_mode,
|
| 303 |
+
doubleSided=True if not remesh else False,
|
| 304 |
+
)
|
| 305 |
+
|
| 306 |
+
# --- Coordinate System Conversion & Final Object ---
|
| 307 |
+
vertices_np = out_vertices.cpu().numpy()
|
| 308 |
+
faces_np = out_faces.cpu().numpy()
|
| 309 |
+
uvs_np = out_uvs.cpu().numpy()
|
| 310 |
+
normals_np = out_normals.cpu().numpy()
|
| 311 |
+
|
| 312 |
+
# Swap Y and Z axes, invert Y (common conversion for GLB compatibility)
|
| 313 |
+
vertices_np[:, 1], vertices_np[:, 2] = vertices_np[:, 2], -vertices_np[:, 1]
|
| 314 |
+
normals_np[:, 1], normals_np[:, 2] = normals_np[:, 2], -normals_np[:, 1]
|
| 315 |
+
uvs_np[:, 1] = 1 - uvs_np[:, 1] # Flip UV V-coordinate
|
| 316 |
+
|
| 317 |
+
textured_mesh = trimesh.Trimesh(
|
| 318 |
+
vertices=vertices_np,
|
| 319 |
+
faces=faces_np,
|
| 320 |
+
vertex_normals=normals_np,
|
| 321 |
+
process=False,
|
| 322 |
+
visual=trimesh.visual.TextureVisuals(uv=uvs_np, material=material)
|
| 323 |
+
)
|
| 324 |
+
|
| 325 |
+
if use_tqdm:
|
| 326 |
+
pbar.update(1)
|
| 327 |
+
pbar.close()
|
| 328 |
+
if verbose:
|
| 329 |
+
print("Done")
|
| 330 |
+
|
| 331 |
+
return textured_mesh
|
wheels/TRELLIS.2/o-voxels/build/lib.linux-x86_64-cpython-310/o_voxel/rasterize.py
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import torch.nn.functional as F
|
| 3 |
+
from easydict import EasyDict as edict
|
| 4 |
+
from . import _C
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def intrinsics_to_projection(
|
| 8 |
+
intrinsics: torch.Tensor,
|
| 9 |
+
near: float,
|
| 10 |
+
far: float,
|
| 11 |
+
) -> torch.Tensor:
|
| 12 |
+
"""
|
| 13 |
+
OpenCV intrinsics to OpenGL perspective matrix
|
| 14 |
+
|
| 15 |
+
Args:
|
| 16 |
+
intrinsics (torch.Tensor): [3, 3] OpenCV intrinsics matrix
|
| 17 |
+
near (float): near plane to clip
|
| 18 |
+
far (float): far plane to clip
|
| 19 |
+
Returns:
|
| 20 |
+
(torch.Tensor): [4, 4] OpenGL perspective matrix
|
| 21 |
+
"""
|
| 22 |
+
fx, fy = intrinsics[0, 0], intrinsics[1, 1]
|
| 23 |
+
cx, cy = intrinsics[0, 2], intrinsics[1, 2]
|
| 24 |
+
ret = torch.zeros((4, 4), dtype=intrinsics.dtype, device=intrinsics.device)
|
| 25 |
+
ret[0, 0] = 2 * fx
|
| 26 |
+
ret[1, 1] = 2 * fy
|
| 27 |
+
ret[0, 2] = 2 * cx - 1
|
| 28 |
+
ret[1, 2] = - 2 * cy + 1
|
| 29 |
+
ret[2, 2] = far / (far - near)
|
| 30 |
+
ret[2, 3] = near * far / (near - far)
|
| 31 |
+
ret[3, 2] = 1.
|
| 32 |
+
return ret
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
class VoxelRenderer:
|
| 36 |
+
"""
|
| 37 |
+
Renderer for the Voxel representation.
|
| 38 |
+
|
| 39 |
+
Args:
|
| 40 |
+
rendering_options (dict): Rendering options.
|
| 41 |
+
"""
|
| 42 |
+
|
| 43 |
+
def __init__(self, rendering_options={}) -> None:
|
| 44 |
+
self.rendering_options = edict({
|
| 45 |
+
"resolution": None,
|
| 46 |
+
"near": 0.1,
|
| 47 |
+
"far": 10.0,
|
| 48 |
+
"ssaa": 1,
|
| 49 |
+
})
|
| 50 |
+
self.rendering_options.update(rendering_options)
|
| 51 |
+
|
| 52 |
+
def render(
|
| 53 |
+
self,
|
| 54 |
+
position: torch.Tensor,
|
| 55 |
+
attrs: torch.Tensor,
|
| 56 |
+
voxel_size: float,
|
| 57 |
+
extrinsics: torch.Tensor,
|
| 58 |
+
intrinsics: torch.Tensor,
|
| 59 |
+
) -> edict:
|
| 60 |
+
"""
|
| 61 |
+
Render the octree.
|
| 62 |
+
|
| 63 |
+
Args:
|
| 64 |
+
position (torch.Tensor): (N, 3) xyz positions
|
| 65 |
+
attrs (torch.Tensor): (N, C) attributes
|
| 66 |
+
voxel_size (float): voxel size
|
| 67 |
+
extrinsics (torch.Tensor): (4, 4) camera extrinsics
|
| 68 |
+
intrinsics (torch.Tensor): (3, 3) camera intrinsics
|
| 69 |
+
|
| 70 |
+
Returns:
|
| 71 |
+
edict containing:
|
| 72 |
+
attr (torch.Tensor): (C, H, W) rendered color
|
| 73 |
+
depth (torch.Tensor): (H, W) rendered depth
|
| 74 |
+
alpha (torch.Tensor): (H, W) rendered alpha
|
| 75 |
+
"""
|
| 76 |
+
resolution = self.rendering_options["resolution"]
|
| 77 |
+
near = self.rendering_options["near"]
|
| 78 |
+
far = self.rendering_options["far"]
|
| 79 |
+
ssaa = self.rendering_options["ssaa"]
|
| 80 |
+
|
| 81 |
+
view = extrinsics
|
| 82 |
+
perspective = intrinsics_to_projection(intrinsics, near, far)
|
| 83 |
+
camera = torch.inverse(view)[:3, 3]
|
| 84 |
+
focalx = intrinsics[0, 0]
|
| 85 |
+
focaly = intrinsics[1, 1]
|
| 86 |
+
args = (
|
| 87 |
+
position,
|
| 88 |
+
attrs,
|
| 89 |
+
voxel_size,
|
| 90 |
+
view.T.contiguous(),
|
| 91 |
+
(perspective @ view).T.contiguous(),
|
| 92 |
+
camera,
|
| 93 |
+
0.5 / focalx,
|
| 94 |
+
0.5 / focaly,
|
| 95 |
+
resolution * ssaa,
|
| 96 |
+
resolution * ssaa,
|
| 97 |
+
)
|
| 98 |
+
color, depth, alpha = _C.rasterize_voxels_cuda(*args)
|
| 99 |
+
|
| 100 |
+
if ssaa > 1:
|
| 101 |
+
color = F.interpolate(color[None], size=(resolution, resolution), mode='bilinear', align_corners=False, antialias=True).squeeze()
|
| 102 |
+
depth = F.interpolate(depth[None, None], size=(resolution, resolution), mode='bilinear', align_corners=False, antialias=True).squeeze()
|
| 103 |
+
alpha = F.interpolate(alpha[None, None], size=(resolution, resolution), mode='bilinear', align_corners=False, antialias=True).squeeze()
|
| 104 |
+
|
| 105 |
+
ret = edict({
|
| 106 |
+
'attr': color,
|
| 107 |
+
'depth': depth,
|
| 108 |
+
'alpha': alpha,
|
| 109 |
+
})
|
| 110 |
+
return ret
|
| 111 |
+
|
wheels/TRELLIS.2/o-voxels/build/lib.linux-x86_64-cpython-310/o_voxel/serialize.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import *
|
| 2 |
+
import torch
|
| 3 |
+
from . import _C
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
@torch.no_grad()
|
| 7 |
+
def encode_seq(coords: torch.Tensor, permute: List[int] = [0, 1, 2], mode: Literal['z_order', 'hilbert'] = 'z_order') -> torch.Tensor:
|
| 8 |
+
"""
|
| 9 |
+
Encodes 3D coordinates into a 30-bit code.
|
| 10 |
+
|
| 11 |
+
Args:
|
| 12 |
+
coords: a tensor of shape [N, 3] containing the 3D coordinates.
|
| 13 |
+
permute: the permutation of the coordinates.
|
| 14 |
+
mode: the encoding mode to use.
|
| 15 |
+
"""
|
| 16 |
+
assert coords.shape[-1] == 3 and coords.ndim == 2, "Input coordinates must be of shape [N, 3]"
|
| 17 |
+
x = coords[:, permute[0]].int()
|
| 18 |
+
y = coords[:, permute[1]].int()
|
| 19 |
+
z = coords[:, permute[2]].int()
|
| 20 |
+
if mode == 'z_order':
|
| 21 |
+
if coords.device.type == 'cpu':
|
| 22 |
+
return _C.z_order_encode_cpu(x, y, z)
|
| 23 |
+
elif coords.device.type == 'cuda':
|
| 24 |
+
return _C.z_order_encode_cuda(x, y, z)
|
| 25 |
+
else:
|
| 26 |
+
raise ValueError(f"Unsupported device type: {coords.device.type}")
|
| 27 |
+
elif mode == 'hilbert':
|
| 28 |
+
if coords.device.type == 'cpu':
|
| 29 |
+
return _C.hilbert_encode_cpu(x, y, z)
|
| 30 |
+
elif coords.device.type == 'cuda':
|
| 31 |
+
return _C.hilbert_encode_cuda(x, y, z)
|
| 32 |
+
else:
|
| 33 |
+
raise ValueError(f"Unsupported device type: {coords.device.type}")
|
| 34 |
+
else:
|
| 35 |
+
raise ValueError(f"Unknown encoding mode: {mode}")
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
@torch.no_grad()
|
| 39 |
+
def decode_seq(code: torch.Tensor, permute: List[int] = [0, 1, 2], mode: Literal['z_order', 'hilbert'] = 'z_order') -> torch.Tensor:
|
| 40 |
+
"""
|
| 41 |
+
Decodes a 30-bit code into 3D coordinates.
|
| 42 |
+
|
| 43 |
+
Args:
|
| 44 |
+
code: a tensor of shape [N] containing the 30-bit code.
|
| 45 |
+
permute: the permutation of the coordinates.
|
| 46 |
+
mode: the decoding mode to use.
|
| 47 |
+
"""
|
| 48 |
+
assert code.ndim == 1, "Input code must be of shape [N]"
|
| 49 |
+
if mode == 'z_order':
|
| 50 |
+
if code.device.type == 'cpu':
|
| 51 |
+
coords = _C.z_order_decode_cpu(code)
|
| 52 |
+
elif code.device.type == 'cuda':
|
| 53 |
+
coords = _C.z_order_decode_cuda(code)
|
| 54 |
+
else:
|
| 55 |
+
raise ValueError(f"Unsupported device type: {code.device.type}")
|
| 56 |
+
elif mode == 'hilbert':
|
| 57 |
+
if code.device.type == 'cpu':
|
| 58 |
+
coords = _C.hilbert_decode_cpu(code)
|
| 59 |
+
elif code.device.type == 'cuda':
|
| 60 |
+
coords = _C.hilbert_decode_cuda(code)
|
| 61 |
+
else:
|
| 62 |
+
raise ValueError(f"Unsupported device type: {code.device.type}")
|
| 63 |
+
else:
|
| 64 |
+
raise ValueError(f"Unknown decoding mode: {mode}")
|
| 65 |
+
x = coords[permute.index(0)]
|
| 66 |
+
y = coords[permute.index(1)]
|
| 67 |
+
z = coords[permute.index(2)]
|
| 68 |
+
return torch.stack([x, y, z], dim=-1)
|
wheels/TRELLIS.2/o-voxels/build/temp.linux-x86_64-cpython-310/.ninja_deps
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6cae8fc7cb7f5636134007f6c9c91f0c2ece68d03d1567a0327487f97b652a23
|
| 3 |
+
size 1057872
|
wheels/TRELLIS.2/o-voxels/build/temp.linux-x86_64-cpython-310/.ninja_log
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ninja log v7
|
| 2 |
+
7 3238 1773840242496575199 /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/build/temp.linux-x86_64-cpython-310/src/serialize/hilbert.o 620d04f51ea188c6
|
| 3 |
+
8 3250 1773840242497575207 /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/build/temp.linux-x86_64-cpython-310/src/serialize/z_order.o 7b7fac2eb5a036d1
|
| 4 |
+
6 26401 1773840242495575192 /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/build/temp.linux-x86_64-cpython-310/src/io/svo.o 8d261fa7e3f60ca8
|
| 5 |
+
6 26485 1773840242495575192 /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/build/temp.linux-x86_64-cpython-310/src/io/filter_parent.o eb54ec7936105d11
|
| 6 |
+
6 27338 1773840242495575192 /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/build/temp.linux-x86_64-cpython-310/src/io/filter_neighbor.o e88f010a31580857
|
| 7 |
+
5 27442 1773840242494575185 /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/build/temp.linux-x86_64-cpython-310/src/ext.o dce684efc2e5d24c
|
| 8 |
+
4 29760 1773840242493575177 /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/build/temp.linux-x86_64-cpython-310/src/convert/volumetic_attr.o 2348c129208ac18d
|
| 9 |
+
3 39725 1773840242493648893 /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/build/temp.linux-x86_64-cpython-310/src/convert/flexible_dual_grid.o 26466d7700cd4124
|
| 10 |
+
7 61383 1773840242496575199 /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/build/temp.linux-x86_64-cpython-310/src/rasterize/rasterize.o e7bfe8d84331d55c
|
| 11 |
+
5 61977 1773840242494575185 /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/build/temp.linux-x86_64-cpython-310/src/hash/hash.o 51b59d781ec49627
|
| 12 |
+
7 62176 1773840242496575199 /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/build/temp.linux-x86_64-cpython-310/src/serialize/api.o 513b59da1fd57a99
|
| 13 |
+
124 2821 1773840767538526413 /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/build/temp.linux-x86_64-cpython-310/src/serialize/z_order.o 567b15870b530455
|
| 14 |
+
124 2891 1773840767537526406 /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/build/temp.linux-x86_64-cpython-310/src/serialize/hilbert.o 504223559c5d990d
|
| 15 |
+
118 20544 1773840767531526360 /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/build/temp.linux-x86_64-cpython-310/src/io/svo.o 7c128174a875bf27
|
| 16 |
+
117 20896 1773840767530526352 /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/build/temp.linux-x86_64-cpython-310/src/io/filter_parent.o e5468b5c5ecd556e
|
| 17 |
+
117 22254 1773840767530526352 /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/build/temp.linux-x86_64-cpython-310/src/io/filter_neighbor.o 491bb1aef67b902b
|
| 18 |
+
116 22401 1773840767529526345 /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/build/temp.linux-x86_64-cpython-310/src/ext.o 7d9f58682fc34f85
|
| 19 |
+
114 24134 1773840767528526337 /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/build/temp.linux-x86_64-cpython-310/src/convert/volumetic_attr.o b48d576157aafe9e
|
| 20 |
+
110 33552 1773840767523526299 /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/build/temp.linux-x86_64-cpython-310/src/convert/flexible_dual_grid.o 2f6b716cc8963ec9
|
| 21 |
+
116 58234 1773840767529526345 /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/build/temp.linux-x86_64-cpython-310/src/hash/hash.o 48398252ff629909
|
| 22 |
+
119 60777 1773840767532526368 /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/build/temp.linux-x86_64-cpython-310/src/rasterize/rasterize.o 7a3fcb3ac7f29257
|
| 23 |
+
120 63914 1773840767533526375 /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/build/temp.linux-x86_64-cpython-310/src/serialize/api.o 65fc2b366ce7b131
|
wheels/TRELLIS.2/o-voxels/build/temp.linux-x86_64-cpython-310/build.ninja
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
ninja_required_version = 1.3
|
| 2 |
+
cxx = c++
|
| 3 |
+
nvcc = /usr/local/cuda/bin/nvcc
|
| 4 |
+
|
| 5 |
+
cflags = -pthread -B /root/miniconda3/envs/reconviagen/compiler_compat -Wno-unused-result -Wsign-compare -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /root/miniconda3/envs/reconviagen/include -fPIC -O2 -isystem /root/miniconda3/envs/reconviagen/include -fPIC -I/root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/third_party/eigen -I/root/miniconda3/envs/reconviagen/lib/python3.10/site-packages/torch/include -I/root/miniconda3/envs/reconviagen/lib/python3.10/site-packages/torch/include/torch/csrc/api/include -I/usr/local/cuda/include -I/root/miniconda3/envs/reconviagen/include/python3.10 -c
|
| 6 |
+
post_cflags = -O3 -std=c++17 -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=_C
|
| 7 |
+
cuda_cflags = -I/root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/third_party/eigen -I/root/miniconda3/envs/reconviagen/lib/python3.10/site-packages/torch/include -I/root/miniconda3/envs/reconviagen/lib/python3.10/site-packages/torch/include/torch/csrc/api/include -I/usr/local/cuda/include -I/root/miniconda3/envs/reconviagen/include/python3.10 -c
|
| 8 |
+
cuda_post_cflags = -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_BFLOAT16_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ --expt-relaxed-constexpr --compiler-options ''"'"'-fPIC'"'"'' -O3 -std=c++17 -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=_C -gencode=arch=compute_90,code=compute_90 -gencode=arch=compute_90,code=sm_90
|
| 9 |
+
cuda_dlink_post_cflags =
|
| 10 |
+
sycl_dlink_post_cflags =
|
| 11 |
+
ldflags =
|
| 12 |
+
|
| 13 |
+
rule compile
|
| 14 |
+
command = $cxx -MMD -MF $out.d $cflags -c $in -o $out $post_cflags
|
| 15 |
+
depfile = $out.d
|
| 16 |
+
deps = gcc
|
| 17 |
+
|
| 18 |
+
rule cuda_compile
|
| 19 |
+
depfile = $out.d
|
| 20 |
+
deps = gcc
|
| 21 |
+
command = $nvcc --generate-dependencies-with-compile --dependency-output $out.d $cuda_cflags -c $in -o $out $cuda_post_cflags
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
build /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/build/temp.linux-x86_64-cpython-310/src/convert/flexible_dual_grid.o: compile /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/src/convert/flexible_dual_grid.cpp
|
| 30 |
+
build /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/build/temp.linux-x86_64-cpython-310/src/convert/volumetic_attr.o: compile /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/src/convert/volumetic_attr.cpp
|
| 31 |
+
build /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/build/temp.linux-x86_64-cpython-310/src/ext.o: compile /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/src/ext.cpp
|
| 32 |
+
build /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/build/temp.linux-x86_64-cpython-310/src/hash/hash.o: cuda_compile /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/src/hash/hash.cu
|
| 33 |
+
build /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/build/temp.linux-x86_64-cpython-310/src/io/filter_neighbor.o: compile /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/src/io/filter_neighbor.cpp
|
| 34 |
+
build /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/build/temp.linux-x86_64-cpython-310/src/io/filter_parent.o: compile /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/src/io/filter_parent.cpp
|
| 35 |
+
build /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/build/temp.linux-x86_64-cpython-310/src/io/svo.o: compile /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/src/io/svo.cpp
|
| 36 |
+
build /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/build/temp.linux-x86_64-cpython-310/src/rasterize/rasterize.o: cuda_compile /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/src/rasterize/rasterize.cu
|
| 37 |
+
build /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/build/temp.linux-x86_64-cpython-310/src/serialize/api.o: cuda_compile /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/src/serialize/api.cu
|
| 38 |
+
build /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/build/temp.linux-x86_64-cpython-310/src/serialize/hilbert.o: cuda_compile /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/src/serialize/hilbert.cu
|
| 39 |
+
build /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/build/temp.linux-x86_64-cpython-310/src/serialize/z_order.o: cuda_compile /root/jiahao/code/ReconViaGen/wheels/TRELLIS.2/o-voxel/src/serialize/z_order.cu
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
|
wheels/TRELLIS.2/o-voxels/build/temp.linux-x86_64-cpython-310/src/convert/flexible_dual_grid.o
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d9bc5e1f32cef608d8a3aecc562f9578e9a5ba8e1ec76fcf8bd68e4cb69651cd
|
| 3 |
+
size 363720
|
wheels/TRELLIS.2/o-voxels/build/temp.linux-x86_64-cpython-310/src/convert/volumetic_attr.o
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0f163de1a412bab1e7607a74b0893e67ae5f426fd522a6154b05bf630e6e9111
|
| 3 |
+
size 343736
|
wheels/TRELLIS.2/o-voxels/build/temp.linux-x86_64-cpython-310/src/ext.o
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:285425db609d3550e231ef5db730c0fd9e16751f9c5c5174622fb65e8f7eded8
|
| 3 |
+
size 377312
|
wheels/TRELLIS.2/o-voxels/build/temp.linux-x86_64-cpython-310/src/hash/hash.o
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e6e6cba634b994cd2c6589237866dc59df54d858b5e7841d380cca32ea4d3f4c
|
| 3 |
+
size 193504
|
wheels/TRELLIS.2/o-voxels/build/temp.linux-x86_64-cpython-310/src/io/filter_neighbor.o
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fb72c224d0a737b94c3789b4d2fdca0163c1332ab6c3b70ec3f87cd12489c1c9
|
| 3 |
+
size 268912
|
wheels/TRELLIS.2/o-voxels/build/temp.linux-x86_64-cpython-310/src/io/filter_parent.o
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e59c4a5e044c2dfb1d14941473f1c40af6cea6b022b7a356e5f030976ae970fe
|
| 3 |
+
size 266160
|
wheels/TRELLIS.2/o-voxels/build/temp.linux-x86_64-cpython-310/src/io/svo.o
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e7a9b69331d34ac97cbebdcee96ede507a128367391fd5ef220304fd9a38ff3e
|
| 3 |
+
size 269312
|
wheels/TRELLIS.2/o-voxels/build/temp.linux-x86_64-cpython-310/src/rasterize/rasterize.o
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b5e98d7125b8a536c38f544a61ae8ef02f5be0e7a1e22bde2ecc1fdf767a46a1
|
| 3 |
+
size 151592
|
wheels/TRELLIS.2/o-voxels/build/temp.linux-x86_64-cpython-310/src/serialize/api.o
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:196f2bad65093bd1d2be37bdb772c92b96f747448d44404e3c30cbcae4dc9cda
|
| 3 |
+
size 104024
|
wheels/TRELLIS.2/o-voxels/build/temp.linux-x86_64-cpython-310/src/serialize/hilbert.o
ADDED
|
Binary file (24 kB). View file
|
|
|
wheels/TRELLIS.2/o-voxels/build/temp.linux-x86_64-cpython-310/src/serialize/z_order.o
ADDED
|
Binary file (17.8 kB). View file
|
|
|