/// <summary> /// VRMファイルを読み込む /// </summary> /// <param name="bytes"></param> /// <returns></returns> async Task <VRMImporterContext> Load(string path) { var context = new VRMImporterContext(); try { context.ParseGlb(File.ReadAllBytes(path)); await context.LoadAsyncTask(); } catch { context.Dispose(); throw; } if (await AskLoadingVRM(path, context.ReadMeta(true))) { return(context); } else { context.Dispose(); return(null); } }
public static VrmMeta Generate(string vrmFileFullName) { var bytes = File.ReadAllBytes(vrmFileFullName); var vrmImporterContext = new VRMImporterContext(); vrmImporterContext.ParseGlb(bytes); var meta = vrmImporterContext.ReadMeta(true); var vrmMeta = new VrmMeta { VrmFileName = Path.GetFileName(vrmFileFullName), Title = meta.Title, Version = meta.Version, Author = meta.Author, ContactInformation = meta.ContactInformation, Reference = meta.Reference, Thumbnail = meta.Thumbnail?.EncodeToPNG(), ThumbnailWidth = meta.Thumbnail ? meta.Thumbnail.width : 0, ThumbnailHeight = meta.Thumbnail ? meta.Thumbnail.height : 0, AllowedUser = meta.AllowedUser, ViolentUssage = meta.ViolentUssage, SexualUssage = meta.SexualUssage, CommercialUssage = meta.CommercialUssage, OtherPermissionUrl = meta.OtherPermissionUrl, LicenseType = meta.LicenseType, OtherLicenseUrl = meta.OtherLicenseUrl, }; vrmImporterContext.Dispose(); return(vrmMeta); }
public void EndPerformance() { //Application.LoadLevel(0); //SceneManager.LoadScene(0); screenoverlays.enabled = true; context.Dispose(); Destroy(LipsSyncContoller); Destroy(mainCameraSwitcher); foreach (var p in objectsNeedsActivation) { Destroy(p); } }
async void ShowAvatarInfo() { VRMMetaObject meta; try { // Load and analyze VRM var ctx = new VRMImporterContext(); ctx.ParseGlb(File.ReadAllBytes(AvatarInput.text)); meta = ctx.ReadMeta(); ctx.Dispose(); // Create information text using (var writer = new StringWriter()) { writer.NewLine = "\n"; writer.WriteLine($"<b>{meta.Title}</b> by <b>{meta.Author} ({meta.ContactInformation})</b>"); // Use Unity's text styling to emphasize some information // (coloring is done in ColorizeVrmAllowedUser and ColorizeVrmUsageLicense methods) // https://docs.unity3d.com/ja/2019.4/Manual/StyledText.html writer.WriteLine($"Allowed user: <b>{ColorizeVrmAllowedUser(meta.AllowedUser)}</b>"); writer.WriteLine($"Violent usage: <b>{ColorizeVrmUsageLicense(meta.ViolentUssage)}</b>"); writer.WriteLine($"Sexual usage: <b>{ColorizeVrmUsageLicense(meta.SexualUssage)}</b>"); writer.WriteLine($"Commercial usage: <b>{ColorizeVrmUsageLicense(meta.CommercialUssage)}</b>"); writer.WriteLine($"Other permission: <b>{meta.OtherPermissionUrl}</b>"); writer.WriteLine($"License: <b>{meta.LicenseType}</b>"); writer.WriteLine($"Other license: <b>{meta.OtherLicenseUrl}</b>"); AvatarInfo.text = writer.ToString(); } } catch (Exception e) { AvatarInfo.text = "<color=red>Avatar load error</color>\n" + e.ToString(); } // Rebuild Vertical Layout Group using new size of AvatarInfo (changed according to its content by Content Size Filter) // https://docs.unity3d.com/ja/2019.4/Manual/UIAutoLayout.html // https://docs.unity3d.com/ja/2019.4/Manual/HOWTO-UIFitContentSize.html await UniTask.WaitForEndOfFrame(); // Somehow, frame wait is needed before MarkLayoutForRebuild LayoutRebuilder.MarkLayoutForRebuild(AvatarInfo.transform.parent.GetComponent <RectTransform>()); }
// Start is called before the first frame update async void Start() { var path = GameObject.Find("SceneController").GetComponent <SceneController>().path; Debug.Log("start" + path); // VRMを読み込む機能の提供 var context = new VRMImporterContext(); // ファイルをByte配列に読み込みファイルを閉じる var bytes = File.ReadAllBytes(path); // GLB形式でJSONを取得しParseする context.ParseGlb(bytes); // metaデータの取得 // 引数にサムネイルの取得設定を行える var meta = context.ReadMeta(false); Debug.LogFormat("meta_title: {0}", meta.Title); // LoadAsync後に引数のメソッドが呼び出されるように登録 // context.LoadAsync(_ => OnLoaded(context)); // 今UnityのVersionだとObsoleteになっている try { // awaitを使いたいのでメソッドにasyncを付ける await context.LoadAsyncTask(); // context.EnableUpdateWhenOffscreen(); OnLoaded(context); } catch (Exception e) { Debug.LogError(e); // 関連するリソースを破棄する context.Dispose(); throw; } }
public void VRMDestroy() { context.Dispose(); next.Transition(); }
public void Dispose() { currentContext?.Dispose(); }
private void OnDestroy() { Context.Dispose(); }
void OnDestroy() { ctx.Dispose(); }