private static Schedulable <GameObject> LoadVrmAsyncInternal(VRMImporterContext ctx, bool show) { var schedulable = Schedulable.Create(); return(schedulable .AddTask(Scheduler.ThreadPool, () => { return glTF_VRM_Material.Parse(ctx.Json); }) .ContinueWith(Scheduler.MainThread, x => { // material function ctx.CreateMaterial = VRMImporter.GetMaterialFunc(x); }) .OnExecute(Scheduler.ThreadPool, parent => { // textures for (int i = 0; i < ctx.GLTF.textures.Count; ++i) { var index = i; parent.AddTask(Scheduler.MainThread, () => { var texture = new TextureItem(ctx.GLTF, index); texture.Process(ctx.GLTF, ctx.Storage); return texture; }) .ContinueWith(Scheduler.ThreadPool, x => ctx.Textures.Add(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, () => gltfImporter.ReadMesh(ctx, index)) .ContinueWith(Scheduler.MainThread, x => gltfImporter.BuildMesh(ctx, x)) .ContinueWith(Scheduler.ThreadPool, x => ctx.Meshes.Add(x)) ; } }) .ContinueWithCoroutine(Scheduler.MainThread, () => LoadNodes(ctx)) .ContinueWithCoroutine(Scheduler.MainThread, () => BuildHierarchy(ctx)) .ContinueWith(Scheduler.CurrentThread, _ => VRMImporter.OnLoadModel(ctx)) .ContinueWith(Scheduler.CurrentThread, _ => { ctx.Root.name = "VRM"; if (show) { ctx.ShowMeshes(); } return ctx.Root; })); }
static IEnumerator LoadTextures(VRMImporterContext context) { for (int i = 0; i < context.GLTF.textures.Count; ++i) { var x = new TextureItem(context.GLTF, i); x.Process(); context.Textures.Add(x); yield return(null); } }
public VRMMetaObject ReadMeta(bool createThumbnail = false) { var meta = ScriptableObject.CreateInstance <VRMMetaObject>(); meta.name = "Meta"; meta.ExporterVersion = GLTF.extensions.VRM.exporterVersion; var gltfMeta = GLTF.extensions.VRM.meta; meta.Version = gltfMeta.version; // model version meta.Author = gltfMeta.author; meta.ContactInformation = gltfMeta.contactInformation; meta.Reference = gltfMeta.reference; meta.Title = gltfMeta.title; var thumbnail = GetTexture(gltfMeta.texture); if (thumbnail != null) { // ロード済み meta.Thumbnail = thumbnail.Texture; } else if (createThumbnail) { // 作成する(先行ロード用) if (gltfMeta.texture >= 0 && gltfMeta.texture < GLTF.textures.Count) { var t = new TextureItem(gltfMeta.texture, CreateTextureLoader(gltfMeta.texture)); t.Process(GLTF, Storage); meta.Thumbnail = t.Texture; } } meta.AllowedUser = gltfMeta.allowedUser; meta.ViolentUssage = gltfMeta.violentUssage; meta.SexualUssage = gltfMeta.sexualUssage; meta.CommercialUssage = gltfMeta.commercialUssage; meta.OtherPermissionUrl = gltfMeta.otherPermissionUrl; meta.LicenseType = gltfMeta.licenseType; meta.OtherLicenseUrl = gltfMeta.otherLicenseUrl; return(meta); }
private static Schedulable <GameObject> LoadVrmAsyncInternal(VRMImporterContext ctx) { var schedulable = Schedulable.Create(); return(schedulable .AddTask(Scheduler.ThreadPool, () => { ctx.GLTF.baseDir = Path.GetDirectoryName(ctx.Path); return Unit.Default; }) .ContinueWith(Scheduler.ThreadPool, _ => { return glTF_VRM_Material.Parse(ctx.Json); }) .ContinueWith(Scheduler.MainThread, x => { // material function ctx.CreateMaterial = VRMImporter.GetMaterialFunc(x); }) .OnExecute(Scheduler.ThreadPool, parent => { // textures for (int i = 0; i < ctx.GLTF.textures.Count; ++i) { var index = i; parent.AddTask(Scheduler.MainThread, () => { var texture = new TextureItem(ctx.GLTF, index); texture.Process(); return texture; }) .ContinueWith(Scheduler.ThreadPool, x => ctx.Textures.Add(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, () => gltfImporter.ReadMesh(ctx, index)) .ContinueWith(Scheduler.MainThread, x => gltfImporter.BuildMesh(ctx, x)) .ContinueWith(Scheduler.ThreadPool, x => ctx.Meshes.Add(x)) ; } }) .ContinueWithCoroutine(Scheduler.MainThread, () => LoadNodes(ctx)) .ContinueWithCoroutine(Scheduler.MainThread, () => BuildHierarchy(ctx)) .ContinueWith(Scheduler.MainThread, _ => VRMImporter.OnLoadModel(ctx)) .ContinueWith(Scheduler.MainThread, _ => { /* * Debug.LogFormat("task end: {0}/{1}/{2}/{3}", * ctx.Textures.Count, * ctx.Materials.Count, * ctx.Meshes.Count, * ctx.Nodes.Count * ); */ ctx.Root.name = Path.GetFileNameWithoutExtension(ctx.Path); // 非表示のメッシュを表示する ctx.ShowMeshes(); return ctx.Root; })); }
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; })); }
protected override Schedulable <Unit> LoadAsync() { return(Schedulable.Create() .AddTask(Scheduler.ThreadPool, () => { using (MeasureTime("glTF_VRM_Material.Parse")) { return glTF_VRM_Material.Parse(Json); } }) .ContinueWith(Scheduler.MainThread, gltfMaterials => { using (MeasureTime("new VRMMaterialImporter")) { SetMaterialImporter(new VRMMaterialImporter(this, gltfMaterials)); } }) .OnExecute(Scheduler.ThreadPool, parent => { // textures for (int i = 0; i < GLTF.textures.Count; ++i) { var index = i; parent.AddTask(Scheduler.MainThread, () => { using (MeasureTime("texture.Process")) { var texture = new TextureItem(index); texture.Process(GLTF, Storage); return texture; } }) .ContinueWith(Scheduler.ThreadPool, x => AddTexture(x)); } }) .ContinueWithCoroutine(Scheduler.MainThread, () => LoadMaterials()) .OnExecute(Scheduler.ThreadPool, parent => { // 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")) { return MeshImporter.BuildMesh(this, x); } }) .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.CurrentThread, _ => { //using (MeasureTime("OnLoadModel")) { OnLoadModel(); return Unit.Default; } }) .ContinueWith(Scheduler.CurrentThread, _ => { Root.name = "VRM"; Debug.Log(GetSpeedLog()); return Unit.Default; })); }