1
0
forked from cgvr/DeltaVR

add glTFast package + load in model after pipeline generation

This commit is contained in:
henrisel
2025-11-05 17:54:48 +02:00
parent 1b0d9fd0b0
commit 9bfc55f2d6
4 changed files with 72 additions and 23 deletions

View File

@@ -41,5 +41,5 @@ Material:
m_Ints: []
m_Floats: []
m_Colors:
- _Color: {r: 0.27382442, g: 0.27382442, b: 0.27382442, a: 1}
- _Color: {r: 1, g: 1, b: 1, a: 1}
m_BuildTextureStacks: []

View File

@@ -1,13 +1,13 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Diagnostics;
using System.Threading.Tasks;
using GLTFast;
public class ModelGenerationPipelineStarter : MonoBehaviour
{
public Material activeMaterial;
public Material inactiveMaterial;
public Transform modelSpawnPoint;
private MeshRenderer meshRenderer;
@@ -31,6 +31,7 @@ public class ModelGenerationPipelineStarter : MonoBehaviour
meshRenderer.material = activeMaterial;
StartModeGenerationPipeline();
//LoadModel("D:\\henrisel\\DeltaVR3DModelGeneration\\3d-generation-pipeline\\models\\2025-11-02-17-03-37\\0\\mesh.glb");
}
}
@@ -43,11 +44,9 @@ public class ModelGenerationPipelineStarter : MonoBehaviour
}
}
private async void StartModeGenerationPipeline()
private async Task<string> GenerateModelAsync()
{
string modelPath = null;
await Task.Run(() =>
return await Task.Run(() =>
{
string inputPrompt = "Uhm I want I think an epic broadsword with a fancy golden pommel";
@@ -83,32 +82,57 @@ public class ModelGenerationPipelineStarter : MonoBehaviour
process.WaitForExit();
// Extract model path from output
foreach (string line in output.Split('\n'))
{
if (line.StartsWith("Generated 3D model file: "))
{
modelPath = line.Replace("Generated 3D model file: ", "").Trim();
break;
return line.Replace("Generated 3D model file: ", "").Trim();
}
}
}
if (!string.IsNullOrEmpty(modelPath))
{
//LoadModel(modelPath);
UnityEngine.Debug.Log("Got generated model path: " + modelPath);
}
else
{
UnityEngine.Debug.LogError("Model path not found in Python output.");
return null;
}
});
}
private async void StartModeGenerationPipeline()
{
string modelPath = await GenerateModelAsync();
if (!string.IsNullOrEmpty(modelPath))
{
UnityEngine.Debug.Log("Got generated model path: " + modelPath);
await LoadModel(modelPath);
}
else
{
UnityEngine.Debug.LogError("Model path not found in Python output.");
}
}
private async Task LoadModel(string modelPath)
{
var gltf = new GltfImport();
bool loadSuccess = await gltf.Load(modelPath);
UnityEngine.Debug.Log("Load model success: " + loadSuccess);
if (loadSuccess)
{
GameObject spawnedObject = new GameObject("spawned model");
spawnedObject.transform.parent = modelSpawnPoint;
spawnedObject.transform.position = modelSpawnPoint.position;
bool spawnSuccess = await gltf.InstantiateMainSceneAsync(spawnedObject.transform);
UnityEngine.Debug.Log("Spawn model success: " + spawnSuccess);
Transform spawnedObjectMainTransform = spawnedObject.transform.GetChild(0).transform;
MeshCollider collider = spawnedObjectMainTransform.GetChild(0).transform.gameObject.AddComponent<MeshCollider>();
collider.convex = true;
spawnedObjectMainTransform.gameObject.AddComponent<Rigidbody>();
}
}
}