After reviewing this particular example involving three.js for drawing particles with images, I found it to work flawlessly. However, I am interested in replacing the image by toggling it with a switch upon clicking a button. Here is the function for this purpose:
const changeImg = function(num) {
switch (num)
{
case 0:
imgData = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA....";
break;
case 1:
imgData = "data:image/png;base64,iVBORw0KGgoAAAAN...";
break;
}
img.src = imgData;
}
Although this approach works, I noticed that the website slows down upon multiple clicks. How can I efficiently update just the image without causing performance issues?
EDIT 1
Upon modifying the code as shown below:
And the THREE.WebGLRenderer is only applied once but when I click to change the image, it does not update and also I still have the problem that the website slows down
it's my first time using three js and i don't know if i'm applying well what it says in the documentation
EDIT 2
When I click to change the image, it does not update and also I still have the problem that the website slows down. I cahaged vertcies.push to vertices.vertices.push()