void LoadOffThread(uint controllerId, SpatialInteractionController controller, SpatialInteractionSourceHandedness handedness) { #if UNITY_WSA && ENABLE_WINMD_SUPPORT System.Diagnostics.Debug.WriteLine("ControllerModelProvider Loading Model"); System.Threading.Tasks.Task.Run(() => { try { var getModelTask = controller.TryGetRenderableModelAsync().AsTask(); getModelTask.Wait(); var modelStream = getModelTask.Result; byte[] fileBytes = new byte[modelStream.Size]; using (DataReader reader = new DataReader(modelStream)) { var loadTask = reader.LoadAsync((uint)modelStream.Size).AsTask(); loadTask.Wait(); reader.ReadBytes(fileBytes); System.Diagnostics.Debug.WriteLine("LoadOffThread read: " + fileBytes.Length); } AddController(controllerId, controller, fileBytes, handedness); } catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); System.Diagnostics.Debug.WriteLine(ex.StackTrace); } }); #endif }
private void UpdateHand(HandPose handPose, SpatialInteractionSourceHandedness handedness) { var handIdx = HandednessToIndex(handedness); var jointArray = handedness == SpatialInteractionSourceHandedness.Right ? rightHandObjects : leftHandObjects; var coordSys = SpatialCoordinateSystemToUnityUtilities.UnitySpatialCoordinateSystem; if (handPose.TryGetJoints(coordSys, jointIndices, jointPoses)) { handVelocity[handIdx] = jointArray[0].transform.position - SystemVector3ToUnity(jointPoses[0].Position); for (int i = 0; i < jointPoses.Length; ++i) { jointArray[i].SetActive(true); var rb = jointArray[i].GetComponent <Rigidbody>(); if (rb) { rb.MovePosition(SystemVector3ToUnity(jointPoses[i].Position)); rb.MoveRotation(SystemQuaternionToUnity(jointPoses[i].Orientation).normalized); } else { jointArray[i].transform.SetPositionAndRotation( SystemVector3ToUnity(jointPoses[i].Position), SystemQuaternionToUnity(jointPoses[i].Orientation)); } } } }
internal WindowsMixedRealityTouchController(TouchControllerHand hand, SpatialInteractionManager interactionManager) { this.hand = (SpatialInteractionSourceHandedness)(hand + 1); this.interactionManager = interactionManager; interactionManager.SourceLost += InteractionManager_SourceLost; }
/// <summary> /// Converts a platform <see cref="SpatialInteractionSourceHandedness"/> into /// the equivalent value in MRTK's defined <see cref="Handedness"/>. /// </summary> /// <param name="handedness">The handedness value to convert.</param> /// <returns>The converted value in the new type.</returns> public static Handedness ToMRTKHandedness(this SpatialInteractionSourceHandedness handedness) { switch (handedness) { case SpatialInteractionSourceHandedness.Left: return(Handedness.Left); case SpatialInteractionSourceHandedness.Right: return(Handedness.Right); case SpatialInteractionSourceHandedness.Unspecified: default: return(Handedness.None); } }
/// <summary> /// Converts the native <see cref="SpatialInteractionSourceHandedness"/> to a XRTK <see cref="Handedness"/>. /// </summary> /// <param name="spatialInteractionSourceHandedness">Value to convert.</param> /// <returns>The XRTK <see cref="Handedness"/> value.</returns> public static Handedness ToHandedness(this SpatialInteractionSourceHandedness spatialInteractionSourceHandedness) { switch (spatialInteractionSourceHandedness) { case SpatialInteractionSourceHandedness.Left: return(Handedness.Left); case SpatialInteractionSourceHandedness.Right: return(Handedness.Right); case SpatialInteractionSourceHandedness.Unspecified: return(Handedness.Other); default: throw new ArgumentOutOfRangeException($"{nameof(SpatialInteractionSourceHandedness)}.{spatialInteractionSourceHandedness} could not be mapped to {nameof(Handedness)}"); } }
private void UpdateHands() { PerceptionTimestamp perceptionTimestamp = PerceptionTimestampHelper.FromHistoricalTargetTime(DateTimeOffset.Now); IReadOnlyList <SpatialInteractionSourceState> sources = SpatialInteractionManager?.GetDetectedSourcesAtTimestamp(perceptionTimestamp); foreach (SpatialInteractionSourceState sourceState in sources) { HandPose handPose = sourceState.TryGetHandPose(); if (handPose != null && handPose.TryGetJoints(SpatialCoordinateSystem, jointIndices, jointPoses)) { SpatialInteractionSourceHandedness handIndex = sourceState.Source.Handedness; if (handIndex == SpatialInteractionSourceHandedness.Left) { ApplyTransforms(leftHandProxy, jointPoses); } else { ApplyTransforms(rightHandProxy, jointPoses); } } } }
void AddController(uint id, SpatialInteractionController controller, byte[] data, SpatialInteractionSourceHandedness handedness) { string productId = MakeProductIdHash(controller, handedness); if (loadingModels.Contains(productId)) { loadingModels.Remove(productId); } if (cachedModels.ContainsKey(productId)) { if (!activeControllers.ContainsKey(id)) { activeControllers.Add(id, productId); } } else { cachedModels.Add(productId, data); activeControllers.Add(id, productId); } #if DEBUG && SAVEMODEL try { SaveModel(productId, data); } catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); System.Diagnostics.Debug.WriteLine(ex.StackTrace); } #endif UnityEngine.WSA.Application.InvokeOnAppThread(() => { TraceHelper.Log("ControllerModelProvider::AddController: " + productId); var eh = ControllerModelAvailable; if (eh != null) { eh(this, new NewControllerModelAvailableEventArgs(id, productId, data)); } }, true); }
private string MakeProductIdHash(SpatialInteractionController controller, SpatialInteractionSourceHandedness handedness) { return(string.Format("{0}-{1}-{2}-{3}", controller.VendorId, controller.ProductId, controller.Version, handedness).ToLower()); }
public bool Contains(SpatialInteractionController controller, SpatialInteractionSourceHandedness handedness) { string id = MakeProductIdHash(controller, handedness); return(cachedModels.ContainsKey(id)); }
int HandednessToIndex(SpatialInteractionSourceHandedness handedness) { return(handedness == SpatialInteractionSourceHandedness.Right ? 1 : 0); }
private bool HasRequestedHandMeshObserver(SpatialInteractionSourceHandedness handedness) => handedness == SpatialInteractionSourceHandedness.Left ? hasRequestedHandMeshObserverLeftHand : handedness == SpatialInteractionSourceHandedness.Right && hasRequestedHandMeshObserverRightHand;