diff --git a/src/components/tools/pen.js b/src/components/tools/pen.js index 9bd18ac7e99a0617cc570211a52757bd519be10a..8abd375a0e6ebbb33999b6b181c9a130d9ac56c9 100644 --- a/src/components/tools/pen.js +++ b/src/components/tools/pen.js @@ -53,7 +53,7 @@ AFRAME.registerComponent("pen", { }, play() { - if (this.data.useMouse) { + if (this.data.useMouse && false) { document.addEventListener("mousedown", this.onMouseDown); document.addEventListener("mouseup", this.onMouseUp); } @@ -61,8 +61,10 @@ AFRAME.registerComponent("pen", { // this.el.parentNode.addEventListener("index_down", this.startDraw); // this.el.parentNode.addEventListener("index_up", this.endDraw); - this.el.parentNode.addEventListener("drag-start", this.startDraw); - this.el.parentNode.addEventListener("drag-end", this.endDraw); + if (!this.data.useMouse) { + this.el.parentNode.addEventListener("activate-start", this.startDraw); + this.el.parentNode.addEventListener("activate-end", this.endDraw); + } }, pause() { @@ -72,8 +74,8 @@ AFRAME.registerComponent("pen", { this.el.parentNode.removeEventListener("index_down", this.startDraw); this.el.parentNode.removeEventListener("index_up", this.endDraw); - this.el.parentNode.removeEventListener("drag-start", this.startDraw); - this.el.parentNode.removeEventListener("drag-end", this.endDraw); + this.el.parentNode.removeEventListener("activate-start", this.startDraw); + this.el.parentNode.removeEventListener("activate-end", this.endDraw); }, tick(t, dt) { diff --git a/src/hub.html b/src/hub.html index af24a06ce66ddfd8ebe8de04e92257a86908f490..7830dce38385efee4b7c2fbddf24f2923bfa3188 100644 --- a/src/hub.html +++ b/src/hub.html @@ -220,12 +220,12 @@ <template id="pen-interactable"> <a-entity gltf-model-plus="src: #interactable-pen; inflate: true;" - class="interactable" + class="interactable sticky" super-networked-interactable="counter: #counter; mass: 1;" body="type: dynamic; shape: none; mass: 1;" - grabbable + grabbable="maxGrabbers: 1; maxGrabBehavior: drop;" hoverable - draggable + activatable="buttonStartEvent: secondary_action_grab; buttonEndEvent: secondary_action_release;" scale="0.5 0.5 0.5" > <a-sphere @@ -271,7 +271,8 @@ colliderEndEvent: collisions; colliderEndEventProperty: clearedEls; grabStartButtons: hand_grab; grabEndButtons: hand_release; stretchStartButtons: hand_grab; stretchEndButtons: hand_release; - dragDropStartButtons: index_down; dragDropEndButtons: index_up;" + dragDropStartButtons: hand_grab; dragDropEndButtons: hand_release; + activateStartButtons: secondary_action_grab; activateEndButtons: secondary_action_release;" collision-filter="collisionForces: false" physics-collider ></a-mixin> @@ -301,7 +302,8 @@ colliderEndEvent: raycaster-intersection-cleared; colliderEndEventProperty: clearedEls; grabStartButtons: cursor-grab; grabEndButtons: cursor-release; stretchStartButtons: cursor-grab; stretchEndButtons: cursor-release; - dragDropStartButtons: cursor-grab; dragDropEndButtons: cursor-release;" + dragDropStartButtons: cursor-grab; dragDropEndButtons: cursor-release; + activateStartButtons: TODO; activateEndButtons: TODO;" segments-height="9" segments-width="9" event-repeater="events: raycaster-intersection, raycaster-intersection-cleared; eventSource: #cursor-controller" diff --git a/src/input-mappings.js b/src/input-mappings.js index d1784c8d1cfba1df975dc1200c2ef87632ab8586..3bf06cc848efb2392438ca0d00f4dbe2d540fc83 100644 --- a/src/input-mappings.js +++ b/src/input-mappings.js @@ -61,8 +61,8 @@ const config = { gripup: ["action_release", "middle_ring_pinky_up"], trackpadtouchstart: "thumb_down", trackpadtouchend: "thumb_up", - triggerdown: ["index_down"], - triggerup: ["index_up"], + triggerdown: ["secondary_action_grab", "index_down"], + triggerup: ["secondary_action_release", "index_up"], scroll: { right: "move_duck" } }, "oculus-touch-controls": { @@ -86,8 +86,8 @@ const config = { surfacetouchend: "thumb_up", thumbsticktouchstart: "thumb_down", thumbsticktouchend: "thumb_up", - triggerdown: ["action_grab", "index_down"], - triggerup: ["action_release", "index_up"], + triggerdown: ["secondary_action_grab", "index_down"], + triggerup: ["secondary_action_release", "index_up"], "axismove.reverseY": { left: "move", right: "move_duck" }, abuttondown: "action_primary_down", abuttonup: "action_primary_up" diff --git a/src/utils/action-event-handler.js b/src/utils/action-event-handler.js index 6288c34e002af618390ab63185a47830067f39f1..fcb9aa736c55e30c0884cc67a0f28a6d3292097b 100644 --- a/src/utils/action-event-handler.js +++ b/src/utils/action-event-handler.js @@ -7,6 +7,7 @@ export default class ActionEventHandler { this.isTeleporting = false; this.handThatAlsoDrivesCursor = null; this.hovered = false; + this.currentlyGrabbingSticky = {}; this.onPrimaryDown = this.onPrimaryDown.bind(this); this.onPrimaryUp = this.onPrimaryUp.bind(this); @@ -23,6 +24,8 @@ export default class ActionEventHandler { this.scene.addEventListener("action_primary_up", this.onPrimaryUp); this.scene.addEventListener("action_grab", this.onGrab); this.scene.addEventListener("action_release", this.onRelease); + this.scene.addEventListener("secondary_action_grab", this.onGrab); + this.scene.addEventListener("secondary_action_release", this.onRelease); this.scene.addEventListener("move_duck", this.onMoveDuck); this.scene.addEventListener("cardboardbuttondown", this.onCardboardButtonDown); // TODO: These should be actions this.scene.addEventListener("cardboardbuttonup", this.onCardboardButtonUp); @@ -33,6 +36,8 @@ export default class ActionEventHandler { this.scene.removeEventListener("action_primary_up", this.onPrimaryUp); this.scene.removeEventListener("action_grab", this.onGrab); this.scene.removeEventListener("action_release", this.onRelease); + this.scene.removeEventListener("secondary_action_grab", this.onGrab); + this.scene.removeEventListener("secondary_action_release", this.onRelease); this.scene.removeEventListener("move_duck", this.onMoveDuck); this.scene.removeEventListener("cardboardbuttondown", this.onCardboardButtonDown); this.scene.removeEventListener("cardboardbuttonup", this.onCardboardButtonUp); @@ -46,27 +51,43 @@ export default class ActionEventHandler { this.handThatAlsoDrivesCursor = handThatAlsoDrivesCursor; } + isSticky(el) { + return el && el.classList.contains("sticky"); + } + onGrab(e) { - if (this.handThatAlsoDrivesCursor && this.handThatAlsoDrivesCursor === e.target) { - if (this.isCursorInteracting) { - return; - } else if (e.target.components["super-hands"].state.has("hover-start")) { + const superHand = e.target.components["super-hands"]; + const grabbed = superHand.state.get("grab-start"); + if (this.currentlyGrabbingSticky[e.target.id] && !grabbed) { + this.currentlyGrabbingSticky[e.target.id] = false; + } + const validGrab = !this.isSticky(grabbed) || !this.currentlyGrabbingSticky[e.target.id] || e.type == "action_grab"; + if (this.handThatAlsoDrivesCursor && this.handThatAlsoDrivesCursor === e.target && !this.isCursorInteracting) { + if (superHand.state.has("hover-start") && validGrab) { e.target.emit("hand_grab"); - return; } else { this.isCursorInteracting = this.cursor.startInteraction(); if (this.isCursorInteracting) { this.isCursorInteractingOnGrab = true; } - return; } - } else { + } else if (validGrab) { e.target.emit("hand_grab"); - return; } } onRelease(e) { + const grabbed = e.target.components["super-hands"].state.get("grab-start"); + if ( + (!this.currentlyGrabbingSticky[e.target.id] && this.isSticky(grabbed)) || + (this.currentlyGrabbingSticky[e.target.id] && e.type != "action_release") + ) { + this.currentlyGrabbingSticky[e.target.id] = true; + return; + } else { + this.currentlyGrabbingSticky[e.target.id] = false; + } + if ( this.isCursorInteracting && this.isCursorInteractingOnGrab && diff --git a/yarn.lock b/yarn.lock index 0dc13a86aa4c0e7a671857cc211ee5934b5b12f0..e94fc5e45e92c14a05b303ebf0202d030f417bee 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7859,8 +7859,8 @@ subarg@^1.0.0: minimist "^1.1.0" "super-hands@https://github.com/mozillareality/aframe-super-hands-component#hubs/master": - version "2.1.0" - resolved "https://github.com/mozillareality/aframe-super-hands-component#579024a260f8b9821cf1cbabd403055116bc2eb9" + version "3.0.0" + resolved "https://github.com/mozillareality/aframe-super-hands-component#2fc7697793005e187f343e59f98a33a5ed45c698" supports-color@1.3.1: version "1.3.1"