1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- #pragma warning disable 649
- using System.IO;
- using TriLibCore.General;
- using TriLibCore.Mappers;
- using UnityEngine;
- #if UNITY_EDITOR
- using UnityEditor;
- #endif
- namespace TriLibCore.Samples
- {
-
-
-
-
- public class LoadModelFromStreamSample : MonoBehaviour
- {
-
-
-
- private AssetLoaderOptions _assetLoaderOptions;
-
-
-
- private string ModelPath
- {
- get
- {
- #if UNITY_EDITOR
- return $"{Application.dataPath}/TriLib/TriLibSamples/LoadModelFromStream/Models/TriLibSampleModel.obj";
- #else
- return "Models/TriLibSampleModel.obj";
- #endif
- }
- }
-
-
-
-
-
-
-
-
- private void Start()
- {
- if (_assetLoaderOptions == null)
- {
- _assetLoaderOptions = AssetLoader.CreateDefaultLoaderOptions(false, true);
- _assetLoaderOptions.ExternalDataMapper = ScriptableObject.CreateInstance<ExternalDataMapperSample>();
- _assetLoaderOptions.TextureMappers = new TextureMapper[] { ScriptableObject.CreateInstance<TextureMapperSample>() };
- }
- AssetLoader.LoadModelFromStream(File.OpenRead(ModelPath), ModelPath, null, OnLoad, OnMaterialsLoad, OnProgress, OnError, null, _assetLoaderOptions);
- }
-
-
-
-
- private void OnError(IContextualizedError obj)
- {
- Debug.LogError($"An error occurred while loading your Model: {obj.GetInnerException()}");
- }
-
-
-
-
-
- private void OnProgress(AssetLoaderContext assetLoaderContext, float progress)
- {
- Debug.Log($"Loading Model. Progress: {progress:P}");
- }
-
-
-
-
-
- private void OnMaterialsLoad(AssetLoaderContext assetLoaderContext)
- {
- Debug.Log("Materials loaded. Model fully loaded.");
- }
-
-
-
-
-
- private void OnLoad(AssetLoaderContext assetLoaderContext)
- {
- Debug.Log("Model loaded. Loading materials.");
- }
- }
- }
|