public RUISKinect2FloorDataCalibrationProcess(RUISCalibrationProcessSettings calibrationSettings) { this.calibrationPhaseObjects = calibrationSettings.calibrationPhaseObjects; this.calibrationResultPhaseObjects = calibrationSettings.calibrationResultPhaseObjects; this.deviceModelObjects = calibrationSettings.deviceModelObjects; this.depthViewObjects = calibrationSettings.depthViewObjects; this.iconObjects = calibrationSettings.iconObjects; this.floorPlane = GameObject.Find ("Floor"); foreach (Transform child in this.deviceModelObjects.transform) { child.gameObject.SetActive(false); } foreach (Transform child in this.depthViewObjects.transform) { child.gameObject.SetActive(false); } foreach (Transform child in this.iconObjects.transform) { child.gameObject.SetActive(false); } if(this.calibrationPhaseObjects) this.calibrationPhaseObjects.SetActive(true); if(this.calibrationResultPhaseObjects) this.calibrationResultPhaseObjects.SetActive(false); this.xmlFilename = calibrationSettings.xmlFilename; coordinateSystem = MonoBehaviour.FindObjectOfType(typeof(RUISCoordinateSystem)) as RUISCoordinateSystem; kinect2SourceManager = MonoBehaviour.FindObjectOfType(typeof(Kinect2SourceManager)) as Kinect2SourceManager; }
private void updateKinect2FloorData() { Kinect2SourceManager kinect2SourceManager = FindObjectOfType(typeof(Kinect2SourceManager)) as Kinect2SourceManager; bool canAccessKinect2 = false; try { if (coordinateSystem != null && kinect2SourceManager != null && kinect2SourceManager.GetSensor() != null && kinect2SourceManager.GetSensor().IsOpen&& kinect2SourceManager.GetSensor().IsAvailable) { canAccessKinect2 = true; } } catch {} if (canAccessKinect2) { if (coordinateSystem.rootDevice == RUISDevice.Kinect_2) { coordinateSystem.ResetFloorNormal(RUISDevice.Kinect_2); coordinateSystem.ResetDistanceFromFloor(RUISDevice.Kinect_2); } Windows.Kinect.Vector4 kinect2FloorPlane = kinect2SourceManager.GetFlootClipPlane(); //print (kinect2FloorPlane.X + " " + kinect2FloorPlane.Y + " " + kinect2FloorPlane.Z + " " + kinect2FloorPlane.W); Vector3 kinect2FloorNormal = new Vector3(kinect2FloorPlane.X, kinect2FloorPlane.Y, kinect2FloorPlane.Z); kinect2FloorNormal.Normalize(); float kinect2DistanceFromFloor = kinect2FloorPlane.W / Mathf.Sqrt(kinect2FloorNormal.sqrMagnitude); if (float.IsNaN(kinect2DistanceFromFloor)) { kinect2DistanceFromFloor = 0; } if (float.IsNaN(kinect2FloorNormal.x) || kinect2FloorNormal.sqrMagnitude < 0.1f) { kinect2FloorNormal = Vector3.up; } if (coordinateSystem.rootDevice == RUISDevice.Kinect_2) { coordinateSystem.SetFloorNormal(kinect2FloorNormal, RUISDevice.Kinect_2); coordinateSystem.SetDistanceFromFloor(kinect2DistanceFromFloor, RUISDevice.Kinect_2); } Debug.Log("Updated Kinect 2 floor normal " + kinect2FloorNormal + " and floor distance (" + kinect2DistanceFromFloor + ")"); } }
void Start() { trackingIDs = new trackedBody[6]; for(int y = 0; y < trackingIDs.Length; y++) { trackingIDs[y] = new trackedBody(-1, false, 1); } coordinateCalibration = FindObjectOfType(typeof(RUISCoordinateCalibration)) as RUISCoordinateCalibration; _SourceManager = SourceManager.GetComponent<Kinect2SourceManager>(); _Sensor = _SourceManager.GetSensor(); if(_Sensor != null) { imageWidth = _Sensor.DepthFrameSource.FrameDescription.Width; imageHeight = _Sensor.DepthFrameSource.FrameDescription.Height; texture = new Texture2D(imageWidth / _DownsampleSize, imageHeight / _DownsampleSize); } }
void Start() { trackingIDs = new trackedBody[6]; for (int y = 0; y < trackingIDs.Length; y++) { trackingIDs[y] = new trackedBody(-1, false, 1); } coordinateCalibration = FindObjectOfType(typeof(RUISCoordinateCalibration)) as RUISCoordinateCalibration; _SourceManager = SourceManager.GetComponent <Kinect2SourceManager>(); _Sensor = _SourceManager.GetSensor(); if (_Sensor != null) { imageWidth = _Sensor.DepthFrameSource.FrameDescription.Width; imageHeight = _Sensor.DepthFrameSource.FrameDescription.Height; texture = new Texture2D(imageWidth / _DownsampleSize, imageHeight / _DownsampleSize); } }
public RUISKinect2FloorDataCalibrationProcess(RUISCalibrationProcessSettings calibrationSettings) { this.calibrationPhaseObjects = calibrationSettings.calibrationPhaseObjects; this.calibrationResultPhaseObjects = calibrationSettings.calibrationResultPhaseObjects; this.deviceModelObjects = calibrationSettings.deviceModelObjects; this.depthViewObjects = calibrationSettings.depthViewObjects; this.iconObjects = calibrationSettings.iconObjects; this.floorPlane = GameObject.Find("Floor"); foreach (Transform child in this.deviceModelObjects.transform) { child.gameObject.SetActive(false); } foreach (Transform child in this.depthViewObjects.transform) { child.gameObject.SetActive(false); } foreach (Transform child in this.iconObjects.transform) { child.gameObject.SetActive(false); } if (this.calibrationPhaseObjects) { this.calibrationPhaseObjects.SetActive(true); } if (this.calibrationResultPhaseObjects) { this.calibrationResultPhaseObjects.SetActive(false); } this.xmlFilename = calibrationSettings.xmlFilename; coordinateSystem = MonoBehaviour.FindObjectOfType(typeof(RUISCoordinateSystem)) as RUISCoordinateSystem; kinect2SourceManager = MonoBehaviour.FindObjectOfType(typeof(Kinect2SourceManager)) as Kinect2SourceManager; }
void Awake() { string[] names = System.Enum.GetNames(typeof(RUISDevice)); foreach (string device in names) { RUISDevice device1Enum = (RUISDevice)System.Enum.Parse(typeof(RUISDevice), device, true); RUISCalibrationResultsFloorPitchRotation[device1Enum] = Quaternion.identity; RUISCalibrationResultsDistanceFromFloor[device1Enum] = 0.0f; foreach (string device2 in names) { if (device != device2) { string devicePairString = device + "-" + device2; RUISCalibrationResultsInVector3[devicePairString] = new Vector3(0, 0, 0); RUISCalibrationResultsInQuaternion[devicePairString] = Quaternion.identity; RUISCalibrationResultsIn4x4Matrix[devicePairString] = Matrix4x4.identity; } } } if (loadFromXML) { if (!LoadMultiXML(coordinateXmlFile)) { createExampleXML(coordinateXmlFile); } } inputManager = FindObjectOfType <RUISInputManager>(); if (switchToAvailableDevice && inputManager) { bool needToSwitch = false; RUISDevice previousDevice = rootDevice; switch (rootDevice) { case RUISDevice.Kinect_1: if (!inputManager.enableKinect) { needToSwitch = true; } break; case RUISDevice.Kinect_2: if (!inputManager.enableKinect2) { needToSwitch = true; } break; case RUISDevice.PS_Move: if (!inputManager.enablePSMove) { needToSwitch = true; } break; case RUISDevice.OpenVR: // If OpenVR can't accessed AND a HMD can't be detected if (!RUISDisplayManager.IsOpenVrAccessible() && !RUISDisplayManager.IsHmdPresent()) { needToSwitch = true; } break; } if (needToSwitch) { // Try to determine if Kinect2 can be used (because this method is run before RUISInputManager can disable enableKinect2) bool kinect2FoundBySystem = false; if (inputManager.enableKinect2) { try { Kinect2SourceManager kinect2SourceManager = FindObjectOfType(typeof(Kinect2SourceManager)) as Kinect2SourceManager; if (kinect2SourceManager != null && kinect2SourceManager.GetSensor() != null && kinect2SourceManager.GetSensor().IsOpen) { // IsOpen seems to return false mostly if Kinect 2 drivers are not installed? // Debug.Log("Kinect 2 was detected by the system."); kinect2FoundBySystem = true; } } catch {} } if (RUISDisplayManager.IsHmdPositionTrackable()) { rootDevice = RUISDevice.OpenVR; } else if (inputManager.enableKinect2 && kinect2FoundBySystem) { rootDevice = RUISDevice.Kinect_2; } else if (inputManager.enableKinect) { rootDevice = RUISDevice.Kinect_1; } else if (inputManager.enablePSMove) { rootDevice = RUISDevice.PS_Move; } if (rootDevice != previousDevice) { if (previousDevice == RUISDevice.OpenVR) { Debug.LogWarning("Switched 'Master Coordinate System Sensor' from " + previousDevice + " to " + rootDevice + " " + "because OpenVR could not be accessed! Is SteamVR installed?"); } else { Debug.LogWarning("Switched 'Master Coordinate System Sensor' from " + previousDevice + " to " + rootDevice + " " + "because the former was not enabled in " + typeof(RUISInputManager) + " while the latter was!"); } } } } }
void Start() { Quaternion dictionaryFloorNormal = coordinateSystem.RUISCalibrationResultsFloorPitchRotation[coordinateSystem.rootDevice]; float dictionaryDistanceFromFloor = coordinateSystem.RUISCalibrationResultsDistanceFromFloor[coordinateSystem.rootDevice]; Vector3 normalVector = dictionaryFloorNormal * Vector3.up; coordinateSystem.SetFloorNormal(normalVector, coordinateSystem.rootDevice); coordinateSystem.SetDistanceFromFloor(dictionaryDistanceFromFloor, coordinateSystem.rootDevice); //check whether the kinect camera is actually connected if (enableKinect) { OpenNISettingsManager settingsManager = FindObjectOfType(typeof(OpenNISettingsManager)) as OpenNISettingsManager; if (settingsManager.UserGenrator == null || !settingsManager.UserGenrator.Valid) { Debug.LogError("Could not start OpenNI! Check your Kinect connection."); GetComponentInChildren <RUISKinectDisabler>().KinectNotAvailable(); } } if (!enableKinect2) { Debug.Log("Kinect 2 is disabled from RUISInputManager."); BodySourceManager kinect2Manager = GetComponentInChildren <BodySourceManager>(); if (kinect2Manager) { kinect2Manager.gameObject.SetActive(false); } } else { bool kinect2FoundBySystem = false; try { Kinect2SourceManager kinect2SourceManager = FindObjectOfType(typeof(Kinect2SourceManager)) as Kinect2SourceManager; if (kinect2SourceManager != null && kinect2SourceManager.GetSensor() != null && kinect2SourceManager.GetSensor().IsOpen) { // IsOpen seems to return false mostly if Kinect 2 drivers are not installed? // Debug.Log("Kinect 2 was detected by the system."); kinect2FoundBySystem = true; } else { Debug.LogError("Kinect 2 was NOT detected by the system. Disabling Kinect 2 in RUISInputManager."); } } catch (System.Exception e) { Debug.LogError("Kinect 2 was NOT detected by the system. Disabling Kinect 2 in RUISInputManager.\n" + e.Message); } if (!kinect2FoundBySystem) { enableKinect2 = false; } } if ((enableKinect && kinectFloorDetection) || (enableKinect2 && kinect2FloorDetection)) { StartFloorDetection(); } //if (enablePSMove) // { // RUISPSMoveWand[] controllers = GetComponentsInChildren<RUISPSMoveWand>(); // moveControllers = new RUISPSMoveWand[controllers.Length]; // foreach (RUISPSMoveWand controller in controllers) // { // moveControllers[controller.controllerId] = controller; // } // } }
public RUISKinect2ToKinectCalibrationProcess(RUISCalibrationProcessSettings calibrationSettings) { this.inputDevice1 = RUISDevice.Kinect_2; this.inputDevice2 = RUISDevice.Kinect_1; this.numberOfSamplesToTake = calibrationSettings.numberOfSamplesToTake; this.numberOfSamplesPerSecond = calibrationSettings.numberOfSamplesPerSecond; trackingIDs = new trackedBody[6]; for(int y = 0; y < trackingIDs.Length; y++) { trackingIDs[y] = new trackedBody(-1, false, 1); } kinectSelection = MonoBehaviour.FindObjectOfType(typeof(NIPlayerManagerCOMSelection)) as NIPlayerManagerCOMSelection; settingsManager = MonoBehaviour.FindObjectOfType(typeof(OpenNISettingsManager)) as OpenNISettingsManager; inputManager = MonoBehaviour.FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager; coordinateSystem = MonoBehaviour.FindObjectOfType(typeof(RUISCoordinateSystem)) as RUISCoordinateSystem; kinect2SourceManager = MonoBehaviour.FindObjectOfType(typeof(Kinect2SourceManager)) as Kinect2SourceManager; this.timeSinceScriptStart = 0; this.timeBetweenSamples = 1 / (float)numberOfSamplesPerSecond; // Limit sample rate if(this.timeBetweenSamples < 0.1f) { this.timeBetweenSamples = 0.1f; } calibrationSpheres = new List<GameObject>(); samples_Kinect1 = new List<Vector3>(); samples_Kinect2 = new List<Vector3>(); this.calibrationCube = calibrationSettings.calibrationCubePrefab; this.calibrationSphere = calibrationSettings.calibrationSpherePrefab; this.calibrationPhaseObjects = calibrationSettings.calibrationPhaseObjects; this.calibrationResultPhaseObjects = calibrationSettings.calibrationResultPhaseObjects; this.deviceModelObjects = calibrationSettings.deviceModelObjects; this.depthViewObjects = calibrationSettings.depthViewObjects; this.iconObjects = calibrationSettings.iconObjects; if(GameObject.Find ("PSMoveWand") != null) GameObject.Find ("PSMoveWand").SetActive(false); // Models this.kinect1ModelObject = GameObject.Find ("KinectCamera"); this.kinect2ModelObject = GameObject.Find ("Kinect2Camera"); RUISSkeletonController skeletonController = Component.FindObjectOfType<RUISSkeletonController>(); Transform rightHand = null; if(skeletonController) rightHand = skeletonController.rightHand; FixedFollowTransform followTransform = Component.FindObjectOfType<FixedFollowTransform>(); if(followTransform && rightHand) followTransform.transformToFollow = rightHand; // Depth view this.depthView = GameObject.Find ("KinectDepthView"); this.depthView2 = GameObject.Find ("Kinect2DepthView"); // Icons this.Kinect1Icon = GameObject.Find ("Kinect Icon"); this.Kinect2Icon = GameObject.Find ("Kinect2 Icon"); this.floorPlane = GameObject.Find ("Floor"); if(this.Kinect1Icon && this.Kinect1Icon.GetComponent<GUITexture>()) this.Kinect1Icon.GetComponent<GUITexture>().pixelInset = new Rect(5.1f, 10.0f, 70.0f, 70.0f); foreach (Transform child in this.deviceModelObjects.transform) { child.gameObject.SetActive(false); } foreach (Transform child in this.depthViewObjects.transform) { child.gameObject.SetActive(false); } foreach (Transform child in this.iconObjects.transform) { child.gameObject.SetActive(false); } if(this.kinect1ModelObject) this.kinect1ModelObject.SetActive(true); if(this.kinect2ModelObject) this.kinect2ModelObject.SetActive(true); if(this.Kinect1Icon) this.Kinect1Icon.SetActive(true); if(this.Kinect2Icon) this.Kinect2Icon.SetActive(true); if(this.calibrationPhaseObjects) this.calibrationPhaseObjects.SetActive(true); if(this.calibrationResultPhaseObjects) this.calibrationResultPhaseObjects.SetActive(false); if(this.depthView) this.depthView.SetActive(true); if(this.depthView2) this.depthView2.SetActive(true); this.xmlFilename = calibrationSettings.xmlFilename; }
public RUISKinect2ToOculusDK2CalibrationProcess(RUISCalibrationProcessSettings calibrationSettings) { this.inputDevice1 = RUISDevice.Oculus_DK2; this.inputDevice2 = RUISDevice.Kinect_2; this.numberOfSamplesToTake = calibrationSettings.numberOfSamplesToTake; this.numberOfSamplesPerSecond = calibrationSettings.numberOfSamplesPerSecond; trackingIDs = new trackedBody[6]; for (int y = 0; y < trackingIDs.Length; y++) { trackingIDs[y] = new trackedBody(-1, false, 1); } inputManager = MonoBehaviour.FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager; coordinateSystem = MonoBehaviour.FindObjectOfType(typeof(RUISCoordinateSystem)) as RUISCoordinateSystem; kinect2SourceManager = MonoBehaviour.FindObjectOfType(typeof(Kinect2SourceManager)) as Kinect2SourceManager; this.timeSinceScriptStart = 0; this.timeBetweenSamples = 1 / (float)numberOfSamplesPerSecond; // Limit sample rate if (this.timeBetweenSamples < 0.1f) { this.timeBetweenSamples = 0.1f; } calibrationSpheres = new List <GameObject>(); samples_Kinect2 = new List <Vector3>(); samples_OculusDK2 = new List <Vector3>(); this.calibrationCube = calibrationSettings.calibrationCubePrefab; this.calibrationSphere = calibrationSettings.calibrationSpherePrefab; this.calibrationPhaseObjects = calibrationSettings.calibrationPhaseObjects; this.calibrationResultPhaseObjects = calibrationSettings.calibrationResultPhaseObjects; this.deviceModelObjects = calibrationSettings.deviceModelObjects; this.depthViewObjects = calibrationSettings.depthViewObjects; this.iconObjects = calibrationSettings.iconObjects; if (GameObject.Find("PSMoveWand") != null) { GameObject.Find("PSMoveWand").SetActive(false); } // Models this.oculusDK2CameraObject = GameObject.Find("OculusDK2Camera"); this.kinect2ModelObject = GameObject.Find("Kinect2Camera"); this.oculusRiftModel = GameObject.Find("OculusRift"); FixedFollowTransform followTransform = Component.FindObjectOfType <FixedFollowTransform>(); if (followTransform && this.oculusRiftModel) { followTransform.transformToFollow = this.oculusRiftModel.transform; } // Depth view this.depthView = GameObject.Find("Kinect2DepthView"); // Icons this.oculusDK2Icon = GameObject.Find("OculusDK2 Icon"); this.kinect2Icon = GameObject.Find("Kinect2 Icon"); this.floorPlane = GameObject.Find("Floor"); if (this.oculusDK2Icon && this.oculusDK2Icon.GetComponent <GUITexture>()) { this.oculusDK2Icon.GetComponent <GUITexture>().pixelInset = new Rect(5.1f, 10.0f, 70.0f, 70.0f); } foreach (Transform child in this.deviceModelObjects.transform) { child.gameObject.SetActive(false); } foreach (Transform child in this.depthViewObjects.transform) { child.gameObject.SetActive(false); } foreach (Transform child in this.iconObjects.transform) { child.gameObject.SetActive(false); } if (this.oculusDK2CameraObject) { this.oculusDK2CameraObject.SetActive(true); } if (this.kinect2ModelObject) { this.kinect2ModelObject.SetActive(true); } if (this.oculusRiftModel) { this.oculusRiftModel.SetActive(true); } if (this.oculusDK2Icon) { this.oculusDK2Icon.SetActive(true); } if (this.kinect2Icon) { this.kinect2Icon.SetActive(true); } if (this.calibrationPhaseObjects) { this.calibrationPhaseObjects.SetActive(true); } if (this.calibrationResultPhaseObjects) { this.calibrationResultPhaseObjects.SetActive(false); } if (this.depthView) { this.depthView.SetActive(true); } this.xmlFilename = calibrationSettings.xmlFilename; }
public RUISKinect2ToPSMoveCalibrationProcess(RUISCalibrationProcessSettings calibrationSettings) { this.inputDevice1 = RUISDevice.Kinect_2; this.inputDevice2 = RUISDevice.PS_Move; this.numberOfSamplesToTake = calibrationSettings.numberOfSamplesToTake; this.numberOfSamplesPerSecond = calibrationSettings.numberOfSamplesPerSecond; trackingIDs = new trackedBody[6]; for(int y = 0; y < trackingIDs.Length; y++) { trackingIDs[y] = new trackedBody(-1, false, 1); } psMoveWrapper = MonoBehaviour.FindObjectOfType(typeof(PSMoveWrapper)) as PSMoveWrapper; inputManager = MonoBehaviour.FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager; coordinateSystem = MonoBehaviour.FindObjectOfType(typeof(RUISCoordinateSystem)) as RUISCoordinateSystem; kinect2SourceManager = MonoBehaviour.FindObjectOfType(typeof(Kinect2SourceManager)) as Kinect2SourceManager; this.timeSinceScriptStart = 0; this.timeBetweenSamples = 1 / (float)numberOfSamplesPerSecond; // Limit sample rate if(this.timeBetweenSamples < 0.1f) { this.timeBetweenSamples = 0.1f; } calibrationSpheres = new List<GameObject>(); samples_PSMove = new List<Vector3>(); samples_Kinect2 = new List<Vector3>(); this.calibrationCube = calibrationSettings.calibrationCubePrefab; this.calibrationSphere = calibrationSettings.calibrationSpherePrefab; this.calibrationPhaseObjects = calibrationSettings.calibrationPhaseObjects; this.calibrationResultPhaseObjects = calibrationSettings.calibrationResultPhaseObjects; this.deviceModelObjects = calibrationSettings.deviceModelObjects; this.depthViewObjects = calibrationSettings.depthViewObjects; this.iconObjects = calibrationSettings.iconObjects; this.PSMoveWandObject = GameObject.Find ("PSMoveWand"); // Models this.psEyeModelObject = GameObject.Find ("PS Eye"); this.kinect2ModelObject = GameObject.Find ("Kinect2Camera"); // Depth view this.depthView = GameObject.Find ("Kinect2DepthView"); // Icons this.psMoveIcon = GameObject.Find ("PS Move Icon"); this.KinectIcon = GameObject.Find ("Kinect2 Icon"); this.floorPlane = GameObject.Find ("Floor"); foreach (Transform child in this.deviceModelObjects.transform) { child.gameObject.SetActive(false); } foreach (Transform child in this.depthViewObjects.transform) { child.gameObject.SetActive(false); } foreach (Transform child in this.iconObjects.transform) { child.gameObject.SetActive(false); } if(this.psEyeModelObject) this.psEyeModelObject.SetActive(true); if(this.PSMoveWandObject) this.PSMoveWandObject.SetActive(true); if(this.kinect2ModelObject) this.kinect2ModelObject.SetActive(true); if(this.psMoveIcon) this.psMoveIcon.SetActive(true); if(this.KinectIcon) this.KinectIcon.SetActive(true); if(this.calibrationPhaseObjects) this.calibrationPhaseObjects.SetActive(true); if(this.calibrationResultPhaseObjects) this.calibrationResultPhaseObjects.SetActive(false); if(this.depthView) this.depthView.SetActive(true); this.xmlFilename = calibrationSettings.xmlFilename; }
public void Awake() { _SourceManager = SourceManager.GetComponent <Kinect2SourceManager>(); }
// Ovr.HmdType ovrHmdVersion; //06to08 void Awake() { if (!scriptEnabled) { return; } inputManager = FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager; bool kinect2 = false; bool kinect = false; bool psmove = false; bool razer = false; // bool isRiftConnected = false; // { // try // { // // Find out if an Oculus HMD is connected // if(OVRManager.display != null) // isRiftConnected = OVRManager.display.isPresent; //06to08 // // // Find out the Oculus HMD version // if(OVRManager.capiHmd != null) // ovrHmdVersion = OVRManager.capiHmd.GetDesc().Type; //06to08 // } // catch(UnityException e) // { // Debug.LogError(e); // } // } // if (inputManager) { kinect2 = inputManager.enableKinect2; kinect = inputManager.enableKinect; psmove = inputManager.enablePSMove; razer = inputManager.enableRazerHydra; int trackerCount = 0; RUISTracker closestMatch = null; int currentMatchScore = 0; bool kinect2FoundBySystem = false; if (kinect2) { try { Kinect2SourceManager kinect2SourceManager = FindObjectOfType(typeof(Kinect2SourceManager)) as Kinect2SourceManager; if (kinect2SourceManager != null && kinect2SourceManager.GetSensor() != null && kinect2SourceManager.GetSensor().IsOpen) { // IsOpen seems to return false mostly if Kinect 2 drivers are not installed? kinect2FoundBySystem = true; } } catch { } if (!kinect2FoundBySystem) { kinect2 = false; } } RUISHeadTrackerAssigner[] assigners = FindObjectsOfType(typeof(RUISHeadTrackerAssigner)) as RUISHeadTrackerAssigner[]; if (!allowMultipleAssigners && assigners.Length > 1) { Debug.LogError("Multiple active RUISHeadTrackerAssigner scripts found while 'Allow Multiple Assigners' is false: " + "Disabling all headtrackers and their child objects that are listed in the RUISHeadTrackerAssigner " + "component of '" + gameObject.name + "' object."); for (int i = 0; i < headTrackers.Capacity; ++i) { if (headTrackers[i] && headTrackers[i].gameObject.activeInHierarchy) { headTrackers[i].gameObject.SetActive(false); } } return; } foreach (RUISTracker trackerScript in headTrackers) { if (trackerScript && trackerScript.gameObject.activeInHierarchy) { ++trackerCount; int foundTrackerScore = 0; // bool openVRHmdFound = false; // try // { // if(RUISDisplayManager.IsOpenVrAccessible() && Valve.VR.OpenVR.IsHmdPresent()) // *** TODO HACK Valve API // openVRHmdFound = true; // } catch{} // Give score to found head trackers if (RUISDisplayManager.IsHmdPresent() && UnityEngine.XR.XRSettings.enabled && trackerScript.headPositionInput == RUISTracker.HeadPositionSource.OpenVR) { foundTrackerScore = 7; } else if (psmove && trackerScript.headPositionInput == RUISTracker.HeadPositionSource.PSMove) { foundTrackerScore = 6; } else if (razer && trackerScript.isRazerBaseMobile && // Legacy: Mobile Hydra Base (custom tracker) trackerScript.headPositionInput == RUISTracker.HeadPositionSource.RazerHydra && trackerScript.mobileRazerBase == RUISTracker.RazerHydraBase.InputTransform) { foundTrackerScore = 5; } else if (kinect2 && trackerScript.headPositionInput == RUISTracker.HeadPositionSource.Kinect2) { foundTrackerScore = 4; } else if (kinect && razer && trackerScript.isRazerBaseMobile && // Legacy: Mobile Hydra Base (Kinect) trackerScript.headPositionInput == RUISTracker.HeadPositionSource.RazerHydra && trackerScript.mobileRazerBase == RUISTracker.RazerHydraBase.Kinect1) { foundTrackerScore = 3; } else if (kinect && trackerScript.headPositionInput == RUISTracker.HeadPositionSource.Kinect1) { foundTrackerScore = 2; } else if (razer && trackerScript.headPositionInput == RUISTracker.HeadPositionSource.RazerHydra && // Plain ol' Razer Hydra !trackerScript.isRazerBaseMobile) { foundTrackerScore = 1; } // Assign new best head tracker candidate if it is better than the previously found if (currentMatchScore < foundTrackerScore) { closestMatch = trackerScript; currentMatchScore = foundTrackerScore; } } } if (trackerCount == 0 && Application.isEditor) { Debug.LogError("No active GameObjects with RUISTracker script found from headTrackers list!"); } string positionTracker = "<None>"; string logString = ""; string names = ""; RUISCamera ruisCamera = null; if (closestMatch == null) { // Disable all but the first active head tracker from the headTrackers list logString = "Could not find a suitable head tracker with regard to " + "enabled devices in RUISInputManager!"; bool disabling = false; int leftEnabledIndex = -1; for (int i = 0; i < headTrackers.Capacity; ++i) { if (headTrackers[i] && headTrackers[i].gameObject.activeInHierarchy) { if (disabling) { if (names.Length > 0) { names = names + ", "; } names = names + headTrackers[i].gameObject.name; headTrackers[i].gameObject.SetActive(false); } else { leftEnabledIndex = i; closestMatch = headTrackers[leftEnabledIndex]; positionTracker = headTrackers[leftEnabledIndex].gameObject.name; disabling = true; } } } if (leftEnabledIndex >= 0) { logString = logString + " Choosing the first head tracker in the list. Using " + positionTracker + " for tracking head position"; if (names.Length > 0) { logString = logString + ", and disabling the following: " + names; } logString = logString + ". This choice was made using a pre-selected list of " + "head trackers."; ruisCamera = headTrackers[leftEnabledIndex].gameObject.GetComponentInChildren <RUISCamera>(); } Debug.LogError(logString); } else { // Disable all but the closest match head tracker from the headTrackers list for (int i = 0; i < headTrackers.Capacity; ++i) { if (headTrackers[i] && headTrackers[i].gameObject.activeInHierarchy) { if (headTrackers[i] != closestMatch) { if (names.Length > 0) { names = names + ", "; } names = names + headTrackers[i].gameObject.name; headTrackers[i].gameObject.SetActive(false); } else { positionTracker = headTrackers[i].gameObject.name; } } } logString = "Found the best head tracker with regard to enabled devices in " + "RUISInputManager! Using " + positionTracker + " for tracking head position"; if (names.Length > 0) { logString = logString + ", and disabling the following: " + names; } Debug.Log(logString + ". This choice was made using a pre-selected list of head trackers."); ruisCamera = closestMatch.gameObject.GetComponentInChildren <RUISCamera>(); if (changePivotIfNoKinect && psmove && !kinect && !kinect2 && closestMatch.headPositionInput == RUISTracker.HeadPositionSource.PSMove) { RUISCharacterController characterController = gameObject.GetComponentInChildren <RUISCharacterController>(); if (characterController != null && characterController.characterPivotType != RUISCharacterController.CharacterPivotType.MoveController) { characterController.characterPivotType = RUISCharacterController.CharacterPivotType.MoveController; characterController.moveControllerId = closestMatch.positionPSMoveID; Debug.Log("PS Move enabled and Kinect disabled. Setting " + characterController.name + "'s Character Pivot as PS Move controller #" + closestMatch.positionPSMoveID + ". PS Move position offset for this pivot is " + characterController.psmoveOffset); } } } if (ruisCamera) { if (display == null) { Debug.LogWarning("No RUISDisplay attached to the RUISHeadTrackerAssigner script!"); RUISDisplay[] displays = FindObjectsOfType(typeof(RUISDisplay)) as RUISDisplay[]; for (int i = 0; i < displays.Length; ++i) { if (displays[i].linkedCamera == null) { Debug.LogWarning("Assigned RUISCamera component from the child of " + positionTracker + " to render on " + displays[i].gameObject.name + " because that " + "RUISDisplay component's RUISCamera field was empty."); displays[i].linkedCamera = ruisCamera; break; } } } else { if (display.linkedCamera == null) { Debug.Log("Assigned RUISCamera component from the child of " + positionTracker + " to render on " + display.gameObject.name); display.linkedCamera = ruisCamera; } else { Debug.LogWarning("RUISDisplay " + display.gameObject.name + " is already connected with a " + "RUISCamera object! Leave the RUISCamera field empty in your RUISDisplay " + "component if you want RUISHeadTrackerAssigner script to automatically " + "assign a RUISCamera to your RUISDisplay."); } } } else { if (closestMatch) { Debug.LogError(positionTracker + " did not have a child with RUISCamera component, " + "and therefore it is not used to draw on any of the displays in " + "DisplayManager."); } } // If we are using Razer with a static base for head tracking, then apply onlyRazerOffset // on the parent objects of the Razer head tracker and the hand-held Razer if (closestMatch != null && razer && closestMatch.headPositionInput == RUISTracker.HeadPositionSource.RazerHydra && !closestMatch.isRazerBaseMobile) { // The parent object of the Razer head tracker must not have RUISCharacterConroller, // because that script will modify the object's position if (closestMatch.transform.parent != null && closestMatch.transform.parent.GetComponent <RUISCharacterController>() == null && (onlyRazerOffset.x != 0 || onlyRazerOffset.y != 0 || onlyRazerOffset.z != 0)) { string razerWandOffsetInfo = ""; closestMatch.transform.parent.localPosition += onlyRazerOffset; if (razerWandParent != null) { razerWandParent.localPosition += onlyRazerOffset; razerWandOffsetInfo = " and " + razerWandParent.gameObject.name + " (parent of hand-held Razer " + "Hydra)"; } Debug.Log("Applying offset of " + onlyRazerOffset + " to " + closestMatch.transform.parent.gameObject.name + " (parent of Razer Hydra head tracker)" + razerWandOffsetInfo + "."); } } // If no Razer, Kinect, or PS Move is available, then apply onlyMouseOffset // on the parent object of the head tracker that is left enabled // if( closestMatch != null && !razer && !kinect && !psmove) // { // // The parent object of the Razer head tracker must not have RUISCharacterConroller, // // because that script will modify the object's position // if( closestMatch.transform.parent != null // && closestMatch.transform.parent.GetComponent<RUISCharacterController>() == null // && (onlyMouseOffset.x != 0 || onlyMouseOffset.y != 0 || onlyMouseOffset.z != 0) ) // { // closestMatch.transform.parent.localPosition += onlyMouseOffset; // Debug.Log( "Applying offset of " + onlyMouseOffset + " to " // + closestMatch.transform.parent.gameObject.name + " (parent of assigned head tracker)."); // } // } // *** HACK TODO: Below is slightly hacky and only for HMDs with drift (i.e. Rift DK1) // Read inputConfig.xml to see if Kinect yaw drift correction for Oculus Rift should be enabled if (closestMatch != null && closestMatch.useHmdRotation && applyKinectDriftCorrectionPreference) { if (inputManager.kinectDriftCorrectionPreferred) { // Preference is to use Kinect for drift correction (if PS Move is not used for head tracking) switch (closestMatch.headPositionInput) { case RUISTracker.HeadPositionSource.Kinect1: if (!psmove && kinect) { closestMatch.externalDriftCorrection = true; closestMatch.compass = RUISTracker.CompassSource.Kinect1; } break; case RUISTracker.HeadPositionSource.RazerHydra: if (!psmove && kinect && razer) { if (closestMatch.isRazerBaseMobile) { closestMatch.externalDriftCorrection = true; closestMatch.compass = RUISTracker.CompassSource.Kinect1; } } break; } } else { // Preference is NOT to use Kinect for drift correction if (closestMatch.headPositionInput == RUISTracker.HeadPositionSource.Kinect1 && !psmove && kinect) { closestMatch.externalDriftCorrection = false; } } } } }
public void Awake() { _SourceManager = SourceManager.GetComponent<Kinect2SourceManager>(); }