Enhance Your Images with Midllle Material Maker Cognitive Actions

24 Apr 2025
Enhance Your Images with Midllle Material Maker Cognitive Actions

In the world of digital content creation, high-quality textures play a crucial role in achieving realistic visuals. The Midllle Material Maker offers a set of powerful Cognitive Actions designed to assist developers in generating essential material maps from images using AI. These pre-built actions simplify the process of creating Normal maps, Displacement maps, and Roughness maps, enabling seamless integration into various applications.

Prerequisites

Before you start using the Midllle Material Maker Cognitive Actions, ensure you have:

  • An API key for the Cognitive Actions platform.
  • Basic knowledge of JSON and HTTP requests.

Authentication typically involves passing your API key in the headers of your requests.

Cognitive Actions Overview

Generate Material Maps

The Generate Material Maps action allows you to create Normal maps, Displacement maps, and Roughness maps for images using AI. It supports various options for seamless upscaling, mirroring, and output in specific texture formats. This action is categorized under image-processing.

Input

To invoke this action, you need to provide the following input parameters:

  • sourceImage (string, required): The URL of the input image that will be processed. Must be a valid URI.
  • mirror (boolean, optional): Enables mirrored upscaling to achieve seamless texture boundaries. Default is false.
  • seamless (boolean, optional): Enables seamless upscaling for textures to ensure smooth transitions at boundaries. Default is false.
  • tileDimension (integer, optional): Specifies the size of the tiles for splitting the image during processing. Default value is 512.
  • ishiirukaFormat (boolean, optional): Saves textures using the Ishiiruka Dolphin material map texture pack format. Default is false.
  • edgePixelPadding (boolean, optional): Applies padding by replicating edge pixels of the texture. Useful for ensuring seamless texture continuation. Default is false.
  • textureEncoderFormat (boolean, optional): Saves textures using the Ishiiruka Dolphin's Texture Encoder format for optimized performance. Default is false.

Here’s an example of the JSON payload needed to invoke this action:

{
  "mirror": false,
  "seamless": false,
  "sourceImage": "https://replicate.delivery/pbxt/KajXezxSitREFMvvfW31HDtp2cD0SW4PJD6ejBLzM2GGT7IW/brick_wall.jpg",
  "tileDimension": 512,
  "ishiirukaFormat": false,
  "edgePixelPadding": false,
  "textureEncoderFormat": false
}

Output

Upon successful execution, this action returns an array of URLs pointing to the generated material maps. Here’s an example of what the output might look like:

[
  "https://assets.cognitiveactions.com/invocations/be85aa87-5c28-439c-b5eb-302ae8c71970/49f92dc5-58ed-4953-8112-590e63489e71.png",
  "https://assets.cognitiveactions.com/invocations/be85aa87-5c28-439c-b5eb-302ae8c71970/4d4e9fe4-d5b4-472d-b0f8-87f3458da6ac.png",
  "https://assets.cognitiveactions.com/invocations/be85aa87-5c28-439c-b5eb-302ae8c71970/a1c633bc-18ac-4927-ad57-55242190a71a.png"
]

Conceptual Usage Example (Python)

Here’s a conceptual example of how you might call the Generate Material Maps action using Python. This snippet demonstrates how to structure the input payload and make a request to a hypothetical Cognitive Actions endpoint.

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 = "4283260f-763b-4eeb-a7df-e69165853769"  # Action ID for Generate Material Maps

# Construct the input payload based on the action's requirements
payload = {
    "mirror": false,
    "seamless": false,
    "sourceImage": "https://replicate.delivery/pbxt/KajXezxSitREFMvvfW31HDtp2cD0SW4PJD6ejBLzM2GGT7IW/brick_wall.jpg",
    "tileDimension": 512,
    "ishiirukaFormat": false,
    "edgePixelPadding": false,
    "textureEncoderFormat": false
}

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 code snippet, you replace the YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action ID and input payload are structured to match what the Generate Material Maps action requires. Note that the endpoint URL and request structure shown are illustrative.

Conclusion

The Midllle Material Maker Cognitive Actions provide an efficient way to generate crucial material maps for your images, enhancing the quality of your digital content. By integrating these actions into your applications, you can save time and improve the workflow of texture creation. Explore potential use cases, such as game development or 3D modeling, to see how these actions can benefit your projects!