My goal is to have my raycaster detect intersections only when the trigger on my Vive controller is pressed.
I was thinking of initializing the raycaster with a dummy class in objects, then switching it to the real one using .prop
and capturing the intersectedEls
let rightHand = document.getElementById('rightController');
rightHand.setAttribute('line', 'color: purple; opacity: 1;');
rightHand.setAttribute('raycaster', { showLine: true, objects: '.none' });
rightHand.setAttribute('cursor', { downEvents: ['triggerdown'], upEvents: ['triggerup'], rayOrigin: 'entity', fuse: false });
let scene = document.getElementById('scene');
scene.addEventListener('triggerdown', this.myTriggerDown);
scene.addEventListener('triggerup', this.myTriggerUp);
myTriggerDown() {
let rightHand = document.getElementById('rightController');
rightHand.setAttribute('raycaster', { showLine: true, objects: '.prop' });
rightHand.components['raycaster'].refreshObjects();
let raycaster = rightHand.components['raycaster'];
let intersectedEls = raycaster.intersectedEls;
if (typeof intersectedEls !== 'undefined' && intersectedEls.length > 0) {
scene.components['resize'].enableResize(intersectedEls[0]);
} else {
console.log('1234 no intersections')
}
}
myTriggerUp() {
let rightHand = document.getElementById('rightController');
rightHand.setAttribute('raycaster', { showLine: true, objects: '.none' });
}
I'm consistently seeing the
console.log('1234 no intersections')
message despite my efforts.
I've tried adding the refreshObjects()
line with no success.
I also attempted toggling the enabled
property instead of changing the objects
, but encountered the same issue.
Any advice or assistance would be greatly appreciated. Thank you
edit:
Interestingly, looking for intersections in the triggerup section seems to work. However, this workaround prevents me from utilizing the intersected element and performing actions while holding the trigger. I still want to understand why enabling the ray/changing target objects and immediately searching for intersections doesn't yield the desired results.