void Start() { _input = IsLeft ? SimpleWebXR.LeftInput : SimpleWebXR.RightInput; _input.SelectStart.AddListener(() => StartCoroutine(DrawCoroutine())); _input.SelectEnd.AddListener(StopAllCoroutines); _renderer = GetComponent <MeshRenderer>(); }
protected void UpdateController(WebXRInputSource controller, Handedness handedness) { if (controller.Available && (controller.IsPositionTracked || controller.Hand.Available)) { if (controller.Hand.Available) { RemoveControllerDevice(handedness); GetOrAddHand(handedness)?.UpdateController(controller); } else { RemoveHandDevice(handedness); GetOrAddController(handedness)?.UpdateController(controller); } } else { RemoveControllerDevice(handedness); RemoveHandDevice(handedness); } }
public void UpdateController(WebXRInputSource controller) { if (!Enabled) { return; } IsPositionAvailable = IsRotationAvailable = controller.Hand.Available; jointPoses[TrackedHandJoint.Wrist] = GetJointMixedRealityPose(controller.Hand.Joints[WebXRHand.WRIST]); for (int i = WebXRHand.THUMB_METACARPAL; i < WebXRHand.JOINT_COUNT; i++) { var joint = controller.Hand.Joints[i]; jointPoses[(TrackedHandJoint)(i + 2)] = GetJointMixedRealityPose(joint); } jointPoses[TrackedHandJoint.Palm] = new MixedRealityPose((jointPoses[TrackedHandJoint.MiddleMetacarpal].Position + jointPoses[TrackedHandJoint.MiddleMetacarpal].Position) / 2, jointPoses[TrackedHandJoint.MiddleMetacarpal].Rotation); var indexPose = jointPoses[TrackedHandJoint.IndexTip]; bool isSelecting; MixedRealityPose spatialPointerPose; if (controller.IsPositionTracked) { isSelecting = controller.Selected; spatialPointerPose = new MixedRealityPose(MixedRealityPlayspace.TransformPoint(controller.Position), MixedRealityPlayspace.Rotation * controller.Rotation); } else { // Is selecting if thumb tip and index tip are close isSelecting = Vector3.Distance(controller.Hand.Joints[WebXRHand.THUMB_PHALANX_TIP].Position, controller.Hand.Joints[WebXRHand.INDEX_PHALANX_TIP].Position) < 0.04; // The hand ray starts from the middle of thumb tip and index tip HandRay.Update((controller.Hand.Joints[WebXRHand.THUMB_PHALANX_TIP].Position + controller.Hand.Joints[WebXRHand.INDEX_PHALANX_TIP].Position) / 2, new Vector3(0.3f, -0.4f, 0.9f), CameraCache.Main.transform, ControllerHandedness); Ray ray = HandRay.Ray; spatialPointerPose = new MixedRealityPose(ray.origin, Quaternion.LookRotation(ray.direction)); } CoreServices.InputSystem?.RaiseSourcePoseChanged(InputSource, this, spatialPointerPose); CoreServices.InputSystem?.RaiseHandJointsUpdated(InputSource, ControllerHandedness, jointPoses); UpdateVelocity(); for (int i = 0; i < Interactions?.Length; i++) { switch (Interactions[i].InputType) { case DeviceInputType.SpatialPointer: Interactions[i].PoseData = spatialPointerPose; if (Interactions[i].Changed) { CoreServices.InputSystem?.RaisePoseInputChanged(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction, Interactions[i].PoseData); } break; case DeviceInputType.SpatialGrip: Interactions[i].PoseData = indexPose; if (Interactions[i].Changed) { CoreServices.InputSystem?.RaisePoseInputChanged(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction, Interactions[i].PoseData); } break; case DeviceInputType.Select: Interactions[i].BoolData = isSelecting || controller.TargetRayMode == WebXRTargetRayModes.Screen; if (Interactions[i].Changed) { if (Interactions[i].BoolData) { CoreServices.InputSystem?.RaiseOnInputDown(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction); } else { CoreServices.InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction); } } break; case DeviceInputType.TriggerPress: Interactions[i].BoolData = isSelecting; if (Interactions[i].Changed) { if (Interactions[i].BoolData) { CoreServices.InputSystem?.RaiseOnInputDown(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction); } else { CoreServices.InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction); } } break; case DeviceInputType.IndexFinger: Interactions[i].PoseData = indexPose; if (Interactions[i].Changed) { CoreServices.InputSystem?.RaisePoseInputChanged(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction, Interactions[i].PoseData); } break; case DeviceInputType.ThumbStick: HandDefinition?.UpdateCurrentTeleportPose(Interactions[i]); break; } } }
public void UpdateController(WebXRInputSource controller) { if (!Enabled) { return; } var position = MixedRealityPlayspace.TransformPoint(controller.Position); var rotation = MixedRealityPlayspace.Rotation * controller.Rotation; var pose = new MixedRealityPose(position, rotation); for (int i = 0; i < Interactions?.Length; i++) { switch (Interactions[i].InputType) { case DeviceInputType.SpatialPointer: Interactions[i].PoseData = pose; if (Interactions[i].Changed) { CoreServices.InputSystem?.RaisePoseInputChanged(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction, pose); } break; case DeviceInputType.SpatialGrip: Interactions[i].PoseData = pose; if (Interactions[i].Changed) { CoreServices.InputSystem?.RaisePoseInputChanged(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction, pose); } break; case DeviceInputType.Select: Interactions[i].BoolData = controller.Selected; if (Interactions[i].Changed) { if (Interactions[i].BoolData) { CoreServices.InputSystem?.RaiseOnInputDown(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction); } else { CoreServices.InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction); } } break; case DeviceInputType.TriggerPress: Interactions[i].BoolData = controller.Squeezed; if (Interactions[i].Changed) { if (Interactions[i].BoolData) { CoreServices.InputSystem?.RaiseOnInputDown(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction); } else { CoreServices.InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction); } } break; } } }
public void UpdateController(WebXRInputSource controller) { if (!Enabled) { return; } IsPositionAvailable = IsRotationAvailable = controller.Hand.Available; for (int i = 0; i < WebXRHand.JOINT_COUNT; i++) { var joint = controller.Hand.Joints[i]; jointPoses[(TrackedHandJoint)(i + 1)] = new MixedRealityPose(joint.Position, joint.Rotation); } var indexJoint = controller.Hand.Joints[WebXRHand.INDEX_PHALANX_TIP]; var indexPose = new MixedRealityPose(indexJoint.Position, indexJoint.Rotation); bool isSelecting; MixedRealityPose spatialPointerPose; if (controller.IsPositionTracked) { isSelecting = controller.Selected; spatialPointerPose = new MixedRealityPose(controller.Position, controller.Rotation); } else { // Is selecting if thumb tip and index tip are close isSelecting = Vector3.Distance(controller.Hand.Joints[WebXRHand.THUMB_PHALANX_TIP].Position, controller.Hand.Joints[WebXRHand.INDEX_PHALANX_TIP].Position) < 0.04; // The hand ray starts from the middle of thumb tip and index tip HandRay.Update((controller.Hand.Joints[WebXRHand.THUMB_PHALANX_TIP].Position + controller.Hand.Joints[WebXRHand.INDEX_PHALANX_TIP].Position) / 2, new Vector3(0.3f, -0.4f, 0.9f), CameraCache.Main.transform, ControllerHandedness); Ray ray = HandRay.Ray; spatialPointerPose = new MixedRealityPose(ray.origin, Quaternion.LookRotation(ray.direction)); } CoreServices.InputSystem?.RaiseSourcePoseChanged(InputSource, this, spatialPointerPose); CoreServices.InputSystem?.RaiseHandJointsUpdated(InputSource, ControllerHandedness, jointPoses); UpdateVelocity(); for (int i = 0; i < Interactions?.Length; i++) { switch (Interactions[i].InputType) { case DeviceInputType.SpatialPointer: Interactions[i].PoseData = spatialPointerPose; if (Interactions[i].Changed) { CoreServices.InputSystem?.RaisePoseInputChanged(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction, Interactions[i].PoseData); } break; case DeviceInputType.SpatialGrip: Interactions[i].PoseData = indexPose; if (Interactions[i].Changed) { CoreServices.InputSystem?.RaisePoseInputChanged(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction, Interactions[i].PoseData); } break; case DeviceInputType.Select: Interactions[i].BoolData = isSelecting; if (Interactions[i].Changed) { if (Interactions[i].BoolData) { CoreServices.InputSystem?.RaiseOnInputDown(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction); } else { CoreServices.InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction); } } break; case DeviceInputType.TriggerPress: Interactions[i].BoolData = isSelecting; if (Interactions[i].Changed) { if (Interactions[i].BoolData) { CoreServices.InputSystem?.RaiseOnInputDown(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction); } else { CoreServices.InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction); } } break; case DeviceInputType.IndexFinger: Interactions[i].PoseData = indexPose; if (Interactions[i].Changed) { CoreServices.InputSystem?.RaisePoseInputChanged(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction, Interactions[i].PoseData); } break; } } }