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

Consistent tileset focusing #109

Merged
merged 4 commits into from
Nov 22, 2022
Merged

Consistent tileset focusing #109

merged 4 commits into from
Nov 22, 2022

Conversation

nithinp7
Copy link
Contributor

@nithinp7 nithinp7 commented Nov 21, 2022

Fixes #95
Changes:

  • Overrides Unity's object focusing behavior in the editor so that it is more consistent and usable for tilesets.
  • Changed the "Place Origin Here" behavior to preserve the forward direction of the camera wrt the globe from before the georeference change.
  • Exposes functions on the CesiumGeoreference to transform direction vectors between ECEF and Unity World.

An easy way to test the old vs new behavior is to add two far-apart tilesets like Denver and Melbourne. Double-click on the further one and then hit "Place Origin Here". Repeat for the other tileset.

The specific mechanism by which I overrode Unity's focusing behavior is a bit hacky, so I'll explain it here briefly. So Unity provides a way to override a gameobject's apparent bounding volume - this overriden bounding volume is what gets used for Unity's built-in focusing functionality. If we simply provide a custom Unity bounding volume (converted from the root tile's ECEF bounding volume), then the camera might awkwardly get positioned below the terrain when focusing a tileset on the other side of the Earth (Unity will not understand the local "up" direction).

So we want to construct the camera focus transform ourselves, which we can do using the SceneView API. However, there is no clear way to get notified on the hierarchy double-click event, and there is no way to explicitly override the default focusing behavior that happens on double-click (apart from custom bounds as mentioned above). So instead what we do is the following:

  • Detect when the SceneView wants to focus on the tileset (SceneView will invoke OnGetFrameBounds to request custom bounds).
  • Run our custom focusing logic, which updates the SceneView.
  • Return dummy bounds with an infinite extent so that the editor's attempt to focus will silently fail. Otherwise our camera update will be squashed by an incorrect transform.

If anyone finds a more elegant way going forward absolutely feel free to throw this hack away, but it seems to work well for now!

@kring
Copy link
Member

kring commented Nov 22, 2022

Thanks @nithinp7!

@kring kring merged commit 78c2cb5 into main Nov 22, 2022
@kring kring deleted the focus-tileset branch November 22, 2022 01:23
@j9liu
Copy link
Contributor

j9liu commented Nov 23, 2022

This works fine for non-global tilesets, but Cesium World Terrain and Cesium OSM Buildings this method doesn't seem to work. It always ends up with the camera inside the globe looking at nothing.

You can see this in our first sample scene by double clicking either CWT or OSM buildings in the Hierarchy, then double clicking the Cesium game object (which is at 0, 0, 0 in Unity world space). It zooms from underneath the tiles to above them.

@nithinp7
Copy link
Contributor Author

@j9liu Hm that's strange I'll look into it, good catch!

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.

Double clicking tileset in hierarchy does not always zoom
3 participants