/// <inheritdoc/> protected override IMixedRealityServiceConfiguration GetDataProviderConfiguration(int index) { MixedRealityInputSystemProfile targetProfile = target as MixedRealityInputSystemProfile; if (targetProfile != null) { var configurations = targetProfile.DataProviderConfigurations; if (configurations != null && index >= 0 && index < configurations.Length) { return(configurations[index]); } } return(null); }
/// <summary> /// Toggles hand mesh visualization /// </summary> public void OnToggleHandMesh() { MixedRealityInputSystemProfile inputSystemProfile = CoreServices.InputSystem?.InputSystemProfile; if (inputSystemProfile == null) { return; } MixedRealityHandTrackingProfile handTrackingProfile = inputSystemProfile.HandTrackingProfile; if (handTrackingProfile != null) { handTrackingProfile.EnableHandMeshVisualization = !handTrackingProfile.EnableHandMeshVisualization; } }
protected override void OnEnable() { base.OnEnable(); inputSystemProfile = thisProfile.ParentProfile as MixedRealityInputSystemProfile; Debug.Assert(inputSystemProfile != null); if (inputSystemProfile.InputActionsProfile == null) { return; } recognizerStartBehaviour = serializedObject.FindProperty("startBehavior"); recognitionConfidenceLevel = serializedObject.FindProperty("recognitionConfidenceLevel"); speechCommands = serializedObject.FindProperty("speechCommands"); actionLabels = inputSystemProfile.InputActionsProfile.InputActions.Select(action => new GUIContent(action.Description)).Prepend(new GUIContent("None")).ToArray(); actionIds = inputSystemProfile.InputActionsProfile.InputActions.Select(action => (int)action.Id).Prepend(0).ToArray(); }
protected override void OnEnable() { base.OnEnable(); inputSystemProfile = ThisProfile.ParentProfile as MixedRealityInputSystemProfile; if (inputSystemProfile.IsNull() || inputSystemProfile.InputActionsProfile == null) { return; } startBehavior = serializedObject.FindProperty(nameof(startBehavior)); recognitionConfidenceLevel = serializedObject.FindProperty(nameof(recognitionConfidenceLevel)); speechCommands = serializedObject.FindProperty(nameof(speechCommands)); actionLabels = inputSystemProfile.InputActionsProfile.InputActions.Select(action => new GUIContent(action.Description)).Prepend(new GUIContent("None")).ToArray(); actionIds = inputSystemProfile.InputActionsProfile.InputActions.Select(action => (int)action.Id).Prepend(0).ToArray(); }
/// <summary> /// Turns the MRTK hand visualization off when the scene is loaded, to defer to the sample scene's representation. /// </summary> private void Start() { MixedRealityInputSystemProfile inputSystemProfile = CoreServices.InputSystem?.InputSystemProfile; if (inputSystemProfile == null) { return; } handTrackingProfile = inputSystemProfile.HandTrackingProfile; if (handTrackingProfile != null) { originalHandMeshVisualization = handTrackingProfile.EnableHandMeshVisualization; originalHandJointVisualization = handTrackingProfile.EnableHandJointVisualization; handTrackingProfile.EnableHandMeshVisualization = false; handTrackingProfile.EnableHandJointVisualization = false; } }
private void DrawRigidBodyWarning() { // Check if rigidbody is attached - if so show warning in case input profile is not configured for individual collider raycast Rigidbody rigidBody = boundsControl.GetComponent <Rigidbody>(); if (rigidBody != null) { MixedRealityInputSystemProfile profile = Microsoft.MixedReality.Toolkit.CoreServices.InputSystem?.InputSystemProfile; if (profile != null && profile.FocusIndividualCompoundCollider == false) { EditorGUILayout.Space(); // Show warning and button to reconfigure profile EditorGUILayout.HelpBox($"When using Bounds Control in combination with Rigidbody 'Focus Individual Compound Collider' must be enabled in Input Profile.", UnityEditor.MessageType.Warning); if (GUILayout.Button($"Enable 'Focus Individual Compound Collider' in Input Profile")) { profile.FocusIndividualCompoundCollider = true; } EditorGUILayout.Space(); } } }
protected override void OnEnable() { base.OnEnable(); gestures = serializedObject.FindProperty("gestures"); gesturesProfile = target as MixedRealityGesturesProfile; Debug.Assert(gesturesProfile != null); inputSystemProfile = gesturesProfile.ParentProfile as MixedRealityInputSystemProfile; Debug.Assert(inputSystemProfile != null); if (inputSystemProfile.InputActionsProfile != null) { actionLabels = inputSystemProfile.InputActionsProfile.InputActions .Select(action => new GUIContent(action.Description)) .Prepend(new GUIContent("None")).ToArray(); actionIds = inputSystemProfile.InputActionsProfile.InputActions .Select(action => (int)action.Id) .Prepend(0).ToArray(); } UpdateGestureLabels(); }
public void UpdateHandMesh(SpatialInteractionSourceState sourceState) { using (UpdateHandMeshPerfMarker.Auto()) { MixedRealityHandTrackingProfile handTrackingProfile = null; MixedRealityInputSystemProfile inputSystemProfile = CoreServices.InputSystem?.InputSystemProfile; if (inputSystemProfile != null) { handTrackingProfile = inputSystemProfile.HandTrackingProfile; } if (handTrackingProfile == null || !handTrackingProfile.EnableHandMeshVisualization) { // If hand mesh visualization is disabled make sure to destroy our hand mesh observer if it has already been created if (handMeshObserver != null) { // Notify that hand mesh has been updated (cleared) HandMeshInfo handMeshInfo = new HandMeshInfo(); CoreServices.InputSystem?.RaiseHandMeshUpdated(InputSource, Handedness, handMeshInfo); hasRequestedHandMeshObserver = false; handMeshObserver = null; } return; } HandPose handPose = sourceState.TryGetHandPose(); // Accessing the hand mesh data involves copying quite a bit of data, so only do it if application requests it. if (handMeshObserver == null && !hasRequestedHandMeshObserver) { SetHandMeshObserver(sourceState); hasRequestedHandMeshObserver = true; } if (handMeshObserver != null && handPose != null) { if (handMeshTriangleIndices == null) { handMeshTriangleIndices = new ushort[handMeshObserver.TriangleIndexCount]; handMeshTriangleIndicesUnity = new int[handMeshObserver.TriangleIndexCount]; handMeshObserver.GetTriangleIndices(handMeshTriangleIndices); Array.Copy(handMeshTriangleIndices, handMeshTriangleIndicesUnity, (int)handMeshObserver.TriangleIndexCount); // Compute neutral pose Vector3[] neutralPoseVertices = new Vector3[handMeshObserver.VertexCount]; HandPose neutralPose = handMeshObserver.NeutralPose; var neutralVertexAndNormals = new HandMeshVertex[handMeshObserver.VertexCount]; HandMeshVertexState handMeshVertexState = handMeshObserver.GetVertexStateForPose(neutralPose); handMeshVertexState.GetVertices(neutralVertexAndNormals); Parallel.For(0, handMeshObserver.VertexCount, i => { neutralVertexAndNormals[i].Position.ConvertToUnityVector3(ref neutralPoseVertices[i]); }); // Compute UV mapping InitializeUVs(neutralPoseVertices); } if (vertexAndNormals == null) { vertexAndNormals = new HandMeshVertex[handMeshObserver.VertexCount]; handMeshVerticesUnity = new Vector3[handMeshObserver.VertexCount]; handMeshNormalsUnity = new Vector3[handMeshObserver.VertexCount]; } if (vertexAndNormals != null && handMeshTriangleIndices != null) { var handMeshVertexState = handMeshObserver.GetVertexStateForPose(handPose); handMeshVertexState.GetVertices(vertexAndNormals); var meshTransform = handMeshVertexState.CoordinateSystem.TryGetTransformTo(WindowsMixedRealityUtilities.SpatialCoordinateSystem); if (meshTransform.HasValue) { System.Numerics.Matrix4x4.Decompose(meshTransform.Value, out System.Numerics.Vector3 scale, out System.Numerics.Quaternion rotation, out System.Numerics.Vector3 translation); Parallel.For(0, handMeshObserver.VertexCount, i => { vertexAndNormals[i].Position.ConvertToUnityVector3(ref handMeshVerticesUnity[i]); vertexAndNormals[i].Normal.ConvertToUnityVector3(ref handMeshNormalsUnity[i]); }); /// Hands should follow the Playspace to accommodate teleporting, so fold in the Playspace transform. Vector3 positionUnity = MixedRealityPlayspace.TransformPoint(translation.ToUnityVector3()); Quaternion rotationUnity = MixedRealityPlayspace.Rotation * rotation.ToUnityQuaternion(); HandMeshInfo handMeshInfo = new HandMeshInfo { vertices = handMeshVerticesUnity, normals = handMeshNormalsUnity, triangles = handMeshTriangleIndicesUnity, uvs = handMeshUVsUnity, position = positionUnity, rotation = rotationUnity }; CoreServices.InputSystem?.RaiseHandMeshUpdated(InputSource, Handedness, handMeshInfo); } } } } }
private void OnFocus() { if (window == null) { Close(); } currentControllerTexture = ControllerMappingLibrary.GetControllerTexture(mappingProfile, currentControllerType, currentHandedness); inputSystemProfile = mappingProfile.ParentProfile.ParentProfile as MixedRealityInputSystemProfile; if (inputSystemProfile == null) { Debug.LogWarning("No Input System Profile found. Be sure to assign this mapping profile to an input system."); return; } #region Interaction Constraint Setup actionIds = inputSystemProfile.InputActionsProfile.InputActions .Select(action => (int)action.Id) .Prepend(0).ToArray(); axisLabels = ControllerMappingLibrary.UnityInputManagerAxes .Select(axis => new GUIContent(axis.Name)) .Prepend(new GUIContent(ControllerMappingLibrary.MouseScroll)) .Prepend(new GUIContent(ControllerMappingLibrary.MouseY)) .Prepend(new GUIContent(ControllerMappingLibrary.MouseX)) .Prepend(new GUIContent(ControllerMappingLibrary.Vertical)) .Prepend(new GUIContent(ControllerMappingLibrary.Horizontal)) .Prepend(new GUIContent("None")).ToArray(); actionIds = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.None) .Select(action => (int)action.Id) .Prepend(0).ToArray(); actionLabels = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.None) .Select(inputAction => new GUIContent(inputAction.Description)) .Prepend(new GUIContent("None")).ToArray(); rawActionIds = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.Raw) .Select(action => (int)action.Id) .Prepend(0).ToArray(); rawActionLabels = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.Raw) .Select(inputAction => new GUIContent(inputAction.Description)) .Prepend(new GUIContent("None")).ToArray(); digitalActionIds = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.Digital) .Select(action => (int)action.Id) .Prepend(0).ToArray(); digitalActionLabels = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.Digital) .Select(inputAction => new GUIContent(inputAction.Description)) .Prepend(new GUIContent("None")).ToArray(); singleAxisActionIds = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.SingleAxis) .Select(action => (int)action.Id) .Prepend(0).ToArray(); singleAxisActionLabels = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.SingleAxis) .Select(inputAction => new GUIContent(inputAction.Description)) .Prepend(new GUIContent("None")).ToArray(); dualAxisActionIds = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.DualAxis) .Select(action => (int)action.Id).Prepend(0).ToArray(); dualAxisActionLabels = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.DualAxis) .Select(inputAction => new GUIContent(inputAction.Description)) .Prepend(new GUIContent("None")).ToArray(); threeDofPositionActionIds = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.ThreeDofPosition) .Select(action => (int)action.Id) .Prepend(0).ToArray(); threeDofPositionActionLabels = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.ThreeDofPosition) .Select(inputAction => new GUIContent(inputAction.Description)) .Prepend(new GUIContent("None")).ToArray(); threeDofRotationActionIds = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.ThreeDofRotation) .Select(action => (int)action.Id) .Prepend(0).ToArray(); threeDofRotationActionLabels = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.ThreeDofRotation) .Select(inputAction => new GUIContent(inputAction.Description)) .Prepend(new GUIContent("None")).ToArray(); sixDofActionIds = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.SixDof) .Select(action => (int)action.Id) .Prepend(0).ToArray(); sixDofActionLabels = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.SixDof) .Select(inputAction => new GUIContent(inputAction.Description)) .Prepend(new GUIContent("None")).ToArray(); #endregion Interaction Constraint Setup }
/// <summary> /// Updates the current hand mesh based on the passed in state of the hand. /// </summary> /// <param name="sourceState">The current hand state.</param> public void UpdateHandMesh(SpatialInteractionSourceState sourceState) { MixedRealityHandTrackingProfile handTrackingProfile = null; MixedRealityInputSystemProfile inputSystemProfile = CoreServices.InputSystem?.InputSystemProfile; if (inputSystemProfile != null) { handTrackingProfile = inputSystemProfile.HandTrackingProfile; } if (handTrackingProfile == null || !handTrackingProfile.EnableHandMeshVisualization) { // If hand mesh visualization is disabled make sure to destroy our hand mesh observer if it has already been created if (handMeshObserver != null) { // Notify that hand mesh has been updated (cleared) HandMeshInfo handMeshInfo = new HandMeshInfo(); CoreServices.InputSystem?.RaiseHandMeshUpdated(inputSource, handedness, handMeshInfo); hasRequestedHandMeshObserver = false; handMeshObserver = null; } return; } HandPose handPose = sourceState.TryGetHandPose(); // Accessing the hand mesh data involves copying quite a bit of data, so only do it if application requests it. if (handMeshObserver == null && !hasRequestedHandMeshObserver) { SetHandMeshObserver(sourceState); hasRequestedHandMeshObserver = true; } if (handMeshObserver != null && handMeshTriangleIndices == null) { uint indexCount = handMeshObserver.TriangleIndexCount; ushort[] indices = new ushort[indexCount]; handMeshObserver.GetTriangleIndices(indices); handMeshTriangleIndices = new int[indexCount]; Array.Copy(indices, handMeshTriangleIndices, (int)handMeshObserver.TriangleIndexCount); // Compute neutral pose Vector3[] neutralPoseVertices = new Vector3[handMeshObserver.VertexCount]; HandPose neutralPose = handMeshObserver.NeutralPose; var vertexAndNormals = new HandMeshVertex[handMeshObserver.VertexCount]; HandMeshVertexState handMeshVertexState = handMeshObserver.GetVertexStateForPose(neutralPose); handMeshVertexState.GetVertices(vertexAndNormals); for (int i = 0; i < handMeshObserver.VertexCount; i++) { neutralPoseVertices[i] = vertexAndNormals[i].Position.ToUnityVector3(); } // Compute UV mapping InitializeUVs(neutralPoseVertices); } if (handPose != null && handMeshObserver != null && handMeshTriangleIndices != null) { var vertexAndNormals = new HandMeshVertex[handMeshObserver.VertexCount]; var handMeshVertexState = handMeshObserver.GetVertexStateForPose(handPose); handMeshVertexState.GetVertices(vertexAndNormals); var meshTransform = handMeshVertexState.CoordinateSystem.TryGetTransformTo(WindowsMixedRealityUtilities.SpatialCoordinateSystem); if (meshTransform.HasValue) { System.Numerics.Vector3 scale; System.Numerics.Quaternion rotation; System.Numerics.Vector3 translation; System.Numerics.Matrix4x4.Decompose(meshTransform.Value, out scale, out rotation, out translation); var handMeshVertices = new Vector3[handMeshObserver.VertexCount]; var handMeshNormals = new Vector3[handMeshObserver.VertexCount]; for (int i = 0; i < handMeshObserver.VertexCount; i++) { handMeshVertices[i] = vertexAndNormals[i].Position.ToUnityVector3(); handMeshNormals[i] = vertexAndNormals[i].Normal.ToUnityVector3(); } HandMeshInfo handMeshInfo = new HandMeshInfo { vertices = handMeshVertices, normals = handMeshNormals, triangles = handMeshTriangleIndices, uvs = handMeshUVs, position = translation.ToUnityVector3(), rotation = rotation.ToUnityQuaternion() }; CoreServices.InputSystem?.RaiseHandMeshUpdated(inputSource, handedness, handMeshInfo); } } }
private void OnFocus() { currentControllerTexture = ControllerMappingLibrary.GetControllerTexture(mappingProfile, currentControllerType, currentHandedness); inputSystemProfile = mappingProfile.ParentProfile.ParentProfile as MixedRealityInputSystemProfile; #region Interaction Constraint Setup actionIds = inputSystemProfile.InputActionsProfile.InputActions .Select(action => (int)action.Id) .Prepend(0).ToArray(); axisLabels = ControllerMappingLibrary.UnityInputManagerAxes .Select(axis => new GUIContent(axis.Name)) .Prepend(new GUIContent("None")).ToArray(); actionIds = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.None) .Select(action => (int)action.Id) .Prepend(0).ToArray(); actionLabels = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.None) .Select(inputAction => new GUIContent(inputAction.Description)) .Prepend(new GUIContent("None")).ToArray(); rawActionIds = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.Raw) .Select(action => (int)action.Id) .Prepend(0).ToArray(); rawActionLabels = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.Raw) .Select(inputAction => new GUIContent(inputAction.Description)) .Prepend(new GUIContent("None")).ToArray(); digitalActionIds = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.Digital) .Select(action => (int)action.Id) .Prepend(0).ToArray(); digitalActionLabels = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.Digital) .Select(inputAction => new GUIContent(inputAction.Description)) .Prepend(new GUIContent("None")).ToArray(); singleAxisActionIds = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.SingleAxis) .Select(action => (int)action.Id) .Prepend(0).ToArray(); singleAxisActionLabels = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.SingleAxis) .Select(inputAction => new GUIContent(inputAction.Description)) .Prepend(new GUIContent("None")).ToArray(); dualAxisActionIds = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.DualAxis) .Select(action => (int)action.Id).Prepend(0).ToArray(); dualAxisActionLabels = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.DualAxis) .Select(inputAction => new GUIContent(inputAction.Description)) .Prepend(new GUIContent("None")).ToArray(); threeDofPositionActionIds = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.ThreeDofPosition) .Select(action => (int)action.Id) .Prepend(0).ToArray(); threeDofPositionActionLabels = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.ThreeDofPosition) .Select(inputAction => new GUIContent(inputAction.Description)) .Prepend(new GUIContent("None")).ToArray(); threeDofRotationActionIds = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.ThreeDofRotation) .Select(action => (int)action.Id) .Prepend(0).ToArray(); threeDofRotationActionLabels = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.ThreeDofRotation) .Select(inputAction => new GUIContent(inputAction.Description)) .Prepend(new GUIContent("None")).ToArray(); sixDofActionIds = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.SixDof) .Select(action => (int)action.Id) .Prepend(0).ToArray(); sixDofActionLabels = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.SixDof) .Select(inputAction => new GUIContent(inputAction.Description)) .Prepend(new GUIContent("None")).ToArray(); #endregion Interaction Constraint Setup }
public MapRaycastProvider( IMixedRealityServiceRegistrar registrar, MixedRealityInputSystemProfile profile) : base(registrar, profile) { }
public MapRaycastProvider(MixedRealityInputSystemProfile profile) : base(profile) { }