public void RemoveTrackerOffset(OffsetsToTrackers type, bool removePositionOffset, bool removeRotationOffset) { Debug.LogWarning($"Removed tracker position and rotation offset: {type}"); if (trackerOffsets[type].RemoveValue(removePositionOffset, removeRotationOffset)) { trackerOffsets.Remove(type); } }
// Tracker offset public void AddTrackerOffset(OffsetsToTrackers type, Vector3 positionValue) { Debug.LogWarning($"Add tracker position offset: {type}"); if (!trackerOffsets.ContainsKey(type)) { trackerOffsets.Add(type, new TrackerOffset(positionValue)); } else { trackerOffsets[type].SetPositionOffset(positionValue); } }
public void AddTrackerOffset(OffsetsToTrackers type, Quaternion rotationValue) { Debug.LogWarning($"Add tracker rotation offset: {type}"); if (!trackerOffsets.ContainsKey(type)) { trackerOffsets.Add(type, new TrackerOffset(rotationValue)); } else { trackerOffsets[type].SetRotationOffset(rotationValue); } }
public static VRTrackerType?GetMatchingTrackerFromOffset(OffsetsToTrackers offsetType) { switch (offsetType) { case OffsetsToTrackers.HeadTrackerToHead: return(VRTrackerType.Head); case OffsetsToTrackers.LeftHandTrackerToWrist: return(VRTrackerType.LeftHand); case OffsetsToTrackers.RightHandTrackerToWrist: return(VRTrackerType.RightHand); case OffsetsToTrackers.LeftElbowTrackerToElbow: return(null); case OffsetsToTrackers.RightElbowTrackerToElbow: return(null); case OffsetsToTrackers.LeftElbowTrackerToShoulder: return(null); case OffsetsToTrackers.RightElbowTrackerToShoulder: return(null); case OffsetsToTrackers.HipTrackerToHip: return(VRTrackerType.Waist); case OffsetsToTrackers.HipTrackerToLeftLeg: return(VRTrackerType.Waist); case OffsetsToTrackers.HipTrackerToRightLeg: return(VRTrackerType.Waist); case OffsetsToTrackers.LeftFootTrackerToAnkle: return(VRTrackerType.LeftFoot); case OffsetsToTrackers.RightFootTrackerToAnkle: return(VRTrackerType.RightFoot); default: return(null); } }
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 override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { // Using BeginProperty / EndProperty on the parent property means that // __prefab__ override logic works on the entire property. EditorGUI.BeginProperty(position, label, property); // Get variables var localOffset = property.FindPropertyRelative("useTrackerLocal"); var parent = property.FindPropertyRelative("useParentTracker"); // Draw label string arrayIndex = Regex.Replace(property.displayName, "[^0-9]", string.Empty); VRTrackerType trackerName = (VRTrackerType)property.FindPropertyRelative("tracker").intValue; OffsetsToTrackers offsetName = (OffsetsToTrackers)property.FindPropertyRelative("localOffset").intValue; VRTrackerType parentName = (VRTrackerType)property.FindPropertyRelative("parentTracker").intValue; label.text = (arrayIndex.Length > 0 ? $"{arrayIndex} - " : string.Empty) + $"{trackerName} Tracker" + (localOffset.boolValue ? $" - (Local: {offsetName})" : string.Empty) + (parent.boolValue ? $" - (Parent: {parentName})" : string.Empty); // Foldout group var expendRect = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight); property.isExpanded = EditorGUI.Foldout(expendRect, property.isExpanded, label); // Don't make child fields be indented var indent = EditorGUI.indentLevel; EditorGUI.indentLevel += 2; // Calculate rects var trackerRect = new Rect(position.x, position.y + EditorGUIUtility.singleLineHeight + lineHeight, position.width, EditorGUIUtility.singleLineHeight); var useLocalRect = new Rect(position.x, position.y + (EditorGUIUtility.singleLineHeight + lineHeight) * 2, position.width * .45f, EditorGUIUtility.singleLineHeight); var useLocalEnumRect = new Rect(position.x + position.width * .45f, position.y + (EditorGUIUtility.singleLineHeight + lineHeight) * 2, position.width * .55f, EditorGUIUtility.singleLineHeight); var useParentRect = new Rect(position.x, position.y + (EditorGUIUtility.singleLineHeight + lineHeight) * 3, position.width * .45f, EditorGUIUtility.singleLineHeight); var useParentEnumRect = new Rect(position.x + position.width * .45f, position.y + (EditorGUIUtility.singleLineHeight + lineHeight) * 3, position.width * .55f, EditorGUIUtility.singleLineHeight); // Draw fields if (property.isExpanded) { EditorGUI.PropertyField(trackerRect, property.FindPropertyRelative("tracker"), new GUIContent("Tracker")); EditorGUI.PropertyField(useLocalRect, property.FindPropertyRelative("useTrackerLocal"), new GUIContent("Use tracker local")); if (localOffset.boolValue) { EditorGUI.PropertyField(useLocalEnumRect, property.FindPropertyRelative("localOffset"), GUIContent.none); } EditorGUI.PropertyField(useParentRect, property.FindPropertyRelative("useParentTracker"), new GUIContent("Use parent")); if (parent.boolValue) { EditorGUI.PropertyField(useParentEnumRect, property.FindPropertyRelative("parentTracker"), GUIContent.none); } } // Set indent back to what it was EditorGUI.indentLevel = indent; EditorGUI.EndProperty(); }
private void VisualizeBodyPart(ref GameObject obj, GameObject objModel, VRTrackerType trackerType, OffsetsToTrackers offset) { if (obj == null) { obj = Instantiate(objModel, transform); obj.SetActive(false); } TransformValues?handTransform = trackers.GetTracker(trackerType); if (profile.trackerOffsets.ContainsKey(offset) && profile.trackerOffsets[offset].position != null) { handTransform = trackers.GetTrackerWithOffset(trackerType, profile.trackerOffsets[offset].Position, Quaternion.identity); } if (handTransform == null || !profile.trackerDirections.ContainsKey(trackerType) || profile.trackerDirections[trackerType].GetAxis(Axis.Z) == null || profile.trackerDirections[trackerType].GetAxis(Axis.Y) == null) { if (obj.activeSelf) { obj.SetActive(false); } return; } if (!obj.activeSelf) { obj.SetActive(true); } Matrix4x4 trackerMatrix = Matrix4x4.TRS(handTransform.Value.position, handTransform.Value.rotation, Vector3.one); Quaternion rotation = Quaternion.LookRotation( trackerMatrix.MultiplyVector(profile.trackerDirections[trackerType].Z), trackerMatrix.MultiplyVector(profile.trackerDirections[trackerType].Y)); obj.transform.SetPositionAndRotation(handTransform.Value.position, rotation); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(position, label, property); // Get variables var currentType = (ArcCalibrationStep.DataType)property.FindPropertyRelative("dataType").intValue; SerializedProperty onLocalPlane = property.FindPropertyRelative("onLocalPlane"); // Draw label ArcCalibrationStep.DataType dataType = (ArcCalibrationStep.DataType)property.FindPropertyRelative("dataType").intValue; string dataName = string.Empty; switch (dataType) { case ArcCalibrationStep.DataType.OffsetToTracker: OffsetsToTrackers trackerOffsetType = (OffsetsToTrackers)property.FindPropertyRelative("trackerOffset").intValue; Axis localPlane = (Axis)property.FindPropertyRelative("localPlane").intValue; string localPlaneName = onLocalPlane.boolValue ? $"Local {localPlane.ToString()} " : string.Empty; dataName = $"{localPlaneName}{trackerOffsetType} ({property.FindPropertyRelative("arcPositionIndex").intValue})"; break; case ArcCalibrationStep.DataType.Length: BodyMeasurements lengthBodyMeasurementType = (BodyMeasurements)property.FindPropertyRelative("measurement").intValue; SerializedProperty indices = property.FindPropertyRelative("arcMeasurementIndices"); string index = string.Empty; for (int i = 0; i < indices.arraySize; i++) { if (i != 0) { index += ", "; } index += indices.GetArrayElementAtIndex(i).intValue.ToString(); } dataName = $"{lengthBodyMeasurementType} ({index})"; break; case ArcCalibrationStep.DataType.Distance: BodyMeasurements distanceBodyMeasurementType = (BodyMeasurements)property.FindPropertyRelative("distanceMeasurement").intValue; string distanceIndex = string.Empty; ArcCalibrationStep.PointType point1Type = (ArcCalibrationStep.PointType)property.FindPropertyRelative("point1").FindPropertyRelative("pointType").intValue; switch (point1Type) { case ArcCalibrationStep.PointType.ArcPoint: distanceIndex += property.FindPropertyRelative("point1").FindPropertyRelative("arcIndex").intValue; break; case ArcCalibrationStep.PointType.Tracker: VRTrackerType trackerTypePoint1 = (VRTrackerType)property.FindPropertyRelative("point1").FindPropertyRelative("tracker").intValue; distanceIndex += trackerTypePoint1; if (property.FindPropertyRelative("point2").FindPropertyRelative("useLocalOffset").boolValue) { distanceIndex += " (Local)"; } break; } distanceIndex += ", "; ArcCalibrationStep.PointType point2Type = (ArcCalibrationStep.PointType)property.FindPropertyRelative("point2").FindPropertyRelative("pointType").intValue; switch (point2Type) { case ArcCalibrationStep.PointType.ArcPoint: distanceIndex += property.FindPropertyRelative("point2").FindPropertyRelative("arcIndex").intValue; break; case ArcCalibrationStep.PointType.Tracker: VRTrackerType trackerTypePoint2 = (VRTrackerType)property.FindPropertyRelative("point2").FindPropertyRelative("tracker").intValue; distanceIndex += trackerTypePoint2; if (property.FindPropertyRelative("point2").FindPropertyRelative("useLocalOffset").boolValue) { distanceIndex += " (Local)"; } break; } dataName = $"{distanceBodyMeasurementType} ({distanceIndex})"; break; case ArcCalibrationStep.DataType.Direction: Axis directionAxis = (Axis)property.FindPropertyRelative("directionAxis").intValue; dataName = $"{directionAxis} ({property.FindPropertyRelative("arcDirectionIndex").intValue})"; break; } label.text = $"{dataType}: {dataName}"; // Foldout group var expendRect = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight); property.isExpanded = EditorGUI.Foldout(expendRect, property.isExpanded, label); // Don't make child fields be indented var indent = EditorGUI.indentLevel; EditorGUI.indentLevel += 2; // Calculate rects var dataTypeRect = new Rect(position.x, position.y + EditorGUIUtility.singleLineHeight + lineHeight, position.width, EditorGUIUtility.singleLineHeight); // Tracker offset var trackerOffsetEnumRect = new Rect(position.x, position.y + (EditorGUIUtility.singleLineHeight + lineHeight) * 2, position.width, EditorGUIUtility.singleLineHeight); var trackerOffetArcIndexRect = new Rect(position.x, position.y + (EditorGUIUtility.singleLineHeight + lineHeight) * 3, position.width, EditorGUIUtility.singleLineHeight); var trackerOffetOnLocalPlaneRect = new Rect(position.x, position.y + (EditorGUIUtility.singleLineHeight + lineHeight) * 4, position.width * .45f, EditorGUIUtility.singleLineHeight); var trackerOffetLocalPlaneRect = new Rect(position.x + position.width * .45f, position.y + (EditorGUIUtility.singleLineHeight + lineHeight) * 4, position.width * .55f, EditorGUIUtility.singleLineHeight); // Length SerializedProperty lengthIndicesProperty = property.FindPropertyRelative("arcMeasurementIndices"); var lengthMeasurementTypeRect = new Rect(position.x, position.y + (EditorGUIUtility.singleLineHeight + lineHeight) * 2, position.width, EditorGUIUtility.singleLineHeight); var lengthIndicesRect = new Rect(position.x, position.y + (EditorGUIUtility.singleLineHeight + lineHeight) * 3, position.width, EditorGUI.GetPropertyHeight(lengthIndicesProperty)); // Distance SerializedProperty distancePoint1 = property.FindPropertyRelative("point1"); SerializedProperty distancePoint2 = property.FindPropertyRelative("point2"); var distanceEnumRect = new Rect(position.x, position.y + (EditorGUIUtility.singleLineHeight + lineHeight) * 2, position.width, EditorGUIUtility.singleLineHeight); var distancePoint1Rect = new Rect(position.x, position.y + (EditorGUIUtility.singleLineHeight + lineHeight) * 3, position.width, EditorGUI.GetPropertyHeight(distancePoint1)); var distancePoint2Rect = new Rect(position.x, position.y + EditorGUI.GetPropertyHeight(distancePoint1) + lineHeight + (EditorGUIUtility.singleLineHeight + lineHeight) * 3, position.width, EditorGUI.GetPropertyHeight(distancePoint2)); // Direction SerializedProperty closestDirection = property.FindPropertyRelative("directionClosest"); var directionAxisRect = new Rect(position.x, position.y + (EditorGUIUtility.singleLineHeight + lineHeight) * 2, position.width, EditorGUIUtility.singleLineHeight); var arcDirectionIndexRect = new Rect(position.x, position.y + (EditorGUIUtility.singleLineHeight + lineHeight) * 3, position.width, EditorGUIUtility.singleLineHeight); var closestDirectionRect = new Rect(position.x, position.y + (EditorGUIUtility.singleLineHeight + lineHeight) * 4, position.width, EditorGUI.GetPropertyHeight(closestDirection)); // Draw fields if (property.isExpanded) { EditorGUI.PropertyField(dataTypeRect, property.FindPropertyRelative("dataType"), new GUIContent("Data type")); switch (currentType) { case ArcCalibrationStep.DataType.OffsetToTracker: EditorGUI.PropertyField(trackerOffsetEnumRect, property.FindPropertyRelative("trackerOffset"), new GUIContent("Tracker offset")); EditorGUI.PropertyField(trackerOffetArcIndexRect, property.FindPropertyRelative("arcPositionIndex"), new GUIContent("Arc index")); EditorGUI.PropertyField(trackerOffetOnLocalPlaneRect, property.FindPropertyRelative("onLocalPlane"), new GUIContent("On local plane")); if (onLocalPlane.boolValue) { EditorGUI.PropertyField(trackerOffetLocalPlaneRect, property.FindPropertyRelative("localPlane"), GUIContent.none); } break; case ArcCalibrationStep.DataType.Length: EditorGUI.PropertyField(lengthMeasurementTypeRect, property.FindPropertyRelative("measurement"), new GUIContent("Measurement")); EditorGUI.PropertyField(lengthIndicesRect, lengthIndicesProperty, new GUIContent("Arc indices"), true); break; case ArcCalibrationStep.DataType.Distance: EditorGUI.PropertyField(distanceEnumRect, property.FindPropertyRelative("distanceMeasurement"), new GUIContent("Measurement")); EditorGUI.PropertyField(distancePoint1Rect, distancePoint1, new GUIContent("Point 1"), true); EditorGUI.PropertyField(distancePoint2Rect, distancePoint2, new GUIContent("Point 2"), true); break; case ArcCalibrationStep.DataType.Direction: EditorGUI.PropertyField(directionAxisRect, property.FindPropertyRelative("directionAxis"), new GUIContent("Axis")); EditorGUI.PropertyField(arcDirectionIndexRect, property.FindPropertyRelative("arcDirectionIndex"), new GUIContent("Arc index")); EditorGUI.PropertyField(closestDirectionRect, closestDirection, new GUIContent("Direction Closest To"), true); break; } } // Set indent back to what it was EditorGUI.indentLevel = indent; EditorGUI.EndProperty(); }