forked from cgvr/DeltaVR
53 lines
1.4 KiB
C#
53 lines
1.4 KiB
C#
using System;
|
|
using Unity.XR.CoreUtils;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class ImageGenerationBox : MonoBehaviour
|
|
{
|
|
public Material inactiveMaterial;
|
|
public Material loadingMaterial;
|
|
|
|
public VoiceTranscriptionBox voiceTranscriptionBox;
|
|
public Image imageDisplay;
|
|
public Texture2D LastTexture { get; private set; }
|
|
|
|
private MeshRenderer meshRenderer;
|
|
private bool isLoading;
|
|
|
|
|
|
// 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)
|
|
{
|
|
isLoading = true;
|
|
meshRenderer.material = loadingMaterial;
|
|
|
|
string inputPrompt = voiceTranscriptionBox.GetTextOutput();
|
|
byte[] imageBytes = await InvokeAiClient.Instance.GenerateImage(inputPrompt);
|
|
LastTexture = ModelGenerationUtils.CreateTexture(imageBytes);
|
|
Sprite sprite = ModelGenerationUtils.CreateSprite(LastTexture);
|
|
imageDisplay.sprite = sprite;
|
|
|
|
isLoading = false;
|
|
meshRenderer.material = inactiveMaterial;
|
|
}
|
|
}
|
|
}
|