forked from cgvr/DeltaVR
add glTFast package + load in model after pipeline generation
This commit is contained in:
parent
1b0d9fd0b0
commit
9bfc55f2d6
@ -41,5 +41,5 @@ Material:
|
|||||||
m_Ints: []
|
m_Ints: []
|
||||||
m_Floats: []
|
m_Floats: []
|
||||||
m_Colors:
|
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: []
|
m_BuildTextureStacks: []
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using GLTFast;
|
||||||
|
|
||||||
public class ModelGenerationPipelineStarter : MonoBehaviour
|
public class ModelGenerationPipelineStarter : MonoBehaviour
|
||||||
{
|
{
|
||||||
public Material activeMaterial;
|
public Material activeMaterial;
|
||||||
public Material inactiveMaterial;
|
public Material inactiveMaterial;
|
||||||
|
public Transform modelSpawnPoint;
|
||||||
|
|
||||||
private MeshRenderer meshRenderer;
|
private MeshRenderer meshRenderer;
|
||||||
|
|
||||||
@ -31,6 +31,7 @@ public class ModelGenerationPipelineStarter : MonoBehaviour
|
|||||||
meshRenderer.material = activeMaterial;
|
meshRenderer.material = activeMaterial;
|
||||||
|
|
||||||
StartModeGenerationPipeline();
|
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;
|
return await Task.Run(() =>
|
||||||
|
|
||||||
await Task.Run(() =>
|
|
||||||
{
|
{
|
||||||
string inputPrompt = "Uhm I want I think an epic broadsword with a fancy golden pommel";
|
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();
|
process.WaitForExit();
|
||||||
|
|
||||||
|
|
||||||
// Extract model path from output
|
// Extract model path from output
|
||||||
foreach (string line in output.Split('\n'))
|
foreach (string line in output.Split('\n'))
|
||||||
{
|
{
|
||||||
if (line.StartsWith("Generated 3D model file: "))
|
if (line.StartsWith("Generated 3D model file: "))
|
||||||
{
|
{
|
||||||
modelPath = line.Replace("Generated 3D model file: ", "").Trim();
|
return line.Replace("Generated 3D model file: ", "").Trim();
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
return null;
|
||||||
|
|
||||||
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.");
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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>();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
"com.unity.2d.tilemap": "1.0.0",
|
"com.unity.2d.tilemap": "1.0.0",
|
||||||
"com.unity.ai.navigation": "1.1.1",
|
"com.unity.ai.navigation": "1.1.1",
|
||||||
"com.unity.cinemachine": "2.9.5",
|
"com.unity.cinemachine": "2.9.5",
|
||||||
|
"com.unity.cloud.gltfast": "6.14.1",
|
||||||
"com.unity.collab-proxy": "2.0.1",
|
"com.unity.collab-proxy": "2.0.1",
|
||||||
"com.unity.ext.nunit": "1.0.6",
|
"com.unity.ext.nunit": "1.0.6",
|
||||||
"com.unity.feature.vr": "1.0.0",
|
"com.unity.feature.vr": "1.0.0",
|
||||||
|
|||||||
@ -31,11 +31,12 @@
|
|||||||
"url": "https://packages.unity.com"
|
"url": "https://packages.unity.com"
|
||||||
},
|
},
|
||||||
"com.unity.burst": {
|
"com.unity.burst": {
|
||||||
"version": "1.8.3",
|
"version": "1.8.24",
|
||||||
"depth": 1,
|
"depth": 1,
|
||||||
"source": "registry",
|
"source": "registry",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"com.unity.mathematics": "1.2.1"
|
"com.unity.mathematics": "1.2.1",
|
||||||
|
"com.unity.modules.jsonserialize": "1.0.0"
|
||||||
},
|
},
|
||||||
"url": "https://packages.unity.com"
|
"url": "https://packages.unity.com"
|
||||||
},
|
},
|
||||||
@ -48,6 +49,19 @@
|
|||||||
},
|
},
|
||||||
"url": "https://packages.unity.com"
|
"url": "https://packages.unity.com"
|
||||||
},
|
},
|
||||||
|
"com.unity.cloud.gltfast": {
|
||||||
|
"version": "6.14.1",
|
||||||
|
"depth": 0,
|
||||||
|
"source": "registry",
|
||||||
|
"dependencies": {
|
||||||
|
"com.unity.burst": "1.8.24",
|
||||||
|
"com.unity.collections": "1.2.4",
|
||||||
|
"com.unity.mathematics": "1.2.6",
|
||||||
|
"com.unity.modules.jsonserialize": "1.0.0",
|
||||||
|
"com.unity.modules.unitywebrequest": "1.0.0"
|
||||||
|
},
|
||||||
|
"url": "https://packages.unity.com"
|
||||||
|
},
|
||||||
"com.unity.collab-proxy": {
|
"com.unity.collab-proxy": {
|
||||||
"version": "2.0.1",
|
"version": "2.0.1",
|
||||||
"depth": 0,
|
"depth": 0,
|
||||||
@ -55,6 +69,16 @@
|
|||||||
"dependencies": {},
|
"dependencies": {},
|
||||||
"url": "https://packages.unity.com"
|
"url": "https://packages.unity.com"
|
||||||
},
|
},
|
||||||
|
"com.unity.collections": {
|
||||||
|
"version": "1.2.4",
|
||||||
|
"depth": 1,
|
||||||
|
"source": "registry",
|
||||||
|
"dependencies": {
|
||||||
|
"com.unity.burst": "1.6.6",
|
||||||
|
"com.unity.test-framework": "1.1.31"
|
||||||
|
},
|
||||||
|
"url": "https://packages.unity.com"
|
||||||
|
},
|
||||||
"com.unity.editorcoroutines": {
|
"com.unity.editorcoroutines": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"depth": 1,
|
"depth": 1,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user