Fix parameter naming in generate3d function for clarity and consistency. Updated rgb and xyz parameters to rgb_image and xyz_image respectively in the mesh export call.
890b999
import os | |
import torch | |
from mesh import Mesh | |
# Ensure the output directory exists | |
def ensure_dir(path): | |
os.makedirs(path, exist_ok=True) | |
def generate3d(model, rgb_image, xyz_image, device="cpu"): | |
output_dir = "outputs" | |
ensure_dir(output_dir) | |
prompt_id = "mesh_output" | |
base_path = os.path.join(output_dir, prompt_id) | |
obj_path = base_path + ".obj" | |
glb_path = base_path + ".glb" | |
# Export mesh using CRM model (generates .obj and textures) | |
model.export_mesh_wt_uv(obj_path, rgb_image, xyz_image, device) | |
# Load and convert to GLB | |
mesh = Mesh.load(obj_path, device=torch.device("cpu")) | |
mesh.write(glb_path) | |
return glb_path | |