How to compare variable name and button id to load content inside variable for ThreeJS?

I am using Three.js to load multiple 3D models and store them in an array in the background. I've multiple buttons with unique ID add that specific model to scene. Now I want to compare the button ID and variable name so that I can load only that specific model and remove any other models added to the scene. I have written a for loop to to loop through all the variable to compare with ID of the clicked button, but I'm not able to access only variable name so that I can compare it with button ID.

Following is my code :

function modelShow() {

  let m;

  var models =  [mandi_0, maxi_0, mandi_1, maxi_1, mandi_2, maxi_2];

  for (m = 0; m < models.length; m++) {

    if(models[m].name == event.target.id){
      scene.add(models[m]);
    }
    else {
      scene.remove(models[m]);
    }
  }
}

let j;

for (j = 0; j < buttons.length; j++) {
   buttons[j].addEventListener('click', modelShow);
} 

How can I compare only variable name with button ID and not the content inside variable?



Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation