# How to create a camera-space 2D bounding box in Geometry Nodes?

I've been trying to create a 2D bounding box. On this website I've found multiple threads about how to do this with code, but not how to do this with Geometry Nodes. Here's an example of what I imagine this would look like. In my case this would be more like a plane slicing through the source mesh or being in front of it:

So far I've been able to figure out that I will need the x and y axis, relative to the camera viewpoint. The "Attribute Statistic" node also seems necessary to get the minimum and maximum positions on camera's x and y axis.

I also tried a couple things with the "Bounding Box" node, but I can't make it face in the direction of the camera without it no longer fitting the source object. If this was possible, I could simply take the frontal plane. That this plane would appear slightly larger because of perspective is not an issue in my case.

Any help is appreciated!

• This is a camera space bounding box. You would need to calculate a camera space min/max x and y and then use that to draw the bounding box Feb 8 at 17:21
• @Markus von Broady How fascinating! However, how does one actually go about calculating the camera space min/max? This does not seem obvious to me or quite possibly, practical. Feb 8 at 19:54

Here's an old method that I recycled for you to do the trick. Although it may not be elegant, it is rather straightforward.

First, we'll take the object to be boxed and reproject it to the camera view.

Once we use a bounding box to encompass our newly flattened object, we would have achieved our goal. To do so, we will align the flattened object to world origin by applying the inverse camera rotation.

Doing so, allows our bounding box to be dynamic for any shape or object. Now, we can apply the Bounding Box node. Even though our bounding box becomes a flat plane when used, its geometry is still that of a box so, we only need 1 face. Thus, we will select the top face of our bounding box since it is the face that is visible to the camera. This face is indexed at $$2$$. Finally, we'll revert the 2D box back to camera view.

Here is the result.

For some extra parameters, I included a Scale and Material for you. The Scale is for you to control how far away 2D box is from the camera and the Material is for you to control how the plane looks when rendered.

Blender 4.0.2

• I don't know what I was thinking, my brain just wasn't functioning when I read this, that's why I made an answer that said the same thing. Sorry. Feb 9 at 21:25
• lol. It's understandable. I didn't really explain in-depth how this node tree works because it was a duplicate answer, I made months ago. A person would just have to go through it and play with it to realize my intentions. Feb 10 at 0:20

Thanks to Obfuscate's reply I managed to find a different solution:

First we rotate the object to align with the camera. We can do this by using the inverted camera rotation. Since I'm still working with Blender 3.6 that looks a little different from Obfuscate's Blender 4.0 solution:

Then we create the 3D bounding box and undo our previous rotation by re-applying the camera rotation. Now we have a bounding box that faces the camera:

After that it's just a matter of separating out the frontal face. As I mentioned in my question, this means that the "2D bounding box" will always appear a little larger than the source mesh. This is fine in my case: