Import PixelForge 3D assets directly into your Unity project using the glTFast package. Works with Unity 2021+ and handles GLB files, PBR materials, and LOD groups automatically.
PixelForge assets are exported as GLB files — Unity's built-in glTFast package handles the import. Add it via Unity Package Manager:
// Window → Package Manager → + → Add from Git URL
com.atteneder.gltfast
Window → Package Manager → Add package from git URL... and paste com.atteneder.gltfast.
Create PixelForgeImporter.cs in your project (e.g. Assets/Scripts/PixelForgeImporter.cs):
using System;
using System.Collections;
using UnityEngine;
using GLTFast;
using GLTFast.Loading;
public class PixelForgeImporter : MonoBehaviour
{
[SerializeField] private string modelUrl;
[SerializeField] private Material[] customMaterials;
private GltfAsset gltfAsset;
public void LoadModel(string url, Action<GameObject> onComplete)
{
var downloader = new HttpRemoteDownloader();
var gltf = new GltfImport(downloader);
StartCoroutine(LoadAsync(gltf, url, onComplete));
}
private IEnumerator LoadAsync(GltfImport gltf, string url, Action<GameObject> onComplete)
{
var task = gltf.LoadAsync(url);
yield return new WaitUntil(() => task.IsCompleted);
if (gltf.Success)
{
GameObject root = new GameObject("PixelForge_Asset");
gltf.InstantiateOn(root.transform);
var renderers = root.GetComponentsInChildren<Renderer>();
for (int i = 0; i < renderers.Length && i < customMaterials?.Length; i++)
{
renderers[i].material = customMaterials[i];
}
onComplete?.Invoke(root);
}
else
{
Debug.LogError($"PixelForge import failed: {gltf.Error}");
}
}
public void LoadFromAssetId(int assetId, string apiBaseUrl, Action<GameObject> onComplete)
{
StartCoroutine(FetchModelUrlAndLoad(assetId, apiBaseUrl, onComplete));
}
private IEnumerator FetchModelUrlAndLoad(int assetId, string apiBaseUrl, Action<GameObject> onComplete)
{
var url = $"{apiBaseUrl}/api/assets/" + assetId + "/export/glb";
var www = new UnityEngine.Networking.UnityWebRequest.Get(url);
yield return www.SendWebRequest();
if (www.result == UnityEngine.Networking.UnityWebRequest.Result.Success)
{
var json = www.downloadHandler.text;
var data = JsonUtility.FromJson<ExportResponse>(json);
if (data != null && !string.IsNullOrEmpty(data.url))
{
LoadModel(data.url, onComplete);
}
}
else
{
Debug.LogError($"Failed to get asset URL: {www.error}");
}
}
[Serializable]
public class ExportResponse { public string url; public string filename; }
}
PixelForge generates three LOD variants. Wire up LOD groups for optimized rendering at any distance:
Add the LODGroupSetup.cs component to your imported prefab to automatically generate LOD renderers and assign transition thresholds.
PixelForge exports four PBR texture channels. Map them in Unity's Standard Shader:
| Channel | Unity Property | Usage |
|---|---|---|
Albedo | Albedo (Base Color) | Base color and opacity |
Normal | Normal Map | Surface detail and curvature |
Metallic | Metallic + Smoothness | Set Metallic = texture R, Smoothness = texture A |
Roughness | Standard (Greyscale) | Set Smoothness = texture G |
Query your PixelForge app directly from Unity:
| Endpoint | Method | Description |
|---|---|---|
/api/assets/generate | POST | Submit a generation job with { "prompt": "..." } |
/api/assets/:id/status | GET | Poll until status: "ready" |
/api/assets/:id/export/glb | GET | Get GLB download URL |
/api/assets/:id/export/fbx | GET | Get FBX download URL (requires live Tripo key) |