Skip to content

Commit

Permalink
use intersection.object.el instead of hardcoded id
Browse files Browse the repository at this point in the history
  • Loading branch information
kfarr committed Nov 23, 2023
1 parent b0ae367 commit 28d2c29
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/app/intersection-spawn.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ AFRAME.registerComponent('intersection-spawn', {
const data = this.data;
const el = this.el;
this.helperVector = new THREE.Vector3();
this.targetEl = document.querySelector('#city-container');

el.addEventListener(data.event, evt => {
// don't spawn if class specified in objects property but it is not matched intersected element
Expand All @@ -24,9 +23,6 @@ AFRAME.registerComponent('intersection-spawn', {
// Create element.
const spawnEl = document.createElement('a-entity');

// // Snap intersection point to grid and offset from center.
// spawnEl.setAttribute('position', evt.detail.intersection.point);

// Set components and properties.
Object.keys(data).forEach(name => {
if (name === 'event' || name === 'objects') { return; }
Expand All @@ -40,10 +36,10 @@ AFRAME.registerComponent('intersection-spawn', {
targetEl.object3D.worldToLocal(helperVector);
return helperVector;
};

const localPos = _worldToLocal(evt.detail.intersection.point, this.targetEl); // convert world intersection position to local position
const targetEl = evt.detail.intersection.object.el;
const localPos = _worldToLocal(evt.detail.intersection.point, targetEl); // convert world intersection position to local position
spawnEl.setAttribute('position', localPos)
this.targetEl.appendChild(spawnEl);
targetEl.appendChild(spawnEl);

});
}
Expand Down

0 comments on commit 28d2c29

Please sign in to comment.