void Awake() { if (_instance == null) { //If I am the first instance, keep track of me _instance = this; //DontDestroyOnLoad(this); Debug.Log("Initialed"); } else { //If a Singleton already exists and you find another reference in scene, destroy it. if (this != _instance) { Debug.Log("ERROR!!!! You have more than one instance of the Motion Capture Streaming Receiver in your scene. There can be only one. Anything that happens from this point on may be weird."); //Destroy(this.gameObject); } } if (mocapServer == MocapServer.Cube_QualisysTrackManager) { QTMInterface = transform.Find("Qualisys_DoNotEdit").GetComponent <QTMInterface> (); QTMInterface.gameObject.SetActive(true); QTMInterface.Initialize(QTMserverIP, QTMserverPort, QTMlocalPort); } else if (mocapServer == MocapServer.Perform_OptitrackMotiveBody) { OMBInterface = transform.Find("Optitrack_DoNotEdit").GetComponent <OptitrackStreamingClient> (); OMBInterface.gameObject.SetActive(true); OMBInterface.Initialize(OMBlocalAddress, OMBserverAddress, OMBdataPort, OMBcommandPort); } }
//public GameObject[] generate_rbState_Objects_1; //public GameObject[] generate_ControllerGameobject_Objects_1; // Use this for initialization void Start() { // If the user didn't explicitly associate a client, find a suitable default. if (this.StreamingClient == null) { this.StreamingClient = OptitrackStreamingClient.FindDefaultClient(); // If we still couldn't find one, disable this component. if (this.StreamingClient == null) { Debug.LogError(GetType().FullName + ": Streaming client not set, and no " + typeof(OptitrackStreamingClient).FullName + " components found in scene; disabling this component.", this); this.enabled = false; return; } } calibrationData = new CalibrationProcessData(); if (calibrateMethod == CalibrationLoadMethod.LOADFILE) { calibrationData.loadMatrixFromFile(); dataInitiate = true; } else if (calibrateMethod == CalibrationLoadMethod.CALIBRATION) { print("Press C for calibration"); } }
public static void GetPositionRotation(OptitrackStreamingClient streamingClient, int trackerId, out Vector position, out Rotation rotation) { OptitrackRigidBodyState rbState = streamingClient.GetLatestRigidBodyState(trackerId); position = Passer.Target.ToVector(rbState.Pose.Position); rotation = Passer.Target.ToRotation(rbState.Pose.Orientation); }
private static void RemoveScript(HumanoidControl humanoid) { OptitrackStreamingClient client = FindObjectOfType <OptitrackStreamingClient>(); if (client != null && client.gameObject.name == "Humanoid OptitrackStreamingClient") { DestroyImmediate(client.gameObject, true); } }
void Start() { // If the user didn't explicitly associate a client, find a suitable default. if (this.StreamingClient == null) { this.StreamingClient = OptitrackStreamingClient.FindDefaultClient(); // If we still couldn't find one, disable this component. if (this.StreamingClient == null) { Debug.LogError(GetType().FullName + ": Streaming client not set, and no " + typeof(OptitrackStreamingClient).FullName + " components found in scene; disabling this component.", this); this.enabled = false; return; } } this.StreamingClient.RegisterSkeleton(this, this.SkeletonAssetName); // Create a lookup from Mecanim anatomy bone names to OptiTrack streaming bone names. CacheBoneNameMap(this.StreamingClient.BoneNamingConvention, this.SkeletonAssetName); // Retrieve the OptiTrack skeleton definition. m_skeletonDef = this.StreamingClient.GetSkeletonDefinitionByName(this.SkeletonAssetName); if (m_skeletonDef == null) { Debug.LogError(GetType().FullName + ": Could not find skeleton definition with the name \"" + this.SkeletonAssetName + "\"", this); this.enabled = false; return; } // Create a hierarchy of GameObjects that will receive the skeletal pose data. string rootObjectName = "OptiTrack Skeleton - " + this.SkeletonAssetName; m_rootObject = new GameObject(rootObjectName); m_boneObjectMap = new Dictionary <Int32, GameObject>(m_skeletonDef.Bones.Count); for (int boneDefIdx = 0; boneDefIdx < m_skeletonDef.Bones.Count; ++boneDefIdx) { OptitrackSkeletonDefinition.BoneDefinition boneDef = m_skeletonDef.Bones[boneDefIdx]; GameObject boneObject = new GameObject(boneDef.Name); boneObject.transform.parent = boneDef.ParentId == 0 ? m_rootObject.transform : m_boneObjectMap[boneDef.ParentId].transform; boneObject.transform.localPosition = boneDef.Offset; m_boneObjectMap[boneDef.Id] = boneObject; } // Hook up retargeting between those GameObjects and the destination Avatar. MecanimSetup(rootObjectName); // Can't re-parent this until after Mecanim setup, or else Mecanim gets confused. m_rootObject.transform.parent = this.StreamingClient.transform; m_rootObject.transform.localPosition = Vector3.zero; m_rootObject.transform.localRotation = Quaternion.identity; }
void Start() { // If the user didn't explicitly associate a client, find a suitable default. if (this.StreamingClient == null) { this.StreamingClient = OptitrackStreamingClient.FindDefaultClient(); // If we still couldn't find one, disable this component. if (this.StreamingClient == null) { Debug.LogError(GetType().FullName + ": Streaming client not set, and no " + typeof(OptitrackStreamingClient).FullName + " components found in scene; disabling this component.", this); this.enabled = false; return; } } if (UnityEngine.XR.XRDevice.isPresent) { string vrDeviceFamily = UnityEngine.XR.XRDevice.family; string vrDeviceModel = UnityEngine.XR.XRDevice.model; bool isOculusDevice = String.Equals(vrDeviceFamily, "oculus", StringComparison.CurrentCultureIgnoreCase); if (isOculusDevice) { if (TryDisableOvrPositionTracking() == false) { Debug.LogError(GetType().FullName + ": Detected Oculus HMD (\"" + vrDeviceModel + "\", but could not disable OVR position tracking.", this); } else { Debug.Log(GetType().FullName + ": Successfully disabled position tracking for HMD \"" + vrDeviceModel + "\".", this); } } else { Debug.LogWarning(GetType().FullName + ": Unrecognized HMD type (\"" + vrDeviceFamily + "\", \"" + vrDeviceModel + "\").", this); } } else { Debug.LogWarning(GetType().FullName + ": No VRDevice present.", this); } // Cache a reference to the gameobject containing the HMD Camera. Camera hmdCamera = this.GetComponentInChildren <Camera>(); if (hmdCamera == null) { Debug.LogError(GetType().FullName + ": Couldn't locate HMD-driven Camera component in children.", this); } else { m_hmdCameraObject = hmdCamera.gameObject; } }
public override void Start(HumanoidControl _humanoid, Transform _targetTransform) { base.Start(_humanoid, _targetTransform); humanoid = _humanoid; tracker = humanoid.optitrack; streamingClient = tracker.streamingClient; targetTransform = _targetTransform; }
private static OptitrackStreamingClient CheckScript() { OptitrackStreamingClient client = FindObjectOfType <OptitrackStreamingClient>(); if (client == null) { GameObject rootGameObject = new GameObject("Humanoid OptitrackStreamingClient"); client = rootGameObject.AddComponent <OptitrackStreamingClient>(); } return(client); }
void SetOptitrackClient() { OptitrackStreamingClient optitrackClient = GameObject.FindObjectOfType <OptitrackStreamingClient> (); OptitrackHmd optitrackHmd = GetComponent <OptitrackHmd> (); optitrackHmd.StreamingClient = optitrackClient; // optitrackHmd.enabled = false; OptitrackRigidBody[] rigidbodies = GetComponentsInChildren <OptitrackRigidBody> (); foreach (OptitrackRigidBody rb in rigidbodies) { rb.StreamingClient = optitrackClient; } }
private void Start() { m_NetworkManager = FindObjectOfType <NetworkManager>(); m_OptitrackStreamingClient = FindObjectOfType <OptitrackStreamingClient>(); m_Text = GetComponent <UnityEngine.UI.Text> (); if (m_Text) { m_Text.supportRichText = true; m_Text.enabled = false; } StartCoroutine(UpdatePerfData()); StartCoroutine(LogData()); }
void Start() { // If the user didn't explicitly associate a client, find a suitable default. if (this.StreamingClient == null) { this.StreamingClient = OptitrackStreamingClient.FindDefaultClient(); // If we still couldn't find one, disable this component. if (this.StreamingClient == null) { Debug.LogError(GetType().FullName + ": Streaming client not set, and no " + typeof(OptitrackStreamingClient).FullName + " components found in scene; disabling this component.", this); this.enabled = false; return; } } }
void Start() { if (useOptitrack) { // If the user didn't explicitly associate a client, find a suitable default. if (this.StreamingClient == null) { this.StreamingClient = OptitrackStreamingClient.FindDefaultClient(); // If we still couldn't find one, disable this component. if (this.StreamingClient == null) { Debug.LogError(GetType().FullName + ": Streaming client not set, and no " + typeof(OptitrackStreamingClient).FullName + " components found in scene; disabling this component.", this); this.enabled = false; return; } } } if (UnityEngine.VR.VRDevice.isPresent) { string vrDeviceFamily = UnityEngine.VR.VRSettings.loadedDeviceName; string vrDeviceModel = UnityEngine.VR.VRDevice.model; bool isOpenVR = String.Equals(vrDeviceFamily, "OpenVR", StringComparison.CurrentCultureIgnoreCase); if (isOpenVR) { Debug.Log(GetType().FullName + ": found OpenVR headset\"" + vrDeviceModel + "\".", this); } else { Debug.LogWarning(GetType().FullName + ": Unsupported HMD type (\"" + vrDeviceFamily + "\", \"" + vrDeviceModel + "\").", this); } } else { Debug.LogWarning(GetType().FullName + ": No VRDevice present.", this); } // Cache a reference to the gameobject containing the HMD Camera. Camera hmdCamera = this.GetComponentInChildren <Camera>(); if (hmdCamera == null) { Debug.LogError(GetType().FullName + ": Couldn't locate HMD-driven Camera component in children.", this); } }
/* * Method called at start of game */ void Start() { // If the user didn't explicitly associate a client, find a suitable default. if (this.StreamingClient == null) { this.StreamingClient = OptitrackStreamingClient.FindDefaultClient(); // If we still couldn't find one, disable this component. if (this.StreamingClient == null) { Debug.LogError(GetType().FullName + ": Streaming client not set, and no " + typeof(OptitrackStreamingClient).FullName + " components found in scene; disabling this component.", this); this.enabled = false; return; } } #region Initialize variables count = 0; //frame number prevPos = Experiment.cuestart; //initialize previous positons to cue starting position //initialize cue velocities cueVelocity = new Vector3(0f, 0f, 0f); VelocityList = new List <Vector3>(); for (int i = 0; i < Experiment.numVelocitiesAverage; i++) { VelocityList.Add(cueVelocity); } //initialize IDs and positions of optitrack markers placed on the pool table corner1ID = -1; corner2ID = -1; corner3ID = -1; C1 = new List <Vector3>(); C2 = new List <Vector3>(); C3 = new List <Vector3>(); //get IDs and positions of optitrack markers backID1 = -1; backID2 = -2; frontID1 = -3; frontID2 = -4; Oback1 = new Vector3(); Oback2 = new Vector3(); Ofront1 = new Vector3(); Ofront2 = new Vector3(); if (Experiment.experiment == 0 && markerIDs) { getCalMarkerId(); } test = true; //for calibration #endregion }
void SetOptitrackID() { client = GameObject.FindObjectOfType <OptitrackStreamingClient>(); filePath = Application.streamingAssetsPath + @"\" + jsonFileName + ".json"; StreamReader reader = new StreamReader(filePath); string json = reader.ReadToEnd(); data = JsonUtility.FromJson <OptitrackRigidbodyList> (json); // Debug.Log (netId.ToString () + " setting ID for IP " + ipAddress); if (!isLocalPlayer) { foreach (ClientIP cl in clientIPList) { // Debug.Log (cl.networkID + ":" + cl.ipAddress); if (netId.ToString() == cl.networkID) { ipAddress = cl.ipAddress; } } } else { ipAddress = Network.player.ipAddress; } if (File.Exists(filePath)) { foreach (OptitrackRigidbodyJson c in data.data) { if (c.ipAddress == ipAddress) { hmd.RigidBodyId = c.headset; leftHand.RigidBodyId = c.left; rightHand.RigidBodyId = c.right; Debug.Log("Local Rigidbodies registered."); } } } else { Debug.Log(Path.GetFileName(filePath) + " not exist"); } }
void Start() { //sets the reference time zeroTime.m_ticks = 0; // null client, find default if (this.StreamingClient == null) { this.StreamingClient = OptitrackStreamingClient.FindDefaultClient(); // disable if no client found if (this.StreamingClient == null) { Debug.LogError(GetType().FullName + ": No streaming clients found, disabling CustomRigidBody", this); this.enabled = false; return; } } }
// Start is called before the first frame update void Start() { if (StreamingClient == null) { StreamingClient = OptitrackStreamingClient.FindDefaultClient(); // If we still couldn't find one, disable this component. if (StreamingClient == null) { Debug.LogError(GetType().FullName + ": Streaming client not set, and no " + typeof(OptitrackStreamingClient).FullName + " components found in scene; disabling this component.", this); this.enabled = false; return; } } InitGO("shoulder1", ref goShoulder1); InitGO("shoulder2", ref goShoulder2); InitGO("forearm", ref goForearm); InitGO("hand", ref goHand); InitGO("indexfinger", ref goIndexfinger); InitGO("hmd", ref goHmd); InitGO("upperarm", ref goUpperarm); }
void Start() { // If the user didn't explicitly associate a client, find a suitable default. if (this.StreamingClient == null) { this.StreamingClient = OptitrackStreamingClient.FindDefaultClient(); // If we still couldn't find one, disable this component. if (this.StreamingClient == null) { //Debug.LogError(GetType().FullName + ": Streaming client not set, and no " + typeof(OptitrackStreamingClient).FullName + " components found in scene; disabling this component.", this); this.enabled = false; return; } } calibrationScript = GameObject.Find("Client - OptiTrack").GetComponent <OptitrackCalibration>(); //Initialize Photos obeject1.gameObject.SetActive(false); obeject2.gameObject.SetActive(false); obeject3.gameObject.SetActive(false); obeject4.gameObject.SetActive(false); object5.gameObject.SetActive(false); object6.gameObject.SetActive(false); object7.gameObject.SetActive(false); object8.gameObject.SetActive(false); object_text.gameObject.SetActive(false); //Initialize Music music_play = false; music1.gameObject.SetActive(false); music2.gameObject.SetActive(false); music3.gameObject.SetActive(false); m_text1.gameObject.SetActive(false); m_text2.gameObject.SetActive(false); m_text3.gameObject.SetActive(false); }
public override void Inspector(HumanoidControl humanoid) { Inspector(humanoid, "OptiTrack"); if (enabledProp.boolValue) { EditorGUI.indentLevel++; OptitrackStreamingClient client = CheckScript(); optiTracker.streamingClient = (OptitrackStreamingClient)EditorGUILayout.ObjectField("Streaming Client", optiTracker.streamingClient, typeof(OptitrackStreamingClient), true); if (optiTracker.streamingClient == null) { optiTracker.streamingClient = client; } trackingTypeProp.intValue = (int)(OptiTracker.TrackingType)EditorGUILayout.EnumPopup("Tracking Type", (OptiTracker.TrackingType)trackingTypeProp.intValue); if ((OptiTracker.TrackingType)trackingTypeProp.intValue == OptiTracker.TrackingType.Skeleton) { if (optiTracker.skeletonName == null) { optiTracker.skeletonName = ""; } optiTracker.skeletonName = EditorGUILayout.TextField("Skeleton name", optiTracker.skeletonName); } else { optiTracker.skeletonName = null; } skeletonNameProp.stringValue = optiTracker.skeletonName; EditorGUI.indentLevel--; } else { RemoveScript(humanoid); } }
void Awake() { client = GameObject.FindObjectOfType <OptitrackStreamingClient> (); client.LocalAddress = Network.player.ipAddress; Debug.Log("Set Streaming Client Local Address to " + client.LocalAddress); }
private void Awake() { StreamingClient = GameObject.FindGameObjectWithTag("OptiClient").GetComponent <OptitrackStreamingClient>(); translation = StreamingClient.transform.GetChild(0); }
private void Awake() { streamingClient = FindObjectOfType <OptitrackStreamingClient>(); }
public OptitrackSensor(DeviceView device, OptitrackStreamingClient _streamingClient) : base(device) { streamingClient = _streamingClient; }
public static Vector GetPosition(OptitrackStreamingClient streamingClient, int trackerId) { OptitrackRigidBodyState rbState = streamingClient.GetLatestRigidBodyState(trackerId); return(Passer.Target.ToVector(rbState.Pose.Position)); }
public static Rotation GetRotation(OptitrackStreamingClient streamingClient, int trackerId) { OptitrackRigidBodyState rbState = streamingClient.GetLatestRigidBodyState(trackerId); return(Passer.Target.ToRotation(rbState.Pose.Orientation)); }