Skip to content

Commit e24af91

Browse files
committed
fix disabling raycaster.line getting overridden by tick line updater
1 parent c2ef054 commit e24af91

File tree

2 files changed

+35
-25
lines changed

2 files changed

+35
-25
lines changed

‎src/components/raycaster.js‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -255,16 +255,18 @@ module.exports.Component = registerComponent('raycaster', {
255255
}
256256

257257
// Update line length.
258-
if (data.showLine) {
259-
if (intersections.length) {
260-
if (intersections[0].object.el === el && intersections[1]) {
261-
lineLength = intersections[1].distance;
262-
} else {
263-
lineLength = intersections[0].distance;
258+
setTimeout(() => {
259+
if (this.data.showLine) {
260+
if (intersections.length) {
261+
if (intersections[0].object.el === el && intersections[1]) {
262+
lineLength = intersections[1].distance;
263+
} else {
264+
lineLength = intersections[0].distance;
265+
}
264266
}
267+
this.drawLine(lineLength);
265268
}
266-
this.drawLine(lineLength);
267-
}
269+
});
268270
};
269271
})(),
270272

‎tests/components/raycaster.test.js‎

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -463,14 +463,18 @@ suite('raycaster', function () {
463463
el.sceneEl.object3D.updateMatrixWorld();
464464
component.refreshObjects();
465465
component.tick();
466-
line = el.getAttribute('line');
467-
assert.equal(new THREE.Vector3().copy(line.start).sub(line.end).length(), 24.5);
468-
box.parentNode.removeChild(box);
469466
setTimeout(() => {
470-
component.tick();
471467
line = el.getAttribute('line');
472-
assert.equal(new THREE.Vector3().copy(line.start).sub(line.end).length(), 1000);
473-
done();
468+
assert.equal(new THREE.Vector3().copy(line.start).sub(line.end).length(), 24.5);
469+
box.parentNode.removeChild(box);
470+
setTimeout(() => {
471+
component.tick();
472+
setTimeout(() => {
473+
line = el.getAttribute('line');
474+
assert.equal(new THREE.Vector3().copy(line.start).sub(line.end).length(), 1000);
475+
done();
476+
});
477+
});
474478
});
475479
});
476480
});
@@ -488,7 +492,7 @@ suite('raycaster', function () {
488492

489493
rayEl2 = document.createElement('a-entity');
490494
rayEl2.setAttribute('raycaster', {
491-
direction: '0 -1 -1',
495+
direction: '0 0 -1',
492496
origin: '0 0 0',
493497
showLine: true,
494498
objects: '#target'
@@ -512,19 +516,23 @@ suite('raycaster', function () {
512516
component.tick();
513517
rayEl2.components.raycaster.tick();
514518
rayEl2.components.raycaster.tick();
515-
// ensure component and geometry are unaffected by other raycaster
516-
line = el.getAttribute('line');
517-
assert.equal(new THREE.Vector3().copy(line.start).sub(line.end).length(), 24.5);
518-
lineEnd.fromArray(lineArray, 3);
519-
assert.equal(lineStart.fromArray(lineArray).sub(lineEnd).length(), 24.5);
520-
box.parentNode.removeChild(box);
521519
setTimeout(() => {
522-
component.tick();
520+
// Ensure component and geometry are unaffected by other raycaster
523521
line = el.getAttribute('line');
524-
assert.equal(new THREE.Vector3().copy(line.start).sub(line.end).length(), 1000);
522+
assert.equal(new THREE.Vector3().copy(line.start).sub(line.end).length(), 24.5);
525523
lineEnd.fromArray(lineArray, 3);
526-
assert.equal(lineStart.fromArray(lineArray).sub(lineEnd).length(), 1000);
527-
done();
524+
assert.equal(lineStart.fromArray(lineArray).sub(lineEnd).length(), 24.5);
525+
box.parentNode.removeChild(box);
526+
setTimeout(() => {
527+
component.tick();
528+
setTimeout(() => {
529+
line = el.getAttribute('line');
530+
assert.equal(new THREE.Vector3().copy(line.start).sub(line.end).length(), 1000);
531+
lineEnd.fromArray(lineArray, 3);
532+
assert.equal(lineStart.fromArray(lineArray).sub(lineEnd).length(), 1000);
533+
done();
534+
});
535+
});
528536
});
529537
});
530538
});

0 commit comments

Comments
 (0)