0

I am using blender for a synthetic data generation for over a month now. I was hoping to achieve the same computation with less time than using BVH tree for collision detection, no luck so far.

I was using bound box in bpy module, like

cube = bpy.data.objects['Cube']
cube.bound_box # return itterable of points in 3d space

There are two problems that I faced,

  1. Bound box won't update on its own because of the transformation of the objects, like rotation, location, scale. For that I had to use bpy.ops.transform_apply(scale=True, location=True, rotation=True)

  2. When I did use that force update, I noticed that the bound box that blender gives isn't ideal as they mention in documents, it can be confirmed in the example below enter image description here The surface of the cube is itself a bound box as it is a cube after all, but the cube.bound_box is giving this bound box shown in pic, which is nowhere near ideal.

Note: If anyone found something wrong in this post, please do comment as I am in the middle of development of a framework which is basically a automation of this scene creation. It will really help me a lot, if you could suggest or provide the solution of my issues that I mentioned above.

lemon
  • 60,295
  • 3
  • 66
  • 136
solus
  • 9
  • 1
  • The boundbox is the bounding coordinates in local space. If you want the global coordinate multiply each coordinate by the matrix world of the object, just as you would to get the global coordinates of each vertex. eg for the default cube the vertex coordinates match the bbox coordinates. Transforming at object level does not effect the coordinates at a local level. – batFINGER Nov 30 '20 at 12:30
  • Algorithm here https://github.com/intel-isl/Open3D/blob/414a67ae5111b352c20511b0d611fdd9cf163177/cpp/open3d/geometry/BoundingVolume.cpp#L148 – lemon Nov 30 '20 at 12:39
  • @lemon .... first step would be to look at AABB (axis aligned bounding box) which is what the blender bounding box is. The OP has transformed the mesh and hence changed the vert coordinates and hence the AABB, whereas would suggest they transform the bbox coords into global space to "See the update" Would be same issue if they used the cube verts which also wouldn't "update" when "using transformation like location, rotation and scale" on the object. eg https://blender.stackexchange.com/a/62047/15543 to calc global bbox center. – batFINGER Nov 30 '20 at 12:49
  • @batFINGER, I think he wants to know the minimal enclosing bb. – lemon Nov 30 '20 at 12:58
  • We'll see. As OP mentioned in post wasn't seeing an update in bbox so applied the transform to the mesh data (local) and hence the bbox now "isn't ideal". Suggest instead to [ob.matrix_world @ Vector(b) for b in ob.bound_box] will giive the transformed coordinates of the "updated bbox" and will be both axis and object aligned as it was in the first place. IMO this is a local vs global coordinates issue, not how to program an OOBB. Anyway we'll see. – batFINGER Nov 30 '20 at 13:01
  • @batFINGER you're probably right (as usual) – lemon Nov 30 '20 at 13:31
  • @batFINGER I understand what you are saying, but is there any confirmation that the first bounding box is in fact the ideal one? I want to know the minimal enclosing bound box. – solus Nov 30 '20 at 14:37
  • Make that your question then. Blender uses an axis aligned bounding box. For most default primitives this is also the minimal enclosing bounding box. As you have noticed applying the transform to the mesh (ie locally to the vert coord data) is of no use whatsoever towards your goal. – batFINGER Nov 30 '20 at 14:44
  • yeah, but the objects that I am using aren't as simple as box or sphere. But thanks I guess that just answered my question. – solus Nov 30 '20 at 14:48

0 Answers0