forked from cgvr/DeltaVR
56 lines
1.6 KiB
C#
56 lines
1.6 KiB
C#
using System;
|
|
using Unity.XR.CoreUtils;
|
|
using UnityEngine;
|
|
|
|
public class ModelGenerationBox : MonoBehaviour
|
|
{
|
|
public Material inactiveMaterial;
|
|
public Material loadingMaterial;
|
|
|
|
public Transform modelSpawnPoint;
|
|
public ImageGenerationBox imageGenerationBox;
|
|
|
|
private MeshRenderer meshRenderer;
|
|
private bool isLoading;
|
|
|
|
public GameObject GeneratedModel { get; private set; }
|
|
|
|
// 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;
|
|
|
|
Texture2D inputTexture = imageGenerationBox.LastTexture;
|
|
string encodedTexture = Convert.ToBase64String(inputTexture.EncodeToJPG());
|
|
byte[] encodedModel = await TrellisClient.Instance.GenerateModel(encodedTexture);
|
|
|
|
GameObject spawnedObject = await PipelineManager.Instance.SpawnModel(encodedModel);
|
|
spawnedObject.AddComponent<Rigidbody>();
|
|
spawnedObject.transform.parent = modelSpawnPoint;
|
|
spawnedObject.transform.position = modelSpawnPoint.position;
|
|
GeneratedModel = spawnedObject;
|
|
|
|
isLoading = false;
|
|
meshRenderer.material = inactiveMaterial;
|
|
}
|
|
}
|
|
}
|