public ProfileData(CalibrationProfile newProfile) { profileRequirements = newProfile.profileRequirements; trackerOffsets = newProfile.trackerOffsets; trackerDirections = newProfile.trackerDirections; bodyMeasurements = newProfile.bodyMeasurements; }
public void SetupCalibrationSequence(CalibrationProfile profile, TrackerReference trackers, MonoBehaviour mono) { this.profile = profile; this.trackers = trackers; this.mono = mono; // TMP: isFinished = false; currentIndex = 0; }
public virtual void Setup(CalibrationProfile profile, TrackerReference trackers, Action finishCallback = null) { if (calibrationEvents != null) { calibrationEvents.RaisePrepareCalibration(); } this.profile = profile; this.trackers = trackers; this.finishCallback = finishCallback; }
public override void Setup(CalibrationProfile profile, TrackerReference trackers, Action finishCallback = null) { base.Setup(profile, trackers, finishCallback); arcArray = new Arc[settings.Length]; for (var i = 0; i < settings.Length; i++) { arcArray[i] = settings[i].useParentTracker ? new Arc(trackers, settings[i].parentTracker) : arcArray[i] = new Arc(); } }
private void VisualizeTrackerOffsets() { for (int i = 0; i < profile.trackerOffsets.Keys.Count; i++) { if (trackerOffsetVisuals.Count < i + 1) { trackerOffsetVisuals.Add(GameObject.CreatePrimitive(PrimitiveType.Sphere)); trackerOffsetVisuals[i].GetComponent <MeshRenderer>().material.color = Color.black; trackerOffsetVisuals[i].transform.localScale = new Vector3(0.05f, 0.05f, 0.05f); trackerOffsetVisuals[i].transform.SetParent(transform); } OffsetsToTrackers offsetType = profile.trackerOffsets.Keys.ToArray()[i]; VRTrackerType type = CalibrationProfile.GetMatchingTrackerFromOffset(offsetType) ?? VRTrackerType.Other; TrackerOffset offset = profile.trackerOffsets[offsetType]; TransformValues?trackerWithOffset = trackers.GetTrackerWithOffset(type, offset.Position, Quaternion.identity); if (trackerWithOffset == null) { if (trackerOffsetVisuals[i].activeSelf) { trackerOffsetVisuals[i].SetActive(false); } continue; } if (!trackerOffsetVisuals[i].activeSelf) { trackerOffsetVisuals[i].SetActive(true); } trackerOffsetVisuals[i]?.transform.SetPositionAndRotation( trackerWithOffset.Value.position, trackerWithOffset.Value.rotation); } }
public static Vector3 GetDirection(Direction settings, TrackerReference trackers, CalibrationProfile profile) { switch (settings.type) { case DirectionType.WorldDirection: return(settings.worldDirection); case DirectionType.TrackerDirection: TransformValues?trackerFrom = trackers.GetTracker(settings.trackerFrom); if (settings.trackerFromLocal) { if (profile.trackerOffsets.ContainsKey(settings.trackerFromLocalOffset) && profile.trackerOffsets[settings.trackerFromLocalOffset].position != null) { trackerFrom = trackers.GetTrackerWithOffset(settings.trackerFrom, profile.trackerOffsets[settings.trackerFromLocalOffset].Position, Quaternion.identity); } } TransformValues?trackerTo = trackers.GetTracker(settings.trackerTo); if (settings.trackerToLocal) { if (profile.trackerOffsets.ContainsKey(settings.trackerToLocalOffset) && profile.trackerOffsets[settings.trackerToLocalOffset].position != null) { trackerTo = trackers.GetTrackerWithOffset(settings.trackerTo, profile.trackerOffsets[settings.trackerToLocalOffset].Position, Quaternion.identity); } } if (trackerFrom == null || trackerTo == null) { Debug.LogError("Not all trackers are connected"); break; } return(trackerTo.Value.position - trackerFrom.Value.position); } return(Vector3.zero); }
public static bool CheckIfDirectionShouldBeInverted(DirectionClosestTo settings, TrackerReference trackers, CalibrationProfile profile, Vector3 worldDirection) { switch (settings.type) { case DirectionClosestType.SingleDirection: Vector3 dir = Direction.GetDirection(settings.singleDirection, trackers, profile); if (Vector3.Distance(dir, worldDirection) > Vector3.Distance(dir, worldDirection * -1)) { return(true); } break; case DirectionClosestType.Cross: Vector3 crossDir1 = Direction.GetDirection(settings.crossDirection1, trackers, profile); Vector3 crossDir2 = Direction.GetDirection(settings.crossDirection2, trackers, profile); Vector3 cross = Vector3.Cross(crossDir1, crossDir2); if (Vector3.Distance(cross, worldDirection) > Vector3.Distance(cross, worldDirection * -1)) { return(true); } break; default: Debug.LogError("Implement your shit"); break; } return(false); }
public static Vector3 GetDirection(DirectionClosestTo settings, TrackerReference trackers, CalibrationProfile profile) { switch (settings.type) { case DirectionClosestType.SingleDirection: return(Direction.GetDirection(settings.singleDirection, trackers, profile)); case DirectionClosestType.Cross: Vector3 crossDir1 = Direction.GetDirection(settings.crossDirection1, trackers, profile); Vector3 crossDir2 = Direction.GetDirection(settings.crossDirection2, trackers, profile); return(Vector3.Cross(crossDir1, crossDir2)); default: Debug.LogError("Implement your shit"); break; } return(Vector3.zero); }
private void VisualizeDirection() { for (int i = 0; i < profile.trackerDirections.Keys.Count; i++) { if (trackerDirectionVisuals.Count < i + 1) { trackerDirectionVisuals.Add( new[] { GameObject.CreatePrimitive(PrimitiveType.Cube), GameObject.CreatePrimitive(PrimitiveType.Cube), GameObject.CreatePrimitive(PrimitiveType.Cube) }); trackerDirectionVisuals[i][0].GetComponent <MeshRenderer>().material.color = Color.red; trackerDirectionVisuals[i][1].GetComponent <MeshRenderer>().material.color = Color.green; trackerDirectionVisuals[i][2].GetComponent <MeshRenderer>().material.color = Color.blue; foreach (GameObject obj in trackerDirectionVisuals[i]) { obj.transform.localScale = new Vector3(0.02f, 0.02f, 0.02f); obj.transform.SetParent(transform); } } VRTrackerType trackerType = profile.trackerDirections.Keys.ToArray()[i]; if (alsoHead == false && trackerType == VRTrackerType.Head) { continue; } OffsetsToTrackers?offsetType = CalibrationProfile.GetMatchingTrackerOffsetForTracker(trackerType); if (offsetType == null) { continue; } Matrix4x4 trackerMatrix; if (profile.trackerOffsets.ContainsKey((OffsetsToTrackers)offsetType)) { TrackerOffset trackerOffset = profile.trackerOffsets[(OffsetsToTrackers)offsetType]; TransformValues trackerTransform = trackers.GetTrackerWithOffset(trackerType, trackerOffset.Position, Quaternion.identity) ?? new TransformValues(Vector3.zero, Quaternion.identity); trackerMatrix = Matrix4x4.TRS(trackerTransform.position, trackerTransform.rotation, Vector3.one); } else { TransformValues trackerTransform = trackers.GetTracker(trackerType) ?? new TransformValues(Vector3.zero, Quaternion.identity); trackerMatrix = Matrix4x4.TRS(trackerTransform.position, trackerTransform.rotation, Vector3.one); } TrackerDirection trackerDirection = profile.trackerDirections[trackerType]; if (trackerDirection.X != Vector3.zero) { trackerDirectionVisuals[i][0].transform.localScale = new Vector3(0.02f, 0.02f, 0.02f); trackerDirectionVisuals[i][0].transform.position = trackerMatrix.GetPosition() + trackerMatrix.MultiplyVector(trackerDirection.X) * 0.1f; } else { trackerDirectionVisuals[i][0].transform.localScale = Vector3.zero; } if (trackerDirection.Y != Vector3.zero) { trackerDirectionVisuals[i][1].transform.localScale = new Vector3(0.02f, 0.02f, 0.02f); trackerDirectionVisuals[i][1].transform.position = trackerMatrix.GetPosition() + trackerMatrix.MultiplyVector(trackerDirection.Y) * 0.1f; } else { trackerDirectionVisuals[i][1].transform.localScale = Vector3.zero; } if (trackerDirection.Z != Vector3.zero) { trackerDirectionVisuals[i][2].transform.localScale = new Vector3(0.02f, 0.02f, 0.02f); trackerDirectionVisuals[i][2].transform.position = trackerMatrix.GetPosition() + trackerMatrix.MultiplyVector(trackerDirection.Z) * 0.1f; } else { trackerDirectionVisuals[i][2].transform.localScale = Vector3.zero; } } }
private void ProcessData(Data[] arcData) { foreach (Data data in arcData) { switch (data.dataType) { case DataType.OffsetToTracker: // Add offset on local plane if (data.onLocalPlane) { // if profile doesn't contain a offset yet, just add it normally if (profile.trackerOffsets.ContainsKey(data.trackerOffset) && profile.trackerOffsets[data.trackerOffset].position != null) { TrackerOffset offset = profile.trackerOffsets[data.trackerOffset]; VRTrackerType trackerType = (VRTrackerType)CalibrationProfile.GetMatchingTrackerFromOffset(data.trackerOffset); // if profile doesn't contain the required axis ignore if (profile.trackerDirections.ContainsKey(trackerType) && profile.trackerDirections[trackerType].GetAxis(data.localPlane) != null) { TransformValues trackerTransform = (TransformValues)trackers.GetTracker(trackerType); Matrix4x4 trackerMatrix = Matrix4x4.TRS(trackerTransform.position, trackerTransform.rotation, Vector3.one); Matrix4x4 inverseTrackerMatrix = trackerMatrix.inverse; Vector3 localAxis = trackerMatrix.MultiplyVector(profile.trackerDirections[trackerType].GetAxis(data.localPlane) ?? Vector3.zero); Vector3 newPositionDirection = trackerMatrix.MultiplyPoint3x4(arcArray[data.arcPositionIndex].GetOffsetToTracker()) - trackerMatrix.MultiplyPoint3x4((Vector3)offset.position); Vector3 newPosition = trackerMatrix.MultiplyPoint3x4((Vector3)offset.position) + Vector3.ProjectOnPlane(newPositionDirection, localAxis); newPosition = inverseTrackerMatrix.MultiplyPoint3x4(newPosition); // Debug.Log(newPosition.magnitude); // Debug.DrawLine(trackerMatrix.MultiplyPoint3x4(arcArray[data.arcPositionIndex].GetOffsetToTracker()), trackerMatrix.MultiplyPoint3x4(arcArray[data.arcPositionIndex].GetOffsetToTracker()), Color.blue, 10f); // Debug.DrawRay(trackerMatrix.MultiplyPoint3x4(arcArray[data.arcPositionIndex].GetOffsetToTracker()), localAxis, Color.red, 10f); arcArray[data.arcPositionIndex].GetOffsetToTracker(); profile.AddTrackerOffset(data.trackerOffset, newPosition); continue; } Debug.LogError($"Could not apply local offset to {trackerType}, plane axis is not applied"); } } profile.AddTrackerOffset(data.trackerOffset, arcArray[data.arcPositionIndex].GetOffsetToTracker()); break; case DataType.Length: // TODO: TMP foreach (int index in data.arcMeasurementIndices) { GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); sphere.transform.position = arcArray[index].IntersectionPoint; sphere.transform.localScale = new Vector3(.05f, .05f, .05f); } float value = data.arcMeasurementIndices.Sum(arc => arcArray[arc].GetArcRadius()) / data.arcMeasurementIndices.Length; profile.AddBodyMeasurement(data.measurement, value); break; case DataType.Distance: Vector3 point1 = Vector3.zero; Vector3 point2 = Vector3.zero; // TODO: make this a function switch (data.point1.pointType) { case PointType.ArcPoint: point1 = arcArray[data.point1.arcIndex].IntersectionPoint; break; case PointType.Tracker: point1 = Vector3.zero; // TODO: calculate local offset to tracker break; } switch (data.point2.pointType) { case PointType.ArcPoint: point2 = arcArray[data.point2.arcIndex].IntersectionPoint; break; case PointType.Tracker: point2 = Vector3.zero; // TODO: calculate local offset to tracker break; } float distance = Vector3.Distance(point1, point2); profile.AddBodyMeasurement(data.distanceMeasurement, distance); break; case DataType.Direction: Vector3 normal = arcArray[data.arcDirectionIndex].GetArcNormalFromTracker(); VRTrackerType trackerDirectionType = settings[data.arcDirectionIndex].parentTracker; TransformValues?trackerDirectionTransform = trackers.GetTracker(trackerDirectionType); if (trackerDirectionTransform == null) { Debug.Log("Not all trackers are assigned"); return; } Matrix4x4 trackerDirectionMatrix = Matrix4x4.TRS(trackerDirectionTransform.Value.position, trackerDirectionTransform.Value.rotation, Vector3.one); Vector3 worldNormal = trackerDirectionMatrix.MultiplyVector(normal); switch (data.directionClosest.type) { case DirectionClosestType.SingleDirection: Vector3 dir = Vector3.zero; // TODO: make this a function switch (data.directionClosest.singleDirection.type) { case DirectionType.WorldDirection: dir = data.directionClosest.singleDirection.worldDirection; dir = dir.normalized; break; case DirectionType.TrackerDirection: TransformValues?trackerFrom = trackers.GetTracker(data.directionClosest.singleDirection.trackerFrom); TransformValues?trackerTo = trackers.GetTracker(data.directionClosest.singleDirection.trackerTo); if (trackerFrom == null || trackerTo == null) { Debug.LogError("Not all trackers are connected"); return; } dir = trackerTo.Value.position - trackerFrom.Value.position; dir = dir.normalized; break; } Debug.DrawRay(trackers.GetTracker(VRTrackerType.LeftHand).Value.position, worldNormal, Color.magenta, 10f); Debug.DrawRay(trackers.GetTracker(VRTrackerType.LeftHand).Value.position, dir, Color.cyan, 10f); if (Vector3.Distance(dir, worldNormal) > Vector3.Distance(dir, worldNormal * -1)) { normal *= -1f; } break; case DirectionClosestType.Cross: Vector3 crossDir1 = Vector3.zero; Vector3 crossDir2 = Vector3.zero; // TODO: make this a function switch (data.directionClosest.crossDirection1.type) { case DirectionType.WorldDirection: crossDir1 = data.directionClosest.crossDirection1.worldDirection; break; case DirectionType.TrackerDirection: TransformValues?trackerFrom = trackers.GetTracker(data.directionClosest.crossDirection1.trackerFrom); TransformValues?trackerTo = trackers.GetTracker(data.directionClosest.crossDirection1.trackerTo); if (trackerFrom == null || trackerTo == null) { Debug.LogError("Not all trackers are connected"); return; } crossDir1 = trackerTo.Value.position - trackerFrom.Value.position; break; } switch (data.directionClosest.crossDirection2.type) { case DirectionType.WorldDirection: crossDir2 = data.directionClosest.crossDirection2.worldDirection; break; case DirectionType.TrackerDirection: TransformValues?trackerFrom = trackers.GetTracker(data.directionClosest.crossDirection2.trackerFrom); TransformValues?trackerTo = trackers.GetTracker(data.directionClosest.crossDirection2.trackerTo); if (trackerFrom == null || trackerTo == null) { Debug.LogError("Not all trackers are connected"); return; } crossDir2 = trackerTo.Value.position - trackerFrom.Value.position; break; } Vector3 cross = Vector3.Cross(crossDir1, crossDir2); if (Vector3.Distance(cross, worldNormal) > Vector3.Distance(cross, worldNormal * -1)) { normal *= -1f; } Debug.DrawRay(trackers.GetTracker(VRTrackerType.LeftHand).Value.position, worldNormal, Color.magenta, 10f); Debug.DrawRay(trackers.GetTracker(VRTrackerType.LeftHand).Value.position, cross, Color.cyan, 10f); break; default: Debug.LogError("Implement your shit"); break; } profile.AddTrackerDirection(trackerDirectionType, data.directionAxis, normal); break; } } }
public static Vector3 GetPoint(Point settings, TrackerReference trackers, CalibrationProfile profile) { switch (settings.type) { case PointType.Tracker: TransformValues?trackerTransform = trackers.GetTracker(settings.tracker); if (settings.useTrackerLocal) { if (!profile.trackerOffsets.ContainsKey(settings.trackerOffset) || profile.trackerOffsets[settings.trackerOffset].position == null) { break; } trackerTransform = trackers.GetTrackerWithOffset(settings.tracker, profile.trackerOffsets[settings.trackerOffset].Position, Quaternion.identity); } if (trackerTransform == null) { break; } return(trackerTransform.Value.position); break; default: Debug.LogError("Not Implemented"); break; } Debug.LogError("Something went wrong here"); return(Vector3.zero); }