/// <summary> /// Toggles hand joint visualization /// </summary> public void OnToggleHandJoint() { MixedRealityHandTrackingProfile handTrackingProfile = CoreServices.InputSystem?.InputSystemProfile?.HandTrackingProfile; if (handTrackingProfile != null) { handTrackingProfile.EnableHandJointVisualization = !handTrackingProfile.EnableHandJointVisualization; } }
public void InitializeHand(OVRHand ovrHand, OculusXRSDKDeviceManagerProfile deviceManagerSettings) { settingsProfile = deviceManagerSettings; handTrackingProfile = CoreServices.InputSystem?.InputSystemProfile.HandTrackingProfile; handRenderer = ovrHand.GetComponent <Renderer>(); UpdateHandMaterial(settingsProfile.CustomHandMaterial); pinchStrengthProp = Shader.PropertyToID(settingsProfile.PinchStrengthMaterialProperty); }
void updateHandVisibility() { MixedRealityHandTrackingProfile handTrackingProfile = InputSystem?.InputSystemProfile?.HandTrackingProfile; if (handTrackingProfile != null) { handTrackingProfile.EnableHandMeshVisualization = isHandMeshVisible; handTrackingProfile.EnableHandJointVisualization = isHandJointVisible; } }
void updateHandVisibility() { MixedRealityHandTrackingProfile handTrackingProfile = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.HandTrackingProfile; if (handTrackingProfile != null) { handTrackingProfile.EnableHandMeshVisualization = isHandMeshVisible; handTrackingProfile.EnableHandJointVisualization = isHandJointVisible; } }
// Start is called before the first frame update void Start() { profilerButton.IsToggled = (CoreServices.DiagnosticsSystem?.ShowProfiler).GetValueOrDefault(false); handRayButton.IsToggled = PointerUtils.GetPointerBehavior <ShellHandRayPointer>(Handedness.Any, InputSourceType.Hand) != PointerBehavior.AlwaysOff; MixedRealityHandTrackingProfile handProfile = null; if (CoreServices.InputSystem?.InputSystemProfile != null) { handProfile = CoreServices.InputSystem.InputSystemProfile.HandTrackingProfile; } handMeshButton.IsToggled = (handProfile != null) ? handProfile.EnableHandMeshVisualization : false; handJointsButton.IsToggled = (handProfile != null) ? handProfile.EnableHandJointVisualization : false; }
public void TestEditorOnlyChanges() { MixedRealityHandTrackingProfile profile = ScriptableObject.CreateInstance <MixedRealityHandTrackingProfile>(); profile.HandJointVisualizationModes = SupportedApplicationModes.Editor | SupportedApplicationModes.Player; profile.HandMeshVisualizationModes = SupportedApplicationModes.Editor | SupportedApplicationModes.Player; // Since these tests run in the Unity editor, setting these to false should only clear the // SupportedApplicationModes.Editor from each of the Hand*VisualizationModes properties. profile.EnableHandJointVisualization = false; profile.EnableHandMeshVisualization = false; Assert.AreEqual(SupportedApplicationModes.Player, profile.HandJointVisualizationModes); Assert.AreEqual(SupportedApplicationModes.Player, profile.HandMeshVisualizationModes); }
/// <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; } }
/// <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; } }
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); } } } } }
public void InitializeHand(OVRHand ovrHand, OculusXRSDKDeviceManagerProfile deviceManagerSettings) { settingsProfile = deviceManagerSettings; handTrackingProfile = CoreServices.InputSystem?.InputSystemProfile.HandTrackingProfile; }
/// <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); } } }