Commit
·
db2fd1d
1
Parent(s):
d65fe1c
Enhance generate3d function to initialize nvdiffrast context for mesh export, improving rendering capabilities. Updated export call to include rendering context and adjusted parameters for UVs and texture image, ensuring better integration with the model.
Browse files- inference.py +9 -2
inference.py
CHANGED
@@ -18,8 +18,15 @@ def generate3d(model, rgb_image, xyz_image, device="cpu"):
|
|
18 |
# CRM export expects a data dictionary
|
19 |
data = {"rgb": rgb_image, "xyz": xyz_image}
|
20 |
|
21 |
-
#
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
# Convert .obj to .glb
|
25 |
mesh = Mesh.load(obj_path, device=torch.device("cpu"))
|
|
|
18 |
# CRM export expects a data dictionary
|
19 |
data = {"rgb": rgb_image, "xyz": xyz_image}
|
20 |
|
21 |
+
# Get rendering context required by xatlas and nvdiffrast
|
22 |
+
try:
|
23 |
+
import nvdiffrast.torch as dr
|
24 |
+
ctx = dr.RasterizeGLContext()
|
25 |
+
except Exception as e:
|
26 |
+
raise RuntimeError("Failed to initialize nvdiffrast context: " + str(e))
|
27 |
+
|
28 |
+
# Export mesh with UVs and texture image
|
29 |
+
model.export_mesh_wt_uv(ctx, data, base_path, 0, device, 512)
|
30 |
|
31 |
# Convert .obj to .glb
|
32 |
mesh = Mesh.load(obj_path, device=torch.device("cpu"))
|