Transform 2D Images into Stunning 3D Models with Trellis

In the world of digital content creation, the ability to convert 2D images into detailed 3D models can significantly enhance user experience and creativity. Trellis offers a powerful Cognitive Action designed specifically for this purpose: the ability to generate 3D models from images. This action harnesses advanced algorithms to transform flat images into scalable 3D assets, ensuring versatility and customization for developers.
Imagine the possibilities: game developers can create realistic characters from concept art, architects can visualize designs from blueprints, and e-commerce platforms can showcase products in 3D, enhancing customer engagement. With Trellis, the process is simplified, allowing developers to focus on innovation rather than technical hurdles.
Prerequisites
To get started, you'll need a Cognitive Actions API key and a basic understanding of making API calls.
Generate 3D Model from Image
The "Generate 3D Model from Image" action transforms a 2D image into a 3D asset, utilizing structured latent variables to ensure high-quality and customizable outputs. This action is categorized under 3D reconstruction, making it an essential tool for developers working in fields like gaming, virtual reality, and product visualization.
Input Requirements
The action requires a JSON object containing the following properties:
- image: (string) The URI of the input image from which the 3D model will be generated. It must be a valid URI string.
- seed: (integer) The initial seed for random number generation. Default is 0.
- textureSize: (integer) Specifies the texture size in pixels for GLB extraction, ranging between 512 and 2048. Default is 512.
- meshSimplify: (number) Determines the degree of mesh simplification during GLB extraction, with possible values between 0 and 0.98. Default is 0.65.
- generateColor: (boolean) If true, a video render with color is produced. Default is false.
- generateModel: (boolean) When true, outputs a 3D model file in GLB format. Default is true.
- randomizeSeed: (boolean) If true, the seed value is randomized. Default is true.
- generateNormal: (boolean) Generates a video render displaying the normal map if true. Default is false.
- sparseStructureSamplingSteps: (integer) Number of sampling steps for the sparse structure generation, between 1 and 50. Default is 12.
- structuredLatentSamplingSteps: (integer) Number of sampling steps for structured latent generation, with a range of 1 to 50. Default is 12.
- sparseStructureGuidanceStrength: (number) Strength of guidance for sparse structure generation, ranging from 0 to 10. Default is 7.5.
- structuredLatentGuidanceStrength: (number) Guidance strength for structured latent generation, acceptable values from 0 to 10, with default set to 3.
Expected Output
Upon successful processing, the action returns:
- model_file: A URL to the generated 3D model file in GLB format.
- color_video: (optional) A URL to the color video render (if generated).
- normal_video: (optional) A URL to the normal map video render (if generated).
- no_background_image: A URL to an image of the generated model without a background.
Use Cases for this Specific Action
This action is especially beneficial in various scenarios:
- Game Development: Instantly convert character sketches or concept art into 3D models, speeding up the design process.
- E-commerce: Provide customers with 3D views of products, enhancing the shopping experience and increasing conversion rates.
- Virtual Reality Applications: Generate immersive environments from 2D images, allowing users to explore new realms interactively.
- Architectural Visualization: Transform architectural drawings into 3D models, helping clients visualize projects before construction.
```python
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 = "7f8ef880-1260-421b-a64f-737785385217" # Action ID for: Generate 3D Model 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": 0,
"image": "https://replicate.delivery/pbxt/MCprdYbZYopM9oV25EeGmNQdKjeYjIB6sfyei5rTFeaXEoun/Set_in_role_playing_game__A_young_woman_with_realistic_adult_proportio_S1009161289_St8_G1.png",
"textureSize": 2048,
"meshSimplify": 0,
"generateColor": false,
"generateModel": true,
"randomizeSeed": true,
"generateNormal": false,
"sparseStructureSamplingSteps": 12,
"structuredLatentSamplingSteps": 12,
"sparseStructureGuidanceStrength": 7.5,
"structuredLatentGuidanceStrength": 3
}
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
Trellis empowers developers to easily transform 2D images into 3D models, streamlining workflows and enhancing creativity across various applications. The ability to customize outputs and generate high-quality assets opens up new avenues for innovation, whether in gaming, e-commerce, or architectural visualization.
To take the next step, consider integrating this action into your projects and explore the endless possibilities of 3D modeling with Trellis.