Hello
Is anyone able to help me with this piece of code? It works fine with the exception of the texture change on runtime, it “destroys” the textures, they get all messed up, without that code the texture from MTL is loaded correctly (also DDS).
const manager = new THREE.LoadingManager()
manager.addHandler(/\.dds$/i, new DDSLoader())
const mtlLoader = new MTLLoader(manager)
mtlLoader.setPath(url!)
mtlLoader.load(`${model}.mtl`, (materials) => {
materials.preload()
const objLoader = new OBJLoader(manager)
objLoader.setMaterials(materials)
objLoader.setPath(url!)
objLoader.load(`${model}.obj`, (object) => {
object.scale.setScalar(1 / 200)
if (type && type === 'WING') {
object.position.y = -0.9
} else {
object.position.y = -0.3
}
object.rotateX(-90 * (Math.PI / 180))
const materialName = Object.values(materials.materialsInfo).filter(({ map_kd }) => map_kd === sourceSkin)[0].name
object.traverse((child) => {
if (child instanceof THREE.Mesh && type === 'ARMOR' && child.material.name === materialName) {
child.material.map = new DDSLoader().load(`${url}${targetSkin}`, () => {
child.material.needsUpdate = true
})
}
child.frustumCulled = false
if ((child as any).material instanceof THREE.MeshPhongMaterial) {
(child as any).material.side = THREE.DoubleSide
}
})
scene.add(object)
}, undefined, (error) => { console.error(error) })
})
The object usually has 2, sometimes 3 texture files, I have the materialName
variable to find the one I need to change, and only change that one keeping the other ones intact.
With texture change in runtime:
Without texture change in runtime, texture loaded from MTL:
Piece of code that has the model and the corresponding textures.
"0": {
"model": "pc2/assassin/assassin_novice",
"sourceSkin": "pc2/assassin/assassin_novice_red.dds",
"targetSkin": "pc2/assassin/assassin_novice_blue.dds"
},
The models (MTL) only have reference to the “sourceSkin”, the “targetSkin” is made somewhere else.
All my DDS textures are Flipped on Y.
nvtt_export -f bc3 -q production --save-flip-y -o "./material/textures/armors/converted/${folderRoot}/${folderRace}/${item}" "./material/textures/armors/${folderRoot}/${folderRace}/${item}"
Any idea on how I can solve this?
Thank you