forked from cgvr/DeltaVR
use voice transcription box and model gen box in archery range
This commit is contained in:
59
Assets/_PROJECT/Scripts/ModeGeneration/ModelGenerationBox.cs
Normal file
59
Assets/_PROJECT/Scripts/ModeGeneration/ModelGenerationBox.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using Unity.XR.CoreUtils;
|
||||
using UnityEngine;
|
||||
|
||||
public class ModelGenerationBox : MonoBehaviour
|
||||
{
|
||||
public Material inactiveMaterial;
|
||||
public Material loadingMaterial;
|
||||
|
||||
public Transform modelSpawnPoint;
|
||||
public VoiceTranscriptionBox voiceTranscriptionTestBox;
|
||||
|
||||
private MeshRenderer meshRenderer;
|
||||
private bool isLoading;
|
||||
|
||||
private string lastModelPath;
|
||||
public string LastModelPath
|
||||
{
|
||||
get {
|
||||
return lastModelPath;
|
||||
}
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
meshRenderer = GetComponent<MeshRenderer>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
async void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (isLoading) return;
|
||||
|
||||
KbmController controller = other.GetComponent<KbmController>();
|
||||
XROrigin playerOrigin = other.GetComponent<XROrigin>();
|
||||
if (controller != null || playerOrigin != null)
|
||||
{
|
||||
string inputPrompt = voiceTranscriptionTestBox.LastTextOutput;
|
||||
|
||||
isLoading = true;
|
||||
meshRenderer.material = loadingMaterial;
|
||||
|
||||
string modelPath = await PipelineManager.Instance.GenerateModelAsync(inputPrompt);
|
||||
lastModelPath = modelPath;
|
||||
|
||||
GameObject spawnedObject = await PipelineManager.Instance.SpawnModel(modelPath);
|
||||
spawnedObject.transform.parent = modelSpawnPoint;
|
||||
spawnedObject.transform.position = modelSpawnPoint.position;
|
||||
|
||||
isLoading = false;
|
||||
meshRenderer.material = inactiveMaterial;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user