Skip to content

Commit 425f2ee

Browse files
authored
Merge pull request #129 from InfiniteLee/feature/stretchable-world-pos
use world position for stretchable component
2 parents 94cebeb + cf9d825 commit 425f2ee

File tree

5 files changed

+39
-44
lines changed

5 files changed

+39
-44
lines changed

dist/super-hands.js

Lines changed: 9 additions & 8 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
});
@@ -1102,8 +1103,8 @@ AFRAME.registerComponent('stretchable', inherit(base, {
11021103
return;
11031104
}
11041105
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'));
1106+
this.stretchers[0].object3D.getWorldPosition(this.handPos);
1107+
this.stretchers[1].object3D.getWorldPosition(this.otherHandPos);
11071108
const currentStretch = this.handPos.distanceTo(this.otherHandPos);
11081109
let deltaStretch = 1;
11091110
if (this.previousStretch !== null && currentStretch !== 0) {

0 commit comments

Comments
 (0)