18 private const string SmilePngData =
19 "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAgMAAABinRfyAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAJUExURQAAAP/yAP///1XtZyMAAAA+SURBVAjXY1gFBAyrQkNXMawMDc1iWBoaGsUwNTQ0jGGqoyOMAHNBxJTQUDGGqaIhQK4DYxhEMVgb2ACQUQBbZhuGX7UQtQAAAABJRU5ErkJggg==";
24 private const string CubeObjData =
27 v -0.500000 -0.500000 0.500000
28 v 0.500000 -0.500000 0.500000
29 v -0.500000 0.500000 0.500000
30 v 0.500000 0.500000 0.500000
31 v -0.500000 0.500000 -0.500000
32 v 0.500000 0.500000 -0.500000
33 v -0.500000 -0.500000 -0.500000
34 v 0.500000 -0.500000 -0.500000
59 vn 0.000000 0.000000 1.000000
60 vn 0.000000 0.000000 1.000000
61 vn 0.000000 0.000000 1.000000
62 vn 0.000000 0.000000 1.000000
63 vn 0.000000 1.000000 0.000000
64 vn 0.000000 1.000000 0.000000
65 vn 0.000000 1.000000 0.000000
66 vn 0.000000 1.000000 0.000000
67 vn 0.000000 0.000000 -1.000000
68 vn 0.000000 0.000000 -1.000000
69 vn 0.000000 0.000000 -1.000000
70 vn 0.000000 0.000000 -1.000000
71 vn 0.000000 -1.000000 0.000000
72 vn 0.000000 -1.000000 0.000000
73 vn 0.000000 -1.000000 0.000000
74 vn 0.000000 -1.000000 0.000000
75 vn 1.000000 0.000000 0.000000
76 vn 1.000000 0.000000 0.000000
77 vn 1.000000 0.000000 0.000000
78 vn 1.000000 0.000000 0.000000
79 vn -1.000000 0.000000 0.000000
80 vn -1.000000 0.000000 0.000000
81 vn -1.000000 0.000000 0.000000
82 vn -1.000000 0.000000 0.000000
85 usemtl initialShadingGroup
86 f 1/17/1 2/18/2 4/19/3 3/20/4
87 f 3/1/5 4/2/6 6/3/7 5/4/8
88 f 5/21/9 6/22/10 8/23/11 7/24/12
89 f 7/5/13 8/6/14 2/7/15 1/8/16
90 f 2/9/17 8/10/18 6/11/19 4/12/20
91 f 7/13/21 1/14/22 3/15/23 5/16/24
97 private const string CubeMtlData =
98 @"newmtl initialShadingGroup
112 private const string CubeObjFilename =
"cube.obj";
117 private const string CubeMtlFilename =
"cube.mtl";
122 private const string SmilePngFilename =
"smile.png";
129 var cubeObjBytes = Encoding.UTF8.GetBytes(CubeObjData);
131 FileUtils.GetFileExtension(CubeObjFilename,
false), OnError, OnProgress, OnModelFullyLoad,
132 CustomDataReceivingCallback, CustomFilenameReceivingCallback, CustomTextureReceivingCallback,
133 CubeObjFilename, gameObject);
141 private Stream CustomTextureReceivingCallback(ITexture texture)
143 var textureShortFilename = FileUtils.GetShortFilename(texture.Filename);
144 if (textureShortFilename == SmilePngFilename)
146 var smilePngBytes = Convert.FromBase64String(SmilePngData);
147 return new MemoryStream(smilePngBytes);
159 private string CustomFilenameReceivingCallback(
string filename)
169 private Stream CustomDataReceivingCallback(
string filename)
171 var externalDataShortFilename = FileUtils.GetShortFilename(filename);
172 if (externalDataShortFilename == CubeMtlFilename)
174 var cubeMtlBytes = Encoding.UTF8.GetBytes(CubeMtlData);
175 return new MemoryStream(cubeMtlBytes);
185 private void OnModelFullyLoad(AssetLoaderContext assetLoaderContext)
187 if (assetLoaderContext.RootGameObject !=
null)
Debug.Log(
"Model successfully loaded.");
195 private void OnProgress(AssetLoaderContext assetLoaderContext,
float progress)
197 Debug.Log($
"Progress: {progress:P}");
204 private void OnError(IContextualizedError contextualizedError)
206 Debug.LogError($
"There was an error loading your model: {contextualizedError}");
Represents a class used to load models from Byte Arrays using callbacks to map External Data and Text...
static AssetLoaderContext LoadModelFromByteData(byte[] data, string modelExtension, Action< IContextualizedError > onError, Action< AssetLoaderContext, float > onProgress, Action< AssetLoaderContext > onModelFullyLoad, Func< string, Stream > customDataReceivingCallback, Func< string, string > customFilenameReceivingCallback, Func< ITexture, Stream > customTextureReceivingCallback, string modelFilename=null, GameObject wrapperGameObject=null, AssetLoaderOptions assetLoaderOptions=null, object customData=null)
Loads a model from the given Byte Array data using the given callbacks to handle events/external data...
This sample loads an OBJ model with a single texture from Strings contents as the data source.