0

I am looking for code or a library call that will let me get the size of a 3D object .obj file in Java. Javagl looked promising but I don't see any. I know the way to get the bounding box comes from analyzing the file itself is to get the difference between max X and min X vertex coordinates of the object(similar for all other axis). Then you can get the center of the model from the bounding box by X size/2 + min X (similar for other axis)

Is there a better way to do this than to read the file itself or do that calculations manually?

I am using Java since I am trying to make an AR application using Android + ARCore.

Jayleen
  • 174
  • 1
  • 12

1 Answers1

0

I'll post this as an answer, though it is by no means complete, simply because it is too large for a comment. This is a rather generalized response - what exact methods you require will depend on the frameworks you use for your rendering (or 3D object processing), in this case ARCore I suppose.


Goal: Find center

If I read you correctly, you intend to find the center of your 3D object. First you need to decide what exactly you mean by "center", because this decides, whether or not you need a bounding box at all.

Some options:

  • Center of mass: A simple implementation of this is assuming all your vertices have equal weight and calculating an average over them. Disadvantage: If your vertices are not distributed uniformly, then the center will shift to whereever most vertices occur.
  • Center of an Axis Aligned Bounding Box: In this case you use your world coordinate system or whatever coordinate system you defined your 3D object in and find x_min, y_min, z_min, x_max, y_max, z_max. The center of your AABB is then simply the average of these two points. Disadvantage: Depending on 3D object orientation and dimensions the center of the AABB can be quite a bit off or not even inside the object at all.
  • Center of an Oriented Bounding Box: However maybe you want to define your bounding box based on the dimensions of your 3D object. This case is similar to AABB, however with AABB your base vectors for your bounding box are aligned with the ones of your world coordinate system. For an OBB you need to find new base vectors, where one is typically parallel to the largest-distance-vector between two points in your 3D object and the other two are orthogonal to it and each other. Once the bounding box is found finding center is the same as with the AABB. Disadvantage: Finding bases is expensive.

Visual explanation of the three options described:

Center of Mass

Center of Mass Ex. 1

Center of Mass Ex. 2

Axis Aligned Bounding Box

enter image description here

enter image description here

Oriented Bounding Box

enter image description here

enter image description here

Further reading

Koenigsberg
  • 1,726
  • 1
  • 10
  • 22