I been researching various places about trying to get the width and height of a mesh but I have been able to find anything that works. I have a collada model that I imported and all I want to do is get the dimension of it in Webgl/Three.js Units so that I can calculate collision in my simple game. So how would I go about getting the width and height of a mesh in THREE.js?
Asked
Active
Viewed 4.1k times
52
-
Please show what you attempted in order for others to be able to help. – Anonymous May 25 '14 at 20:12
-
Can someone tell me why I got -rep? I just want to know to not do it again on my future questions – May 26 '14 at 00:18
-
You got negative reputation because someone down voted your question. A down vote is meant to mean "This question does not show any research effort; it is unclear or not useful." – Anonymous May 26 '14 at 00:19
-
Thank You! I appreciate that you answered :D Also I couldnt add the code before since I was doing this on a tablet, but vincent posted the perfect answer :D – May 26 '14 at 00:35
-
1You're welcome. You may want to still add the code because otherwise, your question is on its way to being closed. – Anonymous May 26 '14 at 00:55
1 Answers
88
If you're ok with a basic bounding box, you can use a THREE.Box3
let measure = new THREE.Vector3();
let box = colladaModel.getSize(measure);
console.log( measure );

vincent
- 1,525
- 12
- 18
-
This looks like the perfect solution, i'll try it when i have a chance and i'll tell u how it went! – May 25 '14 at 22:13
-
2
-
-
2
-
do I need to somehow normalize values in matrix? Id like to flip object on x axis and move its -x_width ... flip is okay, bot move seems incorect – Buksy Oct 25 '15 at 20:09
-
1Just to keep it up two date: `size` method name was changed to `getSize` – Krzysztof Grzybek Jun 05 '18 at 20:04
-
1
-
but if the box(for example a text mesh) is rotated, the size is no more the exact width/height of that text. – iefreer Sep 23 '20 at 09:54
-
Seems like Box3().getSize() has updated usage. A Vector3 needs to be passed into it as an argument. See here for implementation https://stackoverflow.com/a/71819811/1757149 – A__ Apr 10 '22 at 19:37
-
-
Doesn't work for me, throws this error: this.objects[0].getSize is not a function – MAZ Jul 01 '22 at 15:18