44 lines
1.2 KiB
C#
44 lines
1.2 KiB
C#
using UnityEngine;
|
|
using System.Collections;
|
|
using System.IO;
|
|
using UnityEngine.Networking;
|
|
using Siccity.GLTFUtility;
|
|
|
|
public class DownloadGlb : MonoBehaviour
|
|
{
|
|
private string glbUrl = "http://194.62.43.230:8000/media/user_glbs/67f3bc88f1af5a762e4125e9.glb";
|
|
|
|
void Start()
|
|
{
|
|
StartCoroutine(DownloadAndLoadGLB());
|
|
}
|
|
|
|
IEnumerator DownloadAndLoadGLB()
|
|
{
|
|
string filePath = Path.Combine(Application.persistentDataPath, "downloaded_model.glb");
|
|
|
|
using (UnityWebRequest uwr = UnityWebRequest.Get(glbUrl))
|
|
{
|
|
yield return uwr.SendWebRequest();
|
|
|
|
if (uwr.result != UnityWebRequest.Result.Success)
|
|
{
|
|
Debug.LogError("Failed to download GLB: " + uwr.error);
|
|
yield break;
|
|
}
|
|
|
|
File.WriteAllBytes(filePath, uwr.downloadHandler.data);
|
|
}
|
|
|
|
GameObject model = Importer.LoadFromFile(filePath);
|
|
if (model != null)
|
|
{
|
|
model.transform.position = Vector3.zero;
|
|
model.AddComponent<BoxCollider>();
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError("Failed to load GLB model.");
|
|
}
|
|
}
|
|
} |