Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Powertools context menu for cartographic polygon functions #630

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

r-veenstra
Copy link
Contributor

@r-veenstra r-veenstra commented Jan 23, 2024

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 #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)

Screen.sharing.-.2024-01-25.3_24_18.PM.mp4

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
Copy link
Contributor

quite possibly need changing once #626 is merged due to globe anchor changes.

Agreed. I'll review this PR right after #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
Copy link
Contributor Author

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 r-veenstra changed the title Powertools context menu for cartographic polygon conversion Powertools context menu for cartographic polygon functions Jan 25, 2024
@r-veenstra
Copy link
Contributor Author

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor Author

@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
Copy link
Contributor

@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
Copy link
Contributor Author

r-veenstra commented Jan 26, 2024

@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
Copy link
Contributor

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants