Skip to content
Snippets Groups Projects
Commit 98d59492 authored by Marshall Quander's avatar Marshall Quander
Browse files

Reuse raycaster component data

parent 4e5d5a90
No related branches found
No related tags found
No related merge requests found
......@@ -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() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment