Skip to content

Commit 589b54a

Browse files
committed
update stretchable tests to mock position changes on the Object3D
1 parent 0e1f22a commit 589b54a

File tree

4 files changed

+51
-44
lines changed

4 files changed

+51
-44
lines changed

dist/super-hands.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,11 @@ AFRAME.registerComponent('super-hands', {
119119
this.onDragDropEndButton();
120120
},
121121
tick: function () {
122-
let orderChanged = false;
123122
// closer objects and objects with no distance come later in list
124123
function sorter(a, b) {
125124
const aDist = a.distance == null ? -1 : a.distance;
126125
const bDist = b.distance == null ? -1 : b.distance;
127126
if (aDist < bDist) {
128-
orderChanged = true;
129127
return 1;
130128
}
131129
if (bDist < aDist) {
@@ -141,12 +139,15 @@ AFRAME.registerComponent('super-hands', {
141139
}
142140
this.prevCheckTime = time;
143141

144-
orderChanged = false;
142+
let orderChanged = false;
145143
this.hoverElsIntersections.sort(sorter);
146-
if (orderChanged) {
147-
for (let i = 0; i < this.hoverElsIntersections.length; i++) {
144+
for (let i = 0; i < this.hoverElsIntersections.length; i++) {
145+
if (this.hoverEls[i] !== this.hoverElsIntersections[i].object.el) {
146+
orderChanged = true;
148147
this.hoverEls[i] = this.hoverElsIntersections[i].object.el;
149148
}
149+
}
150+
if (orderChanged) {
150151
this.hover();
151152
}
152153
};
@@ -508,7 +509,7 @@ AFRAME.registerComponent('super-hands', {
508509
this.hoverEls.splice(hoverIndex, 1);
509510
const sect = this.hoverElsIntersections.splice(hoverIndex, 1);
510511
this.hoverEls.push(el);
511-
this.hoverElsIntersections.push(sect);
512+
this.hoverElsIntersections.push(sect[0]);
512513
}
513514
}
514515
});
@@ -1075,7 +1076,8 @@ AFRAME.registerComponent('stretchable', inherit(base, {
10751076
schema: {
10761077
usePhysics: { default: 'ifavailable' },
10771078
invert: { default: false },
1078-
physicsUpdateRate: { default: 100 }
1079+
physicsUpdateRate: { default: 100 },
1080+
useWorldPosition: { default: false }
10791081
},
10801082
init: function () {
10811083
this.STRETCHED_STATE = 'stretched';
@@ -1102,8 +1104,13 @@ AFRAME.registerComponent('stretchable', inherit(base, {
11021104
return;
11031105
}
11041106
this.scale.copy(this.el.getAttribute('scale'));
1105-
this.handPos.copy(this.stretchers[0].getAttribute('position'));
1106-
this.otherHandPos.copy(this.stretchers[1].getAttribute('position'));
1107+
if (this.data.useWorldPosition) {
1108+
this.stretchers[0].object3D.getWorldPosition(this.handPos);
1109+
this.stretchers[1].object3D.getWorldPosition(this.otherHandPos);
1110+
} else {
1111+
this.handPos.copy(this.stretchers[0].getAttribute('position'));
1112+
this.otherHandPos.copy(this.stretchers[1].getAttribute('position'));
1113+
}
11071114
const currentStretch = this.handPos.distanceTo(this.otherHandPos);
11081115
let deltaStretch = 1;
11091116
if (this.previousStretch !== null && currentStretch !== 0) {

0 commit comments

Comments
 (0)