public Loaded(RuntimeGltfInstance instance, HumanPoseTransfer src, Transform lookAtTarget) { m_instance = instance; m_controller = instance.GetComponent <Vrm10Instance>(); if (m_controller != null) { // VRM m_controller.UpdateType = Vrm10Instance.UpdateTypes.LateUpdate; // after HumanPoseTransfer's setPose { m_pose = instance.gameObject.AddComponent <HumanPoseTransfer>(); m_pose.Source = src; m_pose.SourceType = HumanPoseTransfer.HumanPoseTransferSourceType.HumanPoseTransfer; m_lipSync = instance.gameObject.AddComponent <VRM10AIUEO>(); m_blink = instance.gameObject.AddComponent <VRM10Blinker>(); m_autoExpression = instance.gameObject.AddComponent <VRM10AutoExpression>(); m_controller.LookAtTargetType = VRM10ObjectLookAt.LookAtTargetTypes.CalcYawPitchToGaze; m_controller.Gaze = lookAtTarget; } } var animation = instance.GetComponent <Animation>(); if (animation && animation.clip != null) { // GLTF animation animation.Play(animation.clip.name); } }
public Loaded(RuntimeGltfInstance instance, HumanPoseTransfer src, Transform lookAtTarget) { _instance = instance; var lookAt = instance.GetComponent <VRMLookAtHead>(); if (lookAt != null) { // vrm _pose = _instance.gameObject.AddComponent <HumanPoseTransfer>(); _pose.Source = src; _pose.SourceType = HumanPoseTransfer.HumanPoseTransferSourceType.HumanPoseTransfer; m_lipSync = instance.gameObject.AddComponent <AIUEO>(); m_blink = instance.gameObject.AddComponent <Blinker>(); lookAt.Target = lookAtTarget; lookAt.UpdateType = UpdateType.LateUpdate; // after HumanPoseTransfer's setPose m_proxy = instance.GetComponent <VRMBlendShapeProxy>(); } // not vrm var animation = instance.GetComponent <Animation>(); if (animation && animation.clip != null) { animation.Play(animation.clip.name); } }
/// <summary> /// 非同期でByte配列からVRMImporterContextの初期化をします /// </summary> /// <param name="vrmByteArray"></param> public async Task InitializeVrmContextFromByteArrayAsync(byte[] vrmByteArray) { #if UNIVRM_LEGACY_IMPORTER // VRMImporterContextがVRMを読み込む機能を提供します currentContext = new VRMImporterContext(); // GLB形式でJSONを取得しParseします await Task.Run(() => currentContext.ParseGlb(vrmByteArray)); #elif UNIVRM_0_68_IMPORTER var parser = new GltfParser(); await Task.Run(() => parser.ParseGlb(vrmByteArray)); currentContext = new VRMImporterContext(parser); #elif UNIVRM_0_77_IMPORTER var parser = new GlbLowLevelParser(string.Empty, vrmByteArray); GltfData data = null; await Task.Run(() => { data = parser.Parse(); }); currentContext = new VRMImporterContext(data); currentInstance = null; #else #endif }
/// <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 }
void SetModel(RuntimeGltfInstance instance) { // cleanup if (m_loaded != null) { m_loaded.Dispose(); m_loaded = null; } instance.ShowMeshes(); instance.EnableUpdateWhenOffscreen(); m_loaded = new Loaded(instance, m_src, m_target.transform); }
void OnLoaded(RuntimeGltfInstance loaded) { var root = loaded.gameObject; root.transform.SetParent(transform, false); //メッシュを表示します loaded.ShowMeshes(); // add motion var humanPoseTransfer = root.AddComponent <UniHumanoid.HumanPoseTransfer>(); if (m_target != null) { GameObject.Destroy(m_target.gameObject); } m_target = humanPoseTransfer; SetupTarget(); }
void SetModel(RuntimeGltfInstance instance) { // cleanup if (m_loaded != null) { m_loaded.Dispose(); m_loaded = null; } if (m_useFastSpringBone.isOn) { FastSpringBoneReplacer.ReplaceAsync(instance.Root); } instance.EnableUpdateWhenOffscreen(); instance.ShowMeshes(); m_loaded = new Loaded(instance, m_src, m_target.transform); }
/// <summary> /// 非同期でByte配列からVRMモデルを読み込む /// </summary> /// <param name="vrmByteArray"></param> /// <returns></returns> public async Task <GameObject> LoadVrmModelFromByteArrayAsync(byte[] vrmByteArray) { #if UNIVRM_LEGACY_IMPORTER await InitializeVrmContextFromByteArrayAsync(vrmByteArray); // 非同期処理(Task)で読み込みます await currentContext.LoadAsyncTask(); // 読込が完了するとcontext.RootにモデルのGameObjectが入っています var root = currentContext.Root; return(root); #elif UNIVRM_0_68_IMPORTER var parser = new GltfParser(); await Task.Run(() => { parser.ParseGlb(vrmByteArray); }); currentContext = new VRMImporterContext(parser); await currentContext.LoadAsync(); return(currentContext.Root); #elif UNIVRM_0_77_IMPORTER var parser = new GlbLowLevelParser(string.Empty, vrmByteArray); GltfData data = null; await Task.Run(() => { data = parser.Parse(); }); currentContext = new VRMImporterContext(data); currentInstance = await currentContext.LoadAsync(); return(currentInstance.Root); #else return(null); #endif }
/// <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. var parser = new GlbFileParser(path); var data = parser.Parse(); context = new VRMImporterContext(data); //Debug.Log("Loading model : " + path); RuntimeGltfInstance instance = context.Load(); instance.EnableUpdateWhenOffscreen(); newModelObject = instance.Root; meta = context.ReadMeta(true); instance.ShowMeshes(); } catch (Exception ex) { if (uiController) { uiController.ShowWarning("Model load failed."); } Debug.LogError("Failed loading " + path); Debug.LogError(ex); return; } if (newModelObject) { if (model) { GameObject.Destroy(model.gameObject); } model = newModelObject.AddComponent <HumanPoseTransfer>(); CreateColliders(model.gameObject); var characterController = model.gameObject.AddComponent <VrmCharacterBehaviour>(); SetMotion(motion, model, meta); if (uiController) { uiController.Show(meta); if (characterController) { uiController.enableRandomMotion = characterController.randomMotion; uiController.enableRandomEmotion = characterController.randomEmotion; } } } }