Skip to content

Commit 36d5dd2

Browse files
committed
spawn pen near hand when user is determined to be using 6-dof
1 parent 3173532 commit 36d5dd2

File tree

2 files changed

+37
-27
lines changed

2 files changed

+37
-27
lines changed

src/components/super-spawner.js

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,19 @@ AFRAME.registerComponent("super-spawner", {
5555
centerSpawnedObject: { default: false },
5656

5757
/**
58-
* Optional event to listen for to spawn an object on the defaultHand
58+
* Optional event to listen for to spawn an object on the preferred superHand
5959
*/
6060
spawnEvent: { type: "string" },
6161

6262
/**
63-
* The hand to use if an object is spawned via spawnEvent
63+
* The superHand to use if an object is spawned via spawnEvent
6464
*/
65-
defaultHand: { type: "selector" }
65+
superHand: { type: "selector" },
66+
67+
/**
68+
* The cursor superHand to use if an object is spawned via spawnEvent
69+
*/
70+
cursorSuperHand: { type: "selector" }
6671
},
6772

6873
init() {
@@ -103,31 +108,38 @@ AFRAME.registerComponent("super-spawner", {
103108
this.heldEntities.clear();
104109
},
105110

106-
async onSpawnEvent() {
107-
const hand = this.data.defaultHand;
111+
onSpawnEvent: (() => {
112+
const spawnOffset = new THREE.Vector3();
113+
return async function() {
114+
const controllerCount = this.el.sceneEl.components["input-configurator"].controllerQueue.length;
115+
const using6DOF = controllerCount > 1 && this.el.sceneEl.is("vr-mode");
116+
const hand = using6DOF ? this.data.superHand : this.data.cursorSuperHand;
108117

109-
if (this.cooldownTimeout || !hand) {
110-
return;
111-
}
118+
if (this.cooldownTimeout || !hand) {
119+
return;
120+
}
112121

113-
const entity = addMedia(this.data.src, this.data.template, ObjectContentOrigins.SPAWNER).entity;
122+
const entity = addMedia(this.data.src, this.data.template, ObjectContentOrigins.SPAWNER).entity;
114123

115-
entity.object3D.position.copy(hand.object3D.position);
116-
entity.object3D.rotation.copy(hand.object3D.rotation);
117-
entity.object3D.scale.copy(this.data.useCustomSpawnScale ? this.data.spawnScale : this.el.object3D.scale);
124+
hand.object3D.getWorldPosition(entity.object3D.position);
125+
hand.object3D.getWorldQuaternion(entity.object3D.quaternion);
126+
if (this.data.useCustomSpawnScale) {
127+
entity.object3D.scale.copy(this.data.spawnScale);
128+
}
118129

119-
this.activateCooldown();
130+
this.activateCooldown();
120131

121-
await waitForEvent("body-loaded", entity);
132+
await waitForEvent("body-loaded", entity);
122133

123-
if (this.data.centerSpawnedObject) {
124-
entity.body.position.copy(hand.object3D.position);
125-
}
134+
hand.object3D.getWorldPosition(entity.object3D.position);
126135

127-
for (let i = 0; i < this.data.grabEvents.length; i++) {
128-
hand.emit(this.data.grabEvents[i], { targetEntity: entity });
129-
}
130-
},
136+
if (!using6DOF) {
137+
for (let i = 0; i < this.data.grabEvents.length; i++) {
138+
hand.emit(this.data.grabEvents[i], { targetEntity: entity });
139+
}
140+
}
141+
};
142+
})(),
131143

132144
async onGrabStart(e) {
133145
if (this.cooldownTimeout) {

src/hub.html

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@
174174
super-networked-interactable="counter: #pen-counter;"
175175
body="type: dynamic; shape: none; mass: 1;"
176176
grabbable-toggle="maxGrabbers: 1;"
177-
sticky-object="autoLockOnRelease: true;"
177+
sticky-object="autoLockOnRelease: true; autoLockOnLoad: true;"
178178
hoverable
179179
activatable__draw-hand="buttonStartEvents: secondary_hand_grab; buttonEndEvents: secondary_hand_release;"
180180
activatable__draw-cursor="buttonStartEvents: secondary-cursor-grab; buttonEndEvents: secondary-cursor-release;"
@@ -440,11 +440,9 @@
440440
super-spawner="
441441
template: #pen-interactable;
442442
src: https://asset-bundles-prod.reticulum.io/interactables/DrawingPen/DrawingPen-484ae5682f.gltf;
443-
centerSpawnedObject: true;
444-
spawnEvent: spawn_pen;
445-
defaultHand: #cursor;
446-
useCustomSpawnScale: true;
447-
spawnScale: 0.5 0.5 0.5;"
443+
spawnEvent: spawn_pen;
444+
superHand: #player-right-controller;
445+
cursorSuperHand: #cursor;"
448446
></a-entity>
449447
</a-scene>
450448

0 commit comments

Comments
 (0)