react-native-cesium 1.2.11 → 1.2.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,6 +4,7 @@
4
4
  #endif
5
5
 
6
6
  #include "CesiumEngine.hpp"
7
+ #include "GeoidConverter.hpp"
7
8
 
8
9
 
9
10
  #include <Cesium3DTilesContent/registerAllTileContentTypes.h>
@@ -608,15 +609,23 @@ void CesiumEngine::updateFrame(double w, double h, FrameResult& result) {
608
609
  const CameraParams camParams = trackTerrainFloor ? camera_.getParams() : CameraParams{};
609
610
  const double camLatRad = glm::radians(camParams.latitude);
610
611
  const double camLonRad = glm::radians(camParams.longitude);
612
+
613
+ // Expected ground ellipsoid height at camera location (from geoid).
614
+ // Used to filter out elevated structures (buildings) during floor sampling.
615
+ const double expectedGroundEllipsoid = trackTerrainFloor
616
+ ? mslToEllipsoidMeters(camParams.latitude, camParams.longitude, 0.0)
617
+ : 0.0;
618
+
611
619
  float bestTerrainFloor = terrainFloorEllipsoidM_; // carry previous value if no tile matches
612
620
  double bestHorizDistSq = std::numeric_limits<double>::max();
613
621
  bool floorScanFound = false;
614
622
 
615
- // Horizontal search radius for floor sampling (50m = reasonable for urban terrain).
616
- // Vertices within this radius are candidates; we pick the lowest (ground level).
623
+ // Horizontal search radius for floor sampling.
617
624
  constexpr double kFloorSearchRadiusM = 50.0;
618
625
  constexpr double kFloorSearchRadiusSq = kFloorSearchRadiusM * kFloorSearchRadiusM;
619
- // 3D fallback: if no vertices within horizontal radius, use closest 3D vertex.
626
+ // Only accept vertices within this tolerance of expected ground (filters out buildings).
627
+ constexpr double kGroundToleranceM = 10.0;
628
+ // 3D fallback: if no ground-level vertices found, use closest 3D vertex.
620
629
  double bestDist3D = std::numeric_limits<double>::max();
621
630
  float bestDist3DFloor = 0.0f;
622
631
 
@@ -689,12 +698,17 @@ void CesiumEngine::updateFrame(double w, double h, FrameResult& result) {
689
698
  const double horizSq = de * de + dn * dn;
690
699
  const float vAlt = prim.altitudes[vi];
691
700
 
692
- // Primary: horizontal search within radius, pick minimum altitude.
701
+ // Primary: horizontal search within radius, only accept vertices near ground level.
702
+ // This filters out elevated structures (buildings) in urban areas.
693
703
  if (horizSq <= kFloorSearchRadiusSq) {
694
- if (!floorScanFound || vAlt < bestTerrainFloor) {
695
- bestTerrainFloor = vAlt;
696
- bestHorizDistSq = horizSq;
697
- floorScanFound = true;
704
+ const double heightAboveGround = static_cast<double>(vAlt) - expectedGroundEllipsoid;
705
+ if (heightAboveGround >= -kGroundToleranceM &&
706
+ heightAboveGround <= kGroundToleranceM) {
707
+ if (!floorScanFound || vAlt < bestTerrainFloor) {
708
+ bestTerrainFloor = vAlt;
709
+ bestHorizDistSq = horizSq;
710
+ floorScanFound = true;
711
+ }
698
712
  }
699
713
  }
700
714
 
@@ -707,10 +721,23 @@ void CesiumEngine::updateFrame(double w, double h, FrameResult& result) {
707
721
  }
708
722
  }
709
723
  }
710
- // If no vertices within horizontal radius, use 3D fallback.
711
- if (!floorScanFound && bestDist3D < std::numeric_limits<double>::max()) {
712
- bestTerrainFloor = bestDist3DFloor;
713
- floorScanFound = true;
724
+ // Fallback: if no ground-level vertices found, use expected ground from geoid.
725
+ // This handles urban areas where terrain tiles only contain building structures.
726
+ if (!floorScanFound) {
727
+ if (bestDist3D < std::numeric_limits<double>::max()) {
728
+ // Use closest 3D vertex only if it's near ground level
729
+ const double heightAboveGround = static_cast<double>(bestDist3DFloor) - expectedGroundEllipsoid;
730
+ if (heightAboveGround >= -kGroundToleranceM &&
731
+ heightAboveGround <= kGroundToleranceM) {
732
+ bestTerrainFloor = bestDist3DFloor;
733
+ floorScanFound = true;
734
+ }
735
+ }
736
+ // Ultimate fallback: use geoid-based ground estimate
737
+ if (!floorScanFound) {
738
+ bestTerrainFloor = static_cast<float>(expectedGroundEllipsoid);
739
+ floorScanFound = true;
740
+ }
714
741
  }
715
742
  }
716
743
 
@@ -814,12 +841,17 @@ void CesiumEngine::updateFrame(double w, double h, FrameResult& result) {
814
841
  const double horizSq = de * de + dn * dn;
815
842
  const float vAlt = prim.altitudes[vi];
816
843
 
817
- // Primary: horizontal search within radius, pick minimum altitude.
844
+ // Primary: horizontal search within radius, only accept vertices near ground level.
845
+ // This filters out elevated structures (buildings) in urban areas.
818
846
  if (horizSq <= kFloorSearchRadiusSq) {
819
- if (!floorScanFound || vAlt < bestTerrainFloor) {
820
- bestTerrainFloor = vAlt;
821
- bestHorizDistSq = horizSq;
822
- floorScanFound = true;
847
+ const double heightAboveGround = static_cast<double>(vAlt) - expectedGroundEllipsoid;
848
+ if (heightAboveGround >= -kGroundToleranceM &&
849
+ heightAboveGround <= kGroundToleranceM) {
850
+ if (!floorScanFound || vAlt < bestTerrainFloor) {
851
+ bestTerrainFloor = vAlt;
852
+ bestHorizDistSq = horizSq;
853
+ floorScanFound = true;
854
+ }
823
855
  }
824
856
  }
825
857
 
@@ -831,10 +863,23 @@ void CesiumEngine::updateFrame(double w, double h, FrameResult& result) {
831
863
  }
832
864
  }
833
865
  }
834
- // If no vertices within horizontal radius, use 3D fallback.
835
- if (!floorScanFound && bestDist3D < std::numeric_limits<double>::max()) {
836
- bestTerrainFloor = bestDist3DFloor;
837
- floorScanFound = true;
866
+ // Fallback: if no ground-level vertices found, use expected ground from geoid.
867
+ // This handles urban areas where terrain tiles only contain building structures.
868
+ if (!floorScanFound) {
869
+ if (bestDist3D < std::numeric_limits<double>::max()) {
870
+ // Use closest 3D vertex only if it's near ground level
871
+ const double heightAboveGround = static_cast<double>(bestDist3DFloor) - expectedGroundEllipsoid;
872
+ if (heightAboveGround >= -kGroundToleranceM &&
873
+ heightAboveGround <= kGroundToleranceM) {
874
+ bestTerrainFloor = bestDist3DFloor;
875
+ floorScanFound = true;
876
+ }
877
+ }
878
+ // Ultimate fallback: use geoid-based ground estimate
879
+ if (!floorScanFound) {
880
+ bestTerrainFloor = static_cast<float>(expectedGroundEllipsoid);
881
+ floorScanFound = true;
882
+ }
838
883
  }
839
884
  }
840
885
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-cesium",
3
- "version": "1.2.11",
3
+ "version": "1.2.12",
4
4
  "description": "Experimental Cesium rendering for React Native via Nitro",
5
5
  "main": "./lib/commonjs/index.js",
6
6
  "module": "./lib/module/index.js",