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

Some fixes for 6DoF #14911

Merged
merged 5 commits into from
Mar 27, 2024
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
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
Loading