Example #1
0
        public virtual async Task <RuntimeGltfInstance> LoadAsync(IAwaitCaller awaitCaller, Func <string, IDisposable> MeasureTime = null)
        {
            if (awaitCaller == null)
            {
                throw new ArgumentNullException();
            }

            if (MeasureTime == null)
            {
                MeasureTime = new ImporterContextSpeedLog().MeasureTime;
            }

            if (GLTF.extensionsRequired != null)
            {
                var sb = new List <string>();
                foreach (var required in GLTF.extensionsRequired)
                {
                    if (UnsupportedExtensions.Contains(required))
                    {
                        sb.Add(required);
                    }
                }
                if (sb.Any())
                {
                    throw new UniGLTFNotSupportedException(string.Join(", ", sb) + " is not supported");
                }
            }

            using (MeasureTime("LoadTextures"))
            {
                await LoadTexturesAsync(awaitCaller);
            }

            using (MeasureTime("LoadMaterials"))
            {
                await LoadMaterialsAsync(awaitCaller);
            }

            await LoadGeometryAsync(awaitCaller, MeasureTime);

            if (LoadAnimation)
            {
                using (MeasureTime("AnimationImporter"))
                {
                    await LoadAnimationAsync(awaitCaller);
                    await SetupAnimationsAsync(awaitCaller);
                }
            }

            await OnLoadHierarchy(awaitCaller, MeasureTime);

            return(RuntimeGltfInstance.AttachTo(Root, this));
        }
        /// <summary>
        /// Build unity objects from parsed gltf
        /// </summary>
        public static void Load(this ImporterContext self)
        {
            var meassureTime = new ImporterContextSpeedLog();
            var task         = self.LoadAsync(default(ImmediateCaller), meassureTime.MeasureTime);

            if (!task.IsCompleted)
            {
                throw new Exception();
            }
#if VRM_DEVELOP
            Debug.Log(meassureTime.GetSpeedLog());
#endif
        }
Example #3
0
        /// <summary>
        /// Build unity objects from parsed gltf
        /// </summary>
        public static void Load(this ImporterContext self)
        {
            var meassureTime = new ImporterContextSpeedLog();
            var task         = self.LoadAsync(default(ImmediateCaller), meassureTime.MeasureTime);

            if (!task.IsCompleted)
            {
                throw new Exception();
            }
            if (task.IsFaulted)
            {
                throw new AggregateException(task.Exception);
            }

#if VRM_DEVELOP
            Debug.Log($"{self.Parser.TargetPath}: {meassureTime.GetSpeedLog()}");
#endif
        }
        /// <summary>
        /// Build unity objects from parsed gltf
        /// </summary>
        public static RuntimeGltfInstance Load(this ImporterContext self)
        {
            var meassureTime = new ImporterContextSpeedLog();
            var task         = self.LoadAsync(new ImmediateCaller(), meassureTime.MeasureTime);

            if (!task.IsCompleted)
            {
                throw new Exception();
            }
            if (task.IsFaulted)
            {
                throw new AggregateException(task.Exception);
            }

#if VRM_DEVELOP
            Debug.Log($"{self.Data.TargetPath}: {meassureTime.GetSpeedLog()}");
#endif

            return(task.Result);
        }
Example #5
0
        /// <summary>
        /// Build unity objects from parsed gltf
        /// </summary>
        public static void Load(this ImporterContext self)
        {
            var meassureTime = new ImporterContextSpeedLog();
            var task         = self.LoadAsync(default(ImmediateCaller), meassureTime.MeasureTime);

            if (!task.IsCompleted)
            {
                throw new Exception();
            }
            if (task.IsFaulted)
            {
                if (task.Exception is AggregateException ae && ae.InnerExceptions.Count == 1)
                {
                    throw ae.InnerException;
                }
                else
                {
                    throw task.Exception;
                }
            }
        /// <summary>
        /// Build unity objects from parsed gltf
        /// </summary>
        public static void Load(this ImporterContext self)
        {
            var meassureTime = new ImporterContextSpeedLog();

            using (var queue = TaskQueue.Create())
            {
                var task = self.LoadAsync(meassureTime.MeasureTime);

                // 中断された await を消化する
                while (!task.IsCompleted)
                {
                    // execute synchronous
                    queue.ExecuteOneCallback();
                }
            }

#if VRM_DEVELOP
            Debug.Log(meassureTime.GetSpeedLog());
#endif
        }