CesiumGS / cesium-omniverse

Bringing the 3D geospatial ecosystem to Omniverse
https://cesium.com/platform/cesium-for-omniverse/
Apache License 2.0
55 stars 7 forks source link

Powertools context menu for cartographic polygon functions #630

Open r-veenstra opened 7 months ago

r-veenstra commented 7 months ago

This PR adds a context menu option to Powertools that converts Basis Curves into Cesium Cartographic Polygons.

The option is available in both the viewport image

And the stage window image

I have based this implementation off context_menu.py in omni.curve.manipulator

The context menu item will be visible with one or more Basis Curves selected. It will not display if any non-basis curve prims are selected.

The logic for conversion is using the pre-existing code for converting Basis Curves, and will quite possibly need changing once https://github.com/CesiumGS/cesium-omniverse/pull/626 is merged due to globe anchor changes.

I'd also propose this functionality be moved from powertools into the core plugin before the next release, given the limitations for authoring Cesium Cartographic Polygons at this stage.

EDIT:

This PR now also includes a feature to create a new BasisCurve from the footprint of a prim(and its children)

https://github.com/CesiumGS/cesium-omniverse/assets/123468416/14842ebc-b276-44ac-90f3-95a9bdd39504

This implementation uses the Shapely library to perform 2D shape functions.

At a high level the logic is

  1. Find all UsdGeom.Mesh prims in a selected prims heirarchy
  2. Flatten all faces in each UsdGeom.Mesh horizontally (takes into account Stage up-axis)
  3. Use Shapelys unary_union function to merge all faces into one or more polygons representing the boundary of the mesh on the horizontal plane
  4. Repeat for all children UsgGeom.Mesh prims (this way the user can select a complex model like an architectural building with many prims and create a footprint for the entire structure)
  5. Combine all mesh boundaries together to form a complete boundary for the entire heirarchy
  6. Generate one or more UsdGeom.BasisCurves from the result

An optimisation has been added that compares the AABB of the current mesh to the accumulated boundary of all meshes processed so far. If the AABB is complately within the accumulated boundary horizontally, it is skipped. This has reduced processing of the above architectural model from ~22s to 4s. Further optimisations could be added, such as sorting the meshs by largest AABB first.

This option is available as a right-click context menu item on many prim heirarchy that contains one or more UsdGeom.Mesh prims.

corybarr commented 7 months ago

quite possibly need changing once https://github.com/CesiumGS/cesium-omniverse/pull/626 is merged due to globe anchor changes.

Agreed. I'll review this PR right after https://github.com/CesiumGS/cesium-omniverse/pull/626

I'd also propose this functionality be moved from powertools into the core plugin before the next release, given the limitations for authoring Cesium Cartographic Polygons at this stage.

I agree. We should also strongly consider moving over the cartographic-polygon footprint tool.

r-veenstra commented 7 months ago

I agree. We should also strongly consider moving over the cartographic-polygon footprint tool.

I'm going to polish it up and add the footprint tool to this PR too

r-veenstra commented 7 months ago

I've added the footprint generation script here. @corybarr it would be good to test on windows to ensure the Shapely library properly installs for a new user. Likewise @lilleyse or @timoore if you could confirm Linux installation works ok that would be great. I've followed the same approach for pip installing that was used for the proj library.

corybarr commented 7 months ago

I've added the footprint generation script here. @corybarr it would be good to test on windows to ensure the Shapely library properly installs for a new user. Likewise @lilleyse or @timoore if you could confirm Linux installation works ok that would be great. I've followed the same approach for pip installing that was used for the proj library.

@r-veenstra There's an issue with numpy on Windows:

Processing c:\users\cbarr\p\co3\exts\cesium.powertools\vendor\shapely-2.0.2-cp310-cp310-win_amd64.whl
ERROR: Could not find a version that satisfies the requirement numpy>=1.14 (from shapely==2.0.2) (from versions: none)
ERROR: No matching distribution found for numpy>=1.14 (from shapely==2.0.2)

2024-01-25 22:49:23 [888,628ms] [Warning] [omni.kit.pipapi.pipapi] 'c:\users\cbarr\p\co3\exts\cesium.powertools\vendor\shapely-2.0.2-cp310-cp310-win_amd64.whl' failed to install.
2024-01-25 22:49:23 [888,629ms] [Error] [cesium.powertools.extension] Could not install wheel for shapely
corybarr commented 7 months ago

I've added the footprint generation script here. @corybarr it would be good to test on windows to ensure the Shapely library properly installs for a new user. Likewise @lilleyse or @timoore if you could confirm Linux installation works ok that would be great. I've followed the same approach for pip installing that was used for the proj library.

@r-veenstra There's an issue with numpy on Windows:

Processing c:\users\cbarr\p\co3\exts\cesium.powertools\vendor\shapely-2.0.2-cp310-cp310-win_amd64.whl
ERROR: Could not find a version that satisfies the requirement numpy>=1.14 (from shapely==2.0.2) (from versions: none)
ERROR: No matching distribution found for numpy>=1.14 (from shapely==2.0.2)

2024-01-25 22:49:23 [888,628ms] [Warning] [omni.kit.pipapi.pipapi] 'c:\users\cbarr\p\co3\exts\cesium.powertools\vendor\shapely-2.0.2-cp310-cp310-win_amd64.whl' failed to install.
2024-01-25 22:49:23 [888,629ms] [Error] [cesium.powertools.extension] Could not install wheel for shapely

I added the numpy 1.26 whls to extension.py, but the shapely whl is still having an issue installing:

Installing whl for pyproj
Successfully installed whl for pyproj
Installing whl for numpy
Successfully installed whl for numpy
Installing whl for shapely
...
ERROR: Could not find a version that satisfies the requirement numpy>=1.14 (from shapely==2.0.2) (from versions: none)
ERROR: No matching distribution found for numpy>=1.14 (from shapely==2.0.2)
2024-01-26 00:07:17 [3,857ms] [Warning] [omni.kit.pipapi.pipapi] 'c:\users\cbarr\p\co3\exts\cesium.powertools\vendor\shapely-2.0.2-cp310-cp310-win_amd64.whl' failed to install.
2024-01-26 00:07:17 [3,858ms] [Error] [cesium.powertools.extension] Could not install whl for shapely
r-veenstra commented 7 months ago

@corybarr oh my bad. I did have numpy whls but thought they were for another powertool I was working on simultaneously. I still have them here uncommitted, so I'll add and test later today

corybarr commented 7 months ago

@corybarr oh my bad. I did have numpy whls but thought they were for another powertool I was working on simultaneously. I still have them here uncommitted, so I'll add and test later today

Sure, I'll give it a test. I'm puzzled why shapely can't see my installed numpy whls. It seems very straightforward to add them. Did you do anything beyond copying them and adding an element to the array in extension.py?

r-veenstra commented 7 months ago

@corybarr I've added back what I had in there, deleted my shapely and numpy folders from USD Composers pip3-env folder and they appeared to install correctly

corybarr commented 7 months ago

@corybarr I've added back what I had in there, deleted my shapely and numpy folders from USD Composers pip3-env folder and they appeared to install correctly

This is puzzling. Your commit is character-by-character exactly what I tried. I still get the same installation error for the shapely whl. It appears that the shapely whl can't see the numpy whl that was just installed. I don't have numpy on this laptop and never have, but that shouldn't matter. The numpy whl is successfully logging as installed prior to the shapely whl attempting its installation.