Skip to content

Commit

Permalink
Some fixes for 6DoF (#14911)
Browse files Browse the repository at this point in the history
* Raise pointer up if pointer down was raised when switching controllers

* XR events instead of near-xr events

* code doc

* set the children's isNearGrabbable to true as well

* fix doc
  • Loading branch information
RaananW committed Mar 27, 2024
1 parent 732f023 commit 470b08c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
12 changes: 6 additions & 6 deletions packages/dev/core/src/Behaviors/Meshes/baseSixDofDragBehavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ export class BaseSixDofDragBehavior implements Behavior<Mesh> {
this._virtualMeshesInfo[pointerId] = this._createVirtualMeshInfo();
}
const virtualMeshesInfo = this._virtualMeshesInfo[pointerId];
const isXRNearPointer = (<IPointerEvent>pointerInfo.event).pointerType === "xr-near";
const isXRPointer = (<IPointerEvent>pointerInfo.event).pointerType === "xr-near" || (<IPointerEvent>pointerInfo.event).pointerType === "xr";

if (pointerInfo.type == PointerEventTypes.POINTERDOWN) {
if (
Expand All @@ -307,10 +307,10 @@ export class BaseSixDofDragBehavior implements Behavior<Mesh> {
pointerInfo.pickInfo.pickedMesh &&
pointerInfo.pickInfo.pickedPoint &&
pointerInfo.pickInfo.ray &&
(!isXRNearPointer || pointerInfo.pickInfo.aimTransform) &&
(!isXRPointer || pointerInfo.pickInfo.aimTransform) &&
pickPredicate(pointerInfo.pickInfo.pickedMesh)
) {
if (!this.allowMultiPointer && this.currentDraggingPointerIds.length > 0) {
if ((!this.allowMultiPointer || isXRPointer) && this.currentDraggingPointerIds.length > 0) {
return;
}

Expand All @@ -326,7 +326,7 @@ export class BaseSixDofDragBehavior implements Behavior<Mesh> {
this._ownerNode.computeWorldMatrix(true);
const virtualMeshesInfo = this._virtualMeshesInfo[pointerId];

if (isXRNearPointer) {
if (isXRPointer) {
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 @@ -352,7 +352,7 @@ export class BaseSixDofDragBehavior implements Behavior<Mesh> {
virtualMeshesInfo.startingOrientation.copyFrom(virtualMeshesInfo.dragMesh.rotationQuaternion!);
virtualMeshesInfo.startingPivotOrientation.copyFrom(virtualMeshesInfo.pivotMesh.rotationQuaternion!);

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

this._ownerNode.computeWorldMatrix(true);
if (!isXRNearPointer) {
if (!isXRPointer) {
this._pointerUpdate2D(pointerInfo.pickInfo.ray!, pointerId, zDragFactor);
} else {
this._pointerUpdateXR(pointerInfo.pickInfo.aimTransform!, pointerInfo.pickInfo.gripTransform, pointerId, zDragFactor);
Expand Down
6 changes: 5 additions & 1 deletion packages/dev/core/src/Behaviors/Meshes/sixDofDragBehavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,17 @@ export class SixDofDragBehavior extends BaseSixDofDragBehavior {

/**
* Attaches the six DoF drag behavior
* In XR mode the mesh and its children will have their isNearGrabbable property set to true
* @param ownerNode The mesh that will be dragged around once attached
*/
public attach(ownerNode: Mesh): void {
super.attach(ownerNode);

ownerNode.isNearGrabbable = true;
// if it has children, make sure they are grabbable too
ownerNode.getChildMeshes().forEach((m) => {
m.isNearGrabbable = true;
});

// Node that will save the owner's transform
this._virtualTransformNode = new TransformNode("virtual_sixDof", BaseSixDofDragBehavior._virtualScene);
Expand Down Expand Up @@ -255,7 +260,6 @@ export class SixDofDragBehavior extends BaseSixDofDragBehavior {
super.detach();

if (this._ownerNode) {
(this._ownerNode as Mesh).isNearGrabbable = false;
this._ownerNode.getScene().onBeforeRenderObservable.remove(this._sceneRenderObserver);
}

Expand Down
7 changes: 5 additions & 2 deletions packages/dev/core/src/Meshes/abstractMesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,12 +432,15 @@ export class AbstractMesh extends TransformNode implements IDisposable, ICullabl
public isPickable = true;

/**
* Gets or sets a boolean indicating if the mesh can be near picked. Default is false
* Gets or sets a boolean indicating if the mesh can be near picked (touched by the XR controller or hands). Default is false
*/
public isNearPickable = false;

/**
* Gets or sets a boolean indicating if the mesh can be near grabbed. Default is false
* Gets or sets a boolean indicating if the mesh can be grabbed. Default is false.
* Setting this to true, while using the XR near interaction feature, will trigger a pointer event when the mesh is grabbed.
* Grabbing means that the controller is using the squeeze or main trigger button to grab the mesh.
* This is different from nearPickable which only triggers the event when the mesh is touched by the controller
*/
public isNearGrabbable = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,17 @@ export class WebXRControllerPointerSelection extends WebXRAbstractFeature {
}
} else {
if (pressed && !this._options.enablePointerSelectionOnAllControllers && !this._options.disableSwitchOnClick) {
// force a pointer up if switching controllers
// get the controller that was attached before
const prevController = this._controllers[this._attachedController];
if (prevController && prevController.pointerDownTriggered && !prevController.finalPointerUpTriggered) {
this._augmentPointerInit(pointerEventInit, prevController.id, prevController.screenCoordinates);
this._scene.simulatePointerUp(new PickingInfo(), {
pointerId: prevController.id,
pointerType: "xr",
});
prevController.finalPointerUpTriggered = true;
}
this._attachedController = xrController.uniqueId;
}
}
Expand Down

0 comments on commit 470b08c

Please sign in to comment.