From 1b0d9fd0b03d953cfc4e083daff39a45a75fe432 Mon Sep 17 00:00:00 2001 From: Henri Sellis Date: Sun, 2 Nov 2025 17:20:41 +0200 Subject: [PATCH] pipeline script passes generated model filepath to Unity --- 3d-generation-pipeline/start_pipeline.py | 3 +- .../ModelGenerationPipelineStarter.cs | 38 ++++++++++++++++--- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/3d-generation-pipeline/start_pipeline.py b/3d-generation-pipeline/start_pipeline.py index c49eef4b..afec6566 100644 --- a/3d-generation-pipeline/start_pipeline.py +++ b/3d-generation-pipeline/start_pipeline.py @@ -104,7 +104,8 @@ def main(): print(f"Generated image file: {image_path}") model_path = pipeline_folder / "models" / timestamp image_to_3d(image_path, model_path) - print(f"Generated 3D model file: {model_path}") + model_file_path = model_path / "0" / "mesh.glb" + print(f"Generated 3D model file: {model_file_path}") if __name__ == "__main__": diff --git a/Assets/_PROJECT/Scripts/3DModeGeneration/ModelGenerationPipelineStarter.cs b/Assets/_PROJECT/Scripts/3DModeGeneration/ModelGenerationPipelineStarter.cs index e3913e51..ae6471b8 100644 --- a/Assets/_PROJECT/Scripts/3DModeGeneration/ModelGenerationPipelineStarter.cs +++ b/Assets/_PROJECT/Scripts/3DModeGeneration/ModelGenerationPipelineStarter.cs @@ -45,15 +45,17 @@ public class ModelGenerationPipelineStarter : MonoBehaviour private async void StartModeGenerationPipeline() { + string modelPath = null; + await Task.Run(() => { string inputPrompt = "Uhm I want I think an epic broadsword with a fancy golden pommel"; // Path to your virtual environment's python.exe - string pythonExe = @"D:\users\henrisel\DeltaVR3DModelGeneration\3d-generation-pipeline\.venv\Scripts\python.exe"; + string pythonExe = @"D:\henrisel\DeltaVR3DModelGeneration\3d-generation-pipeline\.venv\Scripts\python.exe"; // Path to your Python script - string scriptPath = @"D:\users\henrisel\DeltaVR3DModelGeneration\3d-generation-pipeline\start_pipeline.py"; + string scriptPath = @"D:\henrisel\DeltaVR3DModelGeneration\3d-generation-pipeline\start_pipeline.py"; // Arguments to pass to the script string arguments = $"{scriptPath} --prompt \"{inputPrompt}\""; @@ -75,12 +77,38 @@ public class ModelGenerationPipelineStarter : MonoBehaviour process.ErrorDataReceived += (sender, e) => UnityEngine.Debug.LogError(e.Data); process.Start(); - process.BeginOutputReadLine(); - process.BeginErrorReadLine(); + + string output = process.StandardOutput.ReadToEnd(); + string error = process.StandardError.ReadToEnd(); + 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; + } + } + + } + + 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."); } }); - UnityEngine.Debug.Log("Python script finished!"); + + + } }