Tanoda
LoadModelFromStreamSample.cs
Go to the documentation of this file.
1#pragma warning disable 649
2using System.IO;
3using UnityEngine;
4#if UNITY_EDITOR
5using UnityEditor;
6
7#endif
8namespace TriLibCore.Samples
9{
14 public class LoadModelFromStreamSample : MonoBehaviour
15 {
16#if UNITY_EDITOR
20 [SerializeField] private Object ModelAsset;
21#endif
22
26 private string ModelPath
27 {
28 get
29 {
30#if UNITY_EDITOR
31 return AssetDatabase.GetAssetPath(ModelAsset);
32#else
33 return "Models/TriLibSampleModel.obj";
34#endif
35 }
36 }
37
48 private void Start()
49 {
50 var assetLoaderOptions = AssetLoader.CreateDefaultLoaderOptions();
51 assetLoaderOptions.ExternalDataMapper = ScriptableObject.CreateInstance<ExternalDataMapperSample>();
52 assetLoaderOptions.TextureMapper = ScriptableObject.CreateInstance<TextureMapperSample>();
53 AssetLoader.LoadModelFromStream(File.OpenRead(ModelPath), ModelPath, null, OnLoad, OnMaterialsLoad,
54 OnProgress, OnError, null, assetLoaderOptions);
55 }
56
64 private void OnError(IContextualizedError obj)
65 {
66 Debug.LogError($"An error ocurred while loading your Model: {obj.GetInnerException()}");
67 }
68
74 private void OnProgress(AssetLoaderContext assetLoaderContext, float progress)
75 {
76 Debug.Log($"Loading Model. Progress: {progress:P}");
77 }
78
84 private void OnMaterialsLoad(AssetLoaderContext assetLoaderContext)
85 {
86 Debug.Log("Materials loaded. Model fully loaded.");
87 }
88
94 private void OnLoad(AssetLoaderContext assetLoaderContext)
95 {
96 Debug.Log("Model loaded. Loading materials.");
97 }
98 }
99}
UnityEngine.Debug Debug
Definition: TanodaServer.cs:19
Represents a class that finds external resources at the given model base path.
Represents a sample that loads the "TriLibSample.obj" Model from the "Models" folder using a File Str...
Represents a class that finds textures at the given model base path.
UnityEngine.Object Object