I am making a game in OpenGL and Blender and trying to use JBullet as the collision manager. I am using BoxShapes for collisions, which requires a javax.vecmath.Vector3f representing half of the box to create.

How do I calculate the dimensions (width, depth and height) of a Blender model in-game?

| improve this question | | | | |
  • \$\begingroup\$ You need to find MBB of your model as it seems, why did you go into jbullet and physics in your question? Do you want to use MBB as collision body of your 3D model? Please clarify the question and delete unneccessary parts, however if you are using a lib to use OpenGL or using an inline C part please tell, also tell what is the format of your 3D model \$\endgroup\$ – Iman Sep 5 '15 at 18:42

When you're reading the model into your game, you'll be iterating through each vertex of the model. Simply keep track of the max/min for each X, Y and Z axes. Using these values you can find the center of your model as well as the extents. The width is the distance between X min and X max, the depth and height are similarly calculated depending on which axis you're using for which dimension.

| improve this answer | | | | |
  • \$\begingroup\$ Ok, so i am supposed to get the minimum vertex and the higest one for XYZ to get the measures. How exactly is that done? I am using OBJ's exported from blender. \$\endgroup\$ – user69046 Sep 6 '15 at 8:30
  • \$\begingroup\$ We'd have to know how you're processing the vertices when you import a model. It sounds like you're making your own engine, so at some point, you'd be iterating through all the vertices of your model to read in their positions from a file to memory. That is the time when you'd want to read the position of each and get the minimum and maximum. \$\endgroup\$ – MichaelHouse Sep 6 '15 at 14:12
  • \$\begingroup\$ I am using(primarily) the engine made by ThinMatrix. In the engine, there is a method which prosesses the entire model(in OBJ format). \$\endgroup\$ – user69046 Sep 6 '15 at 16:52
  • \$\begingroup\$ @Polarbear0106 Then you need to consult the documentation of the engine you're using to determine how to retrieve the information you're interested in. \$\endgroup\$ – MichaelHouse Sep 7 '15 at 7:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy