예제 #1
0
        public override void Initialize(NVRPlayer player)
        {
            Player = player;
            Player.gameObject.SetActive(false);

            SteamVR_ControllerManager controllerManager = Player.gameObject.AddComponent <SteamVR_ControllerManager>();

            controllerManager.left  = Player.LeftHand.gameObject;
            controllerManager.right = Player.RightHand.gameObject;

            //Player.gameObject.AddComponent<SteamVR_PlayArea>();

            for (int index = 0; index < Player.Hands.Length; index++)
            {
                Player.Hands[index].gameObject.AddComponent <SteamVR_TrackedObject>();
            }


            SteamVR_Camera steamVrCamera = Player.Head.gameObject.AddComponent <SteamVR_Camera>();

            Player.Head.gameObject.AddComponent <SteamVR_Ears>();
            NVRHelpers.SetField(steamVrCamera, "_head", Player.Head.transform, false);
            NVRHelpers.SetField(steamVrCamera, "_ears", Player.Head.transform, false);

            Player.Head.gameObject.AddComponent <SteamVR_TrackedObject>();

            Player.gameObject.SetActive(true);

            SteamVR_Render[] steamvr_objects = GameObject.FindObjectsOfType <SteamVR_Render>();
            for (int objectIndex = 0; objectIndex < steamvr_objects.Length; objectIndex++)
            {
                steamvr_objects[objectIndex].lockPhysicsUpdateRateToRenderFrequency = false; //this generally seems to break things :) Just make sure your Time -> Physics Timestep is set to 0.011
            }
        }
예제 #2
0
        public override void Initialize(NVRPlayer player)
        {
            Player = player;
            Player.gameObject.SetActive(false);

            SteamVR_ControllerManager controllerManager = Player.gameObject.AddComponent <SteamVR_ControllerManager>();

            controllerManager.left  = Player.LeftHand.gameObject;
            controllerManager.right = Player.RightHand.gameObject;
            //controllerManager.objects = new GameObject[2] { Player.LeftHand.gameObject, Player.RightHand.gameObject };

            Player.gameObject.AddComponent <SteamVR_PlayArea>();

            for (int index = 0; index < Player.Hands.Length; index++)
            {
                Player.Hands[index].gameObject.AddComponent <SteamVR_TrackedObject>();
            }


            SteamVR_Camera steamVrCamera = Player.Head.gameObject.AddComponent <SteamVR_Camera>();
            SteamVR_Ears   steamVrEars   = Player.Head.gameObject.AddComponent <SteamVR_Ears>();

            NVRHelpers.SetField(steamVrCamera, "_head", Player.Head.transform, false);
            NVRHelpers.SetField(steamVrCamera, "_ears", Player.Head.transform, false);

            Player.Head.gameObject.AddComponent <SteamVR_TrackedObject>();

            Player.gameObject.SetActive(true);
        }
예제 #3
0
        protected override void Start()
        {
            base.Start();

            if (Initialized == false)
            {
                StartCoroutine(DelayedCameraInit());

                Player = this.GetComponent <NVRPlayer>();

                Cursors = new RectTransform[Player.Hands.Length];
                Lasers  = new LineRenderer[Cursors.Length];

                for (int index = 0; index < Cursors.Length; index++)
                {
                    GameObject cursor = new GameObject("Cursor for " + Player.Hands[index].gameObject.name);
                    cursor.transform.parent        = this.transform;
                    cursor.transform.localPosition = Vector3.zero;
                    cursor.transform.localRotation = Quaternion.identity;

                    Canvas canvas = cursor.AddComponent <Canvas>();
                    cursor.AddComponent <CanvasRenderer>();
                    cursor.AddComponent <CanvasScaler>();
                    cursor.AddComponent <NVRUIIgnoreRaycast>();
                    cursor.AddComponent <GraphicRaycaster>();

                    canvas.renderMode   = RenderMode.WorldSpace;
                    canvas.sortingOrder = 1000; //set to be on top of everything

                    Image image = cursor.AddComponent <Image>();
                    image.sprite   = CursorSprite;
                    image.material = CursorMaterial;

                    if (LaserEnabled == true)
                    {
                        Lasers[index]                = cursor.AddComponent <LineRenderer>();
                        Lasers[index].material       = new Material(Shader.Find("Standard"));
                        Lasers[index].material.color = LaserColor;
                        NVRHelpers.LineRendererSetColor(Lasers[index], LaserColor, LaserColor);
                        NVRHelpers.LineRendererSetWidth(Lasers[index], LaserStartWidth, LaserEndWidth);
                        Lasers[index].useWorldSpace = true;
                        Lasers[index].enabled       = false;
                    }

                    if (CursorSprite == null)
                    {
                        Debug.LogError("Set CursorSprite on " + this.gameObject.name + " to the sprite you want to use as your cursor.", this.gameObject);
                    }

                    Cursors[index] = cursor.GetComponent <RectTransform>();
                }

                CurrentPoint    = new GameObject[Cursors.Length];
                CurrentPressed  = new GameObject[Cursors.Length];
                CurrentDragging = new GameObject[Cursors.Length];
                PointEvents     = new PointerEventData[Cursors.Length];

                Initialized = true;
            }
        }
예제 #4
0
        private IEnumerator DoSetDeviceIndex(int index)
        {
            yield return(new WaitForSeconds(1f));

            yield return(null); //wait for children to be initialized

            Rigidbody = this.GetComponent <Rigidbody>();
            if (Rigidbody == null)
            {
                Rigidbody = this.gameObject.AddComponent <Rigidbody>();
            }
            Rigidbody.isKinematic = true;

            Transform trackhat = this.transform.FindChild("trackhat");

            Collider trackhatCollider = trackhat.GetComponent <Collider>();

            if (trackhatCollider == null)
            {
                trackhatCollider = trackhat.gameObject.AddComponent <SphereCollider>();
            }
            trackhatCollider.isTrigger = true;

            NVRPlayer.Instance.RegisterHand(this);

            if (NVRPlayer.Instance.PhysicalHands == true)
            {
                if (PhysicalController != null)
                {
                    PhysicalController.Kill();
                }

                PhysicalController = this.gameObject.AddComponent <NVRPhysicalController>();
                PhysicalController.Initialize(this, false);

                Color transparentcolor = Color.white;
                transparentcolor.a = (float)VisibilityLevel.Ghost / 100f;

                GhostRenderers = this.GetComponentsInChildren <Renderer>();
                for (int rendererIndex = 0; rendererIndex < GhostRenderers.Length; rendererIndex++)
                {
                    NVRHelpers.SetTransparent(GhostRenderers[rendererIndex].material, transparentcolor);
                }

                GhostColliders    = new Collider[] { trackhatCollider };
                CurrentVisibility = VisibilityLevel.Ghost;
            }

            CurrentHandState = HandState.Idle;
        }
예제 #5
0
        public void Initialize(NVRHand trackingHand, bool initialState)
        {
            Hand = trackingHand;

            PhysicalController      = GameObject.Instantiate(Hand.gameObject);
            PhysicalController.name = PhysicalController.name.Replace("(Clone)", " [Physical]");
            GameObject.DestroyImmediate(PhysicalController.GetComponent <NVRHand>());
            GameObject.DestroyImmediate(PhysicalController.GetComponent <SteamVR_TrackedObject>());
            GameObject.DestroyImmediate(PhysicalController.GetComponent <SteamVR_RenderModel>());

            Collider[] clonedColliders = PhysicalController.GetComponentsInChildren <Collider>();
            for (int index = 0; index < clonedColliders.Length; index++)
            {
                GameObject.DestroyImmediate(clonedColliders[index]);
            }

            PhysicalController.transform.parent     = Hand.transform.parent;
            PhysicalController.transform.position   = Hand.transform.position;
            PhysicalController.transform.rotation   = Hand.transform.rotation;
            PhysicalController.transform.localScale = Hand.transform.localScale;

            Rigidbody             = PhysicalController.GetComponent <Rigidbody>();
            Rigidbody.isKinematic = false;

            Transform trackhat         = PhysicalController.transform.FindChild("trackhat");
            Collider  trackhatCollider = trackhat.gameObject.AddComponent <BoxCollider>();

            Transform body         = PhysicalController.transform.FindChild("body");
            Collider  bodyCollider = body.gameObject.AddComponent <BoxCollider>();

            Colliders = new Collider[] { trackhatCollider, bodyCollider };

            Renderer[] renderers = PhysicalController.GetComponentsInChildren <Renderer>();
            for (int index = 0; index < renderers.Length; index++)
            {
                NVRHelpers.SetOpaque(renderers[index].material);
            }

            if (initialState == false)
            {
                Off();
            }
            else
            {
                On();
            }
        }
예제 #6
0
        public override void Initialize(NVRPlayer player)
        {
            Player = player;
            Player.gameObject.SetActive(false);

            OVRManager manager = Player.gameObject.AddComponent <OVRManager>();

            manager.trackingOriginType = OVRManager.TrackingOrigin.FloorLevel;

            OVRCameraRig rig = Player.gameObject.AddComponent <OVRCameraRig>();

            NVRHelpers.SetProperty(rig, "trackingSpace", Player.transform, true);
            NVRHelpers.SetProperty(rig, "leftHandAnchor", Player.LeftHand.transform, true);
            NVRHelpers.SetProperty(rig, "rightHandAnchor", Player.RightHand.transform, true);
            NVRHelpers.SetProperty(rig, "centerEyeAnchor", Player.Head.transform, true);

            Player.gameObject.SetActive(true);
        }
        public void Initialize(NVRHand trackingHand, bool initialState)
        {
            Hand = trackingHand;

            PhysicalController      = GameObject.Instantiate(Hand.gameObject);
            PhysicalController.name = PhysicalController.name.Replace("(Clone)", " [Physical]");

            GameObject.DestroyImmediate(PhysicalController.GetComponent <NVRPhysicalController>());
            GameObject.DestroyImmediate(PhysicalController.GetComponent <NVRHand>());
            GameObject.DestroyImmediate(PhysicalController.GetComponent <SteamVR_TrackedObject>());
            GameObject.DestroyImmediate(PhysicalController.GetComponent <SteamVR_RenderModel>());
            GameObject.DestroyImmediate(PhysicalController.GetComponent <NVRPhysicalController>());

            Collider[] clonedColliders = PhysicalController.GetComponentsInChildren <Collider>();
            for (int index = 0; index < clonedColliders.Length; index++)
            {
                GameObject.DestroyImmediate(clonedColliders[index]);
            }

            PhysicalController.transform.parent     = Hand.transform.parent;
            PhysicalController.transform.position   = Hand.transform.position;
            PhysicalController.transform.rotation   = Hand.transform.rotation;
            PhysicalController.transform.localScale = Hand.transform.localScale;

            Rigidbody                    = PhysicalController.GetComponent <Rigidbody>();
            Rigidbody.isKinematic        = false;
            Rigidbody.useGravity         = false;
            Rigidbody.angularDrag        = 0;
            Rigidbody.maxAngularVelocity = 100f;

            string controllerModel = Hand.GetDeviceName();

            switch (controllerModel)
            {
            case "vr_controller_05_wireless_b":
                Transform dk1Trackhat         = PhysicalController.transform.FindChild("trackhat");
                Collider  dk1TrackhatCollider = dk1Trackhat.gameObject.GetComponent <BoxCollider>();
                if (dk1TrackhatCollider == null)
                {
                    dk1TrackhatCollider = dk1Trackhat.gameObject.AddComponent <BoxCollider>();
                }

                Transform dk1Body         = PhysicalController.transform.FindChild("body");
                Collider  dk1BodyCollider = dk1Body.gameObject.GetComponent <BoxCollider>();
                if (dk1BodyCollider == null)
                {
                    dk1BodyCollider = dk1Body.gameObject.AddComponent <BoxCollider>();
                }

                Colliders = new Collider[] { dk1TrackhatCollider, dk1BodyCollider };
                break;

            case "vr_controller_vive_1_5":
                Transform dk2TrackhatColliders = PhysicalController.transform.FindChild("VivePreColliders");
                if (dk2TrackhatColliders == null)
                {
                    dk2TrackhatColliders               = GameObject.Instantiate(Resources.Load <GameObject>("VivePreColliders")).transform;
                    dk2TrackhatColliders.parent        = PhysicalController.transform;
                    dk2TrackhatColliders.localPosition = Vector3.zero;
                    dk2TrackhatColliders.localRotation = Quaternion.identity;
                    dk2TrackhatColliders.localScale    = Vector3.one;
                }

                Colliders = dk2TrackhatColliders.GetComponentsInChildren <Collider>();
                break;

            default:
                Debug.LogError("Error. Unsupported device type: " + controllerModel);
                break;
            }

            Renderer[] renderers = PhysicalController.GetComponentsInChildren <Renderer>();
            for (int index = 0; index < renderers.Length; index++)
            {
                NVRHelpers.SetOpaque(renderers[index].material);
            }

            if (initialState == false)
            {
                Off();
            }
            else
            {
                On();
            }
        }
예제 #8
0
파일: NVRHand.cs 프로젝트: rcgray/NewtonVR
        private IEnumerator DoInitialize()
        {
            do
            {
                yield return(null); //wait for render model to be initialized
            } while (RenderModelInitialized == false && CustomModel == null);

            Rigidbody = this.GetComponent <Rigidbody>();
            if (Rigidbody == null)
            {
                Rigidbody = this.gameObject.AddComponent <Rigidbody>();
            }
            Rigidbody.isKinematic        = true;
            Rigidbody.maxAngularVelocity = float.MaxValue;
            Rigidbody.useGravity         = false;

            Collider[] Colliders = null;

            if (CustomModel == null)
            {
                string controllerModel          = GetDeviceName();
                SteamVR_RenderModel renderModel = this.GetComponentInChildren <SteamVR_RenderModel>();

                switch (controllerModel)
                {
                case "vr_controller_05_wireless_b":
                    Transform dk1Trackhat = renderModel.transform.Find("trackhat");
                    if (dk1Trackhat == null)
                    {
                        // Dk1 controller model has trackhat
                    }
                    else
                    {
                        dk1Trackhat.gameObject.SetActive(true);
                    }

                    SphereCollider dk1TrackhatCollider = dk1Trackhat.gameObject.GetComponent <SphereCollider>();
                    if (dk1TrackhatCollider == null)
                    {
                        dk1TrackhatCollider           = dk1Trackhat.gameObject.AddComponent <SphereCollider>();
                        dk1TrackhatCollider.isTrigger = true;
                    }

                    Colliders = new Collider[] { dk1TrackhatCollider };
                    break;

                case "vr_controller_vive_1_5":
                    Transform dk2Trackhat = renderModel.transform.FindChild("trackhat");
                    if (dk2Trackhat == null)
                    {
                        dk2Trackhat = new GameObject("trackhat").transform;
                        dk2Trackhat.gameObject.layer = this.gameObject.layer;
                        dk2Trackhat.parent           = renderModel.transform;
                        dk2Trackhat.localPosition    = new Vector3(0, -0.033f, 0.014f);
                        dk2Trackhat.localScale       = Vector3.one * 0.1f;
                        dk2Trackhat.localEulerAngles = new Vector3(325, 0, 0);
                        dk2Trackhat.gameObject.SetActive(true);
                    }
                    else
                    {
                        dk2Trackhat.gameObject.SetActive(true);
                    }

                    Collider dk2TrackhatCollider = dk2Trackhat.gameObject.GetComponent <SphereCollider>();
                    if (dk2TrackhatCollider == null)
                    {
                        dk2TrackhatCollider           = dk2Trackhat.gameObject.AddComponent <SphereCollider>();
                        dk2TrackhatCollider.isTrigger = true;
                    }

                    Colliders = new Collider[] { dk2TrackhatCollider };
                    break;

                default:
                    Debug.LogError("Error. Unsupported device type: " + controllerModel);
                    break;
                }
            }
            else if (RenderModelInitialized == false)
            {
                RenderModelInitialized = true;
                GameObject CustomModelObject = GameObject.Instantiate(CustomModel);
                Colliders = CustomModelObject.GetComponentsInChildren <Collider>(); //note: these should be trigger colliders

                CustomModelObject.transform.parent        = this.transform;
                CustomModelObject.transform.localScale    = Vector3.one;
                CustomModelObject.transform.localPosition = Vector3.zero;
                CustomModelObject.transform.localRotation = Quaternion.identity;
            }

            NVRPlayer.Instance.RegisterHand(this);

            if (NVRPlayer.Instance.PhysicalHands == true)
            {
                if (PhysicalController != null)
                {
                    PhysicalController.Kill();
                }

                PhysicalController = this.gameObject.AddComponent <NVRPhysicalController>();
                PhysicalController.Initialize(this, false);

                Color transparentcolor = Color.white;
                transparentcolor.a = (float)VisibilityLevel.Ghost / 100f;

                GhostRenderers = this.GetComponentsInChildren <Renderer>();
                for (int rendererIndex = 0; rendererIndex < GhostRenderers.Length; rendererIndex++)
                {
                    NVRHelpers.SetTransparent(GhostRenderers[rendererIndex].material, transparentcolor);
                }

                if (Colliders != null)
                {
                    GhostColliders = Colliders;
                }

                CurrentVisibility = VisibilityLevel.Ghost;
            }
            else
            {
                Color transparentcolor = Color.white;
                transparentcolor.a = (float)VisibilityLevel.Ghost / 100f;

                GhostRenderers = this.GetComponentsInChildren <Renderer>();
                for (int rendererIndex = 0; rendererIndex < GhostRenderers.Length; rendererIndex++)
                {
                    NVRHelpers.SetTransparent(GhostRenderers[rendererIndex].material, transparentcolor);
                }

                if (Colliders != null)
                {
                    GhostColliders = Colliders;
                }

                CurrentVisibility = VisibilityLevel.Ghost;
            }

            CurrentHandState = HandState.Idle;
        }
예제 #9
0
        protected override void Start()
        {
            base.Start();

            if (Initialized == false)
            {
                Player = this.GetComponent <NVRPlayer>();

                ControllerCamera = new GameObject("Controller UI Camera").AddComponent <Camera>();
                ControllerCamera.transform.parent = Player.transform;
                ControllerCamera.clearFlags       = CameraClearFlags.Nothing;
                ControllerCamera.cullingMask      = 0; // 1 << LayerMask.NameToLayer("UI");
                ControllerCamera.stereoTargetEye  = StereoTargetEyeMask.None;

                Cursors = new RectTransform[Player.Hands.Length];
                Lasers  = new LineRenderer[Cursors.Length];

                for (int index = 0; index < Cursors.Length; index++)
                {
                    GameObject cursor = new GameObject("Cursor for " + Player.Hands[index].gameObject.name);
                    cursor.transform.parent        = this.transform;
                    cursor.transform.localPosition = Vector3.zero;
                    cursor.transform.localRotation = Quaternion.identity;

                    Canvas canvas = cursor.AddComponent <Canvas>();
                    cursor.AddComponent <CanvasRenderer>();
                    cursor.AddComponent <CanvasScaler>();
                    cursor.AddComponent <NVRUIIgnoreRaycast>();
                    cursor.AddComponent <GraphicRaycaster>();

                    canvas.renderMode   = RenderMode.WorldSpace;
                    canvas.sortingOrder = 1000; //set to be on top of everything

                    Image image = cursor.AddComponent <Image>();
                    image.sprite   = CursorSprite;
                    image.material = CursorMaterial;

                    if (LaserEnabled == true)
                    {
                        Lasers[index]                = cursor.AddComponent <LineRenderer>();
                        Lasers[index].material       = new Material(Shader.Find("Standard"));
                        Lasers[index].material.color = LaserColor;
                        NVRHelpers.LineRendererSetColor(Lasers[index], LaserColor, LaserColor);
                        NVRHelpers.LineRendererSetWidth(Lasers[index], LaserStartWidth, LaserEndWidth);
                        Lasers[index].useWorldSpace = true;
                        Lasers[index].enabled       = false;
                    }

                    if (CursorSprite == null)
                    {
                        Debug.LogError("Set CursorSprite on " + this.gameObject.name + " to the sprite you want to use as your cursor.", this.gameObject);
                    }

                    Cursors[index] = cursor.GetComponent <RectTransform>();
                }

                CurrentPoint    = new GameObject[Cursors.Length];
                CurrentPressed  = new GameObject[Cursors.Length];
                CurrentDragging = new GameObject[Cursors.Length];
                PointEvents     = new PointerEventData[Cursors.Length];

                Canvas[] canvases = GameObject.FindObjectsOfType <Canvas>();
                foreach (Canvas canvas in canvases)
                {
                    canvas.worldCamera = ControllerCamera;
                }

                Initialized = true;
            }
        }
예제 #10
0
        public void Initialize(NVRHand trackingHand, bool initialState)
        {
            Hand = trackingHand;

            Hand.gameObject.SetActive(false);

            PhysicalController      = Instantiate(Hand.gameObject);
            PhysicalController.name = PhysicalController.name.Replace("(Clone)", " [Physical]");

            Hand.gameObject.SetActive(true);

            Component[] components = PhysicalController.GetComponentsInChildren <Component>(true);

            foreach (Component component in components)
            {
                Type component_type = component.GetType();
                if (KeepTypes.Any(keepType => keepType == component_type || component_type.IsSubclassOf(keepType)) == false)
                {
                    DestroyImmediate(component);
                }
            }

            PhysicalController.transform.parent     = Hand.transform.parent;
            PhysicalController.transform.position   = Hand.transform.position;
            PhysicalController.transform.rotation   = Hand.transform.rotation;
            PhysicalController.transform.localScale = Hand.transform.localScale;

            PhysicalController.SetActive(true);

            if (Hand.HasCustomModel)
            {
                SetupCustomModel();
            }
            else
            {
                Colliders = Hand.SetupDefaultPhysicalColliders(PhysicalController.transform);
            }

            if (Colliders == null)
            {
                Debug.LogError("[NewtonVR] Error: Physical colliders on hand not setup properly.");
            }

            Rigidbody                    = PhysicalController.GetComponent <Rigidbody>();
            Rigidbody.isKinematic        = false;
            Rigidbody.maxAngularVelocity = float.MaxValue;

            if (trackingHand.Player.AutomaticallySetControllerTransparency)
            {
                Renderer[] renderers = PhysicalController.GetComponentsInChildren <Renderer>();
                for (int index = 0; index < renderers.Length; index++)
                {
                    NVRHelpers.SetOpaque(renderers[index].material);
                }
            }

            if (initialState == false)
            {
                Off();
            }
            else
            {
                On();
            }
        }
예제 #11
0
        protected virtual void GetTargetValues(out Vector3 targetHandPosition, out Quaternion targetHandRotation, out Vector3 targetItemPosition, out Quaternion targetItemRotation)
        {
            if (AttachedHands.Count == 1) //faster path if only one hand, which is the standard scenario
            {
                NVRHand hand = AttachedHands[0];

                if (InteractionPoint != null)
                {
                    targetItemPosition = InteractionPoint.position;
                    targetItemRotation = InteractionPoint.rotation;

                    targetHandPosition = hand.transform.position;
                    targetHandRotation = hand.transform.rotation;
                }
                else
                {
                    targetItemPosition = PickupTransforms[hand].position;;
                    targetItemRotation = PickupTransforms[hand].rotation;

                    targetHandPosition = hand.transform.position;
                    targetHandRotation = hand.transform.rotation;
                }
            }
            else if (AttachedHands.Count == 2)
            {
                if (InteractionPoint != null)
                {
                    targetItemPosition = InteractionPoint.position;
                    targetItemRotation = InteractionPoint.rotation;

                    targetHandPosition = AttachedHands[0].transform.position;
                    targetHandRotation = Quaternion.LookRotation(AttachedHands[1].transform.position - AttachedHands[0].transform.position, Vector3.up);
                }
                else
                {
                    NVRHand mainHand;
                    NVRHand secondHand;

                    if (Vector3.Distance(AttachedHands[0].transform.position, transform.position) >= Vector3.Distance(AttachedHands[1].transform.position, transform.position))
                    {
                        mainHand   = AttachedHands[0];
                        secondHand = AttachedHands[1];
                    }
                    else
                    {
                        mainHand   = AttachedHands[1];
                        secondHand = AttachedHands[0];
                    }

                    targetItemPosition = PickupTransforms[mainHand].position;
                    targetItemRotation = this.transform.rotation;

                    targetHandPosition = mainHand.transform.position;
                    if (PickupTransforms[mainHand].localPosition.z <= 0)
                    {
                        targetHandRotation = Quaternion.LookRotation(secondHand.transform.position - mainHand.transform.position, Vector3.up);
                    }
                    else
                    {
                        targetHandRotation = Quaternion.LookRotation(mainHand.transform.position - secondHand.transform.position, Vector3.up);
                    }
                }
            }
            else
            {
                Vector3    cumulativeItemVector   = Vector3.zero;
                Vector4    cumulativeItemRotation = Vector4.zero;
                Quaternion?firstItemRotation      = null;
                targetItemRotation = Quaternion.identity;

                Vector3    cumulativeHandVector   = Vector3.zero;
                Vector4    cumulativeHandRotation = Vector4.zero;
                Quaternion?firstHandRotation      = null;
                targetHandRotation = Quaternion.identity;

                for (int handIndex = 0; handIndex < AttachedHands.Count; handIndex++)
                {
                    NVRHand hand = AttachedHands[handIndex];

                    if (InteractionPoint != null && handIndex == 0)
                    {
                        targetItemRotation    = InteractionPoint.rotation;
                        cumulativeItemVector += InteractionPoint.position;

                        targetHandRotation    = hand.transform.rotation;
                        cumulativeHandVector += hand.transform.position;
                    }
                    else
                    {
                        targetItemRotation    = this.transform.rotation;
                        cumulativeItemVector += this.transform.position;

                        targetHandRotation    = PickupTransforms[hand].rotation;
                        cumulativeHandVector += PickupTransforms[hand].position;
                    }

                    if (firstItemRotation == null)
                    {
                        firstItemRotation = targetItemRotation;
                    }
                    if (firstHandRotation == null)
                    {
                        firstHandRotation = targetHandRotation;
                    }
                }
                targetItemPosition = cumulativeItemVector / AttachedHands.Count;
                targetHandPosition = cumulativeHandVector / AttachedHands.Count;
                targetItemRotation = NVRHelpers.AverageQuaternion(ref cumulativeItemRotation, targetItemRotation, firstItemRotation.Value, AttachedHands.Count);
                targetHandRotation = NVRHelpers.AverageQuaternion(ref cumulativeHandRotation, targetHandRotation, firstHandRotation.Value, AttachedHands.Count);
            }
        }
예제 #12
0
        public void Initialize(NVRHand trackingHand, bool initialState)
        {
            Hand = trackingHand;

            PhysicalController      = GameObject.Instantiate(Hand.gameObject);
            PhysicalController.name = PhysicalController.name.Replace("(Clone)", " [Physical]");

            Component[] components = PhysicalController.GetComponentsInChildren <Component>(true);

            for (int componentIndex = 0; componentIndex < components.Length; componentIndex++)
            {
                Type componentType = components[componentIndex].GetType();
                if (KeepTypes.Any(keepType => keepType == componentType || componentType.IsSubclassOf(keepType)) == false)
                {
                    DestroyImmediate(components[componentIndex]);
                }
            }

            PhysicalController.transform.parent     = Hand.transform.parent;
            PhysicalController.transform.position   = Hand.transform.position;
            PhysicalController.transform.rotation   = Hand.transform.rotation;
            PhysicalController.transform.localScale = Hand.transform.localScale;

            string controllerModel = Hand.GetDeviceName();

            switch (controllerModel)
            {
            case "Custom":
                Transform customCollidersTransform = null;
                if (Hand.CustomPhysicalColliders == null)
                {
                    GameObject customColliders = GameObject.Instantiate(Hand.CustomModel);
                    customColliders.name     = "CustomColliders";
                    customCollidersTransform = customColliders.transform;

                    customCollidersTransform.parent        = PhysicalController.transform;
                    customCollidersTransform.localPosition = Vector3.zero;
                    customCollidersTransform.localRotation = Quaternion.identity;
                    customCollidersTransform.localScale    = Vector3.one;

                    foreach (Collider col in customColliders.GetComponentsInChildren <Collider>())
                    {
                        col.isTrigger = false;
                    }

                    Colliders = customCollidersTransform.GetComponentsInChildren <Collider>();
                }
                else
                {
                    GameObject customColliders = GameObject.Instantiate(Hand.CustomPhysicalColliders);
                    customColliders.name     = "CustomColliders";
                    customCollidersTransform = customColliders.transform;

                    customCollidersTransform.parent        = PhysicalController.transform;
                    customCollidersTransform.localPosition = Vector3.zero;
                    customCollidersTransform.localRotation = Quaternion.identity;
                    customCollidersTransform.localScale    = Hand.CustomPhysicalColliders.transform.localScale;
                }

                Colliders = customCollidersTransform.GetComponentsInChildren <Collider>();
                break;

            default:
                Colliders = Hand.SetupDefaultPhysicalColliders(PhysicalController.transform);
                break;
            }

            if (Colliders == null)
            {
                Debug.LogError("[NewtonVR] Error: Physical colliders on hand not setup properly.");
            }

            Rigidbody                    = PhysicalController.GetComponent <Rigidbody>();
            Rigidbody.isKinematic        = false;
            Rigidbody.maxAngularVelocity = float.MaxValue;

            if (trackingHand.Player.AutomaticallySetControllerTransparency)
            {
                Renderer[] renderers = PhysicalController.GetComponentsInChildren <Renderer>();
                for (int index = 0; index < renderers.Length; index++)
                {
                    NVRHelpers.SetOpaque(renderers[index].material);
                }
            }

            if (initialState == false)
            {
                Off();
            }
            else
            {
                On();
            }
        }
예제 #13
0
        public void Initialize()
        {
            Rigidbody = this.GetComponent <Rigidbody>();
            if (Rigidbody == null)
            {
                Rigidbody = this.gameObject.AddComponent <Rigidbody>();
            }
            Rigidbody.isKinematic        = true;
            Rigidbody.maxAngularVelocity = float.MaxValue;
            Rigidbody.useGravity         = false;

            Collider[] colliders = null;

            if (CustomModel == null)
            {
                colliders = InputDevice.SetupDefaultColliders();
            }
            else
            {
                colliders = RenderModel.GetComponentsInChildren <Collider>(); //note: these should be trigger colliders
            }

            Player.RegisterHand(this);

            if (Player.PhysicalHands == true)
            {
                if (PhysicalController != null)
                {
                    PhysicalController.Kill();
                }

                PhysicalController = this.gameObject.AddComponent <NVRPhysicalController>();
                PhysicalController.Initialize(this, false);

                if (Player.AutomaticallySetControllerTransparency == true)
                {
                    Color transparentcolor = Color.white;
                    transparentcolor.a = (float)VisibilityLevel.Ghost / 100f;

                    GhostRenderers = this.GetComponentsInChildren <Renderer>();
                    for (int rendererIndex = 0; rendererIndex < GhostRenderers.Length; rendererIndex++)
                    {
                        NVRHelpers.SetTransparent(GhostRenderers[rendererIndex].material, transparentcolor);
                    }
                }

                if (colliders != null)
                {
                    GhostColliders = colliders;
                }

                CurrentVisibility = VisibilityLevel.Ghost;
            }
            else
            {
                if (Player.AutomaticallySetControllerTransparency == true)
                {
                    Color transparentcolor = Color.white;
                    transparentcolor.a = (float)VisibilityLevel.Ghost / 100f;

                    GhostRenderers = this.GetComponentsInChildren <Renderer>();
                    for (int rendererIndex = 0; rendererIndex < GhostRenderers.Length; rendererIndex++)
                    {
                        NVRHelpers.SetTransparent(GhostRenderers[rendererIndex].material, transparentcolor);
                    }
                }

                if (colliders != null)
                {
                    GhostColliders = colliders;
                }

                CurrentVisibility = VisibilityLevel.Ghost;
            }

            CurrentHandState = HandState.Idle;
        }
        public void Initialize(NVRHand trackingHand, bool initialState)
        {
            Debug.Log(this.gameObject.name + " PHYSICAL Controller Init");
            Hand = trackingHand;

            // if we don't have custom models to use for collision, copy whatever the hand has
            if (Hand.CustomModel == null && Hand.CustomPhysicalColliders == null)
            {
                // prevent new PhysicalController's components from starting until we're ready
                Hand.gameObject.SetActive(false);

                PhysicalController      = GameObject.Instantiate(Hand.gameObject);
                PhysicalController.name = PhysicalController.name.Replace("(Clone)", " [Physical]");

                // TODO: This could use some cleanup. Plenty of other scripts could cause problems being duplicated...
                GameObject.DestroyImmediate(PhysicalController.GetComponent <NVRPhysicalController>());
                GameObject.DestroyImmediate(PhysicalController.GetComponent <NVRHand>());
                GameObject.DestroyImmediate(PhysicalController.GetComponent <SteamVR_TrackedObject>());

                Hand.gameObject.SetActive(true);
                PhysicalController.gameObject.SetActive(true);
            }
            else
            {
                PhysicalController = new GameObject(Hand.gameObject.name + " [Physical]", typeof(Rigidbody));
            }

            PhysicalController.transform.parent     = Hand.transform.parent;
            PhysicalController.transform.position   = Hand.transform.position;
            PhysicalController.transform.rotation   = Hand.transform.rotation;
            PhysicalController.transform.localScale = Hand.transform.localScale;

            if (Hand.CustomPhysicalColliders != null)
            {
                GameObject customColliders = GameObject.Instantiate(Hand.CustomPhysicalColliders);
                customColliders.name = "CustomColliders";
                Transform customCollidersTransform = customColliders.transform;

                customCollidersTransform.parent        = PhysicalController.transform;
                customCollidersTransform.localPosition = Vector3.zero;
                customCollidersTransform.localRotation = Quaternion.identity;
                customCollidersTransform.localScale    = Vector3.one;
                Colliders = customCollidersTransform.GetComponentsInChildren <Collider>();
            }
            else if (Hand.CustomModel != null)
            {
                GameObject customColliders = GameObject.Instantiate(Hand.CustomModel);
                customColliders.name = "CustomColliders";
                Transform customCollidersTransform = customColliders.transform;

                customCollidersTransform.parent        = PhysicalController.transform;
                customCollidersTransform.localPosition = Vector3.zero;
                customCollidersTransform.localRotation = Quaternion.identity;
                customCollidersTransform.localScale    = Vector3.one;

                Colliders = customCollidersTransform.GetComponentsInChildren <Collider>();
            }
            else
            {
                Colliders = PhysicalController.GetComponentsInChildren <Collider>(true);
            }

            // in case we picked up trigger colliders from a custom/inherited model, mark them as physical
            foreach (Collider col in Colliders)
            {
                col.isTrigger = false;
                col.gameObject.SetActive(true); // for some reason this is sometimes deactivated?
            }

            Rigidbody                    = PhysicalController.GetComponent <Rigidbody>();
            Rigidbody.isKinematic        = false;
            Rigidbody.maxAngularVelocity = float.MaxValue;

            Renderer[] renderers = PhysicalController.GetComponentsInChildren <Renderer>();
            for (int index = 0; index < renderers.Length; index++)
            {
                NVRHelpers.SetOpaque(renderers[index].material);
            }

            if (initialState == false)
            {
                Off();
            }
            else
            {
                On();
            }
        }
예제 #15
0
        public override void Initialize(NVRPlayer player)
        {
            Player = player;

#if UNITY_5_6_OR_NEWER
            Player.Head.gameObject.AddComponent <SteamVR_UpdatePoses>();
#endif

            Player.gameObject.SetActive(false);


            SteamVR_ControllerManager controllerManager = Player.gameObject.AddComponent <SteamVR_ControllerManager>();
            controllerManager.left  = Player.LeftHand.gameObject;
            controllerManager.right = Player.RightHand.gameObject;

            //Player.gameObject.AddComponent<SteamVR_PlayArea>();

            for (int index = 0; index < Player.Hands.Length; index++)
            {
                Player.Hands[index].gameObject.AddComponent <SteamVR_TrackedObject>();
            }


            SteamVR_Camera steamVrCamera = Player.Head.gameObject.AddComponent <SteamVR_Camera>();
            Player.Head.gameObject.AddComponent <SteamVR_Ears>();
            NVRHelpers.SetField(steamVrCamera, "_head", Player.Head.transform, false);
            NVRHelpers.SetField(steamVrCamera, "_ears", Player.Head.transform, false);

            //// Start Integration for Holo with NVR //////

            // Integration for two camera setup needed for Microsoft Holo video with NewtonVr
            Player.Head.gameObject.name = "Head_Left";          // rename original NVR head to avoid confusion in editor

            // Create game object and position it to match NVR existing camera
            GameObject headRight = new GameObject("Head_Right");
            headRight.transform.position = Player.Head.gameObject.transform.position;
            headRight.transform.rotation = Player.Head.transform.rotation;
            headRight.transform.parent   = Player.Head.transform.parent;

            // Add camera to new game object and set for right VR eye
            Camera camRight = headRight.AddComponent <Camera> ();
            camRight.stereoTargetEye = StereoTargetEyeMask.Right;

            // Add steam camera component
            //SteamVR_Camera steamVrCameraRight = headRight.gameObject.AddComponent<SteamVR_Camera>();
            headRight.gameObject.AddComponent <SteamVR_Camera>();

            // If original NVR head has a camera component, set the camera for left VR eye
            Camera camLeft = Player.Head.GetComponent <Camera> ();
            if (camLeft)
            {
                camLeft.stereoTargetEye = StereoTargetEyeMask.Left;
            }

            //// End Integration for Holo with NVR //////
            Player.Head.gameObject.AddComponent <SteamVR_TrackedObject>();

            Player.gameObject.SetActive(true);

            SteamVR_Render[] steamvr_objects = GameObject.FindObjectsOfType <SteamVR_Render>();
            for (int objectIndex = 0; objectIndex < steamvr_objects.Length; objectIndex++)
            {
                steamvr_objects[objectIndex].lockPhysicsUpdateRateToRenderFrequency = false; //this generally seems to break things :) Just make sure your Time -> Physics Timestep is set to 0.011
            }
        }
        protected virtual void GetTargetValues(out Vector3 targetHandPosition, out Quaternion targetHandRotation, out Vector3 targetItemPosition, out Quaternion targetItemRotation)
        {
            if (AttachedHands.Count == 1) //faster path if only one hand, which is the standard scenario
            {
                NVRHand hand = AttachedHands[0];

                if (InteractionPoint != null)
                {
                    targetItemPosition = InteractionPoint.position;
                    targetItemRotation = InteractionPoint.rotation;

                    targetHandPosition = hand.transform.position;
                    targetHandRotation = hand.transform.rotation;
                }
                else
                {
                    targetItemPosition = this.transform.position;
                    targetItemRotation = this.transform.rotation;

                    targetHandPosition = PickupTransforms[hand].position;
                    targetHandRotation = PickupTransforms[hand].rotation;
                }
            }
            else
            {
                Vector3    cumulativeItemVector   = Vector3.zero;
                Vector4    cumulativeItemRotation = Vector4.zero;
                Quaternion?firstItemRotation      = null;
                targetItemRotation = Quaternion.identity;

                Vector3    cumulativeHandVector   = Vector3.zero;
                Vector4    cumulativeHandRotation = Vector4.zero;
                Quaternion?firstHandRotation      = null;
                targetHandRotation = Quaternion.identity;

                for (int handIndex = 0; handIndex < AttachedHands.Count; handIndex++)
                {
                    NVRHand hand = AttachedHands[handIndex];

                    if (InteractionPoint != null && handIndex == 0)
                    {
                        targetItemRotation    = InteractionPoint.rotation;
                        cumulativeItemVector += InteractionPoint.position;

                        targetHandRotation    = hand.transform.rotation;
                        cumulativeHandVector += hand.transform.position;
                    }
                    else
                    {
                        targetItemRotation    = this.transform.rotation;
                        cumulativeItemVector += this.transform.position;

                        targetHandRotation    = PickupTransforms[hand].rotation;
                        cumulativeHandVector += PickupTransforms[hand].position;
                    }

                    if (firstItemRotation == null)
                    {
                        firstItemRotation = targetItemRotation;
                    }
                    if (firstHandRotation == null)
                    {
                        firstHandRotation = targetHandRotation;
                    }

                    targetItemRotation = NVRHelpers.AverageQuaternion(ref cumulativeItemRotation, targetItemRotation, firstItemRotation.Value, handIndex);
                    targetHandRotation = NVRHelpers.AverageQuaternion(ref cumulativeHandRotation, targetHandRotation, firstHandRotation.Value, handIndex);
                }

                targetItemPosition = cumulativeItemVector / AttachedHands.Count;
                targetHandPosition = cumulativeHandVector / AttachedHands.Count;
            }
        }
예제 #17
0
파일: NVRHand.cs 프로젝트: omgware/NewtonVR
        private IEnumerator DoInitialize()
        {
            Debug.Log("DoInitialize() on " + this.name);

            while (RenderModelInitialized == false)
            {
                yield return(null); //wait for render model to be initialized
            }
            Rigidbody = this.GetComponent <Rigidbody>();
            if (Rigidbody == null)
            {
                Rigidbody = this.gameObject.AddComponent <Rigidbody>();
            }
            Rigidbody.isKinematic = true;

            Collider[] Colliders = null;

            string controllerModel = GetDeviceName();

            switch (controllerModel)
            {
            case "vr_controller_05_wireless_b":
                Transform dk1Trackhat = this.transform.FindChild("trackhat");
                if (dk1Trackhat == null)
                {
                    // Dk1 controller model has trackhat
                }
                else
                {
                    dk1Trackhat.gameObject.SetActive(true);
                }

                SphereCollider dk1TrackhatCollider = dk1Trackhat.gameObject.GetComponent <SphereCollider>();
                if (dk1TrackhatCollider == null)
                {
                    dk1TrackhatCollider           = dk1Trackhat.gameObject.AddComponent <SphereCollider>();
                    dk1TrackhatCollider.isTrigger = true;
                }

                Colliders = new Collider[] { dk1TrackhatCollider };
                break;

            case "vr_controller_vive_1_5":

                Transform dk2Trackhat = this.transform.FindChild("trackhat");
                if (dk2Trackhat == null)
                {
                    dk2Trackhat                  = new GameObject("trackhat").transform;
                    dk2Trackhat.parent           = this.transform;
                    dk2Trackhat.localPosition    = new Vector3(0, -0.033f, 0.014f);
                    dk2Trackhat.localScale       = Vector3.one * 0.1f;
                    dk2Trackhat.localEulerAngles = new Vector3(325, 0, 0);
                    dk2Trackhat.gameObject.SetActive(true);
                }
                else
                {
                    dk2Trackhat.gameObject.SetActive(true);
                }

                Collider dk2TrackhatCollider = dk2Trackhat.gameObject.GetComponent <SphereCollider>();
                if (dk2TrackhatCollider == null)
                {
                    dk2TrackhatCollider           = dk2Trackhat.gameObject.AddComponent <SphereCollider>();
                    dk2TrackhatCollider.isTrigger = true;
                }

                Colliders = new Collider[] { dk2TrackhatCollider };
                break;

            default:
                Debug.LogError("Error. Unsupported device type: " + controllerModel);
                break;
            }

            NVRPlayer.Instance.RegisterHand(this);

            if (NVRPlayer.Instance.PhysicalHands == true)
            {
                if (PhysicalController != null)
                {
                    PhysicalController.Kill();
                }

                PhysicalController = this.gameObject.AddComponent <NVRPhysicalController>();
                PhysicalController.Initialize(this, false);

                Color transparentcolor = Color.white;
                transparentcolor.a = (float)VisibilityLevel.Ghost / 100f;

                GhostRenderers = this.GetComponentsInChildren <Renderer>();
                for (int rendererIndex = 0; rendererIndex < GhostRenderers.Length; rendererIndex++)
                {
                    NVRHelpers.SetTransparent(GhostRenderers[rendererIndex].material, transparentcolor);
                }

                GhostColliders    = Colliders;
                CurrentVisibility = VisibilityLevel.Ghost;
            }

            CurrentHandState = HandState.Idle;
        }
예제 #18
0
        public void DoInitialize()
        {
            Rigidbody = this.GetComponent <Rigidbody>();
            if (Rigidbody == null)
            {
                Rigidbody = this.gameObject.AddComponent <Rigidbody>();
            }
            Rigidbody.isKinematic        = true;
            Rigidbody.maxAngularVelocity = float.MaxValue;
            Rigidbody.useGravity         = false;

            Collider[] Colliders = null;

            if (CustomModel != null)
            {
                GameObject CustomModelObject = GameObject.Instantiate(CustomModel);
                Colliders = CustomModelObject.GetComponentsInChildren <Collider>();
                foreach (var collider in Colliders)
                {
                    collider.isTrigger = true;
                }

                CustomModelObject.transform.parent        = this.transform;
                CustomModelObject.transform.localScale    = Vector3.one;
                CustomModelObject.transform.localPosition = Vector3.zero;
                CustomModelObject.transform.localRotation = Quaternion.identity;
            }
            else if (GhostColliders == null)
            {
                Colliders = this.GetComponentsInChildren <Collider>();
            }

            if (ExternalColliders != null)
            {
                ExternalColliders.Subscribe(this);
            }

            player.RegisterHand(this);

            if (player.PhysicalHands == true)
            {
                bool InitialState = false;

                if (PhysicalController != null)
                {
                    if (PhysicalController.State == true)
                    {
                        InitialState = true;
                    }
                    else
                    {
                        InitialState = false;
                    }
                    PhysicalController.Kill();
                }

                PhysicalController = this.gameObject.AddComponent <NVRPhysicalController>();
                PhysicalController.Initialize(this, InitialState);

                if (InitialState == true)
                {
                    ForceGhost();
                }

                GhostRenderers = this.GetComponentsInChildren <Renderer>();
                for (int rendererIndex = 0; rendererIndex < GhostRenderers.Length; rendererIndex++)
                {
                    Color transparentcolor = new Color(0.38f, 0.67f, 0.85f); // GhostRenderers[rendererIndex].material.color;
                    transparentcolor.a = (float)VisibilityLevel.Ghost / 100f;
                    NVRHelpers.SetTransparent(GhostRenderers[rendererIndex].material, transparentcolor);
                }

                if (Colliders != null)
                {
                    GhostColliders = Colliders;
                }

                CurrentVisibility = VisibilityLevel.Ghost;
            }
            else
            {
                GhostRenderers = this.GetComponentsInChildren <Renderer>();
                for (int rendererIndex = 0; rendererIndex < GhostRenderers.Length; rendererIndex++)
                {
                    Color transparentcolor = new Color(0.38f, 0.67f, 0.85f);// GhostRenderers[rendererIndex].material.color;
                    transparentcolor.a = (float)VisibilityLevel.Ghost / 100f;
                    NVRHelpers.SetTransparent(GhostRenderers[rendererIndex].material, transparentcolor);
                }

                if (Colliders != null)
                {
                    GhostColliders = Colliders;
                }

                CurrentVisibility = VisibilityLevel.Ghost;
            }

            CurrentHandState = HandState.Idle;
        }
예제 #19
0
        public override void Initialize(NVRPlayer player)
        {
            Player = player;
            Player.gameObject.SetActive(false);

            OVRManager manager = Player.gameObject.AddComponent <OVRManager>();

            manager.trackingOriginType = OVRManager.TrackingOrigin.FloorLevel;

            // User OVR rig for two camera, per eye setup
            OVRCameraRig rig = Player.gameObject.AddComponent <OVRCameraRig>();

            rig.usePerEyeCameras = true;

            NVRHelpers.SetProperty(rig, "trackingSpace", Player.transform, true);
            NVRHelpers.SetProperty(rig, "leftHandAnchor", Player.LeftHand.transform, true);
            NVRHelpers.SetProperty(rig, "rightHandAnchor", Player.RightHand.transform, true);
            NVRHelpers.SetProperty(rig, "centerEyeAnchor", Player.Head.transform, true);

            Player.gameObject.SetActive(true);

            // Initialize Left and Right eye cameras with components and values matching original head camera
            // This allows image effects, scripts, etc. set up and tested on the main camera to copy
            // over maintaining values to two camera setup

            // Reference to the NVR Head game object with desired camera components and values
            GameObject originalHead = Player.Head.gameObject;

            // Reference to left and right eye cameras created by OVR rig setup
            Camera _leftEyeCamera  = rig.leftEyeAnchor.GetComponent <Camera>();
            Camera _rightEyeCamera = rig.rightEyeAnchor.GetComponent <Camera>();

            if (originalHead != null)
            {
                ///////////////////// LEFT EYE CAMERA SETUP //////////////////////////////

                // Adjust clipping and target eye for stereo camera
                _leftEyeCamera.stereoTargetEye = StereoTargetEyeMask.Left;
                _leftEyeCamera.farClipPlane    = 160f;
                _leftEyeCamera.nearClipPlane   = 0.01f;

                // Background color setup   //change to fix NewtonSubmodule link
                //     _leftEyeCamera.clearFlags = CameraClearFlags.SolidColor;
                //     _leftEyeCamera.backgroundColor = new Color(0.00f, 0.0f, 0.025f);

                // Set all layers to 1, then compare with & to change "RightEye" layer to 0 while keeping all others 1
                // 1111 add 1101 get 1101
                _leftEyeCamera.cullingMask  = originalHead.GetComponent <Camera>().cullingMask;
                _leftEyeCamera.cullingMask &= ~(1 << LayerMask.NameToLayer("RightEye"));

                // Copy over image effect components from the main camera tagged with "ArtSetupCamera"
                // to each target eye camera with reflected component values
                Component[] cameraComponents = originalHead.GetComponents(typeof(Component));

                // Copy over each component from the head to the right eye
                foreach (Component curComponent in cameraComponents)
                {
                    // Get component type
                    System.Type type = curComponent.GetType();

                    // Skip certain components ie left eye already has Camera
                    // component and scene only needs one AudioListener
                    if (type != typeof(Camera) && type != typeof(Transform) &&
                        type != typeof(AudioListener))
                    {
                        // Add component to right eye game object
                        Component copy = rig.leftEyeAnchor.gameObject.AddComponent(type);
                        // Save active status of component from head
                        bool isActive = ((Behaviour)originalHead.GetComponent(type)).enabled;

                        // Reflect all component values from head to right eye
                        System.Reflection.FieldInfo[] fields = type.GetFields();
                        foreach (System.Reflection.FieldInfo field in fields)
                        {
                            field.SetValue(copy, field.GetValue(curComponent));
                        }

                        // Set active status of right eye component from status of head
                        ((Behaviour)rig.leftEyeAnchor.GetComponent(type)).enabled = isActive;
                    }
                }

                ///////////////////// RIGHT EYE CAMERA SETUP //////////////////////////////

                // Adjust clipping and target eye for stereo camera
                _rightEyeCamera.stereoTargetEye = StereoTargetEyeMask.Right;
                _rightEyeCamera.farClipPlane    = 160f;
                _rightEyeCamera.nearClipPlane   = 0.01f;

                // Background color setup
                //     _rightEyeCamera.clearFlags = CameraClearFlags.SolidColor;
                //     _rightEyeCamera.backgroundColor = new Color(0.00f, 0.0f, 0.025f);

                // Set all layers to 1, then compare with & to change "LeftEye" layer to 0 while keeping all others 1
                // 1111 add 1101 get 1101
                _rightEyeCamera.cullingMask  = originalHead.GetComponent <Camera>().cullingMask;
                _rightEyeCamera.cullingMask &= ~(1 << LayerMask.NameToLayer("LeftEye"));
                _rightEyeCamera.tag          = "MainCamera";

                // Copy over image effect components from the main camera tagged with "ArtSetupCamera"
                // to each target eye camera with reflected component values
                // Component[] cameraComponents = originalHead.GetComponents(typeof(Component));

                // Copy over each component from the head to the right eye
                foreach (Component curComponent in cameraComponents)
                {
                    // Get component type
                    System.Type type = curComponent.GetType();

                    // Skip certain components ie right eye already has Camera
                    // component and scene only needs one AudioListener
                    if (type != typeof(Camera) && type != typeof(Transform) &&
                        type != typeof(AudioListener))
                    {
                        // Add component to right eye game object
                        Component copy = rig.rightEyeAnchor.gameObject.AddComponent(type);
                        // Save active status of component from head
                        bool isActive = ((Behaviour)originalHead.GetComponent(type)).enabled;

                        // Reflect all component values from head to right eye
                        System.Reflection.FieldInfo[] fields = type.GetFields();
                        foreach (System.Reflection.FieldInfo field in fields)
                        {
                            field.SetValue(copy, field.GetValue(curComponent));
                        }

                        // Set active status of right eye component from status of head
                        ((Behaviour)rig.rightEyeAnchor.GetComponent(type)).enabled = isActive;
                    }
                }
            }
        }