From 98d59492b332d4b34fa31462cc3a30ce43f2da90 Mon Sep 17 00:00:00 2001 From: Marshall Quander <marshall@quander.me> Date: Fri, 15 Jun 2018 14:26:29 -0700 Subject: [PATCH] Reuse raycaster component data --- src/components/cursor-controller.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/components/cursor-controller.js b/src/components/cursor-controller.js index 83aea2193..e0dda6f0b 100644 --- a/src/components/cursor-controller.js +++ b/src/components/cursor-controller.js @@ -28,8 +28,8 @@ AFRAME.registerComponent("cursor-controller", { this.wasCursorHovered = false; this.origin = new THREE.Vector3(); this.direction = new THREE.Vector3(); + this.raycasterAttr = this.el.getAttribute("raycaster"); this.controllerQuaternion = new THREE.Quaternion(); - this.data.cursor.setAttribute("material", { color: this.data.cursorColorUnhovered }); this._handleCursorLoaded = this._handleCursorLoaded.bind(this); @@ -45,6 +45,12 @@ AFRAME.registerComponent("cursor-controller", { this.setCursorVisibility(false); }, + updateRay: function() { + this.raycasterAttr.origin = this.origin; + this.raycasterAttr.direction = this.direction; + this.el.setAttribute("raycaster", this.raycasterAttr, true); + }, + tick: (() => { const rayObjectRotation = new THREE.Quaternion(); @@ -63,7 +69,7 @@ AFRAME.registerComponent("cursor-controller", { .applyQuaternion(rayObjectRotation) .normalize(); this.origin.setFromMatrixPosition(rayObject.matrixWorld); - this.el.setAttribute("raycaster", { origin: this.origin, direction: this.direction }); + this.updateRay(); } const isGrabbing = this.data.cursor.components["super-hands"].state.has("grab-start"); @@ -100,7 +106,7 @@ AFRAME.registerComponent("cursor-controller", { raycaster.setFromCamera(this.mousePos, camera); this.origin.copy(raycaster.ray.origin); this.direction.copy(raycaster.ray.direction); - this.el.setAttribute("raycaster", { origin: raycaster.ray.origin, direction: raycaster.ray.direction }); + this.updateRay(); }, updateDistanceAndTargetType: function() { -- GitLab