This repo is a Unity project which contains scripts that connect with the Masterpiece X API to generate images and 3D models using generative AI at runtime.
Tested with Unity version 2022.3.60f1
- Follow the getting-started guide on the Masterpiece X API documentation website to ensure you have a developer account setup with credits and an API key.
- Clone this repo.
- Open the project via Unity Hub using 'Add project from disk'.
- Open the
DemoScene
located underAssets/Scenes
- Update the variable
MPXSecretToken
(on line 40) in the scriptRunDemo.cs
(located under theAssets
folder) with your own API key that you should have obtained from Step #1. - Hit play and wait for the generations to pop-up. It should take ~2 mins to generate everything but exact runtime will depend on server load. See below for example output after the generations are completed.
At a high level we utilize the RestClient library to make REST API calls to the MPX endpoints. Generated images are downloaded and displayed as a textured quad using native UnityWebRequest
. Generated 3D models are downloaded and displayed using glTFast.
Make sure to use linear colorspace (instead of the default sRGB) and enable the Read/Write option when using Texture2D
imports as images for 3D model generation. If sRGB is enabled then your models will appear darker than expected. See image below for the specific settings in the Unity inspector.
This repository is available under the MIT License.