USD Frustum across the frame range

   1310   7   0
User Avatar
Member
83 posts
Joined: Nov. 2019
Offline
Hello!

I am using the %bound() pattern to select primitives based on the frustum of a camera. What would be most "USD" way of doing this over the entire frame range? That way the output selection is static and contains all the primitives that at some point were inside the frustum. I am not finding a lot of success this far.

Thanks!
Edited by Cicuta - June 11, 2024 12:41:18
User Avatar
Member
83 posts
Joined: Nov. 2019
Offline
The approach that I was going with is using the timecode within the %bound() pattern; it would need to run in foreach lop for as many frames as specified (it can be every nth frame). What I dislike about this method is that I need to add a cache lop to the input (for both animated primitives and animated cameras) in order for the timecode to work. This slows everything significantly.

An alternative that I thought of, was using an objnetwork to bring in the camera, get its frustum, trail it and use it as bound geometry. It sounds faster to me so I will go with this one. But I am still curious of a method within /stage only.
This method has an weird behavior reported here: https://www.sidefx.com/forum/topic/96433/ [www.sidefx.com]

I will post my findings in a hipfile in this post in case it is useful to anyone.
Edited by Cicuta - June 11, 2024 15:46:28
User Avatar
Member
83 posts
Joined: Nov. 2019
Offline
I felt like trying with python, aiming for accessing attribute values at a specified time code using Get(frame) as I had seen the documentation, that way I could iterate and compare the attributes along the timeline, but Get(frame) its returning the value of the primitive at the frame specified in the time line because my usd is not coming from a disk file but from nodes within houdini.
Edited by Cicuta - June 12, 2024 10:42:25
User Avatar
Member
36 posts
Joined: Sept. 2014
Offline
If you want to do this in python, start with the example here on the usd survival guide.

https://lucascheller.github.io/VFX-UsdSurvivalGuide/dcc/houdini/fx/frustumCulling.html [lucascheller.github.io]

Its nice because it shows how to get the frustum, and just does bounding box intersections against it.

Its not too hard then to change it to target prim kinds like components. Etc.

I recommend using the average method, this way the python code will give you the prims in frustum for the whole camera move.


The whole usd survival guide is a great entry point to openusd python.




Hope this helps.
User Avatar
Member
83 posts
Joined: Nov. 2019
Offline
Kym Watts
https://lucascheller.github.io/VFX-UsdSurvivalGuide/dcc/houdini/fx/frustumCulling.html [lucascheller.github.io]

I have just implemented the logic shown in that link into my specific scenario, tested it and compared it with the non-python method (%bounds() + wacky foreach) I had managed to build. It is a bit faster (and more precise) than what I had before and there is room to optimize its time complexity. And there is no doubt that it is much cleaner! I will share both methods here once I have polished them.
Thanks again for the reference!


Edit: After optimizing the python method, it is significantly faster!
Edited by Cicuta - June 14, 2024 14:15:18
User Avatar
Staff
4521 posts
Joined: July 2005
Offline
Luca's repository there is amazing. Highly recommended for many topics!

That said, I'm a bit confused. In your first post you complain about needing the full camera animation to be available in order to use the %bound prim pattern (which is true), but Luca's example _also_ requires the full camera animation to be available on the stage. As would any solution to this problem, I think. The use of the "Sample Frame Range" feature on the Camera LOP is extremely important here and should not be overlooked as the best way to get animated transforms onto your stage when you can author the transforms in LOPs (no for each loops or cache LOPs required).

Anyway, I took Luca's example files, changed the instancer to create instanceable references (because primitive pattern straight up don't work on point instancer instances - if this is what you're looking for, definitely use that python code), and used a Prune LOP to do the equivalent. Also not time dependent, also doesn't require any foreach loops, runs a little faster than the python version (though of course the python version doesn't work with instanceable references so we're really comparing apples and oranges here).

I hope this is useful.

Attachments:
frustumCulling_pattern.hipnc (744.7 KB)

User Avatar
Member
9 posts
Joined: April 2021
Offline
mtucker
Luca's repository there is amazing. Highly recommended for many topics!

That said, I'm a bit confused. In your first post you complain about needing the full camera animation to be available in order to use the %bound prim pattern (which is true), but Luca's example _also_ requires the full camera animation to be available on the stage. As would any solution to this problem, I think. The use of the "Sample Frame Range" feature on the Camera LOP is extremely important here and should not be overlooked as the best way to get animated transforms onto your stage when you can author the transforms in LOPs (no for each loops or cache LOPs required).

Anyway, I took Luca's example files, changed the instancer to create instanceable references (because primitive pattern straight up don't work on point instancer instances - if this is what you're looking for, definitely use that python code), and used a Prune LOP to do the equivalent. Also not time dependent, also doesn't require any foreach loops, runs a little faster than the python version (though of course the python version doesn't work with instanceable references so we're really comparing apples and oranges here).

I hope this is useful.

really helpful.Thanks
User Avatar
Member
83 posts
Joined: Nov. 2019
Offline
mtucker
The use of the "Sample Frame Range" feature on the Camera LOP
Indeed! Yeah I wasn't very clear about the animation availability, something I got sorted out later.

mtucker
frustumCulling_pattern.hipnc (744.7 KB)
Damn! I didn't know that syntax was possible for the time codes!! I completely missed that part in the documentation.
That is so helpful!

Thanks so much for the file!
Edited by Cicuta - June 17, 2024 16:30:21
  • Quick Links