Take the 2-minute tour ×
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It's 100% free, no registration required.

I am using Blensor v2.67. I have a camera and several objects in my scene. The camera follows a path and I would like to save what the camera sees for each frame. Among other things, I would like to save the (oriented) bounding boxes of my objects. I did some research, but I believe Display bounding box around objects only displays the bounding boxes and in Save the bounding box position of an object in a text file the requirements seem to be different (2D, moving object,...). Any answer on how to do this will be greatly appreciated! Is there inherent functionality to do this or do I need to include a custom script?

share|improve this question
    
I also wonder, if a group of objects can have a "bound box" including all the subobjects... I'm struggling with the same problem as you are. My tests have shown that duplicated groups have no information about their dimension. Is there any solution to get or compute them? I would like to use them in a driver to adjust the scale of an object according to its dimensions. –  user605379 Jul 18 at 9:14
add comment

2 Answers 2

From my answer here, you can create a bounding cube around an object:

  1. Select the target object and press ShiftS> Cursor to selected to move the cursor to the objects origin.

  2. Add a cube to be the bounding box. It will automatically be centered at the 3D cursor, which is snapped to the target object's origin point.

  3. Copy the Dimension and Rotation values from the target object to the bounding cube. These values are located on the Properties region (N in the 3D view):

    enter image description here

    You can quickly copy and paste values by hovering over the number field and pressing CtrlC/CtrlV accordingly.

    Since this process of copying and pasting the values of each channel can be a bit tedious, you can use a quick bit of python to do this for you:

    import bpy
    
    active = bpy.context.active_object
    selected = bpy.context.selected_objects
    
    for obj in selected:
        obj.dimensions = active.dimensions
    
  4. Parent the bounding box to the target object so the relative location, rotation, and scale is kept the same. You can also set the bounding cube's Draw type to Wire in Properties > Object > Display > Maximum Draw Type.

This processes could be automated in python:

import bpy

selected = bpy.context.selected_objects

for obj in selected:
    #create a cube for the bounding box
    bpy.ops.mesh.primitive_cube_add() 
    #our new cube is now the active object, so we can keep track of it in a variable:
    bound_box = bpy.context.active_object 

    #copy transforms
    bound_box.dimensions = obj.dimensions
    bound_box.location = obj.location
    bound_box.rotation_euler = obj.rotation_euler

This adds a bounding box object for every selected object.

share|improve this answer
    
Thanks! To export the boxes rotation etc I would also need to code a Python script I imagine? I guess its time to get into python scripting with blender then.. ;) –  user1809923 Jul 15 at 8:12
    
@user1809923 I've added an example script –  gandalf3 Jul 15 at 8:29
    
Nice! I wonder however if it is necessary to create an extra object for the bounding box. With the show_bounds function a bounding box is already displayed, so this box needs to exist somewhere. Also an object has a "bound_box" (blender.org/documentation/blender_python_api_2_71_release/…). I also wonder, if a group of objects can have a "bound box" including all the subobjects... –  user1809923 Jul 15 at 9:05
add comment

By using the addon I added to your other question you can create a bounding box that has the dimensions that you can easily export to a text file.

If you want to export an individual bounding box for each object you can enable the addon and run the following -

startobjs = [o.name for o in bpy.context.selected_objects]

for objname in startobjs:
    bpy.ops.object.select_all(action='DESELECT')
    bpy.data.objects[objname].select = True
    bpy.ops.mesh.boundbox_add()

As the addon names each bounding box with the name BoundingBox you can easily select just the bounding boxes (using select pattern in the select menu) and then export the selected objects.

enter image description here

Then when you export turn on the selected only option available in most exporters. If your using your own script to export to text then loop over the selected objects.

for obj in bpy.context.selected_objects:
    print(obj.dimensions.x)
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.