Beispiel #1
0
 static IEnumerator LoadTextures(VRMImporterContext context, IStorage storage)
 {
     for (int i = 0; i < context.GLTF.textures.Count; ++i)
     {
         var x = new TextureItem(context.GLTF, i);
         x.Process(context.GLTF, storage);
         context.AddTexture(x);
         yield return(null);
     }
 }
Beispiel #2
0
        private static Schedulable <GameObject> LoadVrmAsyncInternal(VRMImporterContext ctx, bool show)
        {
            return(Schedulable.Create()
                   .AddTask(Scheduler.ThreadPool, () =>
            {
                using (ctx.MeasureTime("glTF_VRM_Material.Parse"))
                {
                    return glTF_VRM_Material.Parse(ctx.Json);
                }
            })
                   .ContinueWith(Scheduler.MainThread, gltfMaterials =>
            {
                using (ctx.MeasureTime("new VRMMaterialImporter"))
                {
                    ctx.MaterialImporter = new VRMMaterialImporter(ctx, gltfMaterials);
                }
            })
                   .OnExecute(Scheduler.ThreadPool, parent =>
            {
                // textures
                for (int i = 0; i < ctx.GLTF.textures.Count; ++i)
                {
                    var index = i;
                    parent.AddTask(Scheduler.MainThread,
                                   () =>
                    {
                        using (ctx.MeasureTime("texture.Process"))
                        {
                            var texture = new TextureItem(ctx.GLTF, index);
                            texture.Process(ctx.GLTF, ctx.Storage);
                            return texture;
                        }
                    })
                    .ContinueWith(Scheduler.ThreadPool, x => ctx.AddTexture(x));
                }
            })
                   .ContinueWithCoroutine(Scheduler.MainThread, () => LoadMaterials(ctx))
                   .OnExecute(Scheduler.ThreadPool, parent =>
            {
                // meshes
                for (int i = 0; i < ctx.GLTF.meshes.Count; ++i)
                {
                    var index = i;
                    parent.AddTask(Scheduler.ThreadPool,
                                   () =>
                    {
                        using (ctx.MeasureTime("ReadMesh"))
                        {
                            return gltfImporter.ReadMesh(ctx, index);
                        }
                    })
                    .ContinueWith(Scheduler.MainThread, x =>
                    {
                        using (ctx.MeasureTime("BuildMesh"))
                        {
                            return gltfImporter.BuildMesh(ctx, x);
                        }
                    })
                    .ContinueWith(Scheduler.ThreadPool, x => ctx.Meshes.Add(x))
                    ;
                }
            })
                   .ContinueWithCoroutine(Scheduler.MainThread, () =>
            {
                using (ctx.MeasureTime("LoadNodes"))
                {
                    return LoadNodes(ctx);
                }
            })
                   .ContinueWithCoroutine(Scheduler.MainThread, () =>
            {
                using (ctx.MeasureTime("BuildHierarchy"))
                {
                    return BuildHierarchy(ctx);
                }
            })
                   .ContinueWith(Scheduler.CurrentThread, _ =>
            {
                //using (ctx.MeasureTime("OnLoadModel"))
                {
                    return VRMImporter.OnLoadModel(ctx);
                }
            })
                   .ContinueWith(Scheduler.CurrentThread,
                                 _ =>
            {
                ctx.Root.name = "VRM";

                if (show)
                {
                    ctx.ShowMeshes();
                }

                Debug.Log(ctx.GetSpeedLog());
                return ctx.Root;
            }));
        }