コード例 #1
0
        public static void Initialize()
        {
            if (s_initialized || !Application.isPlaying)
            {
                return;
            }
            s_initialized = true;

            // update the ViveRole system with initial connecting state
            for (uint index = 0; index < VRModule.MAX_DEVICE_COUNT; ++index)
            {
                OnDeviceConnected(index, VivePose.IsConnected(index));
            }

            VRModule.onDeviceConnected       += OnDeviceConnected;
            VRModule.onControllerRoleChanged += OnTrackedDeviceRoleChanged;

            // assign default role map handlers
            AssignMapHandler(DefaultDeviceRoleHandler);
            AssignMapHandler(DefaultHandRoleHandler);
            AssignMapHandler(DefaultTrackerRoleHandler);
            AssignMapHandler(DefaultTrackedHandRoleHandler);
            AssignMapHandler(DefaultBodyRoleHandler);
            AssignMapHandler(DefaultControllerRoleHandler);
        }
        public override void OnNewPoses()
        {
            var deviceIndex = viveRole.GetDeviceIndex();

            // set targetPose to device pose
            targetPose = VivePose.GetPose(deviceIndex) * new RigidPose(posOffset, Quaternion.Euler(rotOffset));
            ModifyPose(ref targetPose, origin);

            // transform to world space
            var o = origin != null ? origin : transform.parent;

            if (o != null)
            {
                targetPose = new RigidPose(o) * targetPose;
                targetPose.pos.Scale(o.localScale);
            }

            if (m_snap)
            {
                m_snap             = false;
                transform.position = targetPose.pos;
                transform.rotation = targetPose.rot;
            }

            SetIsValid(VivePose.IsValid(deviceIndex));
        }
コード例 #3
0
        //게임 오브젝트 또는 스크립트가 비 활성화 되었을 때 호출
        protected virtual void OnDisable()
        {
            //현재 인스턴스가 Tracker의 Pose를 Listen 할 수 없게 함
            VivePose.RemoveNewPosesListener(this);

            // Pose Tracker를 InValid 하게 변경
            SetIsValid(false);
        }
コード例 #4
0
        private void InternalSetQuadViewActive(bool value)
        {
            if (value && m_externalCamera == null && !string.IsNullOrEmpty(m_configPath) && File.Exists(m_configPath))
            {
                // don't know why SteamVR_ExternalCamera must be instantiated from the prefab
                // when create SteamVR_ExternalCamera using AddComponent, errors came out when disabling
                var prefab = Resources.Load <GameObject>("SteamVR_ExternalCamera");
                if (prefab == null)
                {
                    Debug.LogError("SteamVR_ExternalCamera prefab not found!");
                }
                else
                {
                    var ctrlMgr = Instantiate(prefab);
                    var extCam  = ctrlMgr.transform.GetChild(0);
                    extCam.gameObject.name = "SteamVR External Camera";
                    extCam.SetParent(transform, false);
                    DestroyImmediate(extCam.GetComponent <SteamVR_TrackedObject>());
                    DestroyImmediate(ctrlMgr);

                    m_externalCamera = extCam.GetComponent <SteamVR_ExternalCamera>();
                    SteamVR_Render.instance.externalCamera = m_externalCamera;

                    // resolve config file
                    m_externalCamera.enabled    = false;
                    m_externalCamera.configPath = m_configPath;
                    m_externalCamera.ReadConfig();
                    m_externalCamera.enabled = true; // to preserve sceneResolutionScale on enabled

                    // resolve RenderTexture
                    m_externalCamera.AttachToCamera(SteamVR_Render.Top());
                    var w   = Screen.width / 2;
                    var h   = Screen.height / 2;
                    var cam = m_externalCamera.GetComponentInChildren <Camera>();
                    if (cam.targetTexture == null || cam.targetTexture.width != w || cam.targetTexture.height != h)
                    {
                        var tex = new RenderTexture(w, h, 24, RenderTextureFormat.ARGB32, QualitySettings.activeColorSpace == ColorSpace.Linear ? RenderTextureReadWrite.Linear : RenderTextureReadWrite.Default);
                        tex.antiAliasing  = QualitySettings.antiAliasing == 0 ? 1 : QualitySettings.antiAliasing;
                        cam.targetTexture = tex;
                    }
                }
            }

            if (m_externalCamera != null)
            {
                m_externalCamera.gameObject.SetActive(value);

                if (value)
                {
                    VivePose.AddNewPosesListener(this);
                }
                else
                {
                    VivePose.RemoveNewPosesListener(this);
                }
            }
        }
コード例 #5
0
        public virtual void OnNewPoses()
        {
            TrackPose(VivePose.GetPose(role), origin);

            var isValidCurrent = VivePose.IsValid(role);

            if (isValid != isValidCurrent)
            {
                isValid = isValidCurrent;
                onIsValidChanged.Invoke(isValid);
            }
        }
コード例 #6
0
        public virtual void OnNewPoses()
        {
            var deviceIndex = m_viveRole.GetDeviceIndex();
            var isValid     = VivePose.IsValid(deviceIndex);

            if (isValid)
            {
                TrackPose(VivePose.GetPose(deviceIndex), origin);
            }

            SetIsValid(isValid);
        }
コード例 #7
0
        public virtual void OnNewPoses()
        {
            var deviceIndex = m_viveRole.GetDeviceIndex();

            if (VRModule.IsValidDeviceIndex(deviceIndex))
            {
                m_staticExCamPose = VivePose.GetPose(deviceIndex);
            }

            if (isQuadViewActive)
            {
                RigidPose.SetPose(transform, m_staticExCamPose, m_origin);
            }
        }
コード例 #8
0
        private bool TryGetValidPose(out RigidPose pose)
        {
            pose = default(RigidPose);
            if (!isRoleJointValid)
            {
                return(false);
            }

            var p = VivePose.GetAllHandJoints(m_viveRole)[m_joint];

            if (!p.isValid)
            {
                return(false);
            }

            pose = p.pose;
            return(true);
        }
コード例 #9
0
        private void InternalSetQuadViewActive(bool value)
        {
            if (value && m_externalCamera == null && !string.IsNullOrEmpty(m_configPath) && File.Exists(m_configPath))
            {
                // don't know why SteamVR_ExternalCamera must be instantiated from the prefab
                // when create SteamVR_ExternalCamera using AddComponent, errors came out when disabling
                var prefab = Resources.Load <GameObject>("SteamVR_ExternalCamera");
                if (prefab == null)
                {
                    Debug.LogError("SteamVR_ExternalCamera prefab not found!");
                }
                else
                {
                    var ctrlMgr = Instantiate(prefab);
                    var extCam  = ctrlMgr.transform.GetChild(0);
                    extCam.gameObject.name = "SteamVR External Camera";
                    extCam.SetParent(transform, false);
                    DestroyImmediate(extCam.GetComponent <SteamVR_TrackedObject>());
                    DestroyImmediate(ctrlMgr);

                    m_externalCamera = extCam.GetComponent <SteamVR_ExternalCamera>();
                    SteamVR_Render.instance.externalCamera = m_externalCamera;
                    m_externalCamera.configPath            = m_configPath;
                    m_externalCamera.ReadConfig();
                }
            }

            if (m_externalCamera != null)
            {
                m_externalCamera.gameObject.SetActive(value);

                if (value)
                {
                    VivePose.AddNewPosesListener(this);
                }
                else
                {
                    VivePose.RemoveNewPosesListener(this);
                }
            }
        }
コード例 #10
0
        public virtual void OnNewPoses()
        {
            var deviceIndex = m_viveRole.GetDeviceIndex();
            var isValid     = VivePose.IsValid(deviceIndex);

            if (isValid)
            {
                var pose = VivePose.GetPose(deviceIndex);
                if (m_origin != null && m_origin != transform.parent)
                {
                    pose = new RigidPose(m_origin.transform) * pose;
                    TrackPose(pose, false);
                }
                else
                {
                    TrackPose(pose, true);
                }
            }

            SetIsValid(isValid);
        }
コード例 #11
0
        public override void OnNewPoses()
        {
            targetPose = VivePose.GetPose(role) * new Pose(posOffset, Quaternion.Euler(rotOffset));
            ModifyPose(ref targetPose, origin);

            // transform to world space
            var o = origin != null ? origin : transform.parent;

            if (o != null)
            {
                targetPose = new Pose(o) * targetPose;
                targetPose.pos.Scale(o.localScale);
            }

            var poseValid = VivePose.IsValid(role);

            if (!isPoseValid && poseValid)
            {
                transform.position = targetPose.pos;
                transform.rotation = targetPose.rot;
            }

            SetIsValid(poseValid);
        }
コード例 #12
0
        protected virtual void OnDisable()
        {
            VivePose.RemoveNewPosesListener(this);

            SetIsValid(false);
        }
コード例 #13
0
 //Update 함수가 호출되기 전에 한 번만 호출, 다른 스크립트의 Awake가 모두 실행 된 후 실행
 protected virtual void Start()
 {
     //Role(right hand, left hand)를 Valid로 변경
     SetIsValid(VivePose.IsValid(m_viveRole), true);
 }
コード例 #14
0
 protected virtual void Start()
 {
     isValid = VivePose.IsValid(role);
     onIsValidChanged.Invoke(isValid);
 }
        public virtual void OnNewPoses()
        {
            TrackPose(VivePose.GetPose(role), origin);

            SetIsValid(VivePose.IsValid(role));
        }
コード例 #16
0
 protected virtual void OnDisable()
 {
     VivePose.RemoveNewPosesListener(this);
 }
コード例 #17
0
 protected virtual void Start()
 {
     SetIsValid(VivePose.IsValidEx(viveRole.roleType, viveRole.roleValue), true);
 }
コード例 #18
0
 protected virtual void OnEnable()
 {
     VivePose.AddNewPosesListener(this);
 }
コード例 #19
0
 protected virtual void Start()
 {
     SetIsValid(VivePose.IsValid(m_viveRole), true);
 }
コード例 #20
0
        public void Refresh()
        {
            m_sortedDevices.Clear();

            UnmappingAll();

            MappingRoleIfUnbound(BodyRole.Head, 0u);

            // get related poses and record controller/tracker devices
            var hmdPose = VivePose.GetPose(0u);

            // preserve only y-axis rotation
            hmdPose.rot = Quaternion.Euler(0f, hmdPose.rot.eulerAngles.y, 0f);
            // move center to half height
            hmdPose.pos = Vector3.Scale(hmdPose.pos, new Vector3(1f, 0.5f, 1f));
            var halfHeight        = hmdPose.pos.y;
            var centerPoseInverse = hmdPose.GetInverse();

            for (uint i = 1; i < ViveRole.MAX_DEVICE_COUNT; ++i)
            {
                if (!IsControllerOrTracker(i))
                {
                    continue;
                }

                var relatedCenterPos     = (centerPoseInverse * VivePose.GetPose(i)).pos;
                var normalizedPosOnPlane = Vector3.ProjectOnPlane(relatedCenterPos, Vector3.forward) / halfHeight; // normalize
                m_direction[i] = GetDirection(normalizedPosOnPlane);
                m_distance[i]  = normalizedPosOnPlane.magnitude;

                m_sortedDevices.Add(i);
            }

            if (m_sortedDevices.Count == 0)
            {
                return;
            }

            var index = m_sortedDevices.Count - 1; // pointing last index

            // find 2 feet, should be most farest 2 devices
            m_sortedDevices.Sort(CompareDistance);
            if (IsFoot(m_sortedDevices[index]))
            {
                if (m_sortedDevices.Count <= 1)
                {
                    MappingRoleIfUnbound(BodyRole.RightFoot, m_sortedDevices[index]);
                    return;
                }

                if (!IsFoot(m_sortedDevices[index - 1]))
                {
                    // only 1 foot found
                    MappingRoleIfUnbound(BodyRole.RightFoot, m_sortedDevices[index]);
                    m_sortedDevices.RemoveAt(index--);
                    if (index < 0)
                    {
                        return;
                    }
                }
                else
                {
                    // 2 feet found, deside lef/right foot
                    if (m_direction[m_sortedDevices[index]] < m_direction[m_sortedDevices[index - 1]])
                    {
                        MappingRoleIfUnbound(BodyRole.RightFoot, m_sortedDevices[index]);
                        MappingRoleIfUnbound(BodyRole.LeftFoot, m_sortedDevices[index - 1]);
                    }
                    else
                    {
                        MappingRoleIfUnbound(BodyRole.RightFoot, m_sortedDevices[index - 1]);
                        MappingRoleIfUnbound(BodyRole.LeftFoot, m_sortedDevices[index]);
                    }

                    m_sortedDevices.RemoveAt(index--);
                    m_sortedDevices.RemoveAt(index--);
                    if (index < 0)
                    {
                        return;
                    }
                }
            }

            // find 2 hands, should be most left and most right device
            m_sortedDevices.Sort(CompareDirection);

            // right most device as right hand
            MappingRoleIfUnbound(BodyRole.RightHand, m_sortedDevices[0]);
            if (m_sortedDevices.Count == 1)
            {
                return;
            }

            // left most device as left hand
            MappingRoleIfUnbound(BodyRole.LeftHand, m_sortedDevices[index]);
            if (m_sortedDevices.Count == 2)
            {
                return;
            }

            // middle one as hip
            MappingRoleIfUnbound(BodyRole.Hip, m_sortedDevices[index / 2]);
        }
コード例 #21
0
ファイル: BodyRole.cs プロジェクト: S4nop/URGS
        public void Refresh()
        {
            m_sortedDevices.Clear();

            UnmappingAll();

            MappingRoleIfUnbound(BodyRole.Head, 0u);

            // get related poses and record controller/tracker devices
            var hmdPose = VivePose.GetPose(0u);

            // preserve only y-axis rotation
            hmdPose.rot = Quaternion.Euler(0f, hmdPose.rot.eulerAngles.y, 0f);
            // move center to half height
            hmdPose.pos = Vector3.Scale(hmdPose.pos, new Vector3(1f, 0.5f, 1f));
            var halfHeight        = hmdPose.pos.y;
            var centerPoseInverse = hmdPose.GetInverse();

            for (uint i = 1; i < VRModule.MAX_DEVICE_COUNT; ++i)
            {
                if (!IsTrackingDevice(i))
                {
                    continue;
                }

                var relatedCenterPos = centerPoseInverse.InverseTransformPoint(VRModule.GetCurrentDeviceState(i).pose.pos);
                m_directionPoint[i] = HandRoleHandler.GetDirectionPoint(new Vector2(relatedCenterPos.x, -relatedCenterPos.y));
                m_distanceSqr[i]    = relatedCenterPos.sqrMagnitude / (halfHeight * halfHeight);

                m_sortedDevices.Add(i);
            }

            if (m_sortedDevices.Count == 0)
            {
                return;
            }

            var index = m_sortedDevices.Count - 1; // pointing last index

            // find 2 feet, should be most farest 2 devices
            m_sortedDevices.Sort(CompareDistance);
            if (IsFoot(m_sortedDevices[index]))
            {
                if (m_sortedDevices.Count <= 1)
                {
                    MappingRoleIfUnbound(BodyRole.RightFoot, m_sortedDevices[index]);
                    return;
                }

                if (!IsFoot(m_sortedDevices[index - 1]))
                {
                    // only 1 foot found
                    MappingRoleIfUnbound(BodyRole.RightFoot, m_sortedDevices[index]);
                    m_sortedDevices.RemoveAt(index--);
                    if (index < 0)
                    {
                        return;
                    }
                }
                else
                {
                    // 2 feet found, determine lef/right foot
                    if (m_directionPoint[m_sortedDevices[index]] < m_directionPoint[m_sortedDevices[index - 1]])
                    {
                        MappingRoleIfUnbound(BodyRole.RightFoot, m_sortedDevices[index]);
                        MappingRoleIfUnbound(BodyRole.LeftFoot, m_sortedDevices[index - 1]);
                    }
                    else
                    {
                        MappingRoleIfUnbound(BodyRole.RightFoot, m_sortedDevices[index - 1]);
                        MappingRoleIfUnbound(BodyRole.LeftFoot, m_sortedDevices[index]);
                    }

                    m_sortedDevices.RemoveAt(index--);
                    m_sortedDevices.RemoveAt(index--);
                    if (index < 0)
                    {
                        return;
                    }
                }
            }

            // find 2 hands, should be most left and most right device
            m_sortedDevices.Sort(CompareDirection);

            // right most device as right hand
            MappingRoleIfUnbound(BodyRole.RightHand, m_sortedDevices[0]);
            if (m_sortedDevices.Count == 1)
            {
                return;
            }

            // left most device as left hand
            MappingRoleIfUnbound(BodyRole.LeftHand, m_sortedDevices[index]);
            if (m_sortedDevices.Count == 2)
            {
                return;
            }

            // middle one as hip
            MappingRoleIfUnbound(BodyRole.Hip, m_sortedDevices[index / 2]);
        }
コード例 #22
0
 //인스펙터뷰에서 체크를 통해 게임오브젝트 활성화 될 때 호출
 protected virtual void OnEnable()
 {
     //현재 인스턴스가 Tracker의 Pose를 Listen 할 수 있게 함
     VivePose.AddNewPosesListener(this);
 }