コード例 #1
0
ファイル: Main.cs プロジェクト: VRCMG/ml_lme
        void UpdateExtensionStates()
        {
            if (ms_enabled)
            {
                if (!m_leapInitialized)
                {
                    m_leapInitialized = LeapExtender.LeapInitialize();
                }
                LeapExtender.LeapSetTrackingMode(m_vr ? 1 : 0);
            }
            else
            {
                if (m_leapInitialized)
                {
                    LeapExtender.LeapTerminate();
                    m_leapInitialized = false;
                }

                // Reset HandGestureController, IKSolverVR resets itself
                var l_controller = VRCPlayer.field_Internal_Static_VRCPlayer_0?.field_Private_VRC_AnimationController_0?.field_Private_HandGestureController_0;
                if (l_controller != null)
                {
                    l_controller.field_Internal_Boolean_0 = false;
                    l_controller.field_Private_EnumNPublicSealedvaKeMoCoGaViOcViDaWaUnique_0 = VRCInputManager.EnumNPublicSealedvaKeMoCoGaViOcViDaWaUnique.Mouse;
                }
            }
        }
コード例 #2
0
ファイル: Main.cs プロジェクト: VRCMG/ml_lme
        public override void OnApplicationQuit()
        {
            if (m_leapInitialized)
            {
                LeapExtender.LeapTerminate();
                m_leapInitialized = false;
            }

            m_fingersBendsPtr.Free();
            m_fingersBends = null;

            m_fingersSpreadsPtr.Free();
            m_fingersSpreads = null;

            m_handsPresentPtr.Free();
            m_handsPresent = null;

            m_handPositionsPtr.Free();
            m_handPositions = null;

            m_handRotationsPtr.Free();
            m_handRotations = null;
        }
コード例 #3
0
ファイル: Main.cs プロジェクト: VRCMG/ml_lme
        public override void OnUpdate()
        {
            // Check for VR mode to prevent desktop input lock
            ms_inVrMode = VRCTrackingManager.Method_Public_Static_Boolean_7();

            if (ms_enabled)
            {
                // Use Leap Motion data
                if (m_leapInitialized)
                {
                    LeapExtender.LeapGetHandsData(m_fingersBendsPtr.AddrOfPinnedObject(), m_fingersSpreadsPtr.AddrOfPinnedObject(), m_handsPresentPtr.AddrOfPinnedObject(), m_handPositionsPtr.AddrOfPinnedObject(), m_handRotationsPtr.AddrOfPinnedObject());
                }

                if (m_sdk3)
                {
                    // Set SDK3 parameters directly, user has to make own avatar with specific parameters
                    var l_expParams          = VRCPlayer.field_Internal_Static_VRCPlayer_0?.prop_VRCAvatarManager_0?.prop_VRCAvatarDescriptor_0?.expressionParameters?.parameters;
                    var l_playableController = VRCPlayer.field_Internal_Static_VRCPlayer_0?.field_Private_AnimatorControllerManager_0?.field_Private_AvatarAnimParamController_0?.field_Private_AvatarPlayableController_0;
                    if ((l_expParams != null) && (l_playableController != null))
                    {
                        for (int i = 0; i < l_expParams.Length; i++)
                        {
                            var l_expParam = l_expParams[i];
                            if (l_expParam.name.StartsWith("_FingerValue") && (l_expParam.valueType == VRC.SDK3.Avatars.ScriptableObjects.VRCExpressionParameters.ValueType.Float))
                            {
                                int l_bufferIndex = -1;
                                if (Int32.TryParse(l_expParam.name.Substring(12), out l_bufferIndex))
                                {
                                    if ((l_bufferIndex >= 0) && (l_bufferIndex <= 9))
                                    {
                                        l_playableController.Method_Public_Boolean_Int32_Single_1(i, m_fingersBends[l_bufferIndex]);
                                    }
                                }
                                continue;
                            }
                            if (l_expParam.name.StartsWith("_HandPresent") && (l_expParam.valueType == VRC.SDK3.Avatars.ScriptableObjects.VRCExpressionParameters.ValueType.Bool))
                            {
                                int l_bufferIndex = -1;
                                if (Int32.TryParse(l_expParam.name.Substring(12), out l_bufferIndex))
                                {
                                    if ((l_bufferIndex >= 0) && (l_bufferIndex <= 1))
                                    {
                                        l_playableController.Method_Public_Boolean_Int32_Single_1(i, m_handsPresent[l_bufferIndex] ? 1.0f : 0.0f); // Fallback
                                    }
                                }
                                continue;
                            }
                        }
                    }
                }

                if (!m_fingersOnly)
                {
                    var l_solver = VRCPlayer.field_Internal_Static_VRCPlayer_0?.field_Private_VRC_AnimationController_0?.field_Private_VRIK_0?.solver;
                    if (l_solver != null)
                    {
                        if (m_handsPresent[0])
                        {
                            if (l_solver.leftArm?.target != null)
                            {
                                Vector3    l_newPos = new Vector3(m_handPositions[0], m_handPositions[1], -m_handPositions[2]) * 0.001f;
                                Quaternion l_newRot = new Quaternion(-m_handRotations[0], -m_handRotations[1], m_handRotations[2], m_handRotations[3]);
                                ApplyAdjustment(ref l_newPos, ref l_newRot);

                                Transform l_rootTransform = GetRootTransform(ref l_solver);
                                m_leftTargetPosition = l_rootTransform.position + l_rootTransform.rotation * l_newPos;
                                m_leftTargetRotation = l_rootTransform.rotation * l_newRot;

                                var l_pickupJoint = VRCPlayer.field_Internal_Static_VRCPlayer_0?.field_Private_VRC_AnimationController_0?.field_Private_IkController_0?.field_Private_VRCHandGrasper_0?.field_Private_GameObject_0;
                                if (l_pickupJoint != null)
                                {
                                    l_pickupJoint.transform.position = m_leftTargetPosition;
                                    l_pickupJoint.transform.rotation = m_leftTargetRotation;
                                }
                            }
                        }

                        if (m_handsPresent[1])
                        {
                            if (l_solver.rightArm?.target != null)
                            {
                                Vector3    l_newPos = new Vector3(m_handPositions[3], m_handPositions[4], -m_handPositions[5]) * 0.001f;
                                Quaternion l_newRot = new Quaternion(-m_handRotations[4], -m_handRotations[5], m_handRotations[6], m_handRotations[7]);
                                ApplyAdjustment(ref l_newPos, ref l_newRot);

                                Transform l_rootTransform = GetRootTransform(ref l_solver);
                                m_rightTargetPosition = l_rootTransform.position + l_rootTransform.rotation * l_newPos;
                                m_rightTargetRotation = l_rootTransform.rotation * l_newRot;

                                var l_pickupJoint = VRCPlayer.field_Internal_Static_VRCPlayer_0?.field_Private_VRC_AnimationController_0?.field_Private_IkController_0?.field_Private_VRCHandGrasper_1?.field_Private_GameObject_0;
                                if (l_pickupJoint != null)
                                {
                                    l_pickupJoint.transform.position = m_rightTargetPosition;
                                    l_pickupJoint.transform.rotation = m_rightTargetRotation;
                                }
                            }
                        }
                    }
                }

                var l_handController = VRCPlayer.field_Internal_Static_VRCPlayer_0?.field_Private_VRC_AnimationController_0?.field_Private_HandGestureController_0;
                if (l_handController != null)
                {
                    l_handController.field_Internal_Boolean_0 = true;
                    l_handController.field_Private_EnumNPublicSealedvaKeMoCoGaViOcViDaWaUnique_0 = VRCInputManager.EnumNPublicSealedvaKeMoCoGaViOcViDaWaUnique.Index;

                    for (int i = 0; i < 2; i++)
                    {
                        if (m_handsPresent[i])
                        {
                            for (int j = 0; j < 5; j++)
                            {
                                int l_dataIndex = i * 5 + j;
                                l_handController.field_Private_ArrayOf_VRCInput_0[l_dataIndex].field_Public_Single_0 = 1.0f - m_fingersBends[l_dataIndex]; // Squeeze
                                l_handController.field_Private_ArrayOf_VRCInput_1[l_dataIndex].field_Public_Single_0 = m_fingersSpreads[l_dataIndex];      // Spread
                            }
                        }
                    }
                }
            }
        }