I’ve loaded a GLTF model and I want to get the dimensions of the texture image but I’m having no luck if you could please help…
gltf.scene.traverse( function( node ) {
if ( node.isMesh ) {
var tmp = node.material.map;
console.log('the size is...?? '+tmp)
.....
Try it with:
var tmp = node.material.map;
console.log( tmp.image.width, tmp.image.height );
Thank you, but It gives an error: Cannot read property ‘image’ of null.
I did a console.dir on tmp and it actually does contain the image width and height, but it errors if I access them, I’ve tried tmp.Texture.image.width as well but "Cannot read property ‘Texture’ of null "!
I wonder why the console.dir starts with “Texture” how to access that please?
solved - there isn’t a way to get the image dimensions in javascript. So, the solution is to use console.dir for all meshes of all gltf models used and write down the height and width. Place those all in an array and refer to it every time you load a model. Rubbish, but the only way it can be done.
I don’t think this statement is correct. The following fiddle proves that you can output the dimensions with the code I shared above.
yes, I see the codepen thank you. I managed to get that in the beginning but that code doesn’t work when traversing due to the error message. it’s fine I’m ok with my poor fix.