/// ボタンをクリックした時の処理 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 VRMSimpleSceneTest() { var go = CreateSimpelScene(); var context = new VRMImporterContext(); try { // export var gltf = VRMExporter.Export(go); using (var exporter = new gltfExporter(gltf)) { exporter.Prepare(go); exporter.Export(); // import context.ParseJson(gltf.ToJson(), new SimpleStorage()); //Debug.LogFormat("{0}", context.Json); context.Load(); AssertAreEqual(go.transform, context.Root.transform); } } finally { //Debug.LogFormat("Destory, {0}", go.name); GameObject.DestroyImmediate(go); context.Destroy(true); } }
public void LoadModel(string path) { if (!File.Exists(path)) { return; } Debug.LogFormat("{0}", path); string ext = Path.GetExtension(path).ToLower(); if (ext != ".vrm") { Debug.LogWarning($"unknown file type: {path}"); return; } var context = new VRMImporterContext(); var file = File.ReadAllBytes(path); context.ParseGlb(file); m_texts.UpdateMeta(context); context.Load(); context.ShowMeshes(); context.EnableUpdateWhenOffscreen(); context.ShowMeshes(); SetModel(context.Root); }
/// <summary> /// vrm読み込み /// </summary> void Load() { if (VRM != null) { Destroy(VRM); } Context.Load(); Context.ShowMeshes(); VRM = Context.Root; // 3Dビューの初期表示位置を頭に設定 var anim = VRM.GetComponent <Animator>(); var head = anim.GetBoneTransform(HumanBodyBones.Head); Camera.position = new Vector3(0, head.position.y, 0); // メタ情報とブレンドシェイプの取得 Meta.Get(); BlendShape.Get(); Export.Path = Path; Text.gameObject.SetActive(false); }
private void LoadModel(string path) { if (!File.Exists(path)) { return; } if (Path.GetExtension(path).ToLower() != ".vrm") { LogOutput.Instance.Write($"unknown file type: {path}"); return; } TryWithoutException(() => { var context = new VRMImporterContext(); var file = File.ReadAllBytes(path); context.ParseGlb(file); context.Load(); context.EnableUpdateWhenOffscreen(); context.ShowMeshes(); SetModel(context.Root); }); }
/// <summary> /// メタが不要な場合のローダー /// </summary> async void LoadVRMClicked_without_meta() { #if UNITY_STANDALONE_WIN var path = FileDialogForWindows.FileDialog("open VRM", ".vrm"); #elif UNITY_EDITOR var path = UnityEditor.EditorUtility.OpenFilePanel("Open VRM", "", "vrm"); #else var path = Application.dataPath + "/default.vrm"; #endif if (string.IsNullOrEmpty(path)) { return; } var bytes = File.ReadAllBytes(path); // なんらかの方法でByte列を得た // GLB形式でJSONを取得しParseします var parser = new GltfParser(); parser.ParseGlb(bytes); var context = new VRMImporterContext(parser); if (m_loadAsync) { await context.LoadAsync(); } else { context.Load(); } OnLoaded(context); }
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 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 Loading(Camera mainCamera, int defaultCullingMask, VrmMeta vrmMeta) { //Loading表示に切り替えるために1フレーム待つ yield return(null); var bytes = File.ReadAllBytes(GlobalPath.VrmHomePath + "/" + vrmMeta.VrmFileName); var vrmImporterContext = new VRMImporterContext(); vrmImporterContext.ParseGlb(bytes); vrmImporterContext.Load(); vrmImporterContext.Root.transform.SetParent(vrmRoot, false); var vrmAnimationController = vrmImporterContext.Root.AddComponent <VrmAnimationController>(); vrmAnimationController.Play(defaultAnimation); //BlendShapeProxyの初期化を待つ。 yield return(null); var vrmBlendShapeProxy = vrmImporterContext.Root.GetComponent <VRMBlendShapeProxy>(); vrmBlendShapeProxy.ImmediatelySetValue(defaultBlendShapePreset, defaultBlendShapeValue); vrmImporterContext.EnableUpdateWhenOffscreen(); vrmImporterContext.ShowMeshes(); poolingVrmImporterContexts.Add(new KeyValuePair <string, VRMImporterContext>(vrmMeta.VrmFileName, vrmImporterContext)); mainCamera.cullingMask = defaultCullingMask; }
/// <summary> /// 同期でByte配列からVRMモデルを読み込む /// </summary> /// <param name="vrmByteArray"></param> /// <returns></returns> public GameObject LoadVrmModelFromByteArray(byte[] vrmByteArray) { #if UNIVRM_LEGACY_IMPORTER InitializeVrmContextFromByteArray(vrmByteArray); // 同期処理で読み込みます currentContext.Load(); // 読込が完了するとcontext.RootにモデルのGameObjectが入っています var root = currentContext.Root; return(root); #elif UNIVRM_0_68_IMPORTER var parser = new GltfParser(); parser.ParseGlb(vrmByteArray); currentContext = new VRMImporterContext(parser); currentContext.Load(); return(currentContext.Root); #elif UNIVRM_0_77_IMPORTER var parser = new GlbLowLevelParser(string.Empty, vrmByteArray); var data = parser.Parse(); currentContext = new VRMImporterContext(data); currentInstance = currentContext.Load(); return(currentInstance.Root); #else return(null); #endif }
/// <summary> /// メタが不要な場合のローダー /// </summary> async void LoadVRMClicked_without_meta() { #if UNITY_STANDALONE_WIN var path = FileDialogForWindows.FileDialog("open VRM", ".vrm"); #elif UNITY_EDITOR var path = UnityEditor.EditorUtility.OpenFilePanel("Open VRM", "", "vrm"); #else var path = Application.dataPath + "/default.vrm"; #endif if (string.IsNullOrEmpty(path)) { return; } // GLB形式でJSONを取得しParseします var data = new GlbFileParser(path).Parse(); // VRM extension を parse します var vrm = new VRMData(data); var context = new VRMImporterContext(vrm); var loaded = default(RuntimeGltfInstance); if (m_loadAsync) { loaded = await context.LoadAsync(); } else { loaded = context.Load(); } OnLoaded(loaded); }
/// <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; } } } }
void LoadModel(string path) { if (!File.Exists(path)) { return; } Debug.LogFormat("{0}", path); var ext = Path.GetExtension(path).ToLower(); switch (ext) { case ".vrm": { var context = new VRMImporterContext(); var file = File.ReadAllBytes(path); context.ParseGlb(file); m_texts.UpdateMeta(context); context.Load(); context.ShowMeshes(); context.EnableUpdateWhenOffscreen(); context.ShowMeshes(); SetModel(context.Root); break; } case ".glb": { var context = new UniGLTF.ImporterContext(); var file = File.ReadAllBytes(path); context.ParseGlb(file); context.Load(); context.ShowMeshes(); context.EnableUpdateWhenOffscreen(); context.ShowMeshes(); SetModel(context.Root); break; } case ".gltf": case ".zip": { var context = new UniGLTF.ImporterContext(); context.Parse(path); context.Load(); context.ShowMeshes(); context.EnableUpdateWhenOffscreen(); context.ShowMeshes(); SetModel(context.Root); break; } default: Debug.LogWarningFormat("unknown file type: {0}", path); break; } }
void LoadVRMClicked_WebGL(Byte[] bytes) { var context = new VRMImporterContext(); // GLB形式でJSONを取得しParseします context.ParseGlb(bytes); context.Load(); OnLoaded(context); }
void Start() { var path = @"D:\play\UnityProject\VRM_DollPlay2018\_exe\VRM\AoNana.vrm"; var bytes = File.ReadAllBytes(path); Context = new VRMImporterContext(); Context.ParseGlb(bytes); Context.Load(); Context.ShowMeshes(); }
private void LoadModel(string path) { try { // If BVH trigger is still on if (_bvhLoadingTrigger == true) { LoadMotion(_bvhPathSaved); } if (!File.Exists(path)) { return; } Debug.LogFormat("{0}", path); var bytes = File.ReadAllBytes(path); var context = new VRMImporterContext(); // GLB形式でJSONを取得しParseします context.ParseGlb(bytes); // GLTFにアクセスできます Debug.LogFormat("{0}", context.GLTF); // Call License Update function _licensePanel.LicenseUpdatefunc(context); // GLTFからモデルを生成します try { context.Load(); context.ShowMeshes(); context.EnableUpdateWhenOffscreen(); context.ShowMeshes(); _vrmModel = context.Root; Debug.LogFormat("loaded {0}", _vrmModel.name); } catch (Exception ex) { Debug.LogError(ex); } // Set up Model SetModel(_vrmModel); } catch (Exception e) { _errorMessagePanel.SetMessage(MultipleLanguageSupport.VrmLoadErrorMessage + "\nError message: " + e.Message); throw; } }
public void Load() { var path = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "/avatar.vrm"; if (!File.Exists(path)) { throw new Exception("no file found"); } var data = File.ReadAllBytes(path); var importerContext = new VRMImporterContext(); importerContext.ParseGlb(data); importerContext.Load(); var root = importerContext.Root; importerContext.EnableUpdateWhenOffscreen(); root.GetComponentsInChildren <Renderer>().ToList().ForEach(e => { e.shadowCastingMode = ShadowCastingMode.Off; e.receiveShadows = false; }); var lookAt = root.GetComponent <VRMLookAtHead>(); _humanPoseTransferTarget = root.AddComponent <HumanPoseTransfer>(); _humanPoseTransferTarget.SourceType = HumanPoseTransfer.HumanPoseTransferSourceType.None; lookAt.UpdateType = UpdateType.LateUpdate; //Spring boneのスケジュール SetIK(root, loadSetting); var animator = root.GetComponent <Animator>(); animator.runtimeAnimatorController = animatorController; settingAdjuster.AssignModelRoot(root.transform); var info = new VrmLoadedInfo() { context = importerContext, vrmRoot = root.transform, animator = animator, blendShape = root.GetComponent <VRMBlendShapeProxy>(), }; PreVrmLoaded?.Invoke(info); VrmLoaded?.Invoke(info); }
void LoadFromFile() { //VRMファイルのパスを指定します var path = Application.dataPath + "/Resources/vj_takagi.vrm"; //ファイルをByte配列に読み込みます var bytes = System.IO.File.ReadAllBytes(path); var context = new VRMImporterContext(); // GLB形式でJSONを取得しParseします context.ParseGlb(bytes); context.Load(); OnLoaded(context); }
IEnumerator Loading(Camera mainCamera, int defaultCullingMask, VrmMeta vrmMeta) { //Loading表示に切り替えるために1フレーム待つ yield return(null); var bytes = File.ReadAllBytes(GlobalPath.VrmHomePath + "/" + vrmMeta.VrmFileName); var vrmImporterContext = new VRMImporterContext(); vrmImporterContext.ParseGlb(bytes); vrmImporterContext.Load(); vrmImporterContext.Root.transform.SetParent(vrmRoot, false); vrmImporterContext.EnableUpdateWhenOffscreen(); vrmImporterContext.ShowMeshes(); poolingVrmImporterContexts.Add(new KeyValuePair <string, VRMImporterContext>(vrmMeta.VrmFileName, vrmImporterContext)); mainCamera.cullingMask = defaultCullingMask; }
/// <summary> /// メタが不要な場合のローダー /// </summary> void LoadVRMClicked_without_meta() { #if UNITY_STANDALONE_WIN var path = FileDialogForWindows.FileDialog("open VRM", ".vrm"); #elif UNITY_EDITOR var path = UnityEditor.EditorUtility.OpenFilePanel("Open VRM", "", "vrm"); #else var path = Application.dataPath + "/default.vrm"; #endif if (string.IsNullOrEmpty(path)) { return; } #if true var bytes = File.ReadAllBytes(path); // なんらかの方法でByte列を得た var context = new VRMImporterContext(); // GLB形式でJSONを取得しParseします context.ParseGlb(bytes); if (m_loadAsync) { // ローカルファイルシステムからロードします LoadAsync(context); } else { context.Load(); OnLoaded(context); } #else // ParseしたJSONをシーンオブジェクトに変換していく if (m_loadAsync) { // ローカルファイルシステムからロードします VRMImporter.LoadVrmAsync(path, OnLoaded); } else { var root = VRMImporter.LoadFromPath(path); OnLoaded(root); } #endif }
public void MeshCopyTest() { var path = AliciaPath; var context = new VRMImporterContext(); context.ParseGlb(File.ReadAllBytes(path)); context.Load(); context.ShowMeshes(); context.EnableUpdateWhenOffscreen(); foreach (var mesh in context.Meshes) { var src = mesh.Mesh; var dst = src.Copy(true); MeshTests.MeshEquals(src, dst); } }
public void MeshCopyTest() { var path = AliciaPath; var data = new GlbFileParser(path).Parse(); using (var context = new VRMImporterContext(new VRMData(data))) using (var loaded = context.Load()) { loaded.ShowMeshes(); loaded.EnableUpdateWhenOffscreen(); foreach (var mesh in context.Meshes) { var src = mesh.Mesh; var dst = src.Copy(true); MeshTests.MeshEquals(src, dst); } } }
private static GameObject ImportVRM(string path, string playername) { var bytes = File.ReadAllBytes(path); var context = new VRMImporterContext(); context.ParseGlb(bytes); try { context.Load(); } catch { } // モデルスケール調整 context.Root.transform.localScale *= Settings.ReadFloat(playername, "ModelScale", 1.0f); return(context.Root); }
/// <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)) { return; } GameObject newModel = null; try { // Load from a VRM file. byte[] bytes = File.ReadAllBytes(path); context = new VRMImporterContext(); context.ParseGlb(bytes); context.Load(path); newModel = context.Root; meta = context.ReadMeta(); } catch (Exception ex) { Debug.LogError(ex); return; } if (model) { GameObject.Destroy(model.gameObject); } if (newModel) { model = newModel.AddComponent <HumanPoseTransfer>(); SetMotion(motion, model, meta); model.gameObject.AddComponent <CharacterBehaviour>(); if (uiController) { uiController.Show(meta); } } }
protected void LoadVRMFromBytes(Byte[] bytes) { var context = new VRMImporterContext(); try { context.ParseGlb(bytes); context.Load(); var model = context.Root; var meta = context.ReadMeta(true); model.name = meta.Title; context.ShowMeshes(); OnLoaded(model, meta); } catch (Exception e) { Debug.LogError(e); } }
void SendVRM(string VRM_base64) { Debug.Log("SendVRM run"); Debug.Log($"length: {VRM_base64.Length}"); Debug.Log($"base64: {VRM_base64}"); var rawbt = System.Convert.FromBase64String(VRM_base64); Debug.Log($"raw: {rawbt}"); var context = new VRMImporterContext(); context.ParseGlb(rawbt); context.Load(); var root = context.Root; root.transform.SetParent(transform, false); context.ShowMeshes(); Debug.Log("finish VRM processes."); }
async void LoadVRMClicked() { #if UNITY_STANDALONE_WIN var path = FileDialogForWindows.FileDialog("open VRM", ".vrm"); #elif UNITY_EDITOR var path = UnityEditor.EditorUtility.OpenFilePanel("Open VRM", "", "vrm"); #else var path = Application.dataPath + "/default.vrm"; #endif if (string.IsNullOrEmpty(path)) { return; } var bytes = File.ReadAllBytes(path); // なんらかの方法でByte列を得た // GLB形式でJSONを取得しParseします var parser = new GltfParser(); parser.Parse(path, bytes); using (var context = new VRMImporterContext(parser)) { // metaを取得(todo: thumbnailテクスチャのロード) var meta = await context.ReadMetaAsync(); Debug.LogFormat("meta: title:{0}", meta.Title); // ParseしたJSONをシーンオブジェクトに変換していく if (m_loadAsync) { await context.LoadAsync(); } else { context.Load(); } OnLoaded(context); } }
public IEnumerator Delegate(string name, string url) { VRMImporterContext context = new VRMImporterContext(); UnityWebRequest request = UnityWebRequest.Get(url); Debug.Log("Request start"); yield return(request.SendWebRequest()); Debug.Log("Request end"); if (request.isHttpError || request.isNetworkError) { Debug.Log(request.error); } else { Debug.Log(request.downloadedBytes); context.ParseGlb(request.downloadHandler.data); context.Load(); GameObject root = context.Root; root.name = name; root.transform.SetParent(transform, false); root.transform.position = calcPosition(); Quaternion _q = root.transform.rotation; Quaternion q = Quaternion.AngleAxis(180, new Vector3(0f, 1f, 0f)); root.transform.rotation = _q * q; context.ShowMeshes(); GameObject go = root.transform.gameObject; SetUpGameObject(go); vrmCounter++; } }
public async UniTask <GameObject> LoadVRMAvater() #endif { var path = VRMLoadUniRx.GetVRMPath(); if (path == null) { path = Application.streamingAssetsPath + "/Avater/model.vrm"; } byte[] VRMByteData; GameObject go; #if UNITY_WEBGL VRMByteData = VRMLoadUniRx.GetVRMData(); #else using (var uwr = UnityWebRequest.Get(path)) { await uwr.SendWebRequest(); VRMByteData = uwr.downloadHandler.data; } #endif context = new VRMImporterContext(); context.ParseGlb(VRMByteData); #if UNITY_WEBGL context.Load(); #else await context.LoadAsyncTask(); #endif go = context.Root; context.ShowMeshes(); go.AddComponent <Blinker>(); go.AddComponent <FaceUpdate>(); var animator = go.GetComponent <Animator>(); animator.applyRootMotion = true; animator.runtimeAnimatorController = (RuntimeAnimatorController)Instantiate(Resources.Load("MocapC86")); go.SetLayerRecursively(8); return(go); }
private void ImportVRMSync(string 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); //同期処理で読み込みます context.Load(); //読込が完了するとcontext.RootにモデルのGameObjectが入っています var root = context.Root; //モデルをワールド上に配置します root.transform.SetParent(transform, false); var animator = this.GetComponent <ToAnimator> (); var camIni = this.GetComponent <CameraInitialize> (); var IKIni = this.GetComponent <IKInitialize>(); animator.SetAnimator(root); camIni.CameraPositionInitialize(root); IKIni.IKInitilize(root); var VRMFaceIni = this.GetComponent <VRMFaceInitialize>(); VRMFaceIni.FaceInitialize(root); //メッシュを表示します context.ShowMeshes(); }