36 lines
970 B
Python
36 lines
970 B
Python
from pathlib import Path
|
|
|
|
|
|
def write_surface_archive(mesh, output_path):
|
|
import numpy as np
|
|
|
|
output_path = Path(output_path)
|
|
output_path.parent.mkdir(parents=True, exist_ok=True)
|
|
np.savez_compressed(
|
|
output_path,
|
|
vertices=mesh.vertices,
|
|
faces=mesh.faces,
|
|
uv=mesh.uv,
|
|
intrinsics=mesh.intrinsics,
|
|
image_size=np.asarray(mesh.image_size, dtype=np.int32),
|
|
reference_depth=np.asarray(mesh.reference_depth, dtype=np.float32),
|
|
**mesh.point_attributes,
|
|
**mesh.face_attributes,
|
|
)
|
|
return output_path
|
|
|
|
|
|
def write_normal_texture(normal, output_path):
|
|
import numpy as np
|
|
from PIL import Image
|
|
|
|
normal_rgb = np.clip(
|
|
(normal * np.array([1.0, -1.0, -1.0], dtype=np.float32) + 1.0)
|
|
* 127.5,
|
|
0.0,
|
|
255.0,
|
|
).astype(np.uint8)
|
|
output_path = Path(output_path)
|
|
Image.fromarray(normal_rgb, mode="RGB").save(output_path)
|
|
return output_path
|