Browse Source

drawing functionality added for vr controller

master
Cailean Finn 2 weeks ago
parent
commit
8a7c080edf
  1. 22
      js/Player.js

22
js/Player.js

@ -24,6 +24,7 @@ export class Player {
this.mouseSensitivity = 0.002; this.mouseSensitivity = 0.002;
this.maxInteractionDistance = 200.0; this.maxInteractionDistance = 200.0;
this.vrDrawing = false;
this.isDrawing = false; this.isDrawing = false;
this.raycast = new THREE.Raycaster(); this.raycast = new THREE.Raycaster();
this.pointer = new THREE.Vector2(); this.pointer = new THREE.Vector2();
@ -224,6 +225,7 @@ export class Player {
controller.addEventListener('selectstart', () => this._OnVRSelectStart(i)); controller.addEventListener('selectstart', () => this._OnVRSelectStart(i));
controller.addEventListener('selectend', () => this._OnVRSelectEnd(i)); controller.addEventListener('selectend', () => this._OnVRSelectEnd(i));
controller.addEventListener('squeezestart', () => this._OnVRSqueezeStart(i)); controller.addEventListener('squeezestart', () => this._OnVRSqueezeStart(i));
controller.addEventListener('squeezeend', () => this._OnVRSqueezeEnd(i));
} }
} }
@ -276,12 +278,26 @@ export class Player {
_OnVRSqueezeStart(controllerIndex) { _OnVRSqueezeStart(controllerIndex) {
console.log(`Squeeze Started: ${controllerIndex}`); console.log(`Squeeze Started: ${controllerIndex}`);
// Use squeeze on right controller to detach item // Use squeeze on right controller to detach item
if (controllerIndex === 0 && this.attachedItem) { if (controllerIndex === 0) {
if (!this.attachedItem) {
this.vrDrawing = true;
this.isDrawing = true;
} else {
// Existing detach logic
this.attachedItem.isActive = false; this.attachedItem.isActive = false;
this.attachedItem._removeContentDisplay(); this.attachedItem._removeContentDisplay();
this.attachedItem = null; this.attachedItem = null;
} }
} }
}
_OnVRSqueezeEnd(controllerIndex) {
if (controllerIndex === 0) {
this.vrDrawing = false;
this.isDrawing = false;
}
}
_handleVRJoystick() { _handleVRJoystick() {
// --- Left Controller (Teleport Distance) --- // --- Left Controller (Teleport Distance) ---
@ -427,7 +443,7 @@ export class Player {
const meshesToIntersect = drawableObjects.map(obj => obj.mesh); const meshesToIntersect = drawableObjects.map(obj => obj.mesh);
// Desktop drawing // Desktop drawing
if (this.isDrawing && !this.vrControllers[0]?.userData.isDrawing) { if (this.isDrawing && !this.renderer.xr.isPresenting) {
this.pointer.x = 0; this.pointer.x = 0;
this.pointer.y = 0; this.pointer.y = 0;
this.raycast.setFromCamera(this.pointer, this.camera); this.raycast.setFromCamera(this.pointer, this.camera);
@ -442,7 +458,7 @@ export class Player {
// VR drawing (right controller) // VR drawing (right controller)
const vrController = this.vrControllers[0]; const vrController = this.vrControllers[0];
if (this.isDrawing && vrController) { if (this.vrDrawing && vrController && this.renderer.xr.isPresenting) {
const controllerMatrix = vrController.matrixWorld; const controllerMatrix = vrController.matrixWorld;
const ray = new THREE.Raycaster(); const ray = new THREE.Raycaster();
ray.ray.origin.setFromMatrixPosition(controllerMatrix); ray.ray.origin.setFromMatrixPosition(controllerMatrix);

Loading…
Cancel
Save