Transform Images into Stunning 3D Shapes with Hunyuan3d

In the realm of digital creativity, the ability to convert 2D images into detailed 3D shapes opens up a world of possibilities. The Hunyuan3d 2 Test service provides developers with powerful Cognitive Actions that enable this transformation effortlessly. By harnessing advanced algorithms, this API offers a seamless way to generate 3D models from images, enhancing applications in fields such as gaming, virtual reality, and product design. With this capability, users can expect faster workflows, improved visualization, and enhanced interactive experiences.
Prerequisites
Before diving into the integration of Hunyuan3d 2 Test, ensure you have a valid Cognitive Actions API key and a basic understanding of making API calls.
Generate 3D Shape from Image
The "Generate 3D Shape from Image" action is designed to convert a standard 2D image into an intricate 3D shape. This transformation is achieved through a series of controlled inference steps that incorporate randomness for varied results while maintaining a consistent output through parameters like guidance scale, number of mesh chunks, and octree resolution. This action not only facilitates the background removal from images but also ensures that results are reproducible, making it a reliable tool for developers.
Input Requirements:
- Seed: An integer to initialize the random number generator (default: 1234).
- Image: The URI of the input image (e.g.,
https://replicate.delivery/pbxt/MVC2B2XKgv4X13qIpW6t2m59EVfY2CqaS9e2CSsWNHPJjQAd/image.png). - Steps: Number of inference steps (between 20 and 50, default: 50).
- Guidance Scale: A number to influence the generation (between 1 and 20, default: 5.5).
- Num Chunks: The number of mesh chunks (between 10,000 and 200,000, default: 200,000).
- Octree Resolution: Resolution for mesh generation (choices: 256, 384, 512, 768, 1024; default: 512).
- Remove Background: A boolean flag to indicate background removal (default: true).
- Maximum Face Number: The maximum number of faces for the mesh (between 10,000 and 200,000, default: 40,000).
Expected Output:
The output will be a link to the generated 3D mesh file, which can be utilized in various applications (e.g., .glb format).
Use Cases for this specific action:
- Game Development: Create 3D assets from concept art or character designs, streamlining the asset creation process.
- Augmented Reality: Transform product images into 3D models for AR applications, enhancing customer engagement.
- Animation: Generate 3D shapes for use in animations, allowing for dynamic storytelling and visualization.
- Virtual Prototyping: Enable designers to visualize their ideas in 3D, facilitating better feedback and iteration.
import requests
import json
# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"
action_id = "6a4de8e9-b8d3-4cea-beee-ef1f242a3a4a" # Action ID for: Generate 3D Shape from Image
# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
"seed": 1234,
"image": "https://replicate.delivery/pbxt/MVC2B2XKgv4X13qIpW6t2m59EVfY2CqaS9e2CSsWNHPJjQAd/image.png",
"steps": 50,
"guidanceScale": 5.5,
"octreeResolution": 256,
"removeBackground": true
}
headers = {
"Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
"Content-Type": "application/json",
# Add any other required headers for the Cognitive Actions API
}
# Prepare the request body for the hypothetical execution endpoint
request_body = {
"action_id": action_id,
"inputs": payload
}
print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")
try:
response = requests.post(
COGNITIVE_ACTIONS_EXECUTE_URL,
headers=headers,
json=request_body
)
response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)
result = response.json()
print("Action executed successfully. Result:")
print(json.dumps(result, indent=2))
except requests.exceptions.RequestException as e:
print(f"Error executing action {action_id}: {e}")
if e.response is not None:
print(f"Response status: {e.response.status_code}")
try:
print(f"Response body: {e.response.json()}")
except json.JSONDecodeError:
print(f"Response body (non-JSON): {e.response.text}")
print("------------------------------------------------")
Conclusion
The Hunyuan3d 2 Test's "Generate 3D Shape from Image" action provides an innovative solution for developers looking to elevate their projects with 3D capabilities. By simplifying the conversion of images into 3D models, this API enhances productivity and creativity across various industries. To get started, explore the integration of this action in your applications and unlock new dimensions in digital design and interaction.