Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[XR] Fix XR picking in utility laters #12998

Merged
merged 5 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/dev/core/src/Behaviors/Meshes/baseSixDofDragBehavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ export class BaseSixDofDragBehavior implements Behavior<Mesh> {
this._virtualMeshesInfo[pointerId] = this._createVirtualMeshInfo();
}
const virtualMeshesInfo = this._virtualMeshesInfo[pointerId];
const isXRPointer = (<IPointerEvent>pointerInfo.event).pointerType === "xr";
const isXRNearPointer = (<IPointerEvent>pointerInfo.event).pointerType === "xr-near";

if (pointerInfo.type == PointerEventTypes.POINTERDOWN) {
if (
Expand All @@ -306,7 +306,7 @@ export class BaseSixDofDragBehavior implements Behavior<Mesh> {
pointerInfo.pickInfo.pickedMesh &&
pointerInfo.pickInfo.pickedPoint &&
pointerInfo.pickInfo.ray &&
(!isXRPointer || pointerInfo.pickInfo.aimTransform) &&
(!isXRNearPointer || pointerInfo.pickInfo.aimTransform) &&
pickPredicate(pointerInfo.pickInfo.pickedMesh)
) {
if (!this.allowMultiPointer && this.currentDraggingPointerIds.length > 0) {
Expand All @@ -325,7 +325,7 @@ export class BaseSixDofDragBehavior implements Behavior<Mesh> {
this._ownerNode.computeWorldMatrix(true);
const virtualMeshesInfo = this._virtualMeshesInfo[pointerId];

if (isXRPointer) {
if (isXRNearPointer) {
this._dragging = pointerInfo.pickInfo.originMesh ? this._dragType.NEAR_DRAG : this._dragType.DRAG_WITH_CONTROLLER;
virtualMeshesInfo.originMesh.position.copyFrom(pointerInfo.pickInfo.aimTransform!.position);
if (this._dragging === this._dragType.NEAR_DRAG && pointerInfo.pickInfo.gripTransform) {
Expand All @@ -351,7 +351,7 @@ export class BaseSixDofDragBehavior implements Behavior<Mesh> {
virtualMeshesInfo.startingOrientation.copyFrom(virtualMeshesInfo.dragMesh.rotationQuaternion!);
virtualMeshesInfo.startingPivotOrientation.copyFrom(virtualMeshesInfo.pivotMesh.rotationQuaternion!);

if (isXRPointer) {
if (isXRNearPointer) {
virtualMeshesInfo.originMesh.addChild(virtualMeshesInfo.dragMesh);
virtualMeshesInfo.originMesh.addChild(virtualMeshesInfo.pivotMesh);
} else {
Expand Down Expand Up @@ -415,7 +415,7 @@ export class BaseSixDofDragBehavior implements Behavior<Mesh> {
}

this._ownerNode.computeWorldMatrix(true);
if (!isXRPointer) {
if (!isXRNearPointer) {
this._pointerUpdate2D(pointerInfo.pickInfo.ray!, pointerId, zDragFactor);
} else {
this._pointerUpdateXR(pointerInfo.pickInfo.aimTransform!, pointerInfo.pickInfo.gripTransform, pointerId, zDragFactor);
Expand Down
5 changes: 5 additions & 0 deletions packages/dev/core/src/Events/pointerEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ export class PointerInfoPre extends PointerInfoBase {
*/
public nearInteractionPickingInfo: Nullable<PickingInfo>;

/**
* The original picking info that was used to trigger the pointer event
*/
public originalPickingInfo: Nullable<PickingInfo> = null;

/**
* Defines the local position of the pointer on the canvas.
*/
Expand Down
1 change: 1 addition & 0 deletions packages/dev/core/src/Inputs/scene.inputManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ export class InputManager {
const scene = this._scene;
const pi = new PointerInfoPre(type, evt, this._unTranslatedPointerX, this._unTranslatedPointerY);
if (pickResult) {
pi.originalPickingInfo = pickResult;
pi.ray = pickResult.ray;
if (pickResult.originMesh) {
pi.nearInteractionPickingInfo = pickResult;
Expand Down
16 changes: 10 additions & 6 deletions packages/dev/core/src/Rendering/utilityLayerRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ export class UtilityLayerRenderer implements IDisposable {
} else {
scenePick = new PickingInfo();
}
} else if (scene !== this.utilityLayerScene && prePointerInfo.originalPickingInfo) {
scenePick = prePointerInfo.originalPickingInfo;
} else {
let previousActiveCamera: Nullable<Camera> = null;
// If a camera is set for rendering with this layer
Expand Down Expand Up @@ -290,18 +292,20 @@ export class UtilityLayerRenderer implements IDisposable {
if (!prePointerInfo.skipOnPointerObservable) {
prePointerInfo.skipOnPointerObservable = utilityScenePick.distance > 0;
}
} else if (!this._pointerCaptures[pointerEvent.pointerId] && utilityScenePick.distance > originalScenePick.distance) {
} else if (!this._pointerCaptures[pointerEvent.pointerId] && utilityScenePick.distance >= originalScenePick.distance) {
// We have a pick in both scenes but main is closer than utility

// We touched an utility mesh present in the main scene
if (this.mainSceneTrackerPredicate && this.mainSceneTrackerPredicate(originalScenePick.pickedMesh)) {
this._notifyObservers(prePointerInfo, originalScenePick, pointerEvent);
prePointerInfo.skipOnPointerObservable = true;
} else if (prePointerInfo.type === PointerEventTypes.POINTERMOVE || prePointerInfo.type === PointerEventTypes.POINTERUP) {
if (this._lastPointerEvents[pointerEvent.pointerId]) {
// We need to send a last pointerup to the utilityLayerScene to make sure animations can complete
this.onPointerOutObservable.notifyObservers(pointerEvent.pointerId);
delete this._lastPointerEvents[pointerEvent.pointerId];
} else {
if (prePointerInfo.type === PointerEventTypes.POINTERMOVE || prePointerInfo.type === PointerEventTypes.POINTERUP) {
if (this._lastPointerEvents[pointerEvent.pointerId]) {
// We need to send a last pointerup to the utilityLayerScene to make sure animations can complete
this.onPointerOutObservable.notifyObservers(pointerEvent.pointerId);
delete this._lastPointerEvents[pointerEvent.pointerId];
}
}
this._notifyObservers(prePointerInfo, utilityScenePick, pointerEvent);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/dev/core/src/XR/features/WebXRNearInteraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ export class WebXRNearInteraction extends WebXRAbstractFeature {
const controllerData = this._controllers[xrController.uniqueId];
const pointerEventInit: PointerEventInit = {
pointerId: controllerData.id,
pointerType: "xr",
pointerType: "xr-near",
};
controllerData.onFrameObserver = this._xrSessionManager.onXRFrameObservable.add(() => {
if (
Expand Down Expand Up @@ -766,7 +766,7 @@ export class WebXRNearInteraction extends WebXRAbstractFeature {
// Fire a pointerup
const pointerEventInit: PointerEventInit = {
pointerId: controllerData.id,
pointerType: "xr",
pointerType: "xr-near",
};
this._scene.simulatePointerUp(new PickingInfo(), pointerEventInit);
});
Expand Down