/// <inheritdoc/> protected override bool OnAttached() { if (!base.OnAttached() || this.TouchCursorEntity == null) { return(false); } this.touchCursor = this.TouchCursorEntity.FindComponentInChildren <CursorTouch>(); this.xrJoint = this.TouchCursorEntity.FindComponent <TrackXRJoint>(); this.cursorCollisionCategoryMask = this.TouchCursorEntity.FindComponent <StaticBody3D>().MaskBits; this.UpdateOrder = this.touchCursor.UpdateOrder + 0.1f; // Ensure this is executed always after the main Cursor this.cam = this.Managers.RenderManager.ActiveCamera3D; this.handrayTexture = this.rayLineMesh.DiffuseTexture; return(true); }
/// <summary> /// Check if the join is valid (hololens data can be considered valid). /// </summary> /// <param name="joint">The joint to check.</param> /// <returns>Valid or not.</returns> public static bool IsJointValid(TrackXRJoint joint) { return(joint != null && joint.TrackedDevice != null && joint.TrackedDevice.IsConnected && joint.TrackedDevice.PoseIsValid); }
private static Entity CreateCursor(Scene scene, Material releasedMaterial, Material pressedMaterial, XRHandedness handedness, Texture handRayTexture, SamplerState handRaySampler) { Entity cursor = new Entity("Cursor_" + handedness) .AddComponent(new Transform3D()) .AddComponent(new MaterialComponent()) .AddComponent(new PlaneMesh() { TwoSides = true, Normal = Vector3.Forward, Width = 0.01f, Height = 0.01f }) .AddComponent(new MeshRenderer()) .AddComponent(new SphereCollider3D()) .AddComponent(new StaticBody3D() { CollisionCategories = CollisionCategory3D.Cat2, IsSensor = true, MaskBits = CollisionCategory3D.Cat1 }) .AddComponent(new Cursor() { PressedMaterial = pressedMaterial, ReleasedMaterial = releasedMaterial, UpdateOrder = 0.3f }) .AddComponent(new ProximityLight()) ; TrackXRJoint trackXRJoint = null; var xrPlatform = Application.Current.Container.Resolve <XRPlatform>(); if (xrPlatform != null) { trackXRJoint = new TrackXRJoint() { Handedness = handedness, SelectionStrategy = TrackXRDevice.SelectionDeviceStrategy.ByHandedness, JointKind = XRHandJointKind.IndexTip, TrackingLostMode = TrackXRDevice.XRTrackingLostMode.KeepLastPose, }; // HoloLens 2 cursor.AddComponent(trackXRJoint) .AddComponent(new HoloLensControlBehavior()) ; } else { // Windows cursor.AddComponent(new MouseControlBehavior() { key = handedness == XRHandedness.RightHand ? Keys.LeftShift : Keys.Space }); } scene.Managers.EntityManager.Add(cursor); var lineComp = new LineBezierMesh() { IsCameraAligned = true, LinePoints = new List <BezierPointInfo>() { new BezierPointInfo() { Position = Vector3.Zero, Thickness = 0.003f, Color = Color.White }, new BezierPointInfo() { Position = -Vector3.UnitZ, Thickness = 0.003f, Color = Color.White }, }, Resolution = 10, DiffuseTexture = handRayTexture, DiffuseSampler = handRaySampler, TextureTiling = new Vector2(10.0f, 1.0f), }; Entity bezier = new Entity() .AddComponent(new Transform3D()) .AddComponent(lineComp) .AddComponent(new LineMeshRenderer3D()) ; scene.Managers.EntityManager.Add(bezier); Entity cursorDist = new Entity("CursorDist_" + handedness) .AddComponent(new Transform3D()) .AddComponent(new MaterialComponent()) .AddComponent(new PlaneMesh() { Normal = Vector3.Forward, Width = 0.01f, Height = 0.01f }) .AddComponent(new MeshRenderer()) .AddComponent(new SphereCollider3D()) .AddComponent(new StaticBody3D() { CollisionCategories = CollisionCategory3D.Cat2, IsSensor = true, MaskBits = CollisionCategory3D.Cat1 }) .AddComponent(new Cursor() { PressedMaterial = pressedMaterial, ReleasedMaterial = releasedMaterial, UpdateOrder = 0.3f }) .AddComponent(new CursorRay() { MainCursor = cursor.FindComponent <Cursor>(), LineMesh = lineComp, Joint = trackXRJoint, collisionMask = CollisionCategory3D.Cat1 }) .AddComponent(new Billboard()) .AddComponent(new HoverLight()) ; scene.Managers.EntityManager.Add(cursorDist); return(cursor); }