This commit is contained in:
Huiwenshi
2025-06-14 14:32:20 +08:00
parent ed9531ce7e
commit dd93e7ce4e
6 changed files with 29 additions and 18 deletions

2
.gitignore vendored
View File

@@ -181,3 +181,5 @@ demo_textured_metallic.jpg
demo_textured_roughness.jpg demo_textured_roughness.jpg
demo_untextured.glb demo_untextured.glb
white_mesh_remesh.obj white_mesh_remesh.obj
hy3dpaint/ckpt/

23
demo.py
View File

@@ -18,22 +18,25 @@ except Exception as e:
print(f"Warning: Failed to apply torchvision fix: {e}") print(f"Warning: Failed to apply torchvision fix: {e}")
# shape # shape
model_path = 'tencent/Hunyuan3D-2.1' #model_path = 'tencent/Hunyuan3D-2.1'
pipeline_shapegen = Hunyuan3DDiTFlowMatchingPipeline.from_pretrained(model_path) #pipeline_shapegen = Hunyuan3DDiTFlowMatchingPipeline.from_pretrained(model_path)
##
#image_path = 'assets/demo.png'
#image = Image.open(image_path).convert("RGBA")
#if image.mode == 'RGB':
# rembg = BackgroundRemover()
# image = rembg(image)
# #
image_path = 'assets/demo.png' #mesh = pipeline_shapegen(image=image)[0]
image = Image.open(image_path).convert("RGBA") #mesh.export('demo.glb')
if image.mode == 'RGB':
rembg = BackgroundRemover()
image = rembg(image)
mesh = pipeline_shapegen(image=image)[0]
mesh.export('demo.glb')
# paint # paint
max_num_view = 6 # can be 6 to 9 max_num_view = 6 # can be 6 to 9
resolution = 512 # can be 768 or 512 resolution = 512 # can be 768 or 512
conf = Hunyuan3DPaintConfig(max_num_view, resolution) conf = Hunyuan3DPaintConfig(max_num_view, resolution)
conf.realesrgan_ckpt_path = "hy3dpaint/ckpt/RealESRGAN_x4plus.pth"
conf.multiview_cfg_path = "hy3dpaint/cfgs/hunyuan-paint-pbr.yaml"
conf.custom_pipeline = "hy3dpaint/hunyuanpaintpbr"
paint_pipeline = Hunyuan3DPaintPipeline(conf) paint_pipeline = Hunyuan3DPaintPipeline(conf)
output_mesh_path = 'demo_textured.glb' output_mesh_path = 'demo_textured.glb'

View File

@@ -734,9 +734,9 @@ if __name__ == '__main__':
import argparse import argparse
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("--model_path", type=str, default='tencent/Hunyuan3D-2') parser.add_argument("--model_path", type=str, default='tencent/Hunyuan3D-2.1')
parser.add_argument("--subfolder", type=str, default='hunyuan3d-dit-v2-0') parser.add_argument("--subfolder", type=str, default='hunyuan3d-dit-v2-1')
parser.add_argument("--texgen_model_path", type=str, default='tencent/Hunyuan3D-2') parser.add_argument("--texgen_model_path", type=str, default='tencent/Hunyuan3D-2.1')
parser.add_argument('--port', type=int, default=443) parser.add_argument('--port', type=int, default=443)
parser.add_argument('--host', type=str, default='0.0.0.0') parser.add_argument('--host', type=str, default='0.0.0.0')
parser.add_argument('--device', type=str, default='cuda') parser.add_argument('--device', type=str, default='cuda')
@@ -798,6 +798,9 @@ if __name__ == '__main__':
from hy3dpaint.textureGenPipeline import Hunyuan3DPaintPipeline, Hunyuan3DPaintConfig from hy3dpaint.textureGenPipeline import Hunyuan3DPaintPipeline, Hunyuan3DPaintConfig
conf = Hunyuan3DPaintConfig(max_num_view=8, resolution=768) conf = Hunyuan3DPaintConfig(max_num_view=8, resolution=768)
conf.realesrgan_ckpt_path = "hy3dpaint/ckpt/RealESRGAN_x4plus.pth"
conf.multiview_cfg_path = "hy3dpaint/cfgs/hunyuan-paint-pbr.yaml"
conf.custom_pipeline = "hy3dpaint/hunyuanpaintpbr"
tex_pipeline = Hunyuan3DPaintPipeline(conf) tex_pipeline = Hunyuan3DPaintPipeline(conf)
# Not help much, ignore for now. # Not help much, ignore for now.
@@ -831,7 +834,7 @@ if __name__ == '__main__':
i23d_worker = Hunyuan3DDiTFlowMatchingPipeline.from_pretrained( i23d_worker = Hunyuan3DDiTFlowMatchingPipeline.from_pretrained(
args.model_path, args.model_path,
subfolder=args.subfolder, subfolder=args.subfolder,
use_safetensors=True, use_safetensors=False,
device=args.device, device=args.device,
) )
if args.enable_flashvdm: if args.enable_flashvdm:

View File

@@ -38,8 +38,8 @@ class Hunyuan3DPaintConfig:
def __init__(self, max_num_view, resolution): def __init__(self, max_num_view, resolution):
self.device = "cuda" self.device = "cuda"
self.multiview_cfg_path = "hy3dpaint/cfgs/hunyuan-paint-pbr.yaml" self.multiview_cfg_path = "cfgs/hunyuan-paint-pbr.yaml"
self.custom_pipeline = "hunyuanpaintpbr"
self.multiview_pretrained_path = "tencent/Hunyuan3D-2.1" self.multiview_pretrained_path = "tencent/Hunyuan3D-2.1"
self.dino_ckpt_path = "facebook/dinov2-giant" self.dino_ckpt_path = "facebook/dinov2-giant"
self.realesrgan_ckpt_path = "ckpt/RealESRGAN_x4plus.pth" self.realesrgan_ckpt_path = "ckpt/RealESRGAN_x4plus.pth"

View File

@@ -29,6 +29,7 @@ class multiviewDiffusionNet:
self.device = config.device self.device = config.device
cfg_path = config.multiview_cfg_path cfg_path = config.multiview_cfg_path
custom_pipeline = config.custom_pipeline
cfg = OmegaConf.load(cfg_path) cfg = OmegaConf.load(cfg_path)
self.cfg = cfg self.cfg = cfg
self.mode = self.cfg.model.params.stable_diffusion_config.custom_pipeline[2:] self.mode = self.cfg.model.params.stable_diffusion_config.custom_pipeline[2:]
@@ -41,7 +42,7 @@ class multiviewDiffusionNet:
model_path = os.path.join(model_path, "hunyuan3d-paintpbr-v2-1") model_path = os.path.join(model_path, "hunyuan3d-paintpbr-v2-1")
pipeline = DiffusionPipeline.from_pretrained( pipeline = DiffusionPipeline.from_pretrained(
model_path, model_path,
custom_pipeline="hunyuanpaintpbr", custom_pipeline=custom_pipeline,
torch_dtype=torch.float16 torch_dtype=torch.float16
) )
@@ -52,7 +53,7 @@ class multiviewDiffusionNet:
self.pipeline = pipeline.to(self.device) self.pipeline = pipeline.to(self.device)
if hasattr(self.pipeline.unet, "use_dino") and self.pipeline.unet.use_dino: if hasattr(self.pipeline.unet, "use_dino") and self.pipeline.unet.use_dino:
from hunyuanpaintpbr.modules import Dino_v2 from hunyuanpaintpbr.unet.modules import Dino_v2
self.dino_v2 = Dino_v2(config.dino_ckpt_path).to(torch.float16) self.dino_v2 = Dino_v2(config.dino_ckpt_path).to(torch.float16)
self.dino_v2 = self.dino_v2.to(self.device) self.dino_v2 = self.dino_v2.to(self.device)

View File

@@ -59,6 +59,8 @@ bpy==4.0
onnxruntime==1.16.3 onnxruntime==1.16.3
torchmetrics==1.6.0 torchmetrics==1.6.0
pydantic==2.10.6
timm timm
pythreejs pythreejs
torchdiffeq torchdiffeq