Changing material in model

I am looking for a way to change material for a mesh that is not based on modifying the material itself.
At the moment I was doing it this way:

function setMaterial(type, next){
if(current[type] != next){
    var currentMat = model_materials.find(obj => {
        return === current[type]
    if(last[type] != undefined){
        var lastMat = model_materials.find(obj => {
            return === last[type]
        lastMat.stateSetID = currentMat.stateSetID;
        API.setMaterial(lastMat, function() {
            console.log( 'Material updated' );
            current[type] = last[type];
            last[type] = undefined;
            setMaterial(type, next);
        var nextMat = model_materials.find(obj => {
            return === next
        nextMat.stateSetID = currentMat.stateSetID;
        API.setMaterial(nextMat, function() {
            console.log( 'Material updated' );
            last[type] = current[type];
            current[type] = next;

However, this causes problems when changing more materials and when I change several materials at the same time (the materials stop changing at all). So I’m looking for a less invasive replacement method. Is there such?


There is no such way, all are based on changing materials.

I’m curious about the use case where it’s needed ?

We need it for a configurator with a combination of in total around 180 models of lamp schaders of different materials, textures and colors. Please check my Sketchfab account for all the private models of the shaders. Could you suggest a way?

Each time I tried a mesh it has only material ?
You can only modify that one material.
There is no current possibility to create new material and assign them to different geometry node.
If the model is loaded with one material, you can change that one material.