コード例 #1
0
        private void OnHandUpdate(WebXRHandData handData)
        {
            if (handJointPrefab == null)
            {
                return;
            }
            Quaternion rotationOffset = Quaternion.Inverse(handData.joints[0].rotation);

#if WEBXR_INPUT_PROFILES
            if (useInputProfile && loadedHandModel)
            {
                for (int i = 0; i <= (int)WebXRHandJoint.pinky_finger_tip; i++)
                {
                    if (handModelJoints.ContainsKey(i))
                    {
                        handModelJoints[i].localPosition = rotationOffset * (handData.joints[i].position - handData.joints[0].position);
                        handModelJoints[i].localRotation = rotationOffset * handData.joints[i].rotation * quat180;
                    }
                }
                return;
            }
#endif

            for (int i = 0; i <= (int)WebXRHandJoint.pinky_finger_tip; i++)
            {
                if (handJoints.ContainsKey(i))
                {
                    handJoints[i].localPosition = rotationOffset * (handData.joints[i].position - handData.joints[0].position);
                    handJoints[i].localRotation = rotationOffset * handData.joints[i].rotation;
                    if (handData.joints[i].radius != handJoints[i].localScale.x && handData.joints[i].radius > 0)
                    {
                        handJoints[i].localScale = new Vector3(handData.joints[i].radius, handData.joints[i].radius, handData.joints[i].radius);
                    }
                }
                else
                {
                    var clone = Instantiate(handJointPrefab, transform);
                    clone.localPosition = rotationOffset * (handData.joints[i].position - handData.joints[0].position);
                    clone.localRotation = rotationOffset * handData.joints[i].rotation;
                    if (handData.joints[i].radius > 0f)
                    {
                        clone.localScale = new Vector3(handData.joints[i].radius, handData.joints[i].radius, handData.joints[i].radius);
                    }
                    else
                    {
                        clone.localScale = new Vector3(0.005f, 0.005f, 0.005f);
                    }
                    var collider = clone.GetComponent <Collider>();
                    if (collider != null)
                    {
                        collider.enabled = useCollidersForHandJoints;
                    }
                    handJoints.Add(i, clone);
                    handJointsVisuals[i] = clone.gameObject;
                }
            }
        }
コード例 #2
0
        private void OnHandUpdate(WebXRHandData handData)
        {
            if (handJointPrefab == null)
            {
                return;
            }
            Quaternion rotationOffset = Quaternion.Inverse(handData.joints[0].rotation);

            for (int i = 0; i <= WebXRHandData.LITTLE_PHALANX_TIP; i++)
            {
                if (handData.joints[i].enabled)
                {
                    if (handJoints.ContainsKey(i))
                    {
                        handJoints[i].localPosition = rotationOffset * (handData.joints[i].position - handData.joints[0].position);
                        handJoints[i].localRotation = rotationOffset * handData.joints[i].rotation;
                        if (handData.joints[i].radius != handJoints[i].localScale.x && handData.joints[i].radius > 0)
                        {
                            handJoints[i].localScale = new Vector3(handData.joints[i].radius, handData.joints[i].radius, handData.joints[i].radius);
                        }
                    }
                    else
                    {
                        var clone = Instantiate(handJointPrefab,
                                                rotationOffset * (handData.joints[i].position - handData.joints[0].position),
                                                rotationOffset * handData.joints[i].rotation,
                                                transform);
                        if (handData.joints[i].radius > 0f)
                        {
                            clone.localScale = new Vector3(handData.joints[i].radius, handData.joints[i].radius, handData.joints[i].radius);
                        }
                        else
                        {
                            clone.localScale = new Vector3(0.005f, 0.005f, 0.005f);
                        }
                        handJoints.Add(i, clone);
                        handJointsVisuals[i] = clone.gameObject;
                    }
                }
            }
        }