private VRMData LoadVRM() { var path = WindowsDialogs.OpenFileDialog("VRMファイル選択", ".vrm"); if (string.IsNullOrEmpty(path)) { return null; } var vrmdata = new VRMData(); vrmdata.FilePath = path; var context = new VRMImporterContext(path); var bytes = File.ReadAllBytes(path); // GLB形式でJSONを取得しParseします context.ParseVrm(bytes); // metaを取得 var meta = context.ReadMeta(true); //サムネイル if (meta.Thumbnail != null) { vrmdata.ThumbnailPNGBytes = meta.Thumbnail.EncodeToPNG(); //Or SaveAsPng( memoryStream, texture.Width, texture.Height ) } //Info vrmdata.Title = meta.Title; vrmdata.Version = meta.Version; vrmdata.Author = meta.Author; vrmdata.ContactInformation = meta.ContactInformation; vrmdata.Reference = meta.Reference; // Permission vrmdata.AllowedUser = (ControlWindow.AllowedUser)meta.AllowedUser; vrmdata.ViolentUssage = (ControlWindow.UssageLicense)meta.ViolentUssage; vrmdata.SexualUssage = (ControlWindow.UssageLicense)meta.SexualUssage; vrmdata.CommercialUssage = (ControlWindow.UssageLicense)meta.CommercialUssage; vrmdata.OtherPermissionUrl = meta.OtherPermissionUrl; // Distribution License vrmdata.LicenseType = (ControlWindow.LicenseType)meta.LicenseType; vrmdata.OtherLicenseUrl = meta.OtherLicenseUrl; /* // ParseしたJSONをシーンオブジェクトに変換していく var now = Time.time; var go = await VRMImporter.LoadVrmAsync(context); var delta = Time.time - now; Debug.LogFormat("LoadVrmAsync {0:0.0} seconds", delta); //OnLoaded(go); */ return vrmdata; }
private async void ImportVRM(string path, bool ImportForCalibration) { CurrentSettings.VRMPath = path; var context = new VRMImporterContext(path); var bytes = File.ReadAllBytes(path); // GLB形式でJSONを取得しParseします context.ParseVrm(bytes); if (CurrentModel != null) { CurrentModel.transform.SetParent(null); CurrentModel.SetActive(false); Destroy(CurrentModel); CurrentModel = null; } // ParseしたJSONをシーンオブジェクトに変換していく CurrentModel = await VRMImporter.LoadVrmAsync(context); //LipSync LipSync.ImportVRMmodel(CurrentModel); //まばたき blinkController.ImportVRMmodel(CurrentModel); CurrentModel.transform.SetParent(transform, false); SetVRIK(CurrentModel); if (ImportForCalibration == false) { SetCameraLookTarget(); //SetTrackersToVRIK(); } else { var animator = CurrentModel.GetComponent<Animator>(); if (animator != null) { if (CalibrationCamera != null) { CalibrationCamera.Target = animator.GetBoneTransform(HumanBodyBones.Head); CalibrationCamera.gameObject.SetActive(true); } } } }