Here is my code:
var objLoader = new THREE.OBJLoader2()
try{
objLoader.loadMtl(mtlurl, null, onLoadMtl)
}
catch(e){
console.log('mtl load error:', e)
}
as there is some network error . so I got this below in my console:
three.min.js:619 GET https://xxxx.xxx.xxx/mtl/xxxx net::ERR_CERT_COMMON_NAME_INVALID
But I didn’t catch any error in my own code neither did the onMtlLoader function called.
My question is how to catch this error?
Have you considered to use MTLLoader
and OBJLoader
like in this example?
https://threejs.org/examples/#webgl_loader_obj_mtl
In this way you can pass in an onError()
callback to MTLLoader.load()?
below is my whole code:
function getMeshFromObjAndMtl(objurl, mtlurl){
var objLoader = new THREE.OBJLoader2()
if(mtlurl){
return new Promise((resolve, reject) => {
var onObjLoad = function(event){
resolve(event.detail.loaderRootNode)
}
var onError = function(event){
reject(event)
}
var onLoadMtl = function(mats){
objLoader.setMaterials(mats)
objLoader.load(objurl, onObjLoad, null, onError, null, false)
}
try{
objLoader.loadMtl(mtlurl, null, onLoadMtl)
}
catch(e){
reject(e)
}
})
}
}
onError didn’t called either .
Have you tried my suggestion? There might be a problem with OBJLoader2
. That’s why I refer to OBJLoader
.
OK, I’ll try it later. And tell you the result.
It works. I think there should have also a onError callback for OBJLoader2.loadMtl.
You might want to file an issue at github for this.