From 9bfc55f2d6fb9520fa44800961d71e71b7364419 Mon Sep 17 00:00:00 2001 From: henrisel Date: Wed, 5 Nov 2025 17:54:48 +0200 Subject: [PATCH] add glTFast package + load in model after pipeline generation --- .../Barrier sign yellow Variant 3.mat | 2 +- .../ModelGenerationPipelineStarter.cs | 64 +++++++++++++------ Packages/manifest.json | 1 + Packages/packages-lock.json | 28 +++++++- 4 files changed, 72 insertions(+), 23 deletions(-) diff --git a/Assets/_PROJECT/Components/Guardian/Guardian Barriers/Barrier sign yellow Variant 3.mat b/Assets/_PROJECT/Components/Guardian/Guardian Barriers/Barrier sign yellow Variant 3.mat index 1119195a..b28136c5 100644 --- a/Assets/_PROJECT/Components/Guardian/Guardian Barriers/Barrier sign yellow Variant 3.mat +++ b/Assets/_PROJECT/Components/Guardian/Guardian Barriers/Barrier sign yellow Variant 3.mat @@ -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: [] diff --git a/Assets/_PROJECT/Scripts/3DModeGeneration/ModelGenerationPipelineStarter.cs b/Assets/_PROJECT/Scripts/3DModeGeneration/ModelGenerationPipelineStarter.cs index ae6471b8..a2d26e0f 100644 --- a/Assets/_PROJECT/Scripts/3DModeGeneration/ModelGenerationPipelineStarter.cs +++ b/Assets/_PROJECT/Scripts/3DModeGeneration/ModelGenerationPipelineStarter.cs @@ -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 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(); + collider.convex = true; + spawnedObjectMainTransform.gameObject.AddComponent(); + } } } diff --git a/Packages/manifest.json b/Packages/manifest.json index c1390d2e..0bc7395d 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -4,6 +4,7 @@ "com.unity.2d.tilemap": "1.0.0", "com.unity.ai.navigation": "1.1.1", "com.unity.cinemachine": "2.9.5", + "com.unity.cloud.gltfast": "6.14.1", "com.unity.collab-proxy": "2.0.1", "com.unity.ext.nunit": "1.0.6", "com.unity.feature.vr": "1.0.0", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index d56d202b..e736fa9f 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -31,11 +31,12 @@ "url": "https://packages.unity.com" }, "com.unity.burst": { - "version": "1.8.3", + "version": "1.8.24", "depth": 1, "source": "registry", "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" }, @@ -48,6 +49,19 @@ }, "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": { "version": "2.0.1", "depth": 0, @@ -55,6 +69,16 @@ "dependencies": {}, "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": { "version": "1.0.0", "depth": 1,