The IXrAImageTo3d
interface defines the contract for AI models that generate 3D models from 2D images. This interface enables conversion of flat images into three-dimensional representations.
public interface IXrAImageTo3d
Processes a 2D image and generates a 3D model asynchronously.
public Task<XrAiResult<byte[]>> Execute(Texture2D texture, Dictionary<string, string> options = null)
Parameters:
texture
(Texture2D): The input Unity texture containing the 2D imageoptions
(Dictionary<string, string>, optional): Model-specific options and parametersReturns:
Task<XrAiResult<byte[]>>
: A task that resolves to a result containing the 3D model data as bytes// Load the model
IXrAImageTo3d imageTo3d = XrAiFactory.LoadImageTo3d("StabilityAi", new Dictionary<string, string>
{
{ "apiKey", "your-stability-api-key" }
});
// Execute the model
var result = await imageTo3d.Execute(inputTexture, new Dictionary<string, string>
{
{ "format", "obj" },
{ "quality", "high" }
});
// Handle the result
if (result.IsSuccess)
{
// Process the 3D model data
byte[] modelData = result.Data;
// Convert to GameObject using appropriate helper
// For OBJ files: XrAiOBJHelper.ConvertToGameObject(modelData)
// For GLTF files: XrAiGLTFHelper.ConvertToGameObject(modelData)
}
else
{
Debug.LogError($"Error generating 3D model: {result.ErrorMessage}");
}
Currently supported provider for Image-to-3D generation.
Required Options:
apiKey
: Your Stability AI API keyOptional Parameters:
The returned byte array typically contains 3D model data in formats such as:
The specific format depends on the provider and model configuration.
Use the appropriate helper classes to convert the byte array result into Unity GameObjects:
XrAiOBJHelper
: For OBJ format modelsXrAiGLTFHelper
: For GLTF format modelsTask
XrAiResult<byte[]>
for consistent error handlingTexture2D
objectif (!result.IsSuccess)
{
Debug.LogError($"3D generation failed: {result.ErrorMessage}");
// Handle specific error cases
// - Invalid API key
// - Unsupported image format
// - Service unavailable
// - Processing timeout
}