1
$\begingroup$

Is it possible to find the coordinates of the visible part of an object?

Background

I imported an object to a blender scene from Object File Format (OFF) using this blender addon (e.g. a chair). To segment the object in different parts I just removed some of the OFF face entries, which do not belong to the desired object part. Than I reimport the modified OFF.

Now I'd like to determine the coordinates (bounding box) of the object part, so only the visible and actually rendered faces (e.g. the back of the chair).

bpy.data.objects['object_id'].bound_box only gives the coordinates of the complete object (chair + back of the chair). Is there any way to figure out the part-bounding-box?

Example Scene:

Chair part example

$\endgroup$
  • $\begingroup$ What program did you use to edit your OFF Object? $\endgroup$ – Marten Zander Nov 13 '15 at 13:33
  • $\begingroup$ Since OFF is just a textfile I used a python script (file.write() etc.) $\endgroup$ – frthjf Nov 14 '15 at 22:30
1
$\begingroup$

I found a working solution. I just removed the vertices from OFF which did not correspond with any face. That leads to correct bounding box dimensions. To find the correct bounding box position of the part I used the following:

# create a cube for the bounding box
bpy.ops.mesh.primitive_cube_add()
bound_box = bpy.context.active_object

# copy transforms
ob = bpy.data.objects['off_object_name']
bound_box.dimensions = ob.dimensions
bound_box.rotation_euler = ob.rotation_euler

# calculate part center
centre = sum((Vector(b) for b in ob.bound_box), Vector())
centre /= 8

# set location using world matrix transformation
bound_box.location = (centre[0], centre[1], centre[2])
bound_box.location = ob.matrix_world * bound_box.location
$\endgroup$

Your Answer

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

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