I have a file with a .obj extension that I am currently loading using a loader. This file contains multiple meshes which I want to use separately as individual objects. The challenge I am facing is that each of these objects has a distinct texture. However, when I attempt to load them, the same texture gets loaded twice. I suspect this issue might be related more to JavaScript than three.js itself. Any insights or assistance on this matter would be greatly appreciated!
Below is the code snippet I am currently working with:
for (var i = 0; i < object.children.length; i++)
{
var child = object.children[i]
child.scale.set(15, 15, 15)
child.position.y += 0.01
console.log('Loading texture for: ' + child.name)
textureLoader.load('assets/' + child.name + '.png', function(image)
{
console.log('Searching for: ' + child.name)
var texture = new THREE.Texture()
texture.image = image
texture.needsUpdate = true
child.material.map = texture
console.log('Texture loaded for ' + child.name)
})
}
scene.add(object)
The issue I am encountering is that only the first object from the list is being loaded correctly. Even though the for loop is executing four times with different children, the console log in the textureLoader.load callback is showing the name of the first element twice.