davidvgilmore commited on
Commit
0ed3c7f
·
verified ·
1 Parent(s): f277092

Upload hy3dgen/texgen/utils/simplify_mesh_utils.py with huggingface_hub

Browse files
hy3dgen/texgen/utils/simplify_mesh_utils.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 remesh_mesh(mesh_path, remesh_path, method='trimesh'):
29
+ if method == 'trimesh':
30
+ mesh_simplify_trimesh(mesh_path, remesh_path)
31
+ else:
32
+ raise f'Method {method} has not been implemented.'
33
+
34
+
35
+ def mesh_simplify_trimesh(inputpath, outputpath):
36
+ import pymeshlab
37
+ ms = pymeshlab.MeshSet()
38
+ ms.load_new_mesh(inputpath, load_in_a_single_layer=True)
39
+ ms.save_current_mesh(outputpath.replace('.glb', '.obj'), save_textures=False)
40
+
41
+ courent = trimesh.load(outputpath.replace('.glb', '.obj'), force='mesh')
42
+ face_num = courent.faces.shape[0]
43
+
44
+ if face_num > 100000:
45
+ courent = courent.simplify_quadric_decimation(40000)
46
+ courent.export(outputpath)