davidvgilmore commited on
Commit
1bf255b
·
verified ·
1 Parent(s): daac8f9

Upload hy3dgen/texgen/differentiable_renderer/mesh_utils.py with huggingface_hub

Browse files
hy3dgen/texgen/differentiable_renderer/mesh_utils.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Open Source Model Licensed under the Apache License Version 2.0
2
+ # and Other Licenses of the Third-Party Components therein:
3
+ # The below Model in this distribution may have been modified by THL A29 Limited
4
+ # ("Tencent Modifications"). All Tencent Modifications are Copyright (C) 2024 THL A29 Limited.
5
+
6
+ # Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
7
+ # The below software and/or models in this distribution may have been
8
+ # modified by THL A29 Limited ("Tencent Modifications").
9
+ # All Tencent Modifications are Copyright (C) THL A29 Limited.
10
+
11
+ # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
12
+ # except for the third-party components listed below.
13
+ # Hunyuan 3D does not impose any additional limitations beyond what is outlined
14
+ # in the repsective licenses of these third-party components.
15
+ # Users must comply with all terms and conditions of original licenses of these third-party
16
+ # components and must ensure that the usage of the third party components adheres to
17
+ # all relevant laws and regulations.
18
+
19
+ # For avoidance of doubts, Hunyuan 3D means the large language models and
20
+ # their software and algorithms, including trained model weights, parameters (including
21
+ # optimizer states), machine-learning model code, inference-enabling code, training-enabling code,
22
+ # fine-tuning enabling code and other elements of the foregoing made publicly available
23
+ # by Tencent in accordance with TENCENT HUNYUAN COMMUNITY LICENSE AGREEMENT.
24
+
25
+ import trimesh
26
+
27
+
28
+ def load_mesh(mesh):
29
+ vtx_pos = mesh.vertices if hasattr(mesh, 'vertices') else None
30
+ pos_idx = mesh.faces if hasattr(mesh, 'faces') else None
31
+
32
+ vtx_uv = mesh.visual.uv if hasattr(mesh.visual, 'uv') else None
33
+ uv_idx = mesh.faces if hasattr(mesh, 'faces') else None
34
+
35
+ texture_data = None
36
+
37
+ return vtx_pos, pos_idx, vtx_uv, uv_idx, texture_data
38
+
39
+
40
+ def save_mesh(mesh, texture_data):
41
+ material = trimesh.visual.texture.SimpleMaterial(image=texture_data, diffuse=(255, 255, 255))
42
+ texture_visuals = trimesh.visual.TextureVisuals(uv=mesh.visual.uv, image=texture_data, material=material)
43
+ mesh.visual = texture_visuals
44
+ return mesh