I have a .obj file and mtl.file. And I converted them to json format with obj2three.js (The file is three.js provided,three.js-master\utils\converters\obj2three.js).
After execute obj2three.js with node, the json file is created.
I load the json file with ObjectLoader , but , the material can’t be displayed ,why?
My js code:
var jsonLoader = new THREE.ObjectLoader();
jsonLoader.load( "/public/img/server3D/obj_mtl/_server.json", function( geometry ) {
scene.add( geometry );
});
Thank you very much~ , The materials can be displayed now .
And I have an another question.
My obj and mtl also have png file to display on the 3d model,and I created a zip file containing obj, mtl, png format files.
But png can’t be displayed, there will be some errors in the browser.
It seems this use case is currently not supported by the editor. I suggest the following workaround:
Try to export your assets directly to glTF or convert them via obj2gltf. glTF is the recommended 3D format of three.js. You might want to use it directly instead to convert to JSON.
Please refer my code and the error in browser:
var gltfLoader = new THREE.GLTFLoader();
gltfLoader.load(’/public/img/server3D/obj_mtl/server5.gltf’, (geometry) => {
scene.add(geometry);
});
HI~!!
I refered Troubleshooting Loading JSON Model - #5 by calebcarithers , and modified my code:
scene.add(geometry); → scene.add(geometry.scene);
And the issue was resolved.
Now the gltf file can be displayed well.
Thanks for your help~~~!!
Hi
I have one obj file and it has 3 mtl files
And also mtl file content is JSON format
Mtl file has texture file but it is not displayed
“texture” “http://localhost/assets/textures/my.mtl”
What am I gonna do?