# Picking issue on geometry without authorred \`extent\`

**URL:** <https://forum.aousd.org/t/picking-issue-on-geometry-without-authorred-extent/694>\
**Category:** Hydra\
**Created:** [September 21, 2023, 2:41pm UTC](https://forum.aousd.org/t/picking-issue-on-geometry-without-authorred-extent/694 "2023-09-21T14:41:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![shiuea](https://avatars.discourse-cdn.com/v4/letter/s/7993a0/32.png) [@shiuea](https://forum.aousd.org/u/shiuea)\
**Post date:** [September 21, 2023, 2:41pm UTC](https://forum.aousd.org/t/picking-issue-on-geometry-without-authorred-extent/694/1 "2023-09-21T14:41:19Z")

</div>

Context of the issue: if the geomoery has no authored `extent` attribute, the default extent while creating the boox for pixking test is [-1, 1]. This reaults the picking failed outsite the bbox even if the pick is on the geometry.

According to this [comments](https://github.com/PixarAnimationStudios/OpenUSD/blob/10b62439e9242a55101cf8b200f2c7e02420e1b0/pxr/imaging/hdSt/primUtils.cpp#L820), the default bbox is supposed to be [-FLT\_MAX, FLT\_MAX]. The codes use `prim->GetExtent(delegate)` to create the bbox. Unfortunately, the default extent is [-1, 1] if it has no authored value.

Apparently, I can fix the issue with two solutions:

- Add a new function `prim->HasAuthorredExtent(delegate)` and then create bbox of [-FLT\_MAX, FKT\_MAX] if there is no authorred extent.
- Change the fallback value of `extent` to [-FLT\_MAX, FLT\_MAX]

The first solution is not difficult, I just need to follow the calls of `prim->GetExtent(delegate)` and create `HasAuthorredExtent()`. The call stack is rather long and ugly but it is definitely doable.

I personally prefer the 2nd solution: change the the fallback value of `extent` to [-FLT\_MAX, FLT\_MAX].

Two issues I am having right now is:

1. Will changing the default `extent` have unwanted side effects? To me, [-FLT\_MAX, FLT\_MAX] is clearlly a better default than [-1, 1].
2. How to set the default value of `extent`? I traced `GetFallbackValue()` to learn how the fallback is stored. It looks like `SdfFieldKeys->Default` is used to set the field value. Unfortunately though, I did not find the codes that set the default `extent`.

My main question is on how to set the default value of `extent`. But also apprecicate feedbacks on other parts of my comments. Thanks,

---

<div class="post-metadata">

**Author:** ![tomc](https://avatars.discourse-cdn.com/v4/letter/t/8dc957/32.png) [@tomc](https://forum.aousd.org/u/tomc)\
**Post date:** [October 6, 2023, 11:16pm UTC](https://forum.aousd.org/t/picking-issue-on-geometry-without-authorred-extent/694/2 "2023-10-06T23:16:32Z")

</div>

Can you describe where the extent [-1,1] is coming from? From a quick read of the usdImaging library, if you don’t manually author an “extent” attribute on a prim, the library does indeed construct an empty GfRange3d, which is defined as [-FLT\_MAX, FLT\_MAX]. It sounds like the [-1,1] is definitely a bug but I’m not clear on where it’s coming from.

Thanks!

---

<div class="post-metadata">

**Author:** ![shiuea](https://avatars.discourse-cdn.com/v4/letter/s/7993a0/32.png) [@shiuea](https://forum.aousd.org/u/shiuea)\
**Post date:** [October 12, 2023, 6:59pm UTC](https://forum.aousd.org/t/picking-issue-on-geometry-without-authorred-extent/694/3 "2023-10-12T18:59:42Z")

</div>

If you trace the execution to [this call](https://github.com/PixarAnimationStudios/OpenUSD/blob/10b62439e9242a55101cf8b200f2c7e02420e1b0/pxr/imaging/hdSt/primUtils.cpp#L823), if there is no authored extent, `prim->GetExtent(delegate)` will return [-1, 1] as the fallback value. This conflicts to the comments right above that line.

Another way to verify this is to create a simple usda file:

> #usda 1.0
> 
> def Xform “hello”  
> {  
> def Sphere “world”  
> {  
> double radius = 2  
> }  
> }

Run the following commands in python:

> from pxr import Usd, UsdGeom  
> stage = Usd.Stage.Open(‘HelloWorld.usda’)  
> sphere = stage.GetPrimAtPath(‘/hello/world’)  
> extentAttr = sphere.GetAttribute(‘extent’)  
> extentAttr.Get()

You will get [-1, 1] as well since there is no authored extent in the sphere.

The range is created with the min/max of the extent:

> GfRange3d  
> HdSceneIndexAdapterSceneDelegate::GetExtent(SdfPath const &id)  
> {  
> TRACE\_FUNCTION();  
> HF\_MALLOC\_TAG\_FUNCTION();  
> HdSceneIndexPrim prim = \_inputSceneIndex-\>GetPrim(id);
> 
> ```
> HdExtentSchema extentSchema =
> HdExtentSchema::GetFromParent(prim.dataSource);
> if (!extentSchema.IsDefined()) {
> return GfRange3d();
> }
> 
> GfVec3d min, max;
> if (HdVec3dDataSourceHandle minDs = extentSchema.GetMin()) {
> min = minDs->GetTypedValue(0);
> }
> if (HdVec3dDataSourceHandle maxDs = extentSchema.GetMax()) {
> max = maxDs->GetTypedValue(0);
> }
> 
> return GfRange3d(min, max);
> 
> ```
> 
> }

Min/max are from:

> HdVec3dDataSourceHandle  
> HdExtentSchema::GetMin()  
> {  
> return \_GetTypedDataSource(  
> HdExtentSchemaTokens-\>min);  
> }
> 
> HdVec3dDataSourceHandle  
> HdExtentSchema::GetMax()  
> {  
> return \_GetTypedDataSource(  
> HdExtentSchemaTokens-\>max);  
> }

I lost the trace here. Searched `HdExtentSchemaTokens->max` in USD but cannot find the codes that set the min/max value.

---

<div class="post-metadata">

**Author:** ![tomc](https://avatars.discourse-cdn.com/v4/letter/t/8dc957/32.png) [@tomc](https://forum.aousd.org/u/tomc)\
**Post date:** [October 17, 2023, 8:14pm UTC](https://forum.aousd.org/t/picking-issue-on-geometry-without-authorred-extent/694/4 "2023-10-17T20:14:03Z")

</div>

Hey Andy,

As it turns out, “Gprim” doesn’t define a default extent and when hydra can’t read an extent from USD, we use [-max, max]. However, “Sphere” does define an extent fallback of [-1,1]^3: [https://github.com/PixarAnimationStudios/OpenUSD/blob/release/pxr/usd/usdGeom/schema.usda#L698](https://github.com/PixarAnimationStudios/OpenUSD/blob/release/pxr/usd/usdGeom/schema.usda#L698) … This matches with the radius fallback, but if you define a radius and not an extent that would be badly-formed USD data and I wouldn’t be surprised if it was behaving incorrectly.

Are you seeing this with other prim types? And how hard is it to ensure your data comes in with authored extents? (Since that’s just a better packaging of the data anyhow).

Thanks!  
Tom

---

<div class="post-metadata">

**Author:** ![shiuea](https://avatars.discourse-cdn.com/v4/letter/s/7993a0/32.png) [@shiuea](https://forum.aousd.org/u/shiuea)\
**Post date:** [October 19, 2023, 3:26pm UTC](https://forum.aousd.org/t/picking-issue-on-geometry-without-authorred-extent/694/5 "2023-10-19T15:26:36Z")

</div>

Hi Tom,

It looks like all geometries (such as Sphere, Cube, Cone…etc) have [-1 1] as the fallback extent. The fallback extent though conflicts to this [comment](https://github.com/PixarAnimationStudios/OpenUSD/blob/10b62439e9242a55101cf8b200f2c7e02420e1b0/pxr/imaging/hdSt/primUtils.cpp#L820).

I had a fix right after that comment to check if the extent has an authored value. I pretty much just implemented that comment (the fix is not in the public repo yet). Though I feel fixing the fallback extent is a better fix for the picking issue.

I do understand that fallback extent [-1, 1] matches the fallback Sphere radius. So that kinda makes sense too. Though [-1 1] is not my preferred falbback. I would consider either one of [0 0] , [-max, max] or [max, -max] a better fallback as they have better logical implication.

I am simply a consumer of the scene so I don’t know the difficulty of having the authored extent. I guess it should not be hard for artist. They probably just use one of the usd autoring tools to generate the scene.

My opnion on this though is: fallback extent should not break the USD/Hydra’s behavior or functionality.

If I changed the fallback extent to [max, -max] (to abide by the comment), will it be accpted back to USD repo? I can keep my current fix (explicitly implement that [comment](https://github.com/PixarAnimationStudios/OpenUSD/blob/10b62439e9242a55101cf8b200f2c7e02420e1b0/pxr/imaging/hdSt/primUtils.cpp#L820)) as well if that has a better chance to be accpted.

Thanks,

–Andy
