CesiumGS / cesium-unity

Bringing the 3D geospatial ecosystem to Unity
https://cesium.com/platform/cesium-for-unity/
Apache License 2.0
347 stars 83 forks source link

Allow specifying an activation distance for CesiumOriginShift instead of updating every frame #396

Closed azrogers closed 8 months ago

azrogers commented 8 months ago

Fixes #182.

Currently, CesiumOriginShift sets the origin of its parent georeference every frame. This change adds an activation distance property and a checkbox to enable it. If enabled, the origin will only be shifted when the position of the CesiumGlobeAnchor is greater than activationDistance meters away from the parent CesiumGeoreference.

Originally, this change produced a strange bug with the CharacterController used by CesiumCameraController. I've fixed that bug by moving the movement code in CesiumCameraController to FixedUpdate, as it's manipulating a physics object. In addition, Physics.SyncTransforms needs to be called when updating the origin, so that the physics system is informed of the CharacterController's new position.

I've also added a test for this bug as well as a test for the activation distance property itself.

azrogers commented 8 months ago

@j9liu Updated based on review! I tried comparing profiler results from before and after the changes but nothing seems to jump out at me. I can't tell myself if it's slower or not.

j9liu commented 8 months ago

Thanks @azrogers !