public override void Enable()
        {
            base.Enable();

            cameraRig = GameObject.FindObjectOfType <OVRCameraRig>();
            var ovrHands = cameraRig.GetComponentsInChildren <OVRHand>();

            foreach (var ovrHand in ovrHands)
            {
                var skeltonDataProvider = ovrHand as OVRSkeleton.IOVRSkeletonDataProvider;
                var skeltonType         = skeltonDataProvider.GetSkeletonType();

                var ovrSkelton = ovrHand.GetComponent <OVRSkeleton>();
                if (ovrSkelton == null)
                {
                    continue;
                }

                switch (skeltonType)
                {
                case OVRSkeleton.SkeletonType.HandLeft:
                    leftHand     = ovrHand;
                    leftSkeleton = ovrSkelton;
                    break;

                case OVRSkeleton.SkeletonType.HandRight:
                    rightHand     = ovrHand;
                    rightSkeleton = ovrSkelton;
                    break;
                }
            }
        }
Пример #2
0
        private void SetupInput()
        {
            cameraRig = GameObject.FindObjectOfType <OVRCameraRig>();
            if (cameraRig == null)
            {
                var       mainCamera   = Camera.main;
                Transform cameraParent = null;
                if (mainCamera != null)
                {
                    cameraParent = mainCamera.transform.parent;

                    // Destroy main camera
                    GameObject.Destroy(cameraParent.gameObject);
                }

                // Instantiate camera rig as a child of the MixedRealityPlayspace
                cameraRig = GameObject.Instantiate(MRTKOculusConfig.Instance.OVRCameraRigPrefab);
            }

            bool useAvatarHands = MRTKOculusConfig.Instance.RenderAvatarHandsInsteadOfController;

            // If using Avatar hands, de-activate ovr controller rendering
            foreach (var controllerHelper in cameraRig.gameObject.GetComponentsInChildren <OVRControllerHelper>())
            {
                controllerHelper.gameObject.SetActive(!useAvatarHands);
            }

            if (useAvatarHands)
            {
                // Initialize the local avatar controller
                GameObject.Instantiate(MRTKOculusConfig.Instance.LocalAvatarPrefab, cameraRig.trackingSpace);
            }

            var ovrHands = cameraRig.GetComponentsInChildren <OVRHand>();

            foreach (var ovrHand in ovrHands)
            {
                var skeltonDataProvider = ovrHand as OVRSkeleton.IOVRSkeletonDataProvider;
                var skeltonType         = skeltonDataProvider.GetSkeletonType();

                var ovrSkelton = ovrHand.GetComponent <OVRSkeleton>();
                if (ovrSkelton == null)
                {
                    continue;
                }

                switch (skeltonType)
                {
                case OVRSkeleton.SkeletonType.HandLeft:
                    leftHand     = ovrHand;
                    leftSkeleton = ovrSkelton;
                    break;

                case OVRSkeleton.SkeletonType.HandRight:
                    rightHand     = ovrHand;
                    rightSkeleton = ovrSkelton;
                    break;
                }
            }
        }
Пример #3
0
    protected override void Start()
    {
        // get the Animator
        m_animator = this.gameObject.GetComponent <Animator>();

        // get stereo dialog
        stereoDialog = GameObject.Find("StereoDialog").GetComponent <StereoDialog> ();

        // check if HMD is on
#if !UNITY_WEBPLAYER
        HMDPresent = OVRManager.display.isPresent;
#else
        HMDPresent = false;
#endif

        // find all objects with mouse look script
        ovrCameraRig     = transform.root.GetComponentInChildren <OVRCameraRig> ();
        mouseLookObjects = ovrCameraRig.GetComponentsInChildren <MouseLook> ();
        hydraLookObjects = ovrCameraRig.GetComponentsInChildren <HydraLook> ();

        base.Start();
    }
Пример #4
0
    private void Awake()
    {
        activePath = androidPath;
        var cameras    = ovrCameraRig.GetComponentsInChildren <Camera>();
        var cameraList = new List <Camera>(cameras);

        activeCamera = cameraList.FirstOrDefault(c => c.enabled);

#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
        activePath   = windowsPath;
        activeCamera = desktopCameraRig.GetComponentInChildren <Camera>();
#endif

        VRCameraManager = ovrCameraRig.GetComponent <OVRManager>();
        player.Events.AddListener(OnVideoEvent);
    }
Пример #5
0
        void FindHandData(Side side)
        {
            // Camera
            OVRCameraRig cameraRig = GameObject.FindObjectOfType <OVRCameraRig>();

            if (!cameraRig)
            {
                return;
            }

            if (!HPTK.core.trackingSpace)
            {
                HPTK.core.trackingSpace = cameraRig.trackingSpace;
            }
            if (!HPTK.core.trackedCamera)
            {
                HPTK.core.trackedCamera = cameraRig.trackingSpace.Find("CenterEyeAnchor").transform;
            }

            // Hands
            OVRHand[] ovrHands = cameraRig.GetComponentsInChildren <OVRHand>();

            foreach (var ovrHand in ovrHands)
            {
                OVRSkeleton.IOVRSkeletonDataProvider skeltonDataProvider = ovrHand as OVRSkeleton.IOVRSkeletonDataProvider;
                OVRSkeleton.SkeletonType             skeletonType        = skeltonDataProvider.GetSkeletonType();

                OVRSkeleton ovrSkelton = ovrHand.GetComponent <OVRSkeleton>();
                if (ovrSkelton == null)
                {
                    continue;
                }

                if ((skeletonType == OVRSkeleton.SkeletonType.HandLeft && side == Side.Left) ||
                    (skeletonType == OVRSkeleton.SkeletonType.HandRight && side == Side.Right))
                {
                    handData = ovrHand;
                    boneData = ovrSkelton;
                }
                else
                {
                    continue;
                }
            }
        }
Пример #6
0
        void InitializeRuntime()
        {
            if (!Application.isPlaying || ovrRig != null)
            {
                return;
            }

            ovrRig = FindObjectOfType <OVRCameraRig>();
            ovrRig.EnsureGameObjectIntegrity();

            foreach (var skeleton in ovrRig.GetComponentsInChildren <OVRSkeleton>())
            {
                if (skeleton.GetSkeletonType() != GetSkeletonTypeFromHandedness(handedness))
                {
                    continue;
                }

                skeletonReference = skeleton;
                break;
            }

            Debug.Log($"Hand Runtime {handedness} initilized");
        }
        private void SetupInput()
        {
            cameraRig = GameObject.FindObjectOfType <OVRCameraRig>();
            if (cameraRig == null)
            {
                var mainCamera = CameraCache.Main;

                // Instantiate camera rig as a child of the MixedRealityPlayspace

                var cameraRigObject = GameObject.Instantiate(SettingsProfile.OVRCameraRigPrefab);
                cameraRig = cameraRigObject.GetComponent <OVRCameraRig>();

                // Ensure all related game objects are configured
                cameraRig.EnsureGameObjectIntegrity();

                if (mainCamera != null)
                {
                    // We already had a main camera MRTK probably started using, let's replace the CenterEyeAnchor MainCamera with it
                    GameObject prefabMainCamera = cameraRig.trackingSpace.Find("CenterEyeAnchor").gameObject;
                    prefabMainCamera.SetActive(false);
                    mainCamera.transform.SetParent(cameraRig.trackingSpace.transform);
                    mainCamera.name = prefabMainCamera.name;
                    GameObject.Destroy(prefabMainCamera);
                }
                cameraRig.transform.SetParent(MixedRealityPlayspace.Transform);
            }
            else
            {
                // Ensure all related game objects are configured
                cameraRig.EnsureGameObjectIntegrity();
            }

            bool useAvatarHands = SettingsProfile.RenderAvatarHandsInsteadOfController;

            // If using Avatar hands, de-activate ovr controller rendering
            foreach (var controllerHelper in cameraRig.gameObject.GetComponentsInChildren <OVRControllerHelper>())
            {
                controllerHelper.gameObject.SetActive(!useAvatarHands);
            }

            if (useAvatarHands)
            {
                // Initialize the local avatar controller
                GameObject.Instantiate(SettingsProfile.LocalAvatarPrefab, cameraRig.trackingSpace);
            }

            var ovrHands = cameraRig.GetComponentsInChildren <OVRHand>();

            foreach (var ovrHand in ovrHands)
            {
                // Manage Hand skeleton data
                var skeletonDataProvider = ovrHand as OVRSkeleton.IOVRSkeletonDataProvider;
                var skeletonType         = skeletonDataProvider.GetSkeletonType();

                var ovrSkeleton = ovrHand.GetComponent <OVRSkeleton>();
                if (ovrSkeleton == null)
                {
                    continue;
                }

                switch (skeletonType)
                {
                case OVRSkeleton.SkeletonType.HandLeft:
                    leftHand     = ovrHand;
                    leftSkeleton = ovrSkeleton;
                    break;

                case OVRSkeleton.SkeletonType.HandRight:
                    rightHand     = ovrHand;
                    rightSkeleton = ovrSkeleton;
                    break;
                }
            }
        }
Пример #8
0
    void Find()
    {
        // Camera
        OVRCameraRig cameraRig = GameObject.FindObjectOfType <OVRCameraRig>();

        HPTKCore.core.model.trackedCamera = cameraRig.trackingSpace.Find("CenterEyeAnchor").transform;

        // Reparenting
        if (!rootHPTK)
        {
            rootHPTK = transform;
        }

        if (trackingSpaceIsParent)
        {
            rootHPTK.parent = cameraRig.trackingSpace;
        }

        // Hands
        OVRHand[] ovrHands = cameraRig.GetComponentsInChildren <OVRHand>();

        foreach (var ovrHand in ovrHands)
        {
            OVRSkeleton.IOVRSkeletonDataProvider skeltonDataProvider = ovrHand as OVRSkeleton.IOVRSkeletonDataProvider;
            OVRSkeleton.SkeletonType             skeltonType         = skeltonDataProvider.GetSkeletonType();

            // SMR
            SkinnedMeshRenderer smr = ovrHand.GetComponent <SkinnedMeshRenderer>();

            if (disableDefaultSMR)
            {
                smr.enabled = false;
            }

            if (applyMatToDefaultSMR)
            {
                smr.material = matToApply;
            }

            OVRSkeleton ovrSkelton = ovrHand.GetComponent <OVRSkeleton>();
            if (ovrSkelton == null)
            {
                continue;
            }

            // Fix for static hands in Unity Editor
#if UNITY_EDITOR
            ovrSkelton.ShouldUpdateBonePoses = true;
#endif

            // IDPs
            if (findOVRHandsForIdps)
            {
                switch (skeltonType)
                {
                case OVRSkeleton.SkeletonType.HandLeft:
                    if (!ovrSkeletonTrackerL.handData || !ovrSkeletonTrackerL.boneData)
                    {
                        ovrSkeletonTrackerL.handData = ovrHand;
                        ovrSkeletonTrackerL.boneData = ovrSkelton;
                    }
                    break;

                case OVRSkeleton.SkeletonType.HandRight:
                    if (!ovrSkeletonTrackerR.handData || !ovrSkeletonTrackerR.boneData)
                    {
                        ovrSkeletonTrackerR.handData = ovrHand;
                        ovrSkeletonTrackerR.boneData = ovrSkelton;
                    }
                    break;
                }
            }
        }
    }
Пример #9
0
    void Apply()
    {
        // Camera
        HPTKCore.core.model.trackedCamera = cameraRig.trackingSpace.Find("CenterEyeAnchor").transform;

        // Reparenting
        if (!rootHPTK)
        {
            rootHPTK = transform;
        }

        if (trackingSpaceIsParent)
        {
            rootHPTK.parent = cameraRig.trackingSpace;
        }

        // Hands
        OVRHand[] ovrHands = cameraRig.GetComponentsInChildren <OVRHand>();

        foreach (var ovrHand in ovrHands)
        {
            OVRSkeleton.IOVRSkeletonDataProvider skeltonDataProvider = ovrHand as OVRSkeleton.IOVRSkeletonDataProvider;
            OVRSkeleton.SkeletonType             skeltonType         = skeltonDataProvider.GetSkeletonType();

            // SMR
            SkinnedMeshRenderer smr = ovrHand.GetComponent <SkinnedMeshRenderer>();

            if (disableDefaultSMR)
            {
                smr.enabled = false;
            }

            OVRSkeleton ovrSkelton = ovrHand.GetComponent <OVRSkeleton>();
            if (ovrSkelton == null)
            {
                continue;
            }

            // IDPs
            if (findOVRHandsForIdps)
            {
                switch (skeltonType)
                {
                case OVRSkeleton.SkeletonType.HandLeft:

                    if (!ovrSkeletonTrackerL.handData || !ovrSkeletonTrackerL.boneData)
                    {
                        ovrSkeletonTrackerL.handData = ovrHand;
                        ovrSkeletonTrackerL.boneData = ovrSkelton;
                    }

                    defaultSMR_L = smr;

                    // Copy materials from origin
                    if (copyDefaultSMRMaterial)
                    {
                        Debug.Log("-------------");
                        Debug.Log(smr.name);
                        Debug.Log(avatar.viewModel.leftHand.name);
                        Debug.Log(avatar.viewModel.leftHand.viewModel.slave.skinnedMR.name);
                        Debug.Log("-------------");
                        avatar.viewModel.leftHand.viewModel.slave.skinnedMR.material = defaultSMR_L.material;
                    }

                    break;

                case OVRSkeleton.SkeletonType.HandRight:

                    if (!ovrSkeletonTrackerR.handData || !ovrSkeletonTrackerR.boneData)
                    {
                        ovrSkeletonTrackerR.handData = ovrHand;
                        ovrSkeletonTrackerR.boneData = ovrSkelton;
                    }

                    defaultSMR_R = smr;

                    // Copy materials from origin
                    if (copyDefaultSMRMaterial)
                    {
                        avatar.viewModel.rightHand.viewModel.slave.skinnedMR.material = defaultSMR_R.material;
                    }

                    break;
                }
            }

            // Apply materials to origin
            if (applyMatToDefaultSMR)
            {
                smr.material = matToApply;
            }
        }

        ready = true;
        onReady.Invoke();
    }