123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- using System;
- using TriLibCore;
- using TriLibCore.Utils;
- using UnityEngine;
- public class TriLibLocalLoad
- {
- /// <summary>
- /// Creates the AssetLoaderOptions instance, configures the Web Request, and downloads the Model.
- /// </summary>
- /// <remarks>
- /// You can create the AssetLoaderOptions by right clicking on the Assets Explorer and selecting "TriLib->Create->AssetLoaderOptions->Pre-Built AssetLoaderOptions".
- /// </remarks>
- public static void Load(string ModelURL, Action<AssetLoaderContext> OnLoad, Action<AssetLoaderContext> OnMaterialsLoad, Action<AssetLoaderContext, float> OnProgress, Action<IContextualizedError> OnError, GameObject go = null, AssetLoaderOptions assetLoaderOptions=null)
- {
- if (ModelURL.Contains("http"))
- {
- loadUrl(ModelURL, OnLoad, OnMaterialsLoad, OnProgress, OnError, go, assetLoaderOptions);
- }
- else
- {
- loadFile(ModelURL, OnLoad, OnMaterialsLoad, OnProgress, OnError, go, assetLoaderOptions);
- }
- }
- static void loadUrl(string ModelURL, Action<AssetLoaderContext> OnLoad, Action<AssetLoaderContext> OnMaterialsLoad, Action<AssetLoaderContext, float> OnProgress, Action<IContextualizedError> OnError, GameObject go = null, AssetLoaderOptions assetLoaderOptions = null)
- {
- if(assetLoaderOptions==null)
- assetLoaderOptions = AssetLoader.CreateDefaultLoaderOptions();
- Debug.Log("assetLoaderOptions==>" + assetLoaderOptions.LoadPointClouds);
- var webRequest = AssetDownloader.CreateWebRequest(ModelURL);
- AssetDownloader.LoadModelFromUri(webRequest, OnLoad, OnMaterialsLoad, OnProgress, OnError, go, assetLoaderOptions);
- }
- static void loadFile(string ModelPath, Action<AssetLoaderContext> OnLoad, Action<AssetLoaderContext> OnMaterialsLoad, Action<AssetLoaderContext, float> OnProgress, Action<IContextualizedError> OnError, GameObject go = null, AssetLoaderOptions assetLoaderOptions = null)
- {
- if (assetLoaderOptions == null)
- assetLoaderOptions = AssetLoader.CreateDefaultLoaderOptions();
- Debug.Log("assetLoaderOptions==>" + assetLoaderOptions.LoadPointClouds);
-
- AssetLoader.LoadModelFromFile(ModelPath, OnLoad, OnMaterialsLoad, OnProgress, OnError, go, assetLoaderOptions);
- }
- /// <summary>
- /// Called when any error occurs.
- /// </summary>
- /// <param name="obj">The contextualized error, containing the original exception and the context passed to the method where the error was thrown.</param>
- private void OnError(IContextualizedError obj)
- {
- Debug.LogError($"An error occurred while loading your Model: {obj.GetInnerException()}");
- }
- /// <summary>
- /// Called when the Model loading progress changes.
- /// </summary>
- /// <param name="assetLoaderContext">The context used to load the Model.</param>
- /// <param name="progress">The loading progress.</param>
- private void OnProgress(AssetLoaderContext assetLoaderContext, float progress)
- {
- Debug.Log($"Loading Model. Progress: {progress:P}");
- }
- /// <summary>
- /// Called when the Model (including Textures and Materials) has been fully loaded.
- /// </summary>
- /// <remarks>The loaded GameObject is available on the assetLoaderContext.RootGameObject field.</remarks>
- /// <param name="assetLoaderContext">The context used to load the Model.</param>
- private void OnMaterialsLoad(AssetLoaderContext assetLoaderContext)
- {
- Debug.Log("Materials loaded. Model fully loaded.");
- }
- /// <summary>
- /// Called when the Model Meshes and hierarchy are loaded.
- /// </summary>
- /// <remarks>The loaded GameObject is available on the assetLoaderContext.RootGameObject field.</remarks>
- /// <param name="assetLoaderContext">The context used to load the Model.</param>
- private void OnLoad(AssetLoaderContext assetLoaderContext)
- {
- Debug.Log("Model loaded. Loading materials.");
- }
- }
|