diff --git a/Assets/_PROJECT/Components/Bow/Scripts/ArcheryRange.cs b/Assets/_PROJECT/Components/Bow/Scripts/ArcheryRange.cs index 272c8c6c..f2b4b6d3 100644 --- a/Assets/_PROJECT/Components/Bow/Scripts/ArcheryRange.cs +++ b/Assets/_PROJECT/Components/Bow/Scripts/ArcheryRange.cs @@ -118,17 +118,18 @@ public class ArcheryRange : NetworkBehaviour var randomPos = targetStartPosition.position + new Vector3( Random.Range(minRandomOffset.x, maxRandomOffset.x), - (float)Math.Round(Random.Range(minRandomOffset.y, maxRandomOffset.y)), - Random.Range(minRandomOffset.z, maxRandomOffset.z)); + (float) Math.Round(Random.Range(minRandomOffset.y, maxRandomOffset.y)), + Random.Range(minRandomOffset.z, maxRandomOffset.z) + ); var target = SpawnTarget(randomPos); - _targets.Add(target); } private ArcheryTarget SpawnTarget(Vector3 randomPos) { var prefab = Instantiate(targetPrefab, randomPos, Quaternion.identity, null); + // TODO: replace target prefab's child with the generated model ArcheryTarget target = prefab.GetComponent(); target.endPosition = targetEndPosition.position; target.addScore = AddScore; @@ -148,7 +149,7 @@ public class ArcheryRange : NetworkBehaviour _targets = new List(); if (_maxScore < _score) _maxScore = _score; - if(_presentPlayers.Count != 0) // If there are players in the area. + if (_presentPlayers.Count != 0) // If there are players in the area. { // Gives the score to the player longest-lasting in the area. It would be better to give it to the player that fired the starting arrow, but I'm not spending 10 hours on this. diff --git a/Assets/_PROJECT/Components/Bow/Scripts/ArcheryTarget.cs b/Assets/_PROJECT/Components/Bow/Scripts/ArcheryTarget.cs index a2919c30..3ff2fefd 100644 --- a/Assets/_PROJECT/Components/Bow/Scripts/ArcheryTarget.cs +++ b/Assets/_PROJECT/Components/Bow/Scripts/ArcheryTarget.cs @@ -1,10 +1,7 @@ using System; -using _PROJECT.Scripts.Bow; -using _PROJECT.Scripts.Bow.Extra; using FishNet.Object; using FishNet.Object.Synchronizing; using UnityEngine; -using Random = UnityEngine.Random; public class ArcheryTarget : NetworkBehaviour, IArrowHittable { @@ -13,12 +10,10 @@ public class ArcheryTarget : NetworkBehaviour, IArrowHittable public Vector3 endPosition; public float forwardSpeed = 2f; public Action addScore; - - private bool _flipDirection; private void Awake() { - _flipDirection = Random.value > 0.5f; + } // Update is called once per frame @@ -28,11 +23,12 @@ public class ArcheryTarget : NetworkBehaviour, IArrowHittable float step = forwardSpeed * Time.deltaTime; var position = transform.position; - if (Math.Abs(position.x - endPosition.x) < 0.1) Destroy(gameObject); + if (Math.Abs(position.x - endPosition.x) < 0.1) + { + Destroy(gameObject); + } - - transform.position = Vector3.MoveTowards(position, - new Vector3(endPosition.x, position.y, position.z), step); + transform.position = Vector3.MoveTowards(position, new Vector3(endPosition.x, position.y, position.z), step); } public void Hit(Arrow arrow) diff --git a/Assets/_PROJECT/Scripts/3DModeGeneration/ModelGenerationTestBox.cs b/Assets/_PROJECT/Scripts/3DModeGeneration/ModelGenerationTestBox.cs new file mode 100644 index 00000000..cacc30ac --- /dev/null +++ b/Assets/_PROJECT/Scripts/3DModeGeneration/ModelGenerationTestBox.cs @@ -0,0 +1,51 @@ +using UnityEngine; + +public class ModelGenerationTestBox : MonoBehaviour +{ + public Material activeMaterial; + public Material inactiveMaterial; + public Transform modelSpawnPoint; + public string inputPrompt; + + private MeshRenderer meshRenderer; + + + // Start is called before the first frame update + void Start() + { + meshRenderer = GetComponent(); + } + + // Update is called once per frame + void Update() + { + + } + + async void OnTriggerEnter(Collider other) + { + KbmController controller = other.GetComponent(); + if (controller != null) + { + meshRenderer.material = activeMaterial; + + string modelPath = await PipelineManager.Instance.GenerateModelAsync(inputPrompt); + //LoadModel("D:\\henrisel\\DeltaVR3DModelGeneration\\3d-generation-pipeline\\models\\2025-11-17-16-13-33\\mesh.glb"); + GameObject spawnedObject = await PipelineManager.Instance.SpawnModel(modelPath); + spawnedObject.transform.parent = modelSpawnPoint; + spawnedObject.transform.position = modelSpawnPoint.position; + } + } + + private void OnTriggerExit(Collider other) + { + KbmController controller = other.GetComponent(); + if (controller != null) + { + meshRenderer.material = inactiveMaterial; + } + } + + + +} diff --git a/Assets/_PROJECT/Scripts/3DModeGeneration/ModelGenerationPipelineStarter.cs.meta b/Assets/_PROJECT/Scripts/3DModeGeneration/ModelGenerationTestBox.cs.meta similarity index 100% rename from Assets/_PROJECT/Scripts/3DModeGeneration/ModelGenerationPipelineStarter.cs.meta rename to Assets/_PROJECT/Scripts/3DModeGeneration/ModelGenerationTestBox.cs.meta diff --git a/Assets/_PROJECT/Scripts/3DModeGeneration/ModelGenerationPipelineStarter.cs b/Assets/_PROJECT/Scripts/3DModeGeneration/PipelineManager.cs similarity index 50% rename from Assets/_PROJECT/Scripts/3DModeGeneration/ModelGenerationPipelineStarter.cs rename to Assets/_PROJECT/Scripts/3DModeGeneration/PipelineManager.cs index e829703d..b443657c 100644 --- a/Assets/_PROJECT/Scripts/3DModeGeneration/ModelGenerationPipelineStarter.cs +++ b/Assets/_PROJECT/Scripts/3DModeGeneration/PipelineManager.cs @@ -1,22 +1,21 @@ -using UnityEngine; +using GLTFast; using System.Diagnostics; using System.Threading.Tasks; -using GLTFast; +using UnityEngine; -public class ModelGenerationPipelineStarter : MonoBehaviour +public class PipelineManager : MonoBehaviour { - public Material activeMaterial; - public Material inactiveMaterial; - public Transform modelSpawnPoint; + public static PipelineManager Instance { get; private set; } - private MeshRenderer meshRenderer; - - public string inputPrompt; + private void Awake() + { + Instance = this; + } // Start is called before the first frame update void Start() { - meshRenderer = GetComponent(); + } // Update is called once per frame @@ -25,33 +24,10 @@ public class ModelGenerationPipelineStarter : MonoBehaviour } - void OnTriggerEnter(Collider other) - { - KbmController controller = other.GetComponent(); - if (controller != null) - { - meshRenderer.material = activeMaterial; - - StartModeGenerationPipeline(); - //LoadModel("D:\\henrisel\\DeltaVR3DModelGeneration\\3d-generation-pipeline\\models\\2025-11-17-16-13-33\\mesh.glb"); - } - } - - private void OnTriggerExit(Collider other) - { - KbmController controller = other.GetComponent(); - if (controller != null) - { - meshRenderer.material = inactiveMaterial; - } - } - - private async Task GenerateModelAsync() + public async Task GenerateModelAsync(string inputPrompt) { return await Task.Run(() => { - - // Path to your virtual environment's python.exe string pythonExe = @"D:\users\henrisel\DeltaVR3DModelGeneration\3d-generation-pipeline\.venv\Scripts\python.exe"; @@ -94,51 +70,36 @@ public class ModelGenerationPipelineStarter : MonoBehaviour } } - return null; + throw new System.Exception("Failed to generate 3D model!"); } }); } - 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) + public async Task SpawnModel(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); + if (spawnSuccess) + { + Transform spawnedObjectMainTransform = spawnedObject.transform.GetChild(0).transform; + GameObject spawnedObjectBody = spawnedObjectMainTransform.GetChild(0).transform.gameObject; + MeshCollider collider = spawnedObjectBody.AddComponent(); + collider.convex = true; + MeshRenderer renderer = spawnedObjectBody.GetComponent(); + renderer.material.SetFloat("metallicFactor", 0); + spawnedObjectMainTransform.gameObject.AddComponent(); - Transform spawnedObjectMainTransform = spawnedObject.transform.GetChild(0).transform; - GameObject spawnedObjectBody = spawnedObjectMainTransform.GetChild(0).transform.gameObject; - MeshCollider collider = spawnedObjectBody.AddComponent(); - collider.convex = true; - MeshRenderer renderer = spawnedObjectBody.GetComponent(); - renderer.material.SetFloat("metallicFactor", 0); - - spawnedObjectMainTransform.gameObject.AddComponent(); + return spawnedObject; + } } + throw new System.Exception("Failed to spawn GameObject from model" + modelPath); } } diff --git a/Assets/_PROJECT/Scripts/3DModeGeneration/PipelineManager.cs.meta b/Assets/_PROJECT/Scripts/3DModeGeneration/PipelineManager.cs.meta new file mode 100644 index 00000000..db41e10e --- /dev/null +++ b/Assets/_PROJECT/Scripts/3DModeGeneration/PipelineManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 19e82e42c38cf2d4b912baa8d60c5407 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: