react-native-cesium 1.2.10 → 1.2.11

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.
@@ -612,6 +612,14 @@ void CesiumEngine::updateFrame(double w, double h, FrameResult& result) {
612
612
  double bestHorizDistSq = std::numeric_limits<double>::max();
613
613
  bool floorScanFound = false;
614
614
 
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).
617
+ constexpr double kFloorSearchRadiusM = 50.0;
618
+ constexpr double kFloorSearchRadiusSq = kFloorSearchRadiusM * kFloorSearchRadiusM;
619
+ // 3D fallback: if no vertices within horizontal radius, use closest 3D vertex.
620
+ double bestDist3D = std::numeric_limits<double>::max();
621
+ float bestDist3DFloor = 0.0f;
622
+
615
623
  // ── floor-scan cache lookup ─────────────────────────────────────────
616
624
  // Skip the per-vertex scan when the camera has moved less than ~10 cm in
617
625
  // both lat and lon AND the visible primitive set is unchanged (same
@@ -675,22 +683,35 @@ void CesiumEngine::updateFrame(double w, double h, FrameResult& result) {
675
683
  for (size_t vi = 0; vi < vc; ++vi) {
676
684
  const glm::dvec3 vECEF =
677
685
  glm::dvec3(prim.localPositions[vi]) + prim.rtcCenter;
678
- const glm::dvec3 delta = vECEF - cameraPos;
679
- const double de = glm::dot(delta, floorEast);
680
- const double dn = glm::dot(delta, floorNorth);
686
+ const glm::dvec3 delta = vECEF - cameraPos;
687
+ const double de = glm::dot(delta, floorEast);
688
+ const double dn = glm::dot(delta, floorNorth);
681
689
  const double horizSq = de * de + dn * dn;
682
- if (horizSq < bestHorizDistSq) {
683
- bestHorizDistSq = horizSq;
684
- bestTerrainFloor = prim.altitudes[vi];
685
- floorScanFound = true;
686
- } else if (horizSq <= bestHorizDistSq * (1.0 + 1e-9) + 1e-4) {
687
- bestTerrainFloor =
688
- std::min(bestTerrainFloor, prim.altitudes[vi]);
689
- floorScanFound = true;
690
+ const float vAlt = prim.altitudes[vi];
691
+
692
+ // Primary: horizontal search within radius, pick minimum altitude.
693
+ if (horizSq <= kFloorSearchRadiusSq) {
694
+ if (!floorScanFound || vAlt < bestTerrainFloor) {
695
+ bestTerrainFloor = vAlt;
696
+ bestHorizDistSq = horizSq;
697
+ floorScanFound = true;
698
+ }
699
+ }
700
+
701
+ // Fallback: track closest 3D vertex for sparse/ocean scenarios.
702
+ const double dist3D = glm::length(delta);
703
+ if (dist3D < bestDist3D) {
704
+ bestDist3D = dist3D;
705
+ bestDist3DFloor = vAlt;
690
706
  }
691
707
  }
692
708
  }
693
709
  }
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;
714
+ }
694
715
  }
695
716
 
696
717
  const glm::dvec3 rtcCamRel = c.rtcCenter - glm::dvec3(cameraPos);
@@ -791,17 +812,30 @@ void CesiumEngine::updateFrame(double w, double h, FrameResult& result) {
791
812
  const double de = glm::dot(delta, floorEast);
792
813
  const double dn = glm::dot(delta, floorNorth);
793
814
  const double horizSq = de * de + dn * dn;
794
- if (horizSq < bestHorizDistSq) {
795
- bestHorizDistSq = horizSq;
796
- bestTerrainFloor = prim.altitudes[vi];
797
- floorScanFound = true;
798
- } else if (horizSq <= bestHorizDistSq * (1.0 + 1e-9) + 1e-4) {
799
- bestTerrainFloor =
800
- std::min(bestTerrainFloor, prim.altitudes[vi]);
801
- floorScanFound = true;
815
+ const float vAlt = prim.altitudes[vi];
816
+
817
+ // Primary: horizontal search within radius, pick minimum altitude.
818
+ if (horizSq <= kFloorSearchRadiusSq) {
819
+ if (!floorScanFound || vAlt < bestTerrainFloor) {
820
+ bestTerrainFloor = vAlt;
821
+ bestHorizDistSq = horizSq;
822
+ floorScanFound = true;
823
+ }
824
+ }
825
+
826
+ // Fallback: track closest 3D vertex for sparse/ocean scenarios.
827
+ const double dist3D = glm::length(delta);
828
+ if (dist3D < bestDist3D) {
829
+ bestDist3D = dist3D;
830
+ bestDist3DFloor = vAlt;
802
831
  }
803
832
  }
804
833
  }
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;
838
+ }
805
839
  }
806
840
  }
807
841
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-cesium",
3
- "version": "1.2.10",
3
+ "version": "1.2.11",
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",