react-native-cesium 1.2.3 → 1.2.5

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.
Files changed (44) hide show
  1. package/README.md +100 -27
  2. package/android/CMakeLists.txt +1 -2
  3. package/android/src/main/cpp/CesiumBridgeAndroid.cpp +264 -130
  4. package/android/src/main/cpp/CesiumBridgeAndroid.h +70 -27
  5. package/android/src/main/java/com/margelo/nitro/reactnativecesium/CesiumBridgeJNI.kt +68 -44
  6. package/android/src/main/java/com/margelo/nitro/reactnativecesium/HybridCesiumView.kt +199 -187
  7. package/cpp/engine/CameraIntegrator.cpp +374 -0
  8. package/cpp/engine/CameraIntegrator.hpp +146 -0
  9. package/cpp/engine/EngineTunables.hpp +90 -31
  10. package/cpp/engine/GlobeCamera.cpp +17 -6
  11. package/cpp/engine/GlobeCamera.hpp +11 -8
  12. package/cpp/engine/test/CameraIntegratorTest.cpp +205 -0
  13. package/cpp/engine/test/build_and_run.sh +27 -0
  14. package/example/README.md +1 -1
  15. package/ios/CesiumBridge.h +53 -28
  16. package/ios/CesiumBridge.mm +172 -86
  17. package/ios/HybridCesiumView.swift +256 -145
  18. package/lib/typescript/src/specs/cesium-view.nitro.d.ts +85 -13
  19. package/lib/typescript/src/specs/cesium-view.nitro.d.ts.map +1 -1
  20. package/nitrogen/generated/android/ReactNativeCesiumOnLoad.cpp +2 -0
  21. package/nitrogen/generated/android/c++/JFunc_void_CameraState.hpp +77 -0
  22. package/nitrogen/generated/android/c++/JHybridCesiumViewSpec.cpp +108 -9
  23. package/nitrogen/generated/android/c++/JHybridCesiumViewSpec.hpp +21 -3
  24. package/nitrogen/generated/android/c++/views/JHybridCesiumViewStateUpdater.cpp +24 -0
  25. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativecesium/Func_void_CameraState.kt +80 -0
  26. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativecesium/HybridCesiumViewSpec.kt +71 -3
  27. package/nitrogen/generated/ios/ReactNativeCesium-Swift-Cxx-Bridge.cpp +3 -3
  28. package/nitrogen/generated/ios/ReactNativeCesium-Swift-Cxx-Bridge.hpp +43 -28
  29. package/nitrogen/generated/ios/c++/HybridCesiumViewSpecSwift.hpp +89 -9
  30. package/nitrogen/generated/ios/c++/views/HybridCesiumViewComponent.mm +30 -0
  31. package/nitrogen/generated/ios/swift/Func_void_CameraState.swift +5 -5
  32. package/nitrogen/generated/ios/swift/HybridCesiumViewSpec.swift +15 -3
  33. package/nitrogen/generated/ios/swift/HybridCesiumViewSpec_cxx.swift +242 -16
  34. package/nitrogen/generated/shared/c++/HybridCesiumViewSpec.cpp +21 -3
  35. package/nitrogen/generated/shared/c++/HybridCesiumViewSpec.hpp +22 -4
  36. package/nitrogen/generated/shared/c++/views/HybridCesiumViewComponent.cpp +66 -0
  37. package/nitrogen/generated/shared/c++/views/HybridCesiumViewComponent.hpp +6 -0
  38. package/nitrogen/generated/shared/json/CesiumViewConfig.json +6 -0
  39. package/package.json +1 -1
  40. package/src/specs/cesium-view.nitro.ts +102 -14
  41. package/cpp/engine/CameraSmoother.cpp +0 -68
  42. package/cpp/engine/CameraSmoother.hpp +0 -28
  43. package/cpp/engine/CameraTargetState.cpp +0 -205
  44. package/cpp/engine/CameraTargetState.hpp +0 -126
@@ -1,126 +0,0 @@
1
- #pragma once
2
-
3
- #include "EngineTunables.hpp"
4
- #include "GlobeCamera.hpp"
5
-
6
- #include <atomic>
7
- #include <chrono>
8
- #include <mutex>
9
-
10
- namespace reactnativecesium {
11
-
12
- // Thread-safe holder for the *demand* camera (what the JS side last asked for).
13
- //
14
- // Writers: the React Native JS / worklet thread, via setCamera / setCameraQuaternion.
15
- // Readers: the dedicated render thread (per frame), via shouldRenderNextFrame /
16
- // renderFrame.
17
- //
18
- // We use a small mutex around `target_` because the writes are uncontended and
19
- // the read side only happens once per frame; the cost is negligible compared to
20
- // the cost of *not* synchronising a 56-byte struct that contains a glm::dquat.
21
- //
22
- // `dirty_` and `forceRender_` are independent atomic flags so the read side can
23
- // poll without taking the lock when the camera has not moved.
24
- //
25
- // Per-DoF linear interpolation (lat/lon, altitude, heading)
26
- // ──────────────────────────────────────────────────────────
27
- // Each of lat/lon, altitude, and heading maintains its own independent EWMA
28
- // of inter-arrival times and only updates that EWMA when *its own value*
29
- // actually changes. snapshot() then linearly interpolates each DoF from its
30
- // previous value to its current target over its own EWMA interval.
31
- //
32
- // This means lat/lon, altitude, and heading each self-tune independently:
33
- // - 60 Hz gesture input → EWMA ~16 ms → interpolation near-instant (snap)
34
- // - 1 Hz GPS → EWMA ~1 s → constant-velocity glide between fixes
35
- // - 50 Hz barometer for altitude + 1 Hz GPS for lat/lon → altitude behaves
36
- // near-instant, lat/lon glides — with no special-casing needed.
37
- //
38
- // Special cases in snapshot():
39
- // - t >= 1: camera has reached the target, returns target_ directly.
40
- // - Snap-through guard: large jumps bypass interpolation so deliberate
41
- // teleports remain instant.
42
- // - First change per DoF: "from" = destination, so lerp(dest, dest, t) = dest
43
- // for all t — clean snap, no startup glide.
44
- // - setAll (init-only): never touches any interpolation state.
45
- //
46
- // pitch / roll / viewCorrection are NOT interpolated here; CameraSmoother
47
- // applies fixed-rate exponential curves to them (appropriate for high-rate
48
- // attitude sensors).
49
- class CameraTargetState {
50
- public:
51
- CameraTargetState() = default;
52
-
53
- // Replace the entire target. Used only for engine initialisation; does NOT
54
- // update any interpolation state so the first rendered frame snaps.
55
- void setAll(const CameraParams& target);
56
-
57
- // Update lat/lon/alt + heading/pitch/roll, leaving viewCorrection unchanged.
58
- // Independently tracks cadence for lat/lon, altitude, and heading.
59
- void setHpr(double lat, double lon, double alt,
60
- double heading, double pitch, double roll);
61
-
62
- void setViewCorrection(const glm::dquat& q);
63
-
64
- // Snapshot the demand target for this render frame. lat/lon, altitude, and
65
- // heading are linearly interpolated to their "current" position based on
66
- // each DoF's own EWMA interval. pitch/roll/viewCorrection are returned as-is
67
- // (CameraSmoother handles their exponential curves).
68
- CameraParams snapshot() const;
69
-
70
- // Lightweight, lock-free check used by the render thread to decide whether
71
- // it should bother taking a full snapshot at all.
72
- bool isDirty() const noexcept {
73
- return dirty_.load(std::memory_order_acquire);
74
- }
75
- void clearDirty() noexcept {
76
- dirty_.store(false, std::memory_order_release);
77
- }
78
-
79
- bool consumeForceRender() noexcept {
80
- return forceRender_.exchange(false, std::memory_order_acq_rel);
81
- }
82
- void requestForceRender() noexcept {
83
- forceRender_.store(true, std::memory_order_release);
84
- }
85
-
86
- // Compares snapshot to "current" (the engine's current camera) and returns
87
- // true if any DoF differs by more than the matching epsilon. Used to decide
88
- // whether to render this frame.
89
- static bool deltaExceedsEpsilon(const CameraParams& a, const CameraParams& b);
90
-
91
- private:
92
- mutable std::mutex mutex_;
93
- CameraParams target_;
94
- std::atomic<bool> dirty_{false};
95
- std::atomic<bool> forceRender_{true};
96
-
97
- // ── Per-DoF linear interpolation state (all protected by mutex_) ─────────
98
- // Each DoF has: a "from" value, a wall-clock timestamp of the last change,
99
- // an EWMA of inter-arrival times, and an "active" flag.
100
- //
101
- // Pattern per DoF:
102
- // First change: from = destination (snap), seed EWMA, set active.
103
- // Subsequent change: from = old target, update EWMA, reset clock.
104
- // snapshot(): t = clamp(elapsed/ewma, 0, 1); result = from + t*delta.
105
-
106
- // lat / lon
107
- double posFromLat_{0.0};
108
- double posFromLon_{0.0};
109
- std::chrono::steady_clock::time_point posUpdateTime_{};
110
- double posEwmaIntervalSec_{0.0};
111
- bool hasPosInterp_{false};
112
-
113
- // altitude
114
- double altFrom_{0.0};
115
- std::chrono::steady_clock::time_point altUpdateTime_{};
116
- double altEwmaIntervalSec_{0.0};
117
- bool hasAltInterp_{false};
118
-
119
- // heading
120
- double hdgFrom_{0.0};
121
- std::chrono::steady_clock::time_point hdgUpdateTime_{};
122
- double hdgEwmaIntervalSec_{0.0};
123
- bool hasHdgInterp_{false};
124
- };
125
-
126
- } // namespace reactnativecesium