Transforming 3D Models with Texture Generation using Adirik/Texture Cognitive Actions

22 Apr 2025
Transforming 3D Models with Texture Generation using Adirik/Texture Cognitive Actions

In the realm of 3D modeling, enhancing visual appeal through textures is crucial for creating immersive experiences. The adirik/texture API provides a powerful set of Cognitive Actions designed for developers looking to generate high-quality textures for 3D meshes. By simply providing descriptive text prompts and 3D object files, you can create stunning textures, videos, and more. This article will guide you through the integration of the Generate 3D Mesh Textures action, demonstrating its capabilities and how to implement it in your applications.

Prerequisites

Before diving into the integration process, you should ensure that you have the following:

  • An API key for accessing the Cognitive Actions platform.
  • Basic understanding of making HTTP requests and handling JSON data.
  • Knowledge of Python programming, as we will provide a conceptual example in Python.

Authentication typically involves passing your API key in the request headers to access the Cognitive Actions endpoint.

Cognitive Actions Overview

Generate 3D Mesh Textures

The Generate 3D Mesh Textures action allows you to create stunning textures for 3D meshes based on textual prompts. This action not only generates the textures but also allows you to upload .obj or .off files, resulting in textured meshes and rendered videos.

  • Category: image-generation

Input

The input for this action is structured as follows:

  • shapePath (required): A URI pointing to the 3D object file (e.g., .obj or .off) onto which the texture will be generated.
  • seed (optional): An integer used to initialize the random number generator for texture inference. Default is 0.
  • prompt (optional): A descriptive string used for texture generation (e.g., "A next gen nascar").
  • shapeScale (optional): A decimal value between 0 and 1 to scale the shape. Default is 0.6.
  • guidanceScale (optional): A scaling factor for the guidance image, ranging from 0 to 20. Default is 10.
  • textureResolution (optional): The resolution of the generated texture. Acceptable values are between 512 and 1024, with a default of 1024.
  • textureInterpolationMode (optional): The mode for texture mapping interpolation (options: 'nearest', 'bilinear', 'bicubic'). Default is 'bilinear'.

Example Input

{
  "seed": 0,
  "prompt": "A next gen nascar",
  "shapePath": "https://replicate.delivery/pbxt/Jx2M8TKgFc8gzzMtKbc3X53moPQijBkElGqInyG6wAevq3pU/nascar.obj",
  "shapeScale": 0.6,
  "guidanceScale": 10,
  "textureResolution": 1024,
  "textureInterpolationMode": "bilinear"
}

Output

The action typically returns a list of URLs pointing to the generated assets, including the textured mesh and rendered video.

Example Output

[
  "https://assets.cognitiveactions.com/invocations/b6422322-0bb2-43b1-b415-63434d4ffe10/7e57467f-7a7a-40ee-80c0-cd9744c3fd26.glb",
  "https://assets.cognitiveactions.com/invocations/b6422322-0bb2-43b1-b415-63434d4ffe10/8289e846-48bc-42b8-a583-8eaccefb2c0a.mp4"
]

Conceptual Usage Example (Python)

Here’s how you might call the Generate 3D Mesh Textures action using Python:

import requests
import json

# Replace with your Cognitive Actions API key and endpoint
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute" # Hypothetical endpoint

action_id = "a49a0d5b-b920-4a34-8852-de54a266171f" # Action ID for Generate 3D Mesh Textures

# Construct the input payload based on the action's requirements
payload = {
    "seed": 0,
    "prompt": "A next gen nascar",
    "shapePath": "https://replicate.delivery/pbxt/Jx2M8TKgFc8gzzMtKbc3X53moPQijBkElGqInyG6wAevq3pU/nascar.obj",
    "shapeScale": 0.6,
    "guidanceScale": 10,
    "textureResolution": 1024,
    "textureInterpolationMode": "bilinear"
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json"
}

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json={"action_id": action_id, "inputs": payload} # Hypothetical structure
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully:")
    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: {e.response.text}")

In this example, replace "YOUR_COGNITIVE_ACTIONS_API_KEY" with your actual API key. The input payload is structured according to the action's requirements, and the response will contain the URLs of the generated assets.

Conclusion

The Generate 3D Mesh Textures action from the adirik/texture API empowers developers to create stunning textures for their 3D models with ease. By leveraging descriptive prompts and 3D file uploads, you can enhance your applications with visually appealing elements. Explore these capabilities further and consider how they can fit into your projects to create engaging user experiences. Happy coding!