/// <summary> /// load VRM from byte array /// </summary> /// <param name="file"></param> /// <returns>generated model GameObject</returns> public async Task <GameObject> LoadVRM(byte[] file) { // Parse Json to GLB var context = new VRMImporterContext(); context.ParseGlb(file); // Get VRM Meta data var meta = context.ReadMeta(true); Debug.Log("meta: title: " + meta.Title); //load await context.LoadAsyncTask(); //put model var root = context.Root; root.transform.rotation = new Quaternion(0, 180, 0, 0); root.tag = "Player"; await Task.Delay(500); root.AddComponent <ObjectMover>(); context.ShowMeshes(); return(root); }
async UniTask LoadVRM(string path) { #if UNITY_STANDALONE_WIN //|| UNITY_EDITOR var meta = await VRMMetaImporter.ImportVRMMeta(path, true); #else VRMMetaObject meta; using (UnityWebRequest uwr = UnityWebRequest.Get(path)) { await uwr.SendWebRequest(); VRMdata = uwr.downloadHandler.data; } using (var context = new VRMImporterContext()) { context.ParseGlb(VRMdata); meta = context.ReadMeta(true); } #endif GameObject modalObject = Instantiate(modalWindowPrefabs, canvas.transform) as GameObject; var modalLocale = modalObject.GetComponentInChildren <VRMPreviewLocale>(); modalLocale.SetLocale(language.captionText.text); var modalUi = modalObject.GetComponentInChildren <VRMPreviewUI>(); modalUi.setMeta(meta); modalUi.setLoadable(true); }
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); }
void LoadVRM(byte[] bytes) { // GLB形式のperse var context = new VRMImporterContext(); context.ParseGlb(bytes); // meta情報を読み込む bool createThumbnail = true; var meta = context.ReadMeta(createThumbnail); // ファイル読み込みモーダルウィンドウの呼び出し GameObject modalObject = Instantiate(m_modalWindowPrefab, m_canvas.transform) as GameObject; // 言語設定を取得・反映する var modalLocale = modalObject.GetComponentInChildren <VRMPreviewLocale>(); modalLocale.SetLocale(m_language.captionText.text); // meta情報の反映 var modalUI = modalObject.GetComponentInChildren <VRMPreviewUI>(); modalUI.setMeta(meta); // ファイルを開くことの許可 // ToDo: ファイルの読み込み許可を制御する場合はここで modalUI.setLoadable(true); // UniRxでイベントリスナ作成 modalUI.m_ok.onClick.AsObservable().Subscribe(_ => ModelLoad(context)).AddTo(modalObject); }
private void LoadModel(string path) { if (!File.Exists(path)) { return; } if (Path.GetExtension(path).ToLower() != ".vrm") { LogOutput.Instance.Write($"unknown file type: {path}"); return; } try { var context = new VRMImporterContext(); var file = File.ReadAllBytes(path); context.ParseGlb(file); var meta = context.ReadMeta(false); context.Load(); context.EnableUpdateWhenOffscreen(); context.ShowMeshes(); _sender.SendCommand(MessageFactory.Instance.ModelNameConfirmedOnLoad("VRM File: " + meta.Title)); SetModel(context.Root); } catch (Exception ex) { HandleLoadError(ex); } }
public async void Play() { record.RecordIncr(); var path = Application.streamingAssetsPath + "/" + "host.vrm"; var bytes = await new FileRead().ReadAllBytesAsync(path); var context = new VRMImporterContext(); context.ParseGlb(bytes); var meta = context.ReadMeta(false); Debug.LogFormat("meta: title:{0}", meta.Title); await context.LoadAsyncTask(); var go = context.Root; go.transform.SetParent(transform, false); go.transform.position = new Vector3(0, 0, 0); context.ShowMeshes(); var pos = SetupVRIK(go); int progress = 0; int index = record.RecordIndex; Observable.Interval(TimeSpan.FromSeconds(1 / 60)).Subscribe(_ => { if (progress >= 0) { progress = run(pos, progress, index); } }); }
/// <summary>Create VRMLoaderUI and set callback</summary> /// // Those codes are imported from VRMLoaderUI sample // https://github.com/m2wasabi/VRMLoaderUI/blob/master/Assets/VRMLoaderUI/Example/Scripts/ModelLoaderLegacy.cs void SetupVRMLoaderUI(string[] pathes) { string path = "file:///" + pathes[0]; // Load file var www = new WWW(path); m_context = new VRMImporterContext(); m_context.ParseGlb(www.bytes); var meta = m_context.ReadMeta(true); // instantinate UI GameObject modalObject = Instantiate(m_modalWindowPrefab, m_canvas.transform) as GameObject; // // determine language // var modalLocale = modalObject.GetComponentInChildren<VRMPreviewLocale>(); // modalLocale.SetLocale(m_language.captionText.text); // input VRM meta information to UI var modalUI = modalObject.GetComponentInChildren <VRMPreviewUI>(); modalUI.setMeta(meta); // Permission of file open modalUI.setLoadable(true); // define callback on load completed modalUI.m_ok.onClick.AddListener(ModelLoad); }
public void LoadVRMFromBytes(Byte[] bytes) { var context = new VRMImporterContext(); try { context.ParseGlb(bytes); var meta = context.ReadMeta(true); context.Load(); var model = context.Root; model.gameObject.name = meta.Title; context.ShowMeshes(); LoadVrmObject = context.Root; LoadVrmObject.transform.parent = ShadowObject.transform; LoadVrmObject.transform.localPosition = Vector3.zero; LoadVrmObject.transform.localRotation = Quaternion.identity; Animator ShadowObjectAnimator = ShadowObject.GetComponent <Animator>(); Animator VrmObjectAnimator = LoadVrmObject.GetComponent <Animator>(); ShadowObjectAnimator.avatar = VrmObjectAnimator.avatar; IsVrmLoaded = true; } catch (Exception e) { Debug.LogError(e); } }
IEnumerator LoadVRMCoroutine(string path) { var www = new WWW(path); yield return(www); // GLB形式のperse m_context = new VRMImporterContext(); m_context.ParseGlb(www.bytes); // meta情報を読み込む bool createThumbnail = true; var meta = m_context.ReadMeta(createThumbnail); // ファイル読み込みモーダルウィンドウの呼び出し GameObject modalObject = Instantiate(m_modalWindowPrefab, m_canvas.transform) as GameObject; // 言語設定を取得・反映する var modalLocale = modalObject.GetComponentInChildren <VRMPreviewLocale>(); modalLocale.SetLocale(m_language.captionText.text); // meta情報の反映 var modalUI = modalObject.GetComponentInChildren <VRMPreviewUI>(); modalUI.setMeta(meta); // ファイルを開くことの許可 // ToDo: ファイルの読み込み許可を制御する場合はここで modalUI.setLoadable(true); modalUI.m_ok.onClick.AddListener(ModelLoad); }
private void Start() { Avatar = null; _buttonVRM?.onClick.AddListener(async() => { var bytes = await UniTask.Run(() => ReadBytes()); if (bytes != null) { var context = new VRMImporterContext(); await UniTask.Run(() => context.ParseGlb(bytes)); var meta = context.ReadMeta(false); context.LoadAsync(() => OnLoaded(context)); } }); _buttonAssetBundle?.onClick.AddListener(async() => { string path = await Task.Run(() => OpenFileName.ShowDialog("all", ".")); //前のアバターの消去 GameObject[] othreAvatars = GameObject.FindGameObjectsWithTag("Avatar"); foreach (GameObject otherAvatar in othreAvatars) { Destroy(otherAvatar); } StartCoroutine(LoadBundleCoroutine(path)); }); }
/// ボタンをクリックした時の処理 public void OnClick() { // Open file with filter var extensions = new [] { new ExtensionFilter("VRM Files", "vrm"), new ExtensionFilter("All Files", "*"), }; var paths = StandaloneFileBrowser.OpenFilePanel("Open File", "", extensions, true); if (paths.Length > 0) { var file = paths[0]; byte[] bytes = FileBrowserHelpers.ReadBytesFromFile(file); var context = new VRMImporterContext(); try { context.ParseGlb(bytes); msg.text = "Import VRM finished successfully. (" + file + ")"; var meta = context.ReadMeta(false); //引数をTrueに変えるとサムネイルも読み込みます Debug.LogFormat("meta: title:{0}", meta.Title); //同期処理で読み込みます context.Load(); //読込が完了するとcontext.RootにモデルのGameObjectが入っています Destroy(instance); instance = context.Root; instance.transform.position = new Vector3(0, 0, 0); instance.transform.rotation = Quaternion.Euler(0, 0, 0); instance.AddComponent <PMXExporter>(); context.ShowMeshes(); } catch (Exception ex) { msg.text = "Error: " + ex.Message; } } }
public void LoadRequest(string path, Action <string, byte[]> callback) { byte[] bytes = File.ReadAllBytes(path); var context = new VRMImporterContext(); context.ParseGlb(bytes); var meta = context.ReadMeta(true); GameObject modalObject = Instantiate(m_modalWindowPrefab, m_canvas.transform) as GameObject; var modalLocale = modalObject.GetComponentInChildren <VRMPreviewLocale>(); modalLocale.SetLocale("ja"); if (modalUI != null) { modalUI.destroyMe(); modalUI = null; } modalUI = modalObject.GetComponentInChildren <VRMPreviewUI>(); modalUI.setMeta(meta); modalUI.setLoadable(true); callbackHandler = callback; VRMdata = bytes; VRMpath = path; }
/// <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); } }
void OnLoadClicked() { #if UNITY_STANDALONE_WIN var path = FileDialogForWindows.FileDialog("open VRM", ".vrm"); #else var path = Application.dataPath + "/default.vrm"; #endif if (string.IsNullOrEmpty(path)) { return; } var bytes = File.ReadAllBytes(path); // なんらかの方法でByte列を得た var context = new VRMImporterContext(); // GLB形式でJSONを取得しParseします context.ParseGlb(bytes); // metaを取得(todo: thumbnailテクスチャのロード) var meta = context.ReadMeta(); Debug.LogFormat("meta: title:{0}", meta.Title); // ParseしたJSONをシーンオブジェクトに変換していく context.LoadAsync(() => OnLoaded(context)); }
/// <summary> /// Taskで非同期にロードする例 /// </summary> async void LoadVRMClicked() { #if UNITY_STANDALONE_WIN var path = FileDialogForWindows.FileDialog("open VRM", ".vrm"); #else var path = Application.dataPath + "/default.vrm"; #endif if (string.IsNullOrEmpty(path)) { return; } var context = new VRMImporterContext(); var bytes = await ReadBytesAsync(path); // GLB形式でJSONを取得しParseします context.ParseGlb(bytes); // metaを取得(todo: thumbnailテクスチャのロード) var meta = context.ReadMeta(); Debug.LogFormat("meta: title:{0}", meta.Title); // ParseしたJSONをシーンオブジェクトに変換していく var now = Time.time; await context.LoadAsyncTask(); var delta = Time.time - now; Debug.LogFormat("LoadVrmAsync {0:0.0} seconds", delta); OnLoaded(context); }
public void GetModelFromName(string name, GameObject parent, GameObject MouseObject) { try { string ModelPath = Application.streamingAssetsPath + "../../../Data/vrm/" + name + ".vrm"; if (System.IO.File.Exists(ModelPath)) { var bytes = File.ReadAllBytes(ModelPath); var context = new VRMImporterContext(); context.ParseGlb(bytes); var metaObject = context.ReadMeta(false); /*Debug.LogFormat("meta: title:{0}", metaObject.Title); * Debug.LogFormat("meta: version:{0}", metaObject.Version); * Debug.LogFormat("meta: author:{0}", metaObject.Author); * Debug.LogFormat("meta: exporterVersion:{0}", metaObject.ExporterVersion);*/ var modelD = Path.GetDirectoryName(ModelPath); context.LoadAsync(() => { OnLoaded(context, parent, metaObject, modelD, MouseObject); }, OnError); } else { throw new Exception(Globle.LangController.GetLang("LOG.FileUnisset")); } } catch (Exception err) { Globle.AddDataLog("Main", Globle.LangController.GetLang("LOG.ModelAddationException", err.Message)); } }
void LoadVRM() { var extensions = new[] { new ExtensionFilter("VRM Files", "vrm", "VRM"), new ExtensionFilter("All Files", "*"), }; string path = StandaloneFileBrowser.OpenFilePanel("Open VRM", "", extensions, true)[0]; if (string.IsNullOrEmpty(path)) { return; } var bytes = File.ReadAllBytes(path); // なんらかの方法でByte列を得た var context = new VRMImporterContext(); // GLB形式でJSONを取得しParseします context.ParseGlb(bytes); // metaを取得(todo: thumbnailテクスチャのロード) var meta = context.ReadMeta(true); Debug.LogFormat("meta: title:{0}", meta.Title); ShowMetaInfo(meta); // UIに表示する // ParseしたJSONをシーンオブジェクトに変換していく context.LoadAsync(() => OnLoaded(context)); }
private async void ImportVRMAsync(string FilePath) { //VRMファイルのパスを指定します var path = FilePath; //ファイルをByte配列に読み込みます var bytes = File.ReadAllBytes(path); //VRMImporterContextがVRMを読み込む機能を提供します var context = new VRMImporterContext(); // GLB形式でJSONを取得しParseします context.ParseGlb(bytes); // VRMのメタデータを取得 var meta = context.ReadMeta(false); //引数をTrueに変えるとサムネイルも読み込みます //読み込めたかどうかログにモデル名を出力してみる Debug.LogFormat("meta: title:{0}", meta.Title); //非同期処理で読み込みます //context.LoadAsync(_ => OnLoaded(context)); await context.LoadAsyncTask(); OnLoaded(context); }
/// <summary> /// Metaデータの読み出し /// </summary> /// <param name="createThumbnail">サムネイルを作成するかどうか</param> /// <returns>VRMMetaObject</returns> public VRMMetaObject GetMeta(bool createThumbnail) { if (currentContext == null) { throw new InvalidOperationException("Need to initialize VRM model first."); } return(currentContext.ReadMeta(createThumbnail)); }
/// <summary> /// Get VRM model thumbnail from byte array /// </summary> /// <param name="file">Current model Thumbnail</param> /// <returns>Thumnail Texture2D</returns> public Texture2D GetVRMThumbnail(byte[] file) { //load metadata from vrm byte array var context = new VRMImporterContext(); var meta = context.ReadMeta(true); return(meta.Thumbnail); }
/// <summary> /// Unload the old model and load the new model from VRM file. /// </summary> /// <param name="path"></param> private void LoadModel(string path) { if (!File.Exists(path)) { Debug.Log("Model " + path + " is not exits."); return; } GameObject newModelObject = null; try { // Load from a VRM file. context = new VRMImporterContext(); //Debug.Log("Loading model : " + path); context.Load(path); newModelObject = context.Root; meta = context.ReadMeta(true); context.ShowMeshes(); } catch (Exception ex) { if (uiController) { uiController.SetWarning("Model load failed."); } Debug.LogError("Failed loading " + path); Debug.LogError(ex); return; } if (newModelObject) { if (model) { GameObject.Destroy(model.gameObject); } model = newModelObject.AddComponent <HumanPoseTransfer>(); var characterController = model.gameObject.AddComponent <CharacterBehaviour>(); SetMotion(motion, model, meta); if (uiController) { uiController.Show(meta); if (characterController) { uiController.enableRandomMotion = characterController.randomMotion; uiController.enableRandomEmotion = characterController.randomEmotion; } } } }
private async System.Threading.Tasks.Task onLoadVRMAsync(AvatarSetting setting) { videoCapture.PlayStop(); var path = ""; if (setting.AvatarType == 0) { path = setting.VRMFilePath; } else { path = setting.FBXFilePath; } if (path != "") { //ファイルをByte配列に読み込みます var bytes = File.ReadAllBytes(path); //VRMImporterContextがVRMを読み込む機能を提供します var context = new VRMImporterContext(); // GLB形式でJSONを取得しParseします context.ParseGlb(bytes); // VRMのメタデータを取得 var meta = context.ReadMeta(false); //引数をTrueに変えるとサムネイルも読み込みます //読み込めたかどうかログにモデル名を出力してみる //Debug.LogFormat("meta: title:{0}", meta.Title); //非同期処理(Task)で読み込みます await context.LoadAsyncTask(); /// //読込が完了するとcontext.RootにモデルのGameObjectが入っています var avatarObject = context.Root; avatarObject.name = setting.AvatarName; //モデルをワールド上に配置します avatarObject.transform.SetParent(transform.parent, false); SetVRMBounds(avatarObject.transform); //メッシュを表示します context.ShowMeshes(); setting.Avatar = avatarObject.AddComponent <VNectModel>(); setting.Avatar.ModelObject = avatarObject; setting.Avatar.SetNose(setting.FaceOriX, setting.FaceOriY, setting.FaceOriZ); setting.Avatar.SkeletonMaterial = skeletonMaterial; DiactivateAvatars(); avatars.options.Add(new Dropdown.OptionData(setting.AvatarName)); barracudaRunner.InitVNectModel(setting.Avatar, configurationSetting); } }
private static VRMImporterContext LoadFile(string filePath) { var bytes = File.ReadAllBytes(filePath); var context = new VRMImporterContext(); context.ParseGlb(bytes); var meta = context.ReadMeta(false); return(context); }
/// <summary> /// Metaデータの読み出し /// </summary> /// <param name="createThumbnail">サムネイルを作成するかどうか</param> /// <returns>VRMMetaObject</returns> public VRMMetaObject GetMeta(bool createThumbnail) { #if UNIVRM_LEGACY_IMPORTER || UNIVRM_0_68_IMPORTER || UNIVRM_0_77_IMPORTER if (currentContext == null) { throw new InvalidOperationException("Need to initialize VRM model first."); } return(currentContext.ReadMeta(createThumbnail)); #else return(null); #endif }
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; }
void VRM(string path) { var bytes = File.ReadAllBytes(path); var context = new VRMImporterContext(); context.ParseGlb(bytes); var meta = context.ReadMeta(true); var modal = Instantiate(LoadConfirmModal, Canvas.transform) as GameObject; var ui = modal.GetComponentInChildren <VRMPreviewUI>(); ui.setMeta(meta); ui.setLoadable(true); ui.m_ok.onClick.AddListener(() => LoadAsync(context, path)); }
private void OnGUI() { if (GUI.Button(new Rect(100, 100, 200, 40), "VRM Import")) { string path = OpenFileName.ShowDialog("open vrm", "vrm"); var bytes = File.ReadAllBytes(path); var context = new VRMImporterContext(); context.ParseGlb(bytes); var meta = context.ReadMeta(false); context.LoadAsync(_ => OnLoaded(context)); } }
/// <summary> /// upload VRM file to server /// </summary> /// <param name="filepath">Current VRM model path</param> public async Task UploadVRM(string filepath) { var fileType = new MetadataChange(); StorageReference vrmPath = Storage_ref.Child("VRP/" + CurrentUser.UserId + "/vrm/" + Path.GetFileName(filepath)); //get thumbnail form vrm var context = new VRMImporterContext(); byte[] vrmByte = null; using (FileStream fs = new FileStream(filepath, FileMode.Open, FileAccess.Read)) { vrmByte = new byte[fs.Length]; fs.Read(vrmByte, 0, vrmByte.Length); context.ParseGlb(vrmByte); } var meta = context.ReadMeta(true); string th; byte[] thumbnailData = meta.Thumbnail.EncodeToPNG(); try { th = Convert.ToBase64String(thumbnailData); } catch (Exception e) { th = ""; } isUploading = true; fileType.ContentType = "application/vrm"; await vrmPath.PutBytesAsync(vrmByte, fileType).ContinueWith((Task <StorageMetadata> task) => { if (task.IsFaulted || task.IsCanceled) { Debug.Log(task.Exception.ToString()); // Uh-oh, an error occurred! isUploading = false; } else { // Metadata contains file metadata such as size, content-type, and download URL. metadata = task.Result; Debug.Log("Finished uploading..."); } isUploading = false; }); }
/// <summary> /// vrm読み込み確認 /// </summary> public void Load(string path) { var bytes = File.ReadAllBytes(path); Context = new VRMImporterContext(); Context.ParseGlb(bytes); // VRMLoaderUI var modalObject = Instantiate(m_modalWindowPrefab, m_canvas.transform) as GameObject; var modalUI = modalObject.GetComponentInChildren <VRMPreviewUI>(); modalUI.setMeta(Context.ReadMeta(true)); modalUI.setLoadable(true); modalUI.m_ok.onClick.AddListener(Load); Path = path; }
public async Task <Transform> LoadVRM() { var bytes = File.ReadAllBytes(vrmPath); var context = new VRMImporterContext(); context.ParseGlb(bytes); var metadata = context.ReadMeta(false); Debug.LogFormat("meta: title: {0}", metadata.Title); await context.LoadAsyncTask(); context.ShowMeshes(); return(context.Root.transform); }