Exemplo n.º 1
0
        /// <summary>
        /// Export data asynchronously to a byte array.
        /// </summary>
        /// <param name="scene">The scene representation to export.</param>
        /// <param name="filename">The name of the file corresponding to the exported data. The extension is used to determine which codec use.</param>
        /// <param name="return_callback">The calback used to notify the caller when the export is completed.</param>
        /// <param name="progress_callback">The callback to regularly notify the caller of the export progress.</param>
        /// <returns>An iterator to use inside a coroutine.</returns>
        public IEnumerator ExportToBytes(Scene scene, string filename, ExporterReturnCallback return_callback, ProgressCallback progress_callback)
        {
            // Assimp currently does not support export to byte array directly
            bool success = false;

            // Create a temporary file to export the data
            string tmp_file = Path.GetTempPath() + Path.GetFileName(filename);

            // Export to the temporary file
            IEnumerator it = ExportToFile(scene, tmp_file, result => success = result, progress_callback);

            while (it.MoveNext())
            {
                yield return(it.Current);
            }

            FileInfo file_info = new FileInfo(tmp_file);

            if (file_info.Exists)
            {
                // Read the exported data and send it back to the caller
                if (success && return_callback != null)
                {
                    return_callback(File.ReadAllBytes(file_info.FullName));
                }

                // Remove the temporary file if it exists
                file_info.Delete();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Export data asynchronously to a byte array.
        /// </summary>
        /// <param name="scene">The scene representation to export.</param>
        /// <param name="filename">The name of the file corresponding to the exported data. The extension is used to determine which codec use.</param>
        /// <param name="return_callback">The calback used to notify the caller when the export is completed.</param>
        /// <param name="progress_callback">The callback to regularly notify the caller of the export progress.</param>
        /// <returns>An iterator to use inside a coroutine.</returns>
        public IEnumerator ExportToBytes(Scene scene, string filename, ExporterReturnCallback return_callback, ProgressCallback progress_callback)
        {
            return(Import.Binary.serializer.Serialize(scene, (data, written) => {
                byte[] result = new byte[written];

                Array.Copy(data, result, (int)written);

                return_callback(result);
            }, p => progress_callback(p)));
        }