Add Tripo AI support for Text-to-3D and Image-to-3D models

This commit is contained in:
Aryan
2026-02-06 19:55:04 +05:30
parent 6de26b8e99
commit 6a00fcfeaf
6 changed files with 207 additions and 4 deletions
+2 -1
View File
@@ -4,4 +4,5 @@
GEMINI_API_KEY="your_gemini_api_key"
OPENAI_API_KEY="your_openai_api_key"
XI_API_KEY="your_elevenlabs_api_key"
REPLICATE_API_TOKEN="your_replicate_api_token"
REPLICATE_API_TOKEN="your_replicate_api_token"
TRIPO_API_KEY="your_tripo_api_key"
+22
View File
@@ -17,6 +17,8 @@ A collection of powerful custom nodes for ComfyUI that connect your local workfl
* **Veo Video Generator:** Generate high-quality video clips from text prompts using Google's Veo model via Vertex AI or the Gemini API.
* **ElevenLabs TTS:** Generate high-quality speech from text using ElevenLabs' diverse range of voices and models.
* **Gemini TTS:** Create speech from text using Google's Gemini models.
* **Tripo Text-to-3D:** Generate 3D models from text prompts using Tripo AI's advanced 3D generation API.
* **Tripo Image-to-3D:** Convert images into detailed 3D models using Tripo AI's image-to-model capability.
---
@@ -49,6 +51,7 @@ All nodes in this collection require API keys to function.
* **Gemini, Imagen, Nano Banana, Gemini TTS, Gemini Diarization, and Veo (Gemini API) Nodes:** You will need a [Google AI Studio API Key](https://aistudio.google.com/app/api-keys).
* **OpenAI Nodes (GPT Image Edit, OpenAI LLM, OpenAI TTS):** You will need an [OpenAI API Key](https://platform.openai.com/api-keys).
* **ElevenLabs TTS Node:** You will need an [ElevenLabs API Key](https://elevenlabs.io/).
* **Tripo Nodes (Text-to-3D, Image-to-3D):** You will need a [Tripo API Key](https://tripo3d.ai/).
* **Vertex AI Nodes (Imagen Edit, Veo Vertex AI):** You will need a Google Cloud Project ID, a service account with appropriate permissions, and the location for the resources.
You can paste your key directly into the `api_key` field on the corresponding node. For Vertex AI nodes, you will need to provide the project ID, location, and paste your service account JSON content.
@@ -64,6 +67,7 @@ Instead of pasting API keys directly into nodes, you can store them in a `.env`
OPENAI_API_KEY=your_openai_key_here
XI_API_KEY=your_elevenlabs_key_here
REPLICATE_API_TOKEN=your_replicate_token_here
TRIPO_API_KEY=your_tripo_api_key_here
```
3. In the node's `api_key` field, enter the variable name (e.g., `GEMINI_API_KEY`) instead of the actual key
@@ -195,6 +199,24 @@ Generate speech using Google's Gemini TTS models.
* **Key Inputs:** `text`, `voice_id`, `system_prompt` (optional)
* **Output:** `audio`
### Tripo Text-to-3D
Generate high-quality 3D models from text prompts using Tripo AI's powerful generation engine.
* **Category:** `3D/generation`
* **Key Inputs:** `prompt`, `model_version` (v3.0, v2.5, v2.0, v1.4, Turbo), `texture_quality` (standard/detailed), `save_name`
* **Optional Inputs:** `seed`, `face_limit` (500-100000, default 20000), `texture_size` (512/1024/2048), `pbr` (realistic lighting), `negative_prompt`
* **Output:** `glb` (3D model file)
### Tripo Image-to-3D
Convert images into detailed 3D models using Tripo AI's advanced image-to-model technology.
* **Category:** `3D/generation`
* **Key Inputs:** `image`, `model_version` (v3.0, v2.5, v2.0, v1.4), `texture_quality` (standard/detailed), `save_name`
* **Optional Inputs:** `seed`, `texture_seed` (randomness of colors/textures), `face_limit` (500-100000, default 20000), `texture_size` (512/1024/2048), `pbr` (realistic lighting)
* **Output:** `glb` (3D model file)
## Acknowledgements
+4 -2
View File
@@ -18,7 +18,9 @@ from .openai_tts import NODE_CLASS_MAPPINGS as OPENAI_TTS_MAPPINGS, NODE_DISPLAY
from .openai_node import NODE_CLASS_MAPPINGS as OPENAI_LLM_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS as OPENAI_LLM_DISPLAY
from .sora import NODE_CLASS_MAPPINGS as SORA_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS as SORA_DISPLAY
from .cleanup import NODE_CLASS_MAPPINGS as CLEANUP_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS as CLEANUP_DISPLAY
from .tripoTextToModel import NODE_CLASS_MAPPINGS as TRIPO_TEXT_TO_MODEL_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS as TRIPO_TEXT_TO_MODEL_DISPLAY
from .tripoImageToModel import NODE_CLASS_MAPPINGS as TRIPO_IMAGE_TO_MODEL_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS as TRIPO_IMAGE_TO_MODEL_DISPLAY
NODE_CLASS_MAPPINGS = {**PRO_MAPPINGS, **GEMINI_MAPPINGS, **GEMINI_DIAR_MAPPINGS, **GPT_IMAGE_MAPPINGS, **IMAGEN_IMAGE_MAPPINGS, **IMAGEN_EDIT_MAPPINGS, **VEO_MAPPINGS, **VEO_GEMINI_MAPPINGS, **GEMINI_SEGMENT_MAPPINGS, **NANO_BANANA_MAPPINGS, **GEMINI_TTS_MAPPINGS, **ELEVENLABS_TTS_MAPPINGS, **FLUX2_MAPPINGS, **OPENAI_TTS_MAPPINGS, **OPENAI_LLM_MAPPINGS, **SORA_MAPPINGS, **CLEANUP_MAPPINGS}
NODE_DISPLAY_NAME_MAPPINGS = {**PRO_DISPLAY, **GEMINI_DISPLAY, **GEMINI_DIAR_DISPLAY, **GPT_IMAGE_DISPLAY, **IMAGEN_IMAGE_DISPLAY, **IMAGEN_EDIT_DISPLAY, **VEO_DISPLAY, **VEO_GEMINI_DISPLAY, **GEMINI_SEGMENT_DISPLAY, **NANO_BANANA_DISPLAY, **GEMINI_TTS_DISPLAY, **ELEVENLABS_TTS_DISPLAY, **FLUX2_DISPLAY, **OPENAI_TTS_DISPLAY, **OPENAI_LLM_DISPLAY, **SORA_DISPLAY, **CLEANUP_DISPLAY}
NODE_CLASS_MAPPINGS = {**PRO_MAPPINGS, **GEMINI_MAPPINGS, **GEMINI_DIAR_MAPPINGS, **GPT_IMAGE_MAPPINGS, **IMAGEN_IMAGE_MAPPINGS, **IMAGEN_EDIT_MAPPINGS, **VEO_MAPPINGS, **VEO_GEMINI_MAPPINGS, **GEMINI_SEGMENT_MAPPINGS, **NANO_BANANA_MAPPINGS, **GEMINI_TTS_MAPPINGS, **ELEVENLABS_TTS_MAPPINGS, **FLUX2_MAPPINGS, **OPENAI_TTS_MAPPINGS, **OPENAI_LLM_MAPPINGS, **SORA_MAPPINGS, **CLEANUP_MAPPINGS, **TRIPO_TEXT_TO_MODEL_MAPPINGS, **TRIPO_IMAGE_TO_MODEL_MAPPINGS}
NODE_DISPLAY_NAME_MAPPINGS = {**PRO_DISPLAY, **GEMINI_DISPLAY, **GEMINI_DIAR_DISPLAY, **GPT_IMAGE_DISPLAY, **IMAGEN_IMAGE_DISPLAY, **IMAGEN_EDIT_DISPLAY, **VEO_DISPLAY, **VEO_GEMINI_DISPLAY, **GEMINI_SEGMENT_DISPLAY, **NANO_BANANA_DISPLAY, **GEMINI_TTS_DISPLAY, **ELEVENLABS_TTS_DISPLAY, **FLUX2_DISPLAY, **OPENAI_TTS_DISPLAY, **OPENAI_LLM_DISPLAY, **SORA_DISPLAY, **CLEANUP_DISPLAY, **TRIPO_TEXT_TO_MODEL_DISPLAY, **TRIPO_IMAGE_TO_MODEL_DISPLAY}
__all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS']
+1 -1
View File
@@ -1,7 +1,7 @@
[project]
name = "externalapi-helpers"
description = "Various ComfyUI nodes for Gemini, Replicate and OpenAI"
version = "1.0.7"
version = "1.0.8"
license = {file = "LICENSE"}
# classifiers = [
# # For OS-independent nodes (works on all operating systems)
+85
View File
@@ -0,0 +1,85 @@
import os
import time
import requests
import io
import numpy as np
from PIL import Image
import folder_paths #type: ignore
class TripoITM:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"image": ("IMAGE",),
"model_version": (["v3.0-20250812", "v2.5-20250123", "v2.0-20240919", "v1.4-20240625"], {"default": "v2.5-20250123"}),
"texture_quality": (["standard", "detailed"], {"default": "standard"}),
"api_key": ("STRING", {"multiline": False, "default": "", "tooltip": "Tripo API key or .env variable name (TRIPO_API_KEY)"}),
"save_name": ("STRING", {"default": "tripo_img_model"}),
},
"optional": {
"seed": ("INT", {"default": 69, "min": 0, "max": 2147483646, "step": 1}),
"texture_seed": ("INT", {"default": 420, "min": 0, "max": 2147483646, "step": 1, "tooltip": "Controls randomness of colors/textures."}),
"face_limit": ("INT", {"default": 20000, "min": 500, "max": 100000, "tooltip": "Max triangles in mesh."}),
"texture_size": ([512, 1024, 2048], {"default": 1024}),
"pbr": ("BOOLEAN", {"default": True, "tooltip": "Include realistic lighting maps."}),
}
}
RETURN_TYPES, RETURN_NAMES = ("STRING",), ("glb",)
FUNCTION, CATEGORY = "gen", "3D/generation"
def gen(self, image, model_version, texture_quality, api_key, save_name, **kw):
# 1. Auth & Session
key = os.environ.get(api_key.strip(), api_key.strip()) or os.environ.get("TRIPO_API_KEY")
if not key: raise ValueError("No API Key")
s = requests.Session()
s.headers.update({"Authorization": f"Bearer {key}"})
# 2. Image Prep (Tensor to PNG Bytes)
img = Image.fromarray(np.clip(255. * image[0].cpu().numpy(), 0, 255).astype(np.uint8))
buf = io.BytesIO(); img.save(buf, format="PNG"); buf.seek(0)
# 3. Upload & Task Submission
try:
up = s.post("https://api.tripo3d.ai/v2/openapi/upload", files={'file': ('i.png', buf, 'image/png')}, timeout=60).json()
token = up["data"]["image_token"]
payload = {
"type": "image_to_model", "model_version": model_version, "texture_quality": texture_quality,
"file": {"type": "png", "file_token": token},
"face_limit": kw.get("face_limit", 20000), "texture_size": kw.get("texture_size", 1024), "pbr": kw.get("pbr", True),
"model_seed": kw.get("seed", 0), "texture_seed": kw.get("texture_seed", 0)
}
task = s.post("https://api.tripo3d.ai/v2/openapi/task", json=payload, timeout=30).json()
return self._poll(s, task["data"]["task_id"], save_name)
except Exception as e: raise Exception(f"Tripo Error: {e}")
def _poll(self, s, tid, name):
url, start, m_url = f"https://api.tripo3d.ai/v2/openapi/task/{tid}", time.time(), None
while (time.time() - start) < 600:
try:
res = s.get(url, timeout=15).json().get("data", {})
status = res.get("status")
print(f"Tripo [{tid[:8]}]: {status} ({res.get('progress', 0)}%)")
if status == "success":
m_url = res.get("output", {}).get("model") or res.get("output", {}).get("pbr_model")
if m_url: break
elif status in ["failed", "cancelled", "expired"]: raise Exception(f"Task {status}: {res.get('error')}")
except Exception as e:
if "Task failed" in str(e): raise e
time.sleep(5)
if not m_url: raise Exception("Tripo error: Success but no URL provided.")
path = os.path.join(folder_paths.get_output_directory(), f"{name}_{int(time.time())}.glb")
with open(path, "wb") as f: f.write(s.get(m_url, timeout=120).content)
return (path,)
@classmethod
def IS_CHANGED(cls, seed, texture_seed, **kw):
return f"{seed}-{texture_seed}"
NODE_CLASS_MAPPINGS = {"TripoITM": TripoITM}
NODE_DISPLAY_NAME_MAPPINGS = {"TripoITM": "Tripo Image-to-3D (API)"}
+93
View File
@@ -0,0 +1,93 @@
import os
import time
import requests
import folder_paths #type: ignore
class TripoTTM:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"prompt": ("STRING", {"multiline": True, "default": "A cute 3D robot toy", "tooltip": "Describe the object you want to create in 3D."}),
"model_version": (["v3.0-20250812", "v2.5-20250123", "v2.0-20240919", "v1.4-20240625", "Turbo-v1.0-20250506"], {"default": "v2.5-20250123"}),
"texture_quality": (["standard", "detailed"], {"default": "standard"}),
"api_key": ("STRING", {"multiline": False, "default": "", "tooltip": "Tripo API key or .env variable name (TRIPO_API_KEY)"}),
"save_name": ("STRING", {"default": "tripo_model"}),
},
"optional": {
"seed": ("INT", {"default": 69, "min": 0, "max": 2147483646, "step": 1}),
"face_limit": ("INT", {"default": 20000, "min": 500, "max": 100000, "tooltip": "Polygon count. 20,000 is good; 50,000+ is high detail."}),
"texture_size": ([512, 1024, 2048], {"default": 1024}),
"pbr": ("BOOLEAN", {"default": True, "tooltip": "Adds realistic lighting data (shine, roughness, metalness)."}),
"negative_prompt": ("STRING", {"multiline": True, "default": "", "tooltip": "Things for the AI to avoid."})
}
}
RETURN_TYPES, RETURN_NAMES = ("STRING",), ("glb",)
FUNCTION, CATEGORY = "gen", "3D/generation"
def gen(self, prompt, model_version, texture_quality, api_key, save_name, **kw):
# 1. Setup Auth & Session
key = os.environ.get(api_key.strip(), api_key.strip()) or os.environ.get("TRIPO_API_KEY")
if not key: raise ValueError("No Tripo API key provided.")
s = requests.Session()
s.headers.update({"Authorization": f"Bearer {key}", "Content-Type": "application/json"})
# 2. Prepare Payload
payload = {
"type": "text_to_model",
"model_version": model_version,
"prompt": prompt,
"texture_quality": texture_quality,
"face_limit": kw.get("face_limit", 20000),
"texture_size": kw.get("texture_size", 1024),
"pbr": kw.get("pbr", True),
"model_seed": kw.get("seed", 0) # Maps 'seed' widget to 'model_seed' API key
}
if kw.get("negative_prompt"): payload["negative_prompt"] = kw["negative_prompt"]
# 3. Submit Task
print(f"Submitting Tripo Task: {prompt[:30]}...")
try:
res = s.post("https://api.tripo3d.ai/v2/openapi/task", json=payload, timeout=30)
res.raise_for_status()
task_id = res.json()["data"]["task_id"]
except Exception as e: raise Exception(f"Tripo Submission Failed: {e}")
# 4. Poll & Download
return self._poll(s, task_id, save_name)
def _poll(self, s, tid, name):
url, start, m_url = f"https://api.tripo3d.ai/v2/openapi/task/{tid}", time.time(), None
while (time.time() - start) < 600: # 10 min timeout
try:
res = s.get(url, timeout=15).json().get("data", {})
status = res.get("status")
print(f"Tripo [{tid[:8]}]: {status} ({res.get('progress', 0)}%)")
if status == "success":
out = res.get("output", {})
m_url = out.get("model") or out.get("pbr_model") or out.get("base_model")
if m_url: break
elif status in ["failed", "cancelled", "expired", "banned"]:
raise Exception(f"Tripo Task {status}: {res.get('error')}")
except Exception as e:
if "Task" in str(e): raise e
time.sleep(5)
if not m_url: raise Exception("Tripo error: Task finished but no URL provided.")
path = os.path.join(folder_paths.get_output_directory(), f"{name}_{int(time.time())}.glb")
with open(path, "wb") as f:
f.write(s.get(m_url, timeout=120).content)
return (path,)
@classmethod
def IS_CHANGED(cls, prompt, seed, **kw):
return f"{prompt}-{seed}"
NODE_CLASS_MAPPINGS = {"TripoTTM": TripoTTM}
NODE_DISPLAY_NAME_MAPPINGS = {"TripoTTM": "Tripo Text-to-3D (API)"}