Example #1
0
        /// <summary>
        /// Loads a <see cref="UnityEngine.GameObject"/> from input byte array (Accept ZIP files).
        /// </summary>
        /// <param name="fileData">File data.</param>
        /// <param name="assetExtension">Asset extension.</param>
        /// <param name="options"><see cref="AssetLoaderOptions"/> used to load the object.</param>
        /// <param name="wrapperGameObject">Use this field to load the new <see cref="UnityEngine.GameObject"/> into referenced <see cref="UnityEngine.GameObject"/>.</param>
        /// <param name="basePath">Base path from the loaded file.</param>
        /// <param name="dataCallback">Custom resource data retrieval callback. Pass this parameter when you need to load external data while loading from memory.</param>
        /// <param name="existsCallback">Custom resource size retrieval callback. Pass this parameter when you need to load external data while loading from memory.</param>
        /// <param name="progressCallback">Callback used to retrieve file loading percentage.</param>
        /// <returns><c>true</c> if model was loaded, otherwise <c>false</c>.</returns>
        public GameObject LoadFromMemoryWithTextures(byte[] fileData, string assetExtension, AssetLoaderOptions options = null, GameObject wrapperGameObject = null, string basePath = null, AssimpInterop.DataCallback dataCallback = null, AssimpInterop.ExistsCallback existsCallback = null, AssimpInterop.ProgressCallback progressCallback = null)
        {
            if (basePath == null)
            {
                basePath = FileUtils.GetFileDirectory(assetExtension);
            }
            InternalLoadFromMemoryAndZip(fileData, assetExtension, basePath, options, wrapperGameObject != null, dataCallback, existsCallback, null, progressCallback);
            var loadedGameObject = BuildGameObject(options, assetExtension, wrapperGameObject);

            ReleaseImport();
            return(loadedGameObject);
        }
Example #2
0
        /// <summary>
        /// Loads a <see cref="UnityEngine.GameObject"/> from input byte array with defined options.
        /// @warning To ensure your materials will be loaded, don´t remove material files included in the package.
        /// </summary>
        /// <param name="fileBytes">Data used to load the <see cref="UnityEngine.GameObject"/>.</param>
        /// <param name="filename">Original file name, if you know it. Otherwise, use the original file extension instead. (Eg: ".FBX")</param>
        /// <param name="options"><see cref="AssetLoaderOptions"/> used to load the object.</param>
        /// <param name="wrapperGameObject">Use this field to load the new <see cref="UnityEngine.GameObject"/> into referenced <see cref="UnityEngine.GameObject"/>.</param>
        /// <param name="basePath">Base path from the loaded file.</param>
        /// <param name="dataCallback">Custom resource data retrieval callback. Pass this parameter when you need to load external data while loading from memory.</param>
        /// <param name="existsCallback">Custom resource size retrieval callback. Pass this parameter when you need to load external data while loading from memory.</param>
        /// <param name="loadTextureDataCallback">Pass this callback to load texture data from custom sources.</param>
        /// <param name="progressCallback">Callback used to retrieve file loading percentage.</param>
        /// <returns>A new <see cref="UnityEngine.GameObject"/>.</returns>
        /// <example>
        /// @code
        /// protected void Awake() {
        ///     GameObject myGameObject;
        ///     try {
        ///         using (var assetLoader = new AssetLoader()) {
        ///             //In case you don't have a valid filename, set this to the file extension
        ///             //to help TriLib assigning a file loader to this file
        ///             //example value: ".FBX"
        ///             var filename = "c:/models/mymodel.fbx";
        ///             var fileData = File.ReadAllBytes(filename);
        ///             gameObject = assetLoader.LoadFromMemory(fleData, filename);
        ///         }
        ///     } catch (Exception e) {
        ///         Debug.LogFormat("Unable to load mymodel.fbx. The loader returned: {0}", e);
        ///     }
        /// }
        /// @endcode
        /// </example>
        public GameObject LoadFromMemory(byte[] fileBytes, string filename, AssetLoaderOptions options = null, GameObject wrapperGameObject = null, string basePath = null, AssimpInterop.DataCallback dataCallback = null, AssimpInterop.ExistsCallback existsCallback = null, LoadTextureDataCallback loadTextureDataCallback = null, AssimpInterop.ProgressCallback progressCallback = null)
        {
            if (basePath == null)
            {
                basePath = FileUtils.GetFileDirectory(filename);
            }
            InternalLoadFromMemory(fileBytes, filename, basePath, options, wrapperGameObject != null, dataCallback, existsCallback, loadTextureDataCallback, progressCallback);
            var loadedGameObject = BuildGameObject(options, basePath, wrapperGameObject);

            ReleaseImport();
            return(loadedGameObject);
        }
Example #3
0
        /// <summary>
        /// Asynchronously loads a <see cref="UnityEngine.GameObject"/> from input byte array (Accept ZIP files).
        /// </summary>
        /// <param name="fileData">File data.</param>
        /// <param name="assetExtension">Asset extension.</param>
        /// <param name="options"><see cref="AssetLoaderOptions"/> used to load the object.</param>
        /// <param name="wrapperGameObject">Use this field to load the new <see cref="UnityEngine.GameObject"/> into referenced <see cref="UnityEngine.GameObject"/>.</param>
        /// <param name="onAssetLoaded">The action that will be executed when the <see cref="UnityEngine.GameObject"/> be loaded</param>
        /// <param name="basePath">Base path from the loaded file.</param>
        /// <param name="dataCallback">Custom resource data retrieval callback. Pass this parameter when you need to load external data while loading from memory.</param>
        /// <param name="existsCallback">Custom resource size retrieval callback. Pass this parameter when you need to load external data while loading from memory.</param>
        /// <returns>The created Thread on NET 2.0, otherwise returns the created Task.</returns>
#if (NET_4_6 || NETFX_CORE)
        public Task LoadFromMemoryWithTextures(byte[] fileData, string assetExtension, AssetLoaderOptions options, GameObject wrapperGameObject, ObjectLoadedHandle onAssetLoaded, string basePath = null, AssimpInterop.DataCallback dataCallback = null, AssimpInterop.ExistsCallback existsCallback = null)
Example #4
0
        public Thread LoadFromMemoryWithTextures(byte[] fileData, string assetExtension, AssetLoaderOptions options, GameObject wrapperGameObject, ObjectLoadedHandle onAssetLoaded, string basePath = null, AssimpInterop.DataCallback dataCallback = null, AssimpInterop.ExistsCallback existsCallback = null)
#endif
        {
            if (basePath == null)
            {
                basePath = FileUtils.GetFileDirectory(assetExtension);
            }
            var usesWrapperGameObject = wrapperGameObject != null;

            return(ThreadUtils.RunThread(delegate
            {
                InternalLoadFromMemoryAndZip(fileData, assetExtension, basePath, options, usesWrapperGameObject, dataCallback, existsCallback);
            },
                                         delegate
            {
                var loadedGameObject = BuildGameObject(options, assetExtension, wrapperGameObject);
                if (onAssetLoaded != null)
                {
                    onAssetLoaded(loadedGameObject);
                }
            }
                                         ));
        }
Example #5
0
        /// <summary>
        /// Asynchronously loads a <see cref="UnityEngine.GameObject"/> from input byte array with defined options.
        /// @warning To ensure your materials will be loaded, don´t remove material files included in the package.
        /// </summary>
        /// <param name="fileBytes">Data used to load the <see cref="UnityEngine.GameObject"/>.</param>
        /// <param name="filename">Original file name, if you know it. Otherwise, use the original file extension instead. (Eg: ".FBX")</param>
        /// <param name="options"><see cref="AssetLoaderOptions"/> used to load the object.</param>
        /// <param name="wrapperGameObject">Use this field to load the new <see cref="UnityEngine.GameObject"/> into referenced <see cref="UnityEngine.GameObject"/>.</param>
        /// <param name="onAssetLoaded">The action that will be executed when the <see cref="UnityEngine.GameObject"/> be loaded</param>
        /// <param name="basePath">Base path from the loaded file.</param>        ///
        /// <param name="dataCallback">Custom resource data retrieval callback. Pass this parameter when you need to load external data while loading from memory.</param>
        /// <param name="existsCallback">Custom resource size retrieval callback. Pass this parameter when you need to load external data while loading from memory.</param>
        /// <param name="loadTextureDataCallback">Pass this callback to load texture data from custom sources.</param>
        /// <returns>The created Thread on NET 2.0, otherwise returns the created Task.</returns>
        /// <example>
        /// @code
        /// protected void Awake() {
        ///     GameObject myGameObject;
        ///     try {
        ///         using (var assetLoader = new AssetLoader()) {
        ///             //In case you don't have a valid filename, set this to the file extension
        ///             //to help TriLib assigining a file loader to this file
        ///             //example value: ".FBX"
        ///             var filename = "c:/models/mymodel.fbx";
        ///             var fileData = File.ReadAllBytes(filename);
        ///             assetLoader.LoadFromMemory(fleData, filename, delegate(GameObject loadedGameObject) {
        ///                 Debug.Log("My object '" + loadedGameObject.name +  "' has been loaded!");
        ///             });
        ///         }
        ///     } catch (Exception e) {
        ///         Debug.LogFormat("Unable to load mymodel.fbx. The loader returned: {0}", e);
        ///     }
        /// }
        /// @endcode
        /// </example>
#if (NET_4_6 || NETFX_CORE)
        public Task LoadFromMemory(byte[] fileBytes, string filename, AssetLoaderOptions options,
                                   GameObject wrapperGameObject, ObjectLoadedHandle onAssetLoaded, string basePath = null, AssimpInterop.DataCallback dataCallback = null, AssimpInterop.ExistsCallback existsCallback = null, LoadTextureDataCallback loadTextureDataCallback = null)
        public Thread LoadFromBrowserFilesWithTextures(int filesCount, AssetLoaderOptions options, GameObject wrapperGameObject, ObjectLoadedHandle onAssetLoaded, AssimpInterop.DataCallback dataCallback = null, AssimpInterop.ExistsCallback existsCallback = null, AssimpInterop.ProgressCallback progressCallback = null)
#endif
        {
            byte[] fileData;
            string fileName;
            string fileExtension;

            if (!GetSupportedBrowserFileData(filesCount, out fileData, out fileName, out fileExtension))
            {
                return(null);
            }
            var usesWrapperGameObject = wrapperGameObject != null;

            return(ThreadUtils.RunThread(delegate
            {
                InternalLoadFromBrowserFiles(filesCount, fileData, fileName, fileExtension, options, usesWrapperGameObject, dataCallback, existsCallback, null, progressCallback);
            },
                                         delegate
            {
                var loadedGameObject = BuildGameObject(options, fileExtension, wrapperGameObject);
                if (onAssetLoaded != null)
                {
                    onAssetLoaded(loadedGameObject);
                }
                ReleaseImport();
            }
                                         ));
        }
        /// <summary>
        /// Loads a <see cref="UnityEngine.GameObject"/> from browser files.
        /// </summary>
        /// <param name="filesCount">Browser files count.</param>
        /// <param name="options"><see cref="AssetLoaderOptions"/> used to load the object.</param>
        /// <param name="wrapperGameObject">Use this field to load the new <see cref="UnityEngine.GameObject"/> into referenced <see cref="UnityEngine.GameObject"/>.</param>
        /// <param name="onAssetLoaded">The action that will be executed when the <see cref="UnityEngine.GameObject"/> be loaded</param>
        /// <param name="dataCallback">Custom resource data retrieval callback. Pass this parameter when you need to load external data while loading from memory.</param>
        /// <param name="existsCallback">Custom resource size retrieval callback. Pass this parameter when you need to load external data while loading from memory.</param>
        /// <param name="progressCallback">Callback used to retrieve file loading percentage.</param>
        /// <returns>The created Thread on NET 2.0, otherwise returns the created Task.</returns>
#if !UNITY_EDITOR && (NETFX_CORE || NET_4_6 || NET_STANDARD_2_0) && !ENABLE_IL2CPP && !ENABLE_MONO
        public Task LoadFromMemoryWithTextures(int filesCount, AssetLoaderOptions options, GameObject wrapperGameObject, ObjectLoadedHandle onAssetLoaded, AssimpInterop.DataCallback dataCallback = null, AssimpInterop.ExistsCallback existsCallback = null, AssimpInterop.ProgressCallback progressCallback = null)
        public Thread LoadFromMemory(byte[] fileBytes, string filename, AssetLoaderOptions options = null,
                                     GameObject wrapperGameObject = null, ObjectLoadedHandle onAssetLoaded = null, string basePath = null, AssimpInterop.DataCallback dataCallback = null, AssimpInterop.ExistsCallback existsCallback = null, LoadTextureDataCallback loadTextureDataCallback = null, AssimpInterop.ProgressCallback progressCallback = null)
#endif
        {
            if (basePath == null)
            {
                basePath = FileUtils.GetFileDirectory(filename);
            }
            var usesWrapperGameObject = wrapperGameObject != null;

            return(ThreadUtils.RunThread(delegate
            {
                InternalLoadFromMemory(fileBytes, filename, basePath, options, usesWrapperGameObject, dataCallback, existsCallback, loadTextureDataCallback, progressCallback);
            },
                                         delegate
            {
                var loadedGameObject = BuildGameObject(options, filename, wrapperGameObject);
                if (onAssetLoaded != null)
                {
                    onAssetLoaded(loadedGameObject);
                }
                ReleaseImport();
            }
                                         ));
        }
Example #9
0
        /// <summary>
        /// Loads a <see cref="UnityEngine.GameObject"/> from browser files.
        /// </summary>
        /// <param name="filesCount">Browser files count.</param>
        /// <param name="options"><see cref="AssetLoaderOptions"/> used to load the object.</param>
        /// <param name="wrapperGameObject">Use this field to load the new <see cref="UnityEngine.GameObject"/> into referenced <see cref="UnityEngine.GameObject"/>.</param>
        /// <param name="dataCallback">Custom resource data retrieval callback. Pass this parameter when you need to load external data while loading from memory.</param>
        /// <param name="existsCallback">Custom resource size retrieval callback. Pass this parameter when you need to load external data while loading from memory.</param>
        /// <param name="progressCallback">Callback used to retrieve file loading percentage.</param>
        /// <returns>Loaded <see cref="UnityEngine.GameObject"></see>.</returns>
        public GameObject LoadFromBrowserFilesWithTextures(int filesCount, AssetLoaderOptions options = null, GameObject wrapperGameObject = null, AssimpInterop.DataCallback dataCallback = null, AssimpInterop.ExistsCallback existsCallback = null, AssimpInterop.ProgressCallback progressCallback = null)
        {
            byte[] fileData;
            string fileName;
            string fileExtension;

            if (!GetSupportedBrowserFileData(filesCount, out fileData, out fileName, out fileExtension))
            {
                return(null);
            }
            InternalLoadFromBrowserFiles(filesCount, fileData, fileName, fileExtension, options, wrapperGameObject != null, dataCallback, existsCallback, null, progressCallback);
            var loadedGameObject = BuildGameObject(options, fileExtension, wrapperGameObject);

            ReleaseImport();
            return(loadedGameObject);
        }