@@ -81870,25 +81870,30 @@ AFRAME.registerComponent('grabbable', inherit(base, {
8187081870 this.yFactor = (this.data.invert ? -1 : 1) * !this.data.suppressY;
8187181871 },
8187281872 tick: function () {
81873- var entityPosition;
81874- if (this.grabber) {
81875- // reflect on z-axis to point in same direction as the laser
81876- this.targetPosition.copy(this.grabDirection);
81877- this.targetPosition.applyQuaternion(this.grabber.object3D.getWorldQuaternion()).setLength(this.grabDistance).add(this.grabber.object3D.getWorldPosition()).add(this.grabOffset);
81878- if (this.deltaPositionIsValid) {
81879- // relative position changes work better with nested entities
81880- this.deltaPosition.sub(this.targetPosition);
81881- entityPosition = this.el.getAttribute('position');
81882- this.destPosition.x = entityPosition.x - this.deltaPosition.x * this.xFactor;
81883- this.destPosition.y = entityPosition.y - this.deltaPosition.y * this.yFactor;
81884- this.destPosition.z = entityPosition.z - this.deltaPosition.z * this.zFactor;
81885- this.el.setAttribute('position', this.destPosition);
81886- } else {
81887- this.deltaPositionIsValid = true;
81873+ var q = new THREE.Quaternion();
81874+ var v = new THREE.Vector3();
81875+
81876+ return function () {
81877+ var entityPosition;
81878+ if (this.grabber) {
81879+ // reflect on z-axis to point in same direction as the laser
81880+ this.targetPosition.copy(this.grabDirection);
81881+ this.targetPosition.applyQuaternion(this.grabber.object3D.getWorldQuaternion(q)).setLength(this.grabDistance).add(this.grabber.object3D.getWorldPosition(v)).add(this.grabOffset);
81882+ if (this.deltaPositionIsValid) {
81883+ // relative position changes work better with nested entities
81884+ this.deltaPosition.sub(this.targetPosition);
81885+ entityPosition = this.el.getAttribute('position');
81886+ this.destPosition.x = entityPosition.x - this.deltaPosition.x * this.xFactor;
81887+ this.destPosition.y = entityPosition.y - this.deltaPosition.y * this.yFactor;
81888+ this.destPosition.z = entityPosition.z - this.deltaPosition.z * this.zFactor;
81889+ this.el.setAttribute('position', this.destPosition);
81890+ } else {
81891+ this.deltaPositionIsValid = true;
81892+ }
81893+ this.deltaPosition.copy(this.targetPosition);
8188881894 }
81889- this.deltaPosition.copy(this.targetPosition);
81890- }
81891- },
81895+ };
81896+ }(),
8189281897 remove: function () {
8189381898 this.el.removeEventListener(this.GRAB_EVENT, this.start);
8189481899 this.el.removeEventListener(this.UNGRAB_EVENT, this.end);
@@ -81939,19 +81944,23 @@ AFRAME.registerComponent('grabbable', inherit(base, {
8193981944 }
8194081945 },
8194181946 resetGrabber: function () {
81942- let raycaster;
81943- if (!this.grabber) {
81944- return false;
81945- }
81946- raycaster = this.grabber.getAttribute('raycaster');
81947- this.deltaPositionIsValid = false;
81948- this.grabDistance = this.el.object3D.getWorldPosition().distanceTo(this.grabber.object3D.getWorldPosition());
81949- if (raycaster) {
81950- this.grabDirection = raycaster.direction;
81951- this.grabOffset = raycaster.origin;
81952- }
81953- return true;
81954- },
81947+ var objPos = new THREE.Vector3();
81948+ var grabPos = new THREE.Vector3();
81949+ return function () {
81950+ let raycaster;
81951+ if (!this.grabber) {
81952+ return false;
81953+ }
81954+ raycaster = this.grabber.getAttribute('raycaster');
81955+ this.deltaPositionIsValid = false;
81956+ this.grabDistance = this.el.object3D.getWorldPosition(objPos).distanceTo(this.grabber.object3D.getWorldPosition(grabPos));
81957+ if (raycaster) {
81958+ this.grabDirection = raycaster.direction;
81959+ this.grabOffset = raycaster.origin;
81960+ }
81961+ return true;
81962+ };
81963+ }(),
8195581964 lostGrabber: function (evt) {
8195681965 let i = this.grabbers.indexOf(evt.relatedTarget);
8195781966 // if a queued, non-physics grabber leaves the collision zone, forget it
0 commit comments