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); }
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; } }
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; } }
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); } }); }
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); } }
public async Task ImportVrmAsync(string fullPath, Transform parent) { var bytes = System.IO.File.ReadAllBytes(fullPath); var context = new VRMImporterContext(); context.ParseGlb(bytes); await context.LoadAsyncTask(); var root = context.Root; root.transform.SetParent(parent, false); root.transform.localPosition = new Vector3(0, 1f, 0); // 先にRigidbodyつける var rb = root.AddComponent <Rigidbody>(); rb.freezeRotation = true; // コライダつける var capsuleCollider = root.AddComponent <CapsuleCollider>(); capsuleCollider.center = new Vector3(0, 0.7f, 0); capsuleCollider.radius = 0.2f; capsuleCollider.height = 1.5f; // アニメーションできるように、Animatorつける var rootAnimator = root.GetComponent <Animator>(); rootAnimator.runtimeAnimatorController = loadedAnimatorController; // Playerとして扱うならタグつける root.tag = TagName.Player; context.ShowMeshes(); }
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; }
void ImportVRM(string path) { if (VRM != null) { Destroy(VRM); } var context = new VRMImporterContext(); context.Parse(path); context.LoadAsync(() => { var gameObject = context.Root; gameObject.transform.position = new Vector3(0, 0, 0); gameObject.transform.eulerAngles = new Vector3(0, 180, 0); context.ShowMeshes(); // メッシュの表示・ここ重要 ExportVCI.VRM = gameObject; Description.SetActive(false); VRM = gameObject; }); }
// Use this for initialization void Start() { var path = Application.streamingAssetsPath + "/" + "AliciaSolid.vrm"; var context = new VRMImporterContext(); context.Parse(path); context.LoadAsync(() => { var avatar = context.Root; avatar.transform.parent = this.transform; foreach (var t in avatar.transform.Decendants()) { t.gameObject.layer = AvatarLayer; } // Set Avatar to System var blendShapeClipChanger = GetComponentInChildren <BlendShapeClipChanger>(); blendShapeClipChanger.VRM = avatar.GetComponent <VRMBlendShapeProxy>(); var vrmLipSync = GetComponentInChildren <OVRLipSyncVRMTarget>(); vrmLipSync.BlendShapeProxy = avatar.GetComponent <VRMBlendShapeProxy>(); var vrikProvider = GetComponentInChildren <VRIKProvider>(); vrikProvider.Avatar = avatar; vrikProvider.CallSetUp(); context.ShowMeshes(); }); }
/// <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); }
//ファイルからモデルを読み込む public void LoadVRMFromData(byte[] VRMdata) { if (isLoading) { Debug.LogError("Now Loading! load request is rejected."); return; } DestroyModel(); //読み込み VRMImporterContext vrmImporter = new VRMImporterContext(); vrmImporter.ParseGlb(VRMdata); isLoading = true; vrmImporter.LoadAsync(() => { isLoading = false; Model = vrmImporter.Root; //ExternalReceiverの下にぶら下げる LoadedModelParent = new GameObject(); LoadedModelParent.transform.SetParent(transform, false); LoadedModelParent.name = "LoadedModelParent"; //その下にモデルをぶら下げる Model.transform.SetParent(LoadedModelParent.transform, false); vrmImporter.EnableUpdateWhenOffscreen(); vrmImporter.ShowMeshes(); //カメラなどの移動補助のため、頭の位置を格納する animator = Model.GetComponent <Animator>(); HeadPosition = animator.GetBoneTransform(HumanBodyBones.Head).position; }); }
/// ボタンをクリックした時の処理 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; } } }
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> /// 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); }
/// <summary> /// VRMファイルのパスを取得して読み込みまで行う /// </summary> /// <returns></returns> async public Task <GameObject> Load() { string path = !string.IsNullOrWhiteSpace(CommandLineArgs.VRM) ? CommandLineArgs.VRM : AskVRMPath(); VRMImporterContext context = null; if (path != null) { try { context = await Load(path); } catch (Exception exception) { DisplayLoadingError(path, exception); } } if (context == null) { path = GetDefaultModelPath(); context = await Load(path); } context.Root.transform.parent = null; context.ShowMeshes(); return(context.Root); }
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); } }
/// <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; } } } }
public void OnLoaded(VRMImporterContext context) { // BuildHierarchyメソッドが内部で呼び出されRootの中にVRMGameObject生成 var root = context.Root; root.transform.position = new Vector3(0, 0, 0); // メッシュを表示する context.ShowMeshes(); }
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 LoadVRM(byte[] vrmFileBinary, Action <GameObject> onLoaded) { VRMImporterContext context = new VRMImporterContext(); context.ParseGlb(vrmFileBinary); context.LoadAsync((unit) => { context.ShowMeshes(); onLoaded(context.Root); }); }
private void modelLoad() { _context.LoadAsync(_ => { _context.ShowMeshes(); var go = _context.Root; go.transform.position = new Vector3(0, 0, 1); go.transform.Rotate(new Vector3(0, 180, 0)); }, Debug.LogError ); }
private void OnLoaded(VRMImporterContext context) { _avatar = context.Root; _avatar.transform.SetParent(transform, false); _avatar.gameObject.tag = "Avatar"; context.ShowMeshes(); AvatarLoaded(); }
/// <summary>Initialize model's gameobject (i.e. attaching assets, etc)</summary> private void ModelLoad() { m_context.LoadAsync(_ => { m_context.ShowMeshes(); GameObject root = m_context.Root; loadedVRM = root; SetupVRM(); SetupCamera(); }, Debug.LogError); }
protected virtual void OnLoaded(VRMImporterContext context, GameObject parent, VRMMetaObject metaObject, string path, GameObject MouseObject) { var root = context.Root; context.ShowMeshes(); root.transform.SetParent(parent.transform, false); var meta = root.GetComponent <VRMMeta>(); meta.transform.localPosition = new Vector3(0, 0, 0); SetupTarget(meta, root, metaObject, path, MouseObject); }
private void OnLoaded(VRMImporterContext context) { //読込が完了するとcontext.RootにモデルのGameObjectが入っています var root = context.Root; //モデルをワールド上に配置します root.transform.position = new Vector3(0, 0, 0); root.transform.Rotate(new Vector3(0, 180, 0)); //メッシュを表示します context.ShowMeshes(); }
public async Task LoadModel(string path) { if (!File.Exists(path)) { Debug.LogError("file not found path = " + path); return; } //VRMファイルの読み込み var bytes = File.ReadAllBytes(path); var context = new VRMImporterContext(); context.ParseGlb(bytes); var meta = context.ReadMeta(false); await context.LoadAsyncTask(); //VRMファイルの表示 context.ShowMeshes(); context.EnableUpdateWhenOffscreen(); context.ShowMeshes(); model = GameObject.Find("VRM"); //VRMオブジェクトへの動的アタッチ model.AddComponent <AvatarController>(); this.GetComponent <KinectManager>().ResetAvatarControllers(); //thisをKinectManagerをアタッチしたGameObjectに変更 //BoneSendへのVRMオブジェクト代入 this.GetComponent <SampleBonesSend>().Model = model; //thisをSampleBonesSendをアタッチしたGameObjectに変更 //BoneReceiveへのVRMオブジェクト代入 this.GetComponent <SampleBonesReceive>().Model = model; //thisをSampleBonesSendをアタッチしたGameObjectに変更 //Blinker追加 var lookAt = model.GetComponent <VRMLookAtHead>(); if (lookAt != null) { model.AddComponent <Blinker>(); blinker = model.GetComponent <Blinker>(); } //AniLipSync-VRMへのVRMオブジェクト代入 LipSync.blendShapeProxy = model.GetComponent <VRMBlendShapeProxy>(); //thisをSampleBonesSendをアタッチしたGameObjectに変更 }
private void OnLoaded(VRMImporterContext context) { //読込が完了するとcontext.RootにモデルのGameObjectが入っています var root = context.Root; _animator = root.GetComponent <Animator>(); root.transform.position = new Vector3(0, -1, 1); root.transform.rotation = Quaternion.Euler(0, 180f, 0); _animator.applyRootMotion = true; //メッシュを表示します context.ShowMeshes(); }
void OnLoaded(VRMImporterContext context) { if (m_model != null) { GameObject.Destroy(m_model.gameObject); } m_model = context.Root; m_model.transform.rotation = Quaternion.Euler(0, 180, 0); context.ShowMeshes(); context.EnableUpdateWhenOffscreen(); }
/// <summary> /// 読み込んだモデルを実際に表示する /// </summary> public void ShowMeshes() { if (Model == null) { throw new InvalidOperationException("Need to load VRM model first."); } currentContext.ShowMeshes(); #if UNIVRM_0_68_IMPORTER currentContext.DisposeOnGameObjectDestroyed(); #endif }