ReubenSun commited on
Commit
f55e443
·
1 Parent(s): ba7a511
app.py CHANGED
@@ -34,10 +34,7 @@ from step1x3d_geometry.models.pipelines.pipeline import Step1X3DGeometryPipeline
34
  from step1x3d_texture.pipelines.step1x_3d_texture_synthesis_pipeline import (
35
  Step1X3DTexturePipeline,
36
  )
37
- from step1x3d_texture.utils.shape_post_process import (
38
- FaceReducer,
39
- DegenerateFaceRemover,
40
- )
41
 
42
 
43
  parser = argparse.ArgumentParser()
@@ -88,8 +85,8 @@ def generate_func(
88
  geometry_mesh = out.mesh[0]
89
  geometry_mesh.export(geometry_save_path)
90
 
91
- geometry_mesh = DegenerateFaceRemover()(geometry_mesh)
92
- geometry_mesh = FaceReducer()(geometry_mesh)
93
  textured_mesh = texture_model(input_image_path, geometry_mesh)
94
  textured_save_path = f"{args.cache_dir}/{save_name}-textured.glb"
95
  textured_mesh.export(textured_save_path)
 
34
  from step1x3d_texture.pipelines.step1x_3d_texture_synthesis_pipeline import (
35
  Step1X3DTexturePipeline,
36
  )
37
+ from step1x3d_geometry.models.pipelines.pipeline_utils import reduce_face, remove_degenerate_face
 
 
 
38
 
39
 
40
  parser = argparse.ArgumentParser()
 
85
  geometry_mesh = out.mesh[0]
86
  geometry_mesh.export(geometry_save_path)
87
 
88
+ geometry_mesh = remove_degenerate_face()(geometry_mesh)
89
+ geometry_mesh = reduce_face()(geometry_mesh)
90
  textured_mesh = texture_model(input_image_path, geometry_mesh)
91
  textured_save_path = f"{args.cache_dir}/{save_name}-textured.glb"
92
  textured_mesh.export(textured_save_path)
step1x3d_texture/pipelines/step1x_3d_texture_synthesis_pipeline.py CHANGED
@@ -24,11 +24,7 @@ import trimesh
24
  import xatlas
25
  import scipy.sparse
26
  from scipy.sparse.linalg import spsolve
27
- from step1x3d_texture.utils.shape_post_process import (
28
- FaceReducer,
29
- FloaterRemover,
30
- DegenerateFaceRemover,
31
- )
32
  from step1x3d_geometry.models.pipelines.pipeline_utils import smart_load_model
33
 
34
 
@@ -333,7 +329,7 @@ class Step1X3DTexturePipeline:
333
  return texture
334
 
335
  @torch.no_grad()
336
- def __call__(self, image, mesh, remove_bg=True):
337
  if remove_bg:
338
  birefnet = AutoModelForImageSegmentation.from_pretrained(
339
  "ZhengPeng7/BiRefNet", trust_remote_code=True
@@ -367,7 +363,7 @@ class Step1X3DTexturePipeline:
367
  width=768,
368
  num_inference_steps=self.config.num_inference_steps,
369
  guidance_scale=self.config.guidance_scale,
370
- seed=self.config.seed,
371
  lora_scale=self.config.lora_scale,
372
  reference_conditioning_scale=self.config.reference_conditioning_scale,
373
  negative_prompt=self.config.negative_prompt,
 
24
  import xatlas
25
  import scipy.sparse
26
  from scipy.sparse.linalg import spsolve
27
+
 
 
 
 
28
  from step1x3d_geometry.models.pipelines.pipeline_utils import smart_load_model
29
 
30
 
 
329
  return texture
330
 
331
  @torch.no_grad()
332
+ def __call__(self, image, mesh, remove_bg=True, seed=2025):
333
  if remove_bg:
334
  birefnet = AutoModelForImageSegmentation.from_pretrained(
335
  "ZhengPeng7/BiRefNet", trust_remote_code=True
 
363
  width=768,
364
  num_inference_steps=self.config.num_inference_steps,
365
  guidance_scale=self.config.guidance_scale,
366
+ seed=seed if seed is not None else self.config.seed,
367
  lora_scale=self.config.lora_scale,
368
  reference_conditioning_scale=self.config.reference_conditioning_scale,
369
  negative_prompt=self.config.negative_prompt,
step1x3d_texture/utils/shape_post_process.py DELETED
@@ -1,145 +0,0 @@
1
- # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
- # except for the third-party components listed below.
3
- # Hunyuan 3D does not impose any additional limitations beyond what is outlined
4
- # in the repsective licenses of these third-party components.
5
- # Users must comply with all terms and conditions of original licenses of these third-party
6
- # components and must ensure that the usage of the third party components adheres to
7
- # all relevant laws and regulations.
8
-
9
- # For avoidance of doubts, Hunyuan 3D means the large language models and
10
- # their software and algorithms, including trained model weights, parameters (including
11
- # optimizer states), machine-learning model code, inference-enabling code, training-enabling code,
12
- # fine-tuning enabling code and other elements of the foregoing made publicly available
13
- # by Tencent in accordance with TENCENT HUNYUAN COMMUNITY LICENSE AGREEMENT.
14
-
15
- import os
16
- import tempfile
17
- from typing import Union
18
-
19
- import numpy as np
20
- import pymeshlab
21
- import torch
22
- import trimesh
23
-
24
-
25
- def load_mesh(path):
26
- if path.endswith(".glb"):
27
- mesh = trimesh.load(path)
28
- else:
29
- mesh = pymeshlab.MeshSet()
30
- mesh.load_new_mesh(path)
31
- return mesh
32
-
33
-
34
- def reduce_face(mesh: pymeshlab.MeshSet, max_facenum: int = 200000):
35
- if max_facenum > mesh.current_mesh().face_number():
36
- return mesh
37
-
38
- mesh.apply_filter(
39
- "meshing_decimation_quadric_edge_collapse",
40
- targetfacenum=max_facenum,
41
- qualitythr=1.0,
42
- preserveboundary=True,
43
- boundaryweight=3,
44
- preservenormal=True,
45
- preservetopology=True,
46
- autoclean=True,
47
- )
48
- return mesh
49
-
50
-
51
- def remove_floater(mesh: pymeshlab.MeshSet):
52
- mesh.apply_filter(
53
- "compute_selection_by_small_disconnected_components_per_face", nbfaceratio=0.005
54
- )
55
- mesh.apply_filter("compute_selection_transfer_face_to_vertex", inclusive=False)
56
- mesh.apply_filter("meshing_remove_selected_vertices_and_faces")
57
- return mesh
58
-
59
-
60
- def pymeshlab2trimesh(mesh: pymeshlab.MeshSet):
61
- with tempfile.NamedTemporaryFile(suffix=".ply", delete=False) as temp_file:
62
- mesh.save_current_mesh(temp_file.name)
63
- mesh = trimesh.load(temp_file.name)
64
- # 检查加载的对象类型
65
- if isinstance(mesh, trimesh.Scene):
66
- combined_mesh = trimesh.Trimesh()
67
- # 如果是Scene,遍历所有的geometry并合并
68
- for geom in mesh.geometry.values():
69
- combined_mesh = trimesh.util.concatenate([combined_mesh, geom])
70
- mesh = combined_mesh
71
- return mesh
72
-
73
-
74
- def trimesh2pymeshlab(mesh: trimesh.Trimesh):
75
- with tempfile.NamedTemporaryFile(suffix=".ply", delete=False) as temp_file:
76
- if isinstance(mesh, trimesh.scene.Scene):
77
- for idx, obj in enumerate(mesh.geometry.values()):
78
- if idx == 0:
79
- temp_mesh = obj
80
- else:
81
- temp_mesh = temp_mesh + obj
82
- mesh = temp_mesh
83
- mesh.export(temp_file.name)
84
- mesh = pymeshlab.MeshSet()
85
- mesh.load_new_mesh(temp_file.name)
86
- return mesh
87
-
88
-
89
- def import_mesh(
90
- mesh: Union[pymeshlab.MeshSet, trimesh.Trimesh, str],
91
- ) -> pymeshlab.MeshSet:
92
- if isinstance(mesh, str):
93
- mesh = load_mesh(mesh)
94
-
95
- if isinstance(mesh, (trimesh.Trimesh, trimesh.scene.Scene)):
96
- mesh = trimesh2pymeshlab(mesh)
97
-
98
- return mesh
99
-
100
-
101
- def export_mesh(input, output):
102
- if isinstance(input, pymeshlab.MeshSet):
103
- mesh = output
104
- else:
105
- mesh = pymeshlab2trimesh(output)
106
- return mesh
107
-
108
-
109
- class FaceReducer:
110
- def __call__(
111
- self,
112
- mesh: Union[pymeshlab.MeshSet, trimesh.Trimesh, str],
113
- max_facenum: int = 40000,
114
- ) -> Union[pymeshlab.MeshSet, trimesh.Trimesh]:
115
- ms = import_mesh(mesh)
116
- ms = reduce_face(ms, max_facenum=max_facenum)
117
- mesh = export_mesh(mesh, ms)
118
- return mesh
119
-
120
-
121
- class FloaterRemover:
122
- def __call__(
123
- self,
124
- mesh: Union[pymeshlab.MeshSet, trimesh.Trimesh, str],
125
- ) -> Union[pymeshlab.MeshSet, trimesh.Trimesh]:
126
- ms = import_mesh(mesh)
127
- ms = remove_floater(ms)
128
- mesh = export_mesh(mesh, ms)
129
- return mesh
130
-
131
-
132
- class DegenerateFaceRemover:
133
- def __call__(
134
- self,
135
- mesh: Union[pymeshlab.MeshSet, trimesh.Trimesh, str],
136
- ) -> Union[pymeshlab.MeshSet, trimesh.Trimesh]:
137
- ms = import_mesh(mesh)
138
-
139
- with tempfile.NamedTemporaryFile(suffix=".ply", delete=False) as temp_file:
140
- ms.save_current_mesh(temp_file.name)
141
- ms = pymeshlab.MeshSet()
142
- ms.load_new_mesh(temp_file.name)
143
-
144
- mesh = export_mesh(mesh, ms)
145
- return mesh