Fixed "WARNING TOO BIG (stack overflow)" message -> Updated Cumesh package

This commit is contained in:
Bruno Fargnoli
2025-12-26 21:45:05 +01:00
parent f9534d8b21
commit 87f48b0726
7 changed files with 289 additions and 270 deletions
+224 -269
View File
@@ -2,7 +2,7 @@
"id": "440427ce-0c6a-4462-af51-639ed2f16dec",
"revision": 0,
"last_node_id": 47,
"last_link_id": 95,
"last_link_id": 96,
"nodes": [
{
"id": 39,
@@ -13,7 +13,7 @@
],
"size": [
301.7261859434295,
130
154
],
"flags": {},
"order": 0,
@@ -38,9 +38,168 @@
"TRELLIS.2-4B",
"flash_attn",
"cuda",
true,
true
]
},
{
"id": 46,
"type": "Trellis2Remesh",
"pos": [
1000.0828330856959,
557.5238047089168
],
"size": [
316.630859375,
154
],
"flags": {},
"order": 3,
"mode": 0,
"inputs": [
{
"name": "mesh",
"type": "MESHWITHVOXEL",
"link": 96
}
],
"outputs": [
{
"name": "mesh",
"type": "MESHWITHVOXEL",
"links": [
92
]
}
],
"properties": {
"aux_id": "visualbruno/ComfyUI-Trellis2",
"ver": "7b7c73f87eb65a3ff1fd5c28bdd7d097e57eb9dc",
"Node name for S&R": "Trellis2Remesh",
"widget_ue_connectable": {}
},
"widgets_values": [
1,
0,
true,
0.03,
"Auto"
]
},
{
"id": 10,
"type": "Preview3D",
"pos": [
1009.5641496496474,
763.6500296419599
],
"size": [
626.8865556299502,
658.2643216794061
],
"flags": {},
"order": 7,
"mode": 0,
"inputs": [
{
"name": "camera_info",
"shape": 7,
"type": "LOAD3D_CAMERA",
"link": null
},
{
"name": "bg_image",
"shape": 7,
"type": "IMAGE",
"link": null
},
{
"name": "model_file",
"type": "STRING",
"widget": {
"name": "model_file"
},
"link": 22
}
],
"outputs": [],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.4.0",
"Node name for S&R": "Preview3D",
"widget_ue_connectable": {},
"Last Time Model File": "Cyborg_NoTexture_00001_.glb",
"Scene Config": {
"showGrid": true,
"backgroundColor": "#282828",
"backgroundImage": "",
"backgroundRenderMode": "tiled"
},
"Camera Config": {
"cameraType": "perspective",
"fov": 35,
"state": {
"position": {
"x": 1.5940872974312115,
"y": 8.300916247283151,
"z": 9.675558475883504
},
"target": {
"x": 0,
"y": 2.5,
"z": 0
},
"zoom": 1,
"cameraType": "perspective"
}
},
"Light Config": {
"intensity": 3
}
},
"widgets_values": [
"Cyborg_NoTexture_00001_.glb",
""
]
},
{
"id": 43,
"type": "Trellis2MeshWithVoxelToTrimesh",
"pos": [
1648.0662046700654,
567.1377197654879
],
"size": [
336.5202391989493,
26
],
"flags": {},
"order": 5,
"mode": 0,
"inputs": [
{
"name": "mesh",
"type": "MESHWITHVOXEL",
"link": 83
}
],
"outputs": [
{
"name": "trimesh",
"type": "TRIMESH",
"links": [
84
]
}
],
"properties": {
"aux_id": "visualbruno/ComfyUI-Trellis2",
"ver": "a28d6cf93b0cf24aa9e7d3dccfd14f406227fbd0",
"Node name for S&R": "Trellis2MeshWithVoxelToTrimesh",
"widget_ue_connectable": {}
},
"widgets_values": []
},
{
"id": 6,
"type": "Trellis2LoadImageWithTransparency",
@@ -82,29 +241,34 @@
"widget_ue_connectable": {}
},
"widgets_values": [
"Image_2048_00002_.png",
"Image_4096_00003_.png",
"image"
]
},
{
"id": 47,
"type": "Trellis2SimplifyMesh",
"id": 45,
"type": "Trellis2MeshWithVoxelAdvancedGenerator",
"pos": [
866.4482629540897,
386.39471720369016
561.6847153407034,
553.6781550684681
],
"size": [
270,
82
413.1841796875,
510
],
"flags": {},
"order": 3,
"order": 2,
"mode": 0,
"inputs": [
{
"name": "mesh",
"type": "MESHWITHVOXEL",
"link": 93
"name": "pipeline",
"type": "TRELLIS2PIPELINE",
"link": 87
},
{
"name": "image",
"type": "IMAGE",
"link": 88
}
],
"outputs": [
@@ -112,63 +276,78 @@
"name": "mesh",
"type": "MESHWITHVOXEL",
"links": [
95
96
]
}
],
"properties": {
"aux_id": "visualbruno/ComfyUI-Trellis2",
"ver": "a28d6cf93b0cf24aa9e7d3dccfd14f406227fbd0",
"widget_ue_connectable": {},
"Node name for S&R": "Trellis2SimplifyMesh"
"Node name for S&R": "Trellis2MeshWithVoxelAdvancedGenerator",
"widget_ue_connectable": {}
},
"widgets_values": [
5000000,
"Meshlib"
363877961,
"randomize",
"1024_cascade",
12,
7.5,
0.7,
5,
12,
7.5,
0.5,
3,
12,
1,
0,
3,
999999,
4,
32,
false
]
},
{
"id": 46,
"type": "Trellis2Remesh",
"id": 19,
"type": "Trellis2ExportMesh",
"pos": [
1000.0828330856959,
557.5238047089168
1678.2694956590033,
644.2707634178166
],
"size": [
316.630859375,
154
270,
106
],
"flags": {},
"order": 4,
"order": 6,
"mode": 0,
"inputs": [
{
"name": "mesh",
"type": "MESHWITHVOXEL",
"link": 95
"name": "trimesh",
"type": "TRIMESH",
"link": 84
}
],
"outputs": [
{
"name": "mesh",
"type": "MESHWITHVOXEL",
"name": "glb_path",
"type": "STRING",
"links": [
92
22
]
}
],
"properties": {
"aux_id": "visualbruno/ComfyUI-Trellis2",
"ver": "7b7c73f87eb65a3ff1fd5c28bdd7d097e57eb9dc",
"widget_ue_connectable": {},
"Node name for S&R": "Trellis2Remesh"
"ver": "e7f9b30df7a09bcedf1c955e176754c73f983254",
"Node name for S&R": "Trellis2ExportMesh",
"widget_ue_connectable": {}
},
"widgets_values": [
1,
0,
true,
0.03,
"Auto"
"Helmet",
"glb",
true
]
},
{
@@ -183,7 +362,7 @@
82
],
"flags": {},
"order": 5,
"order": 4,
"mode": 0,
"inputs": [
{
@@ -209,223 +388,7 @@
},
"widgets_values": [
1000000,
"Meshlib"
]
},
{
"id": 10,
"type": "Preview3D",
"pos": [
1009.5641496496474,
763.6500296419599
],
"size": [
626.8865556299502,
658.2643216794061
],
"flags": {},
"order": 8,
"mode": 0,
"inputs": [
{
"name": "camera_info",
"shape": 7,
"type": "LOAD3D_CAMERA",
"link": null
},
{
"name": "bg_image",
"shape": 7,
"type": "IMAGE",
"link": null
},
{
"name": "model_file",
"type": "STRING",
"widget": {
"name": "model_file"
},
"link": 22
}
],
"outputs": [],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.4.0",
"Node name for S&R": "Preview3D",
"widget_ue_connectable": {},
"Last Time Model File": "Cyborg_NoTexture_00001_.glb",
"Scene Config": {
"showGrid": true,
"backgroundColor": "#282828",
"backgroundImage": "",
"backgroundRenderMode": "tiled"
},
"Camera Config": {
"cameraType": "perspective",
"fov": 35,
"state": {
"position": {
"x": 2.100849689958477,
"y": 3.0394995290713793,
"z": 11.18496965925252
},
"target": {
"x": 0,
"y": 2.5,
"z": 0
},
"zoom": 1,
"cameraType": "perspective"
}
},
"Light Config": {
"intensity": 3
}
},
"widgets_values": [
"Cyborg_NoTexture_00001_.glb",
""
]
},
{
"id": 43,
"type": "Trellis2MeshWithVoxelToTrimesh",
"pos": [
1648.0662046700654,
567.1377197654879
],
"size": [
336.5202391989493,
26
],
"flags": {},
"order": 6,
"mode": 0,
"inputs": [
{
"name": "mesh",
"type": "MESHWITHVOXEL",
"link": 83
}
],
"outputs": [
{
"name": "trimesh",
"type": "TRIMESH",
"links": [
84
]
}
],
"properties": {
"aux_id": "visualbruno/ComfyUI-Trellis2",
"ver": "a28d6cf93b0cf24aa9e7d3dccfd14f406227fbd0",
"Node name for S&R": "Trellis2MeshWithVoxelToTrimesh",
"widget_ue_connectable": {}
},
"widgets_values": []
},
{
"id": 19,
"type": "Trellis2ExportMesh",
"pos": [
1678.2694956590033,
644.2707634178166
],
"size": [
270,
106
],
"flags": {},
"order": 7,
"mode": 0,
"inputs": [
{
"name": "trimesh",
"type": "TRIMESH",
"link": 84
}
],
"outputs": [
{
"name": "glb_path",
"type": "STRING",
"links": [
22
]
}
],
"properties": {
"aux_id": "visualbruno/ComfyUI-Trellis2",
"ver": "e7f9b30df7a09bcedf1c955e176754c73f983254",
"Node name for S&R": "Trellis2ExportMesh",
"widget_ue_connectable": {}
},
"widgets_values": [
"Cyborg_NoTexture",
"glb",
true
]
},
{
"id": 45,
"type": "Trellis2MeshWithVoxelAdvancedGenerator",
"pos": [
561.6847153407034,
553.6781550684681
],
"size": [
413.1841796875,
438
],
"flags": {},
"order": 2,
"mode": 0,
"inputs": [
{
"name": "pipeline",
"type": "TRELLIS2PIPELINE",
"link": 87
},
{
"name": "image",
"type": "IMAGE",
"link": 88
}
],
"outputs": [
{
"name": "mesh",
"type": "MESHWITHVOXEL",
"links": [
93
]
}
],
"properties": {
"aux_id": "visualbruno/ComfyUI-Trellis2",
"ver": "a28d6cf93b0cf24aa9e7d3dccfd14f406227fbd0",
"Node name for S&R": "Trellis2MeshWithVoxelAdvancedGenerator",
"widget_ue_connectable": {}
},
"widgets_values": [
0,
"randomize",
"1024_cascade",
12,
7.5,
0.7,
5,
12,
7.5,
0.5,
3,
12,
7.5,
0.5,
3,
49152
"Cumesh"
]
}
],
@@ -479,17 +442,9 @@
"MESHWITHVOXEL"
],
[
93,
96,
45,
0,
47,
0,
"MESHWITHVOXEL"
],
[
95,
47,
0,
46,
0,
"MESHWITHVOXEL"
@@ -503,12 +458,12 @@
"ds": {
"scale": 0.6934334949441419,
"offset": [
16.116546017676637,
-239.3006263844426
110.3338509718548,
-269.10395450061213
]
},
"links_added_by_ue": [],
"frontendVersion": "1.34.9",
"frontendVersion": "1.35.9",
"VHS_latentpreview": false,
"VHS_latentpreviewrate": 0,
"VHS_MetadataImage": true,
+65 -1
View File
@@ -134,6 +134,8 @@ class Trellis2LoadModel:
os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "expandable_segments:True" # Can save GPU memory
os.environ['ATTN_BACKEND'] = backend
torch.backends.cudnn.benchmark = False
download_path = os.path.join(folder_paths.models_dir,"microsoft")
model_path = os.path.join(download_path, modelname)
@@ -1160,7 +1162,67 @@ class Trellis2LoadMesh:
trimesh = Trimesh.load(glb_path, force="mesh")
return (trimesh,)
return (trimesh,)
class Trellis2PreProcessImage:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"image": ("IMAGE",),
}
}
RETURN_TYPES = ("IMAGE",)
RETURN_NAMES = ("image",)
FUNCTION = "process"
CATEGORY = "Trellis2Wrapper"
def process(self, image):
image = tensor2pil(image)
image = self.preprocess_image(image)
image = pil2tensor(image)
return (image,)
def preprocess_image(self, input: Image.Image) -> Image.Image:
"""
Preprocess the input image.
"""
# if has alpha channel, use it directly; otherwise, remove background
has_alpha = False
if input.mode == 'RGBA':
alpha = np.array(input)[:, :, 3]
if not np.all(alpha == 255):
has_alpha = True
max_size = max(input.size)
scale = min(1, 1024 / max_size)
if scale < 1:
input = input.resize((int(input.width * scale), int(input.height * scale)), Image.Resampling.LANCZOS)
# if has_alpha:
# output = input
# else:
# input = input.convert('RGB')
# if self.low_vram:
# self.rembg_model.to(self.device)
# output = self.rembg_model(input)
# if self.low_vram:
# self.rembg_model.cpu()
output = input
output_np = np.array(output)
alpha = output_np[:, :, 3]
bbox = np.argwhere(alpha > 0.8 * 255)
bbox = np.min(bbox[:, 1]), np.min(bbox[:, 0]), np.max(bbox[:, 1]), np.max(bbox[:, 0])
center = (bbox[0] + bbox[2]) / 2, (bbox[1] + bbox[3]) / 2
size = max(bbox[2] - bbox[0], bbox[3] - bbox[1])
size = int(size * 1)
bbox = center[0] - size // 2, center[1] - size // 2, center[0] + size // 2, center[1] + size // 2
output = output.crop(bbox) # type: ignore
output = np.array(output).astype(np.float32) / 255
output = output[:, :, :3] * output[:, :, 3:4]
output = Image.fromarray((output * 255).astype(np.uint8))
return output
NODE_CLASS_MAPPINGS = {
"Trellis2LoadModel": Trellis2LoadModel,
@@ -1176,6 +1238,7 @@ NODE_CLASS_MAPPINGS = {
"Trellis2Remesh": Trellis2Remesh,
"Trellis2MeshTexturing": Trellis2MeshTexturing,
"Trellis2LoadMesh": Trellis2LoadMesh,
"Trellis2PreProcessImage": Trellis2PreProcessImage,
}
NODE_DISPLAY_NAME_MAPPINGS = {
@@ -1192,4 +1255,5 @@ NODE_DISPLAY_NAME_MAPPINGS = {
"Trellis2Remesh": "Trellis2 - Remesh",
"Trellis2MeshTexturing": "Trellis2 - Mesh Texturing",
"Trellis2LoadMesh": "Trellis2 - Load Mesh",
"Trellis2PreProcessImage": "Trellis2 - PreProcess Image",
}