Skip to content

Commit 7bedd65

Browse files
committed
Added support for fast version
1 parent cb6f7a4 commit 7bedd65

File tree

5 files changed

+155
-79
lines changed

5 files changed

+155
-79
lines changed

README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ This custom node might fail after the first restart. Restart ComfyUI again. Cl
88

99
## If it doesn't install...
1010

11+
### Windows
12+
13+
You will need to install [Visual C++ build tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/)
14+
15+
### ComfyUI\_windows\_portable
16+
17+
If you installed ComfyUI with ComfyUI\_windows\_portable, it is using a version of python which is missing the libs and header files. The way around it is to either copy some folders or install the module from else where. See [issue #]()
18+
19+
1120
### Ubuntu
1221

1322
`sudo apt install python3-dev libgl-dev`
@@ -28,10 +37,9 @@ Hunyuan-3D needs g++ 13, Suse has g++ 14+ by default
2837
## Workarounds...
2938

3039
* If you get a square panel. Make sure you have a transparent background in the image. If the image came from another node, insert an "invert mask" node before giving the mask to this node, some nodes have a mask that's reversed.
31-
* Hunyuan-3D-2 uses more main memory than GPU memory. On a 16gb RAM main memory computer, you'll have to quit everything else other than ComfyUI, have only a few custom\_nodes installed. Or use the command line version. I have ran it on 16gb RAM, 8gb VRAM without paint. Best to have 24gb+ RAM, 12gb+ VRAM.
3240

3341

34-
### Install from git.
42+
### Install from git
3543

3644
Not recommended because ComfyUI-Manager will auto update when you press the update button. git will need manual updates for every custom\_node you have.
3745

@@ -43,5 +51,13 @@ cd ComfyUI-Hunyuan-3D-2
4351
git submodule update --init # You need to get the submodules if you install from git
4452
```
4553

54+
### Other models...
55+
56+
* Right click on the node, click "convert input to widget", "model".
57+
* connect a string node to the "model" input.
58+
* Put in the string node the ID of the model on hugging face. ie. tencent/Hunyuan3D-2
59+
60+
* The big model files are downloaded into `~/.cache/huggingface/hub`
61+
4662

4763
![Screenshot, workflow is in the examples/ folder](assets/workflow_screenshot.png)

examples/Hunyuan-3d-2-example.json

Lines changed: 86 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,7 @@
11
{
2-
"last_node_id": 21,
3-
"last_link_id": 24,
2+
"last_node_id": 23,
3+
"last_link_id": 26,
44
"nodes": [
5-
{
6-
"id": 18,
7-
"type": "Hunyuan3D2ImageTo3D",
8-
"pos": [
9-
-307.19512939453125,
10-
705.976318359375
11-
],
12-
"size": [
13-
315,
14-
222
15-
],
16-
"flags": {},
17-
"order": 1,
18-
"mode": 0,
19-
"inputs": [
20-
{
21-
"name": "image",
22-
"type": "IMAGE",
23-
"link": 24
24-
},
25-
{
26-
"name": "mask",
27-
"type": "MASK",
28-
"link": 23,
29-
"shape": 7
30-
}
31-
],
32-
"outputs": [
33-
{
34-
"name": "filename",
35-
"type": "STRING",
36-
"links": [
37-
16
38-
],
39-
"slot_index": 0
40-
}
41-
],
42-
"properties": {
43-
"Node name for S&R": "Hunyuan3D2ImageTo3D"
44-
},
45-
"widgets_values": [
46-
30,
47-
true,
48-
true,
49-
true,
50-
false
51-
]
52-
},
535
{
546
"id": 7,
557
"type": "LoadImage",
@@ -92,11 +44,11 @@
9244
]
9345
},
9446
{
95-
"id": 12,
47+
"id": 23,
9648
"type": "Preview3D",
9749
"pos": [
98-
89.18033599853516,
99-
632.212646484375
50+
149.37188720703125,
51+
686.0650024414062
10052
],
10153
"size": [
10254
315,
@@ -109,36 +61,91 @@
10961
{
11062
"name": "model_file",
11163
"type": "STRING",
112-
"link": 16,
64+
"link": 26,
11365
"widget": {
11466
"name": "model_file"
11567
}
11668
}
11769
],
11870
"outputs": [],
11971
"properties": {
120-
"Node name for S&R": "Preview3D"
72+
"Node name for S&R": "Preview3D",
73+
"Show Grid": true,
74+
"Camera Info": {
75+
"position": {
76+
"x": 7.749448299061437,
77+
"y": 10.439857209476756,
78+
"z": 7.757242217589018
79+
},
80+
"target": {
81+
"x": 0,
82+
"y": 2.5,
83+
"z": 0
84+
},
85+
"zoom": 1,
86+
"cameraType": "perspective"
87+
}
12188
},
12289
"widgets_values": [
123-
"hunyuan3d_70E30.glb",
90+
"hunyuan3d_7CE38.glb",
12491
"original",
125-
"#000000",
12692
10,
12793
"original",
12894
75,
12995
null
13096
]
97+
},
98+
{
99+
"id": 18,
100+
"type": "Hunyuan3D2ImageTo3D",
101+
"pos": [
102+
-307.19512939453125,
103+
705.976318359375
104+
],
105+
"size": [
106+
315,
107+
222
108+
],
109+
"flags": {},
110+
"order": 1,
111+
"mode": 0,
112+
"inputs": [
113+
{
114+
"name": "image",
115+
"type": "IMAGE",
116+
"link": 24
117+
},
118+
{
119+
"name": "mask",
120+
"type": "MASK",
121+
"link": 23,
122+
"shape": 7
123+
}
124+
],
125+
"outputs": [
126+
{
127+
"name": "model file",
128+
"type": "STRING",
129+
"links": [
130+
26
131+
],
132+
"slot_index": 0
133+
}
134+
],
135+
"properties": {
136+
"Node name for S&R": "Hunyuan3D2ImageTo3D"
137+
},
138+
"widgets_values": [
139+
30,
140+
true,
141+
true,
142+
true,
143+
false,
144+
"tencent/Hunyuan3D-2/hunyuan3d-dit-v2-0"
145+
]
131146
}
132147
],
133148
"links": [
134-
[
135-
16,
136-
18,
137-
0,
138-
12,
139-
0,
140-
"STRING"
141-
],
142149
[
143150
23,
144151
7,
@@ -154,16 +161,24 @@
154161
18,
155162
0,
156163
"IMAGE"
164+
],
165+
[
166+
26,
167+
18,
168+
0,
169+
23,
170+
0,
171+
"STRING"
157172
]
158173
],
159174
"groups": [],
160175
"config": {},
161176
"extra": {
162177
"ds": {
163-
"scale": 0.683013455365071,
178+
"scale": 1.3109994191499976,
164179
"offset": [
165-
958.835786988787,
166-
-207.04284573998368
180+
485.2584426492523,
181+
-467.91069644496645
167182
]
168183
},
169184
"0246.VERSION": [
@@ -172,10 +187,10 @@
172187
4
173188
],
174189
"node_versions": {
175-
"ComfyUI-Hunyuan-3D-2": "7c8cfc0ca3154ead3491e0d8a356d644b97710bf",
176-
"comfy-core": "0.3.12"
190+
"comfy-core": "0.3.13",
191+
"ComfyUI-Hunyuan-3D-2": "cb6f7a41feebf9bbdf8a12ab0fc4fc1ff2067410"
177192
},
178193
"ue_links": []
179194
},
180195
"version": 0.4
181-
}
196+
}

hunyuan_3d_node.py

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@
1010
import torch
1111
import hashlib
1212
import platform
13+
import re
1314
from PIL import Image
1415
import numpy as np
1516

1617

1718
class Hunyuan3DImageTo3D:
1819
@classmethod
1920
def INPUT_TYPES(s):
21+
models = [
22+
'tencent/Hunyuan3D-2/hunyuan3d-dit-v2-0',
23+
'tencent/Hunyuan3D-2/hunyuan3d-dit-v2-0-fast',
24+
]
2025
return {
2126
"required": {
2227
"image": ("IMAGE",),
@@ -27,11 +32,17 @@ def INPUT_TYPES(s):
2732
"floater_remover": ("BOOLEAN", {"default": True}),
2833
"face_remover": ("BOOLEAN", {"default": True}),
2934
"face_reducer": ("BOOLEAN", {"default": True}),
30-
"paint": ("BOOLEAN", {"default": False}),
35+
"paint": ("BOOLEAN", {
36+
"default": False,
37+
"tooltip": "Paint needs a lot more VRAM",
38+
}),
39+
"model": (models, {
40+
"tooltip": "huggingface id of model. ie. author/name/subfolder",
41+
}),
3142
}
3243
}
3344
RETURN_TYPES = ("STRING",)
34-
RETURN_NAMES = ("filename",)
45+
RETURN_NAMES = ("model file",)
3546
FUNCTION = "process"
3647
CATEGORY = "3d"
3748

@@ -55,6 +66,12 @@ def popen_print_output(args, cwd=None, shell=False):
5566
@staticmethod
5667
def install_check():
5768
this_path = os.path.dirname(os.path.realpath(__file__))
69+
70+
Hunyuan3DImageTo3D.popen_print_output(
71+
['git', 'submodule', 'update', '--init', '--recursive'],
72+
this_path,
73+
shell=True,
74+
)
5875
if importlib.util.find_spec('custom_rasterizer') is None:
5976
print("Installing custom_rasterizer")
6077
Hunyuan3DImageTo3D.popen_print_output(
@@ -106,11 +123,29 @@ def process(
106123
face_remover,
107124
face_reducer,
108125
paint,
126+
model='tencent/Hunyuan3D-2',
109127
):
110128
from hy3dgen.shapegen import Hunyuan3DDiTFlowMatchingPipeline
111129
import hy3dgen.shapegen
112130

113131
output_dir = folder_paths.get_output_directory()
132+
checkpoint_dir = os.path.join(
133+
folder_paths.get_folder_paths('checkpoints')[0],
134+
'Hunyuan3D-2'
135+
)
136+
if not os.path.exists(checkpoint_dir):
137+
os.mkdir(checkpoint_dir)
138+
139+
# Not working
140+
# if 'HY3DGEN_MODELS' not in os.environ:
141+
# os.environ['HY3DGEN_MODELS'] = checkpoint_dir
142+
143+
subfolder = None
144+
subfolder_m = re.match(r"^([^/]+/[^/]+)/(.+)$", model)
145+
if subfolder_m is not None:
146+
model = subfolder_m.group(1)
147+
subfolder = subfolder_m.group(2)
148+
114149
output_3d_file = None
115150
with tempfile.TemporaryDirectory() as temp_dir:
116151
for img, mask1 in zip(image, mask):
@@ -121,14 +156,18 @@ def process(
121156
mask = Image.fromarray(m)
122157
mask = np.clip(mask, 0, 255).astype(np.uint8)
123158
mask = 255 - mask
159+
# If it crashes here,
160+
# check that you have transparency in the image
124161
img.putalpha(Image.fromarray(mask, mode='L'))
125162
input_image_file = os.path.join(temp_dir, "input.png")
126163
img.save(input_image_file)
127164

128165
mask = i = img = None
129166

130-
model_path = 'tencent/Hunyuan3D-2'
131-
pipeline = Hunyuan3DDiTFlowMatchingPipeline.from_pretrained(model_path) # noqa: E501
167+
pipeline = Hunyuan3DDiTFlowMatchingPipeline.from_pretrained(
168+
model,
169+
subfolder=subfolder,
170+
)
132171

133172
output_3d_file = Hunyuan3DImageTo3D.get_spare_filename(
134173
os.path.join(output_dir, 'hunyuan3d_{:05X}.glb')
@@ -145,7 +184,10 @@ def process(
145184

146185
if paint:
147186
from hy3dgen.texgen import Hunyuan3DPaintPipeline
148-
pipeline = Hunyuan3DPaintPipeline.from_pretrained(model_path) # noqa: E501
187+
pipeline = Hunyuan3DPaintPipeline.from_pretrained(
188+
model,
189+
subfolder=subfolder,
190+
)
149191
mesh = pipeline(mesh, image=input_image_file)
150192

151193
mesh.export(output_3d_file)
@@ -161,11 +203,13 @@ def IS_CHANGED(
161203
face_remover,
162204
face_reducer,
163205
paint,
206+
model,
164207
):
165208
m = hashlib.sha256()
166209
m.update(steps)
167210
m.update(floater_remover)
168211
m.update(face_remover)
169212
m.update(face_reducer)
170213
m.update(paint)
214+
m.update(model)
171215
return m.digest().hex()

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
name = "comfyui-hunyuan-3d-2"
33
description = "Image to 3D using Hunyuan-3D-2"
4-
version = "0.9.1"
4+
version = "0.9.2"
55
license = {text = "MIT License"}
66

77
[project.urls]

0 commit comments

Comments
 (0)