I want to change the color of only my selected points, but my code seems to be changing the color of all points in the scene, not just the selected ones.
Code of interest:
//beginning comand
document.addEventListener( 'pointerdown', function ( event ) {
// #1 1/6 for coordinates on left hand side of screen
selectionBox.startPoint.set(
((event.clientX - (window.innerWidth*1/6)) / concGui.offsetWidth)*2-1,
- ( event.clientY / concGui.offsetHeight )*2+1,
0.5 );
//
//console.log(((event.clientX - (window.innerWidth*1/6)) / concGui.offsetWidth)*2-1)
//console.log(-( event.clientY / concGui.offsetHeight )*2+1)
} );
//while mouse is moving
document.addEventListener( 'pointermove', function ( event ) {
if ( helper.isDown ) {
//#2
selectionBox.endPoint.set(
((event.clientX - (window.innerWidth*1/6)) / concGui.offsetWidth)*2-1,
- ( event.clientY / concGui.offsetHeight )*2+1,
0.5 );
const allSelected = selectionBox.select();
//this is the color for when you are mouse dragging
for ( let i = 0; i < allSelected.length; i ++ ) {
if (allSelected[ i ].constructor.name == "Points") {
allSelected[ i ].material.color.set( 0xFF7F00);
}
}
}
} );
//when you unselect the left mouse
document.addEventListener( 'pointerup', function ( event ) {
//#3
selectionBox.endPoint.set(
((event.clientX - (window.innerWidth*1/6)) / concGui.offsetWidth)*2-1,
- ( event.clientY / concGui.offsetHeight)*2+1,
0.5 );
const allSelected = selectionBox.select();
for ( let i = 0; i < allSelected.length; i ++ ) {
// filtering for points selected
if (allSelected[ i ].constructor.name == "Points") {
allSelected[ i ].material.color.set( 0xFF7F00);
allSelected[ i ].geometry.colorsNeedUpdate=true
console.log(allSelected)
}
else {
//reset all the points to original color
allSelected[ i ].material.color.set( 0x00FF00);
}
}
} );
My selection box is accurate with selections, but as you can see in the example below, selecting the upper right (3) points causes all (4) points to turn orange.
Any ideas where I went wrong? Full code on github
I am also looking for a good way to reset the color back to green if the points are deselected. Seems like I need to gather all points in the scene and reset them back to the original green color if they are not selected. Any guidance on this is appreciated.
Thanks!