fix remesh export resolution
Browse files- export_worker.py +3 -3
- service_runtime.py +16 -15
export_worker.py
CHANGED
|
@@ -27,13 +27,13 @@ def export_glb(
|
|
| 27 |
arrays = np.load(payload_npz)
|
| 28 |
meta = json.loads(payload_meta.read_text(encoding="utf-8"))
|
| 29 |
attr_layout = _deserialize_attr_layout(meta["attr_layout"])
|
|
|
|
|
|
|
| 30 |
|
| 31 |
vertices = torch.from_numpy(arrays["vertices"]).cuda()
|
| 32 |
faces = torch.from_numpy(arrays["faces"]).cuda()
|
| 33 |
attr_volume = torch.from_numpy(arrays["attrs"]).cuda()
|
| 34 |
coords = torch.from_numpy(arrays["coords"]).cuda()
|
| 35 |
-
grid_size = torch.from_numpy(arrays["grid_size"]).cuda()
|
| 36 |
-
aabb = torch.from_numpy(arrays["aabb"]).cuda()
|
| 37 |
|
| 38 |
torch.cuda.synchronize()
|
| 39 |
glb = o_voxel.postprocess.to_glb(
|
|
@@ -42,7 +42,7 @@ def export_glb(
|
|
| 42 |
attr_volume=attr_volume,
|
| 43 |
coords=coords,
|
| 44 |
attr_layout=attr_layout,
|
| 45 |
-
grid_size=
|
| 46 |
aabb=aabb,
|
| 47 |
decimation_target=decimation_target,
|
| 48 |
texture_size=texture_size,
|
|
|
|
| 27 |
arrays = np.load(payload_npz)
|
| 28 |
meta = json.loads(payload_meta.read_text(encoding="utf-8"))
|
| 29 |
attr_layout = _deserialize_attr_layout(meta["attr_layout"])
|
| 30 |
+
resolution = int(meta["resolution"])
|
| 31 |
+
aabb = meta["aabb"]
|
| 32 |
|
| 33 |
vertices = torch.from_numpy(arrays["vertices"]).cuda()
|
| 34 |
faces = torch.from_numpy(arrays["faces"]).cuda()
|
| 35 |
attr_volume = torch.from_numpy(arrays["attrs"]).cuda()
|
| 36 |
coords = torch.from_numpy(arrays["coords"]).cuda()
|
|
|
|
|
|
|
| 37 |
|
| 38 |
torch.cuda.synchronize()
|
| 39 |
glb = o_voxel.postprocess.to_glb(
|
|
|
|
| 42 |
attr_volume=attr_volume,
|
| 43 |
coords=coords,
|
| 44 |
attr_layout=attr_layout,
|
| 45 |
+
grid_size=resolution,
|
| 46 |
aabb=aabb,
|
| 47 |
decimation_target=decimation_target,
|
| 48 |
texture_size=texture_size,
|
service_runtime.py
CHANGED
|
@@ -133,7 +133,7 @@ class TrellisRuntime:
|
|
| 133 |
"1536": "1536_cascade",
|
| 134 |
}[generation.resolution]
|
| 135 |
try:
|
| 136 |
-
outputs = pipeline.run(
|
| 137 |
image,
|
| 138 |
seed=generation.seed,
|
| 139 |
preprocess_image=False,
|
|
@@ -156,12 +156,14 @@ class TrellisRuntime:
|
|
| 156 |
"rescale_t": generation.tex_slat_rescale_t,
|
| 157 |
},
|
| 158 |
pipeline_type=pipeline_type,
|
| 159 |
-
return_latent=
|
| 160 |
)
|
| 161 |
torch.cuda.synchronize()
|
| 162 |
mesh = outputs[0]
|
| 163 |
-
|
|
|
|
| 164 |
del outputs
|
|
|
|
| 165 |
del mesh
|
| 166 |
torch.cuda.empty_cache()
|
| 167 |
return payload
|
|
@@ -171,20 +173,13 @@ class TrellisRuntime:
|
|
| 171 |
raise classify_runtime_error("generate", error) from error
|
| 172 |
|
| 173 |
@staticmethod
|
| 174 |
-
def _mesh_to_payload(mesh: Any) -> dict[str, Any]:
|
| 175 |
-
origin = mesh.origin.detach().cpu().numpy().astype(np.float32)
|
| 176 |
-
spatial_shape = np.array(mesh.voxel_shape[-3:], dtype=np.int32)
|
| 177 |
-
voxel_size = float(mesh.voxel_size)
|
| 178 |
-
aabb = np.stack(
|
| 179 |
-
[origin, origin + voxel_size * spatial_shape.astype(np.float32)]
|
| 180 |
-
)
|
| 181 |
return {
|
| 182 |
"vertices": mesh.vertices.detach().cpu().numpy().astype(np.float32),
|
| 183 |
"faces": mesh.faces.detach().cpu().numpy().astype(np.int32),
|
| 184 |
"attrs": mesh.attrs.detach().cpu().numpy().astype(np.float32),
|
| 185 |
"coords": mesh.coords.detach().cpu().numpy().astype(np.int32),
|
| 186 |
-
"
|
| 187 |
-
"aabb": aabb.astype(np.float32),
|
| 188 |
"attr_layout": {
|
| 189 |
key: {"start": value.start, "stop": value.stop}
|
| 190 |
for key, value in mesh.layout.items()
|
|
@@ -205,11 +200,17 @@ def save_export_payload(job_dir: Path, payload: dict[str, Any]) -> tuple[Path, P
|
|
| 205 |
faces=payload["faces"],
|
| 206 |
attrs=payload["attrs"],
|
| 207 |
coords=payload["coords"],
|
| 208 |
-
grid_size=payload["grid_size"],
|
| 209 |
-
aabb=payload["aabb"],
|
| 210 |
)
|
| 211 |
meta_path.write_text(
|
| 212 |
-
json.dumps(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
encoding="utf-8",
|
| 214 |
)
|
| 215 |
return npz_path, meta_path
|
|
|
|
| 133 |
"1536": "1536_cascade",
|
| 134 |
}[generation.resolution]
|
| 135 |
try:
|
| 136 |
+
outputs, latents = pipeline.run(
|
| 137 |
image,
|
| 138 |
seed=generation.seed,
|
| 139 |
preprocess_image=False,
|
|
|
|
| 156 |
"rescale_t": generation.tex_slat_rescale_t,
|
| 157 |
},
|
| 158 |
pipeline_type=pipeline_type,
|
| 159 |
+
return_latent=True,
|
| 160 |
)
|
| 161 |
torch.cuda.synchronize()
|
| 162 |
mesh = outputs[0]
|
| 163 |
+
_, _, resolution = latents
|
| 164 |
+
payload = self._mesh_to_payload(mesh, resolution)
|
| 165 |
del outputs
|
| 166 |
+
del latents
|
| 167 |
del mesh
|
| 168 |
torch.cuda.empty_cache()
|
| 169 |
return payload
|
|
|
|
| 173 |
raise classify_runtime_error("generate", error) from error
|
| 174 |
|
| 175 |
@staticmethod
|
| 176 |
+
def _mesh_to_payload(mesh: Any, resolution: int) -> dict[str, Any]:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
return {
|
| 178 |
"vertices": mesh.vertices.detach().cpu().numpy().astype(np.float32),
|
| 179 |
"faces": mesh.faces.detach().cpu().numpy().astype(np.int32),
|
| 180 |
"attrs": mesh.attrs.detach().cpu().numpy().astype(np.float32),
|
| 181 |
"coords": mesh.coords.detach().cpu().numpy().astype(np.int32),
|
| 182 |
+
"resolution": int(resolution),
|
|
|
|
| 183 |
"attr_layout": {
|
| 184 |
key: {"start": value.start, "stop": value.stop}
|
| 185 |
for key, value in mesh.layout.items()
|
|
|
|
| 200 |
faces=payload["faces"],
|
| 201 |
attrs=payload["attrs"],
|
| 202 |
coords=payload["coords"],
|
|
|
|
|
|
|
| 203 |
)
|
| 204 |
meta_path.write_text(
|
| 205 |
+
json.dumps(
|
| 206 |
+
{
|
| 207 |
+
"attr_layout": payload["attr_layout"],
|
| 208 |
+
"resolution": payload["resolution"],
|
| 209 |
+
"aabb": [[-0.5, -0.5, -0.5], [0.5, 0.5, 0.5]],
|
| 210 |
+
},
|
| 211 |
+
indent=2,
|
| 212 |
+
sort_keys=True,
|
| 213 |
+
),
|
| 214 |
encoding="utf-8",
|
| 215 |
)
|
| 216 |
return npz_path, meta_path
|