protected virtual Schedulable <Unit> LoadAsync()
        {
            return
                (Schedulable.Create()
                 .AddTask(Scheduler.ThreadPool, () =>
            {
                if (m_textures.Count == 0)
                {
                    //
                    // runtime
                    //
                    CreateTextureItems();
                }
                else
                {
                    //
                    // already CreateTextures(by assetPostProcessor or editor menu)
                    //
                }
            })
                 .ContinueWithCoroutine(Scheduler.ThreadPool, TexturesProcessOnAnyThread)
                 .ContinueWithCoroutine(Scheduler.MainThread, TexturesProcessOnMainThread)
                 .ContinueWithCoroutine(Scheduler.MainThread, LoadMaterials)
                 .OnExecute(Scheduler.ThreadPool, parent =>
            {
                // UniGLTF does not support draco
                // https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_draco_mesh_compression/README.md#conformance
                if (GLTF.extensionsRequired.Contains("KHR_draco_mesh_compression"))
                {
                    throw new UniGLTFNotSupportedException("draco is not supported");
                }

                // meshes
                var meshImporter = new MeshImporter();
                for (int i = 0; i < GLTF.meshes.Count; ++i)
                {
                    var index = i;
                    parent.AddTask(Scheduler.ThreadPool,
                                   () =>
                    {
                        using (MeasureTime("ReadMesh"))
                        {
                            return meshImporter.ReadMesh(this, index);
                        }
                    })
                    .ContinueWith(Scheduler.MainThread, x =>
                    {
                        using (MeasureTime("BuildMesh"))
                        {
                            var meshWithMaterials = MeshImporter.BuildMesh(this, x);

                            var mesh = meshWithMaterials.Mesh;

                            // mesh name
                            if (string.IsNullOrEmpty(mesh.name))
                            {
                                mesh.name = string.Format("UniGLTF import#{0}", i);
                            }
                            var originalName = mesh.name;
                            for (int j = 1; Meshes.Any(y => y.Mesh.name == mesh.name); ++j)
                            {
                                mesh.name = string.Format("{0}({1})", originalName, j);
                            }

                            return meshWithMaterials;
                        }
                    })
                    .ContinueWith(Scheduler.ThreadPool, x => Meshes.Add(x))
                    ;
                }
            })
                 .ContinueWithCoroutine(Scheduler.MainThread, LoadNodes)
                 .ContinueWithCoroutine(Scheduler.MainThread, BuildHierarchy)
                 .ContinueWith(Scheduler.MainThread, _ =>
            {
                using (MeasureTime("AnimationImporter"))
                {
                    AnimationImporter.ImportAnimation(this);
                }
            })
                 .ContinueWith(Scheduler.CurrentThread,
                               _ =>
            {
                OnLoadModel();
                if (m_showSpeedLog)
                {
                    Debug.Log(GetSpeedLog());
                }
                return Unit.Default;
            }));
        }
Пример #2
0
        protected virtual Schedulable <Unit> LoadAsync()
        {
            return
                (Schedulable.Create()
                 .AddTask(Scheduler.ThreadPool, () =>
            {
                if (m_textures.Count == 0)
                {
                    //
                    // runtime
                    //
                    CreateTextureItems();
                }
                else
                {
                    //
                    // already CreateTextures(by assetPostProcessor or editor menu)
                    //
                }
            })
                 .ContinueWithCoroutine(Scheduler.ThreadPool, () =>
            {
                using (MeasureTime("TexturesProcessOnAnyThread"))
                {
                    return TexturesProcessOnAnyThread();
                }
            })
                 .ContinueWithCoroutine(Scheduler.MainThread, () =>
            {
                using (MeasureTime("TexturesProcessOnMainThread"))
                {
                    return TexturesProcessOnMainThread();
                }
            })
                 .ContinueWithCoroutine(Scheduler.MainThread, () =>
            {
                using (MeasureTime("LoadMaterials"))
                {
                    return LoadMaterials();
                }
            })
                 .OnExecute(Scheduler.ThreadPool, parent =>
            {
                if (GLTF.meshes
                    .SelectMany(x => x.primitives)
                    .Any(x => x.extensions.KHR_draco_mesh_compression != null))
                {
                    throw new UniGLTFNotSupportedException("draco is not supported");
                }

                // meshes
                var meshImporter = new MeshImporter();
                for (int i = 0; i < GLTF.meshes.Count; ++i)
                {
                    var index = i;
                    parent.AddTask(Scheduler.ThreadPool,
                                   () =>
                    {
                        using (MeasureTime("ReadMesh"))
                        {
                            return meshImporter.ReadMesh(this, index);
                        }
                    })
                    .ContinueWith(Scheduler.MainThread, x =>
                    {
                        using (MeasureTime("BuildMesh"))
                        {
                            var meshWithMaterials = MeshImporter.BuildMesh(this, x);

                            var mesh = meshWithMaterials.Mesh;

                            // mesh name
                            if (string.IsNullOrEmpty(mesh.name))
                            {
                                mesh.name = string.Format("UniGLTF import#{0}", i);
                            }
                            var originalName = mesh.name;
                            for (int j = 1; Meshes.Any(y => y.Mesh.name == mesh.name); ++j)
                            {
                                mesh.name = string.Format("{0}({1})", originalName, j);
                            }

                            return meshWithMaterials;
                        }
                    })
                    .ContinueWith(Scheduler.ThreadPool, x => Meshes.Add(x))
                    ;
                }
            })
                 .ContinueWithCoroutine(Scheduler.MainThread, () =>
            {
                using (MeasureTime("LoadNodes"))
                {
                    return LoadNodes();
                }
            })
                 .ContinueWithCoroutine(Scheduler.MainThread, () =>
            {
                using (MeasureTime("BuildHierarchy"))
                {
                    return BuildHierarchy();
                }
            })
                 .ContinueWith(Scheduler.MainThread, _ =>
            {
                AnimationImporter.ImportAnimation(this);
            })
                 .ContinueWith(Scheduler.CurrentThread,
                               _ =>
            {
                OnLoadModel();
                Debug.Log(GetSpeedLog());
                return Unit.Default;
            }));
        }