forked from cgvr/DeltaVR
add glTFast package + load in model after pipeline generation
This commit is contained in:
@@ -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>();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user