0

I am trying to write code to align an object to another. To do so, I calculate the objects' bounding boxes like so:

bbox_a =  [Vector(bbvert) @ mesh_object_a.matrix_world for bbvert in mesh_object_a.bound_box]
bbox_b =  [Vector(bbvert) @ mesh_object_b.matrix_world for bbvert in mesh_object_b.bound_box]

then compare the min or max along the chosen axis, and move the location of the second object accordingly.

However I've noticed that, even if object_b has a location of

<Vector (-4.0000, 0.0000, 0.0000)>

bbox_b is

[
 Vector((-1.4142135381698608, 0.0, -1.0)), Vector((-1.4142135381698608, 0.0, 1.0)),
 Vector((0.0, 1.4142135381698608, 1.0)), Vector((0.0, 1.4142135381698608, -1.0)),
 Vector((0.0, -1.4142135381698608, -1.0)), Vector((0.0, -1.4142135381698608, 1.0)),
 Vector((1.4142135381698608, 0.0, 1.0)), Vector((1.4142135381698608, 0.0, -1.0))
]

i.e.: it looks like it has ignored location.

Did I get it right? do I have to apply location on top of matrix_world in order to find out the actual bounding box of the object? and (to future-proof the question) is it so for all other transforms too?

simone
  • 745
  • 4
  • 14
  • 1
    The correct syntax is matrix @ vector, not the other way around – Gorgious Aug 02 '21 at 07:54
  • 1
    @Gorgious - yes it does, thanks. I got the vector @ matrix thing from https://blender.stackexchange.com/questions/88914/how-to-get-3d-vertex-bounding-box-around-the-object-in-python – simone Aug 02 '21 at 08:44
  • 1
    You're right, the answer you linked is wrong. (the error was pointed out in the comments) It will be edited, thanks :) – Gorgious Aug 02 '21 at 08:50
  • @Gorgious - I edited it already but I'd appreciate any check, as a newbie – simone Aug 02 '21 at 10:07
  • Alright, you're all set. Thanks for the feedback :) – Gorgious Aug 02 '21 at 10:46

0 Answers0