I’m wondering if it’s somehow possible to get a “true” boundingBox representation, regardless of frozen transforms and orientation?
Say for example this cube, which has a rotation on it, but frozen transforms.
I basicly just want the eight corners of the mesh, but I can’t figure out how to do it. Any tips?
I’m not sure if Maya has a built-in implementation for it. Yet algorithms for the ‘bounding box’ problem do exist: Minimum bounding box algorithms - Wikipedia
If there’s no built-in command or off the shelf script it’s a matter of defining how badly you need it. Is it a ‘nice to have’ or ‘must-have’. Defining what is a suitable bounding box for any shape is also nice. Since the smallest fitting bounding box isn’t neccesarily in a straight line with what you’d like.
Looking at the algorithm description on wikipedia you might be able to offload some of the math to Maya. I think in theory one could take each edge (looping over the mesh) and orient the mesh so that it is in line with one of the world axis, then call exactBoundingBox on the object and keep the result with the smallest bounding box as correct orientation. Using a convex hull for the mesh will speed it up since it’ll likely have less edges.
I typed this off of my phone so it’s hard to check if this is right, but I remember vaguely (I think) that the Bullet (built-in dynamics plugin) implementation defines a smallest fitting bounding box for nodes that become rigid bodies. If not I’m pretty sure it does create convex hulls for objects. So maybe that could be a starting point.
From an artist perspective it might be nicer or at least closer to expectations to select an edge (or set of points?) and then base the orientation off of that one. That way results can be closer to what they expect.
Not sure what your script/programming level is. But this could trigger some ideas.
Have fun!
Once you freeze the transforms, all bets are off. You will need to calculate the bounding box yourself.
FYI: You should never need to freeze transforms in maya, you should always manipulate components/pivots (although it is generally safe to Freeze Scale).
When I first started leanrrng Maya I was taught to constantly delete history and freeze transforms. Deleting history is fine, but you should never Freeze Transforms. I still work with lots of artists who have developed this bad habit and breaking it is nigh impossible
You can get a ‘best fit’ bounding box like this:
-
make a list of all the vertex to vertex vectors (ie vtx 1 to vtx2, vtx1 to vtx 3, etc…)
-
The longest axis is the new ‘up’ axis
-
run through all the remainingg vert-to-vert vectors, getting the dot product against the first vector. The closest dot products to zero are the closest to orthogonal to the long axis. Pick the longest one of these
-
the first secondary axis is the normalized cross vector of of the vectors from (2) and (3)
-
the next secondary axis is tne normalized cross vector of the vectors from (2) and (4)
-
your primary axis is the normalized vector from (2)
-
the first point of the long axis will be your origin
-
Make a matrix using the vectors from (4)(5) and (6):
primary.x primary,y primary.z, 0
secondary_1.x, secondary_1.y secondary_1.z, 0
secondary_2.x, secondary_2.y secondary_2.z, 0
origin.x, origin.y, origin.z, 1
-
that matrix represents a best-fit orientation. If you multiply the world vert positions from the original mesh by the inverse of that matrix, you’ll can do a simple min-max on all the x, y, and z components to get the local-space bounding box in that matrix
Thank you so much guys! It was a lot more complex than what I thought, but now I have a lot to go on, thanks again
I went for a bit different approach. I thought that getting the eight corners of the mesh would be enough to create a perfectly aligned bounding box, which it would if I knew the order of the points. I’ve managed to get all eight corners of the mesh, but I’m stuck on how I can categorize/order/distinguish the points. I have no clue on how I can make a procedure that is able to order the points regardless of the shape (rectangular, quadrangular, tapered, skewed). Is that even possible to do without having to compute millions of different scenarios?
Yeah, so basicly I want to generate a mesh from eight points without knowing the order of the points, sounds so easy…But it isn’t!! :(:
Theodox: I haven’t tried your method yet, unless you count reading your step-by-step 50 times as attempts, heh :p: It’s a bit over my head, but I’m not giving up though! It’s just one thing, before I use days on trying to grasp your guide, could you tell me if you’ve tried this method yourself? Does it work?
There’s a couple of things you could do:
-
a convex hull generator like Qhull or DDConvexHull will give you what you want if your shapes started life as boxes. However you’ll still have to use something like the algo I sketched out if you want to find the local transform where that box is an axis-aligned bounding box
-
Again, if you’re sure the geometry is the box you can look make a list of all the point-to-point distances. You’ll see several groups:
a) the longest ones will be corner-to-corner diagonals. ignore these
b) the second-longest set will be the long outer edges of the volume ; keep them
c) the third-longest set will be the diagonals of the top and bottom; ignore these
d) the shortest set will be the outer edges of the top and bottom faces; keep them
(note: this works for shapes like those in your example: for a cube there will be 3, not 4 groups with long diagonals, short diagonals, and then cube edges)
once you’ve got the edges you need to assemble triangular faces for each point. Each will have one long edge and two short ones. With a little pen and paper work you should be able to work out a winding order that gives you a bounding box.
Thanks man! I really appreciate it :D: