5
$\begingroup$

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:

enter image description here

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!

$\endgroup$
2
  • 1
    $\begingroup$ 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 $\endgroup$ Commented Feb 8 at 17:21
  • 1
    $\begingroup$ @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. $\endgroup$
    – Obfuscate
    Commented Feb 8 at 19:54

2 Answers 2

6
$\begingroup$

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

enter image description here

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

enter image description here

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.

enter image description here

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.

enter image description here

Here is the result.

enter image description here

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.

enter image description here


Blender 4.0.2

$\endgroup$
2
  • $\begingroup$ 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. $\endgroup$
    – Nathan
    Commented Feb 9 at 21:25
  • $\begingroup$ 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. $\endgroup$
    – Obfuscate
    Commented Feb 10 at 0:20
1
$\begingroup$

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

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: 2

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: 3

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: 4

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .