The Parse method of the Loader object in three.js allows you to specify a callback function that will be triggered upon completion of the parsing process. This callback will receive a unique argument which represents the parsed object.
However, I am encountering an issue where I need to pass an additional argument to the callback function. This is because I am using the parse method within a loop and I want to create multiple callbacks, each with a specific value of a variable.
Currently, if I set this value within the loop but outside the callback function, the callback always receives the last value that was set in the loop. This is not the desired behavior.
Below is the code snippet:
for(var foldcont_index in foldcont) {
var foldit = foldcont[foldcont_index];
if(foldit.isDirectory()) {
loadBFiles(fold+'/'+foldit.name);
}
if(foldit.isFile()) {
var buigltf = fs.readFileSync(fold+'/'+foldit.name, 'utf8');
loader.parse(
buigltf,
undefined,
function(o) {
var oname= // !!! before issue with foldit.name
objectstank['xxx_'+oname]= o;
loadpoint = loadpoint + loadpercentage;
loadbar.set(loadpoint);
if(loadpoint >= 100) { document.getElementById("load-bar").style.display = 'none'; }
},
undefined
);
}
}
Can anyone offer a solution to this issue?