/// <summary> /// VRMがロード済みの状態で呼び出すと、 /// キーボード、マウス用のレイアウトパラメータと、ゲームパッド用のレイアウトパラメータを計算します。 /// VRMがロードされていない場合はnullを返します。 /// </summary> /// <returns></returns> public DeviceLayoutAutoAdjustParameters GetDeviceLayoutParameters() { if (_vrmRoot == null) { return(null); } var result = new DeviceLayoutAutoAdjustParameters(); var animator = _vrmRoot.GetComponent <Animator>(); Transform chest = animator.GetBoneTransform(HumanBodyBones.Chest); result.HeightFactor = (chest != null) ? chest.position.y / ReferenceChestHeight : animator.GetBoneTransform(HumanBodyBones.Spine).position.y / ReferenceSpineHeight; var upperArm = animator.GetBoneTransform(HumanBodyBones.RightUpperArm).position; var lowerArm = animator.GetBoneTransform(HumanBodyBones.RightLowerArm).position; var wrist = animator.GetBoneTransform(HumanBodyBones.RightHand).position; float armLength = Vector3.Distance(upperArm, lowerArm) + Vector3.Distance(lowerArm, wrist); result.ArmLengthFactor = armLength / ReferenceArmLength; return(result); }
/// <summary> /// 指定されたパラメータベースを用いてタッチパッドとキーボードの位置を初期化します。 /// </summary> /// <param name="parameters"></param> public void SetHidLayoutByParameter(DeviceLayoutAutoAdjustParameters parameters) { SetKeyboardLayout(parameters); SetTouchPadLayout(parameters); SetMidiControllerLayout(parameters); void SetKeyboardLayout(DeviceLayoutAutoAdjustParameters p) { var keyboardTransform = keyboard.transform; keyboardTransform.localRotation = Quaternion.Euler(refKeyboardRotation); keyboardTransform.localPosition = new Vector3( refKeyboardPosition.x * p.ArmLengthFactor, refKeyboardPosition.y * p.HeightFactor, refKeyboardPosition.z * p.ArmLengthFactor ); keyboardTransform.localScale = new Vector3( refKeyboardScale.x * p.ArmLengthFactor, 1.0f, refKeyboardScale.z * p.ArmLengthFactor ); } void SetTouchPadLayout(DeviceLayoutAutoAdjustParameters p) { var touchpadTransform = touchpad.transform; touchpadTransform.localRotation = Quaternion.Euler(refTouchpadRotation); touchpadTransform.localPosition = new Vector3( refTouchpadPosition.x * p.ArmLengthFactor, refTouchpadPosition.y * p.HeightFactor, refTouchpadPosition.z * p.ArmLengthFactor ); touchpadTransform.localScale = new Vector3( refTouchpadScale.x * p.ArmLengthFactor, refTouchpadScale.y * p.ArmLengthFactor, 1.0f ); } void SetMidiControllerLayout(DeviceLayoutAutoAdjustParameters p) { var midiTransform = midiController.transform; midiTransform.localRotation = Quaternion.Euler(refMidiRotation); midiTransform.localPosition = new Vector3( refMidiPosition.x * p.ArmLengthFactor, refMidiPosition.y * p.HeightFactor, refMidiPosition.z * p.ArmLengthFactor ); midiTransform.localScale = p.ArmLengthFactor * refMidiScale; } }
/// <summary> /// リセット処理などで明示的に呼ばれた場合、指定されたパラメタベースでゲームパッドの位置を初期化します。 /// </summary> /// <param name="parameters"></param> public void SetLayoutByParameter(DeviceLayoutAutoAdjustParameters parameters) { var t = transform; t.localRotation = Quaternion.Euler(baseRotation); t.localPosition = new Vector3( basePosition.x * parameters.ArmLengthFactor, basePosition.y * parameters.HeightFactor, basePosition.z * parameters.ArmLengthFactor ); t.localScale = (baseScale * parameters.ArmLengthFactor) * Vector3.one; }