react-native-cesium 1.2.2 → 1.2.4
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.
- package/README.md +100 -26
- package/android/CMakeLists.txt +1 -2
- package/android/src/main/cpp/CesiumBridgeAndroid.cpp +264 -130
- package/android/src/main/cpp/CesiumBridgeAndroid.h +70 -27
- package/android/src/main/java/com/margelo/nitro/reactnativecesium/CesiumBridgeJNI.kt +68 -44
- package/android/src/main/java/com/margelo/nitro/reactnativecesium/HybridCesiumView.kt +160 -187
- package/cpp/engine/CameraIntegrator.cpp +374 -0
- package/cpp/engine/CameraIntegrator.hpp +146 -0
- package/cpp/engine/CesiumEngine.cpp +3 -1
- package/cpp/engine/EngineTunables.hpp +80 -21
- package/cpp/engine/GlobeCamera.cpp +17 -6
- package/cpp/engine/GlobeCamera.hpp +11 -8
- package/cpp/engine/test/CameraIntegratorTest.cpp +205 -0
- package/cpp/engine/test/build_and_run.sh +27 -0
- package/example/README.md +1 -1
- package/ios/CesiumBridge.h +53 -28
- package/ios/CesiumBridge.mm +172 -86
- package/ios/HybridCesiumView.swift +213 -145
- package/lib/typescript/src/specs/cesium-view.nitro.d.ts +77 -13
- package/lib/typescript/src/specs/cesium-view.nitro.d.ts.map +1 -1
- package/nitrogen/generated/android/c++/JHybridCesiumViewSpec.cpp +90 -9
- package/nitrogen/generated/android/c++/JHybridCesiumViewSpec.hpp +19 -3
- package/nitrogen/generated/android/c++/views/JHybridCesiumViewStateUpdater.cpp +20 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativecesium/HybridCesiumViewSpec.kt +57 -3
- package/nitrogen/generated/ios/ReactNativeCesium-Swift-Cxx-Bridge.hpp +9 -9
- package/nitrogen/generated/ios/c++/HybridCesiumViewSpecSwift.hpp +82 -9
- package/nitrogen/generated/ios/c++/views/HybridCesiumViewComponent.mm +25 -0
- package/nitrogen/generated/ios/swift/HybridCesiumViewSpec.swift +14 -3
- package/nitrogen/generated/ios/swift/HybridCesiumViewSpec_cxx.swift +210 -16
- package/nitrogen/generated/shared/c++/HybridCesiumViewSpec.cpp +19 -3
- package/nitrogen/generated/shared/c++/HybridCesiumViewSpec.hpp +20 -4
- package/nitrogen/generated/shared/c++/views/HybridCesiumViewComponent.cpp +55 -0
- package/nitrogen/generated/shared/c++/views/HybridCesiumViewComponent.hpp +5 -0
- package/nitrogen/generated/shared/json/CesiumViewConfig.json +5 -0
- package/package.json +2 -2
- package/src/specs/cesium-view.nitro.ts +93 -14
- package/cpp/engine/CameraSmoother.cpp +0 -71
- package/cpp/engine/CameraSmoother.hpp +0 -25
- package/cpp/engine/CameraTargetState.cpp +0 -140
- package/cpp/engine/CameraTargetState.hpp +0 -103
|
@@ -1,25 +1,40 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
+
#include <atomic>
|
|
3
4
|
#include <jni.h>
|
|
4
5
|
#include <memory>
|
|
5
6
|
#include <string>
|
|
6
7
|
|
|
7
|
-
#include "engine/
|
|
8
|
+
#include "engine/CameraIntegrator.hpp"
|
|
8
9
|
#include "engine/CesiumEngine.hpp"
|
|
9
10
|
#include "engine/MetricsAggregator.hpp"
|
|
10
11
|
|
|
12
|
+
struct ANativeWindow;
|
|
13
|
+
|
|
11
14
|
namespace reactnativecesium {
|
|
12
15
|
class VulkanBackend;
|
|
13
16
|
struct FrameResult;
|
|
14
17
|
} // namespace reactnativecesium
|
|
15
18
|
|
|
16
|
-
// Thin Android shell. All cross-platform logic (camera
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
+
// Thin Android shell. All cross-platform logic (per-DoF camera integrator,
|
|
20
|
+
// FPS / metrics aggregation, credit HTML stripping) lives in shared C++ next
|
|
21
|
+
// to CesiumEngine. This class only owns:
|
|
19
22
|
// - the JNI/window surface,
|
|
20
23
|
// - the Vulkan backend instance, and
|
|
21
24
|
// - the EngineConfig snapshot mirrored from JS props.
|
|
22
25
|
struct CesiumBridgeAndroid {
|
|
26
|
+
CesiumBridgeAndroid() = default;
|
|
27
|
+
// Defensive: if Kotlin ever forgets to call shutdown() before destroy() the
|
|
28
|
+
// destructor still tears down the engine and releases the ANativeWindow
|
|
29
|
+
// reference acquired in init(), preventing native handle / SQLite handle
|
|
30
|
+
// leaks.
|
|
31
|
+
~CesiumBridgeAndroid();
|
|
32
|
+
|
|
33
|
+
CesiumBridgeAndroid(const CesiumBridgeAndroid&) = delete;
|
|
34
|
+
CesiumBridgeAndroid& operator=(const CesiumBridgeAndroid&) = delete;
|
|
35
|
+
CesiumBridgeAndroid(CesiumBridgeAndroid&&) = delete;
|
|
36
|
+
CesiumBridgeAndroid& operator=(CesiumBridgeAndroid&&) = delete;
|
|
37
|
+
|
|
23
38
|
void init(JNIEnv* env, jobject surface, int width, int height,
|
|
24
39
|
const std::string& cacheDir, const std::string& cacertPath);
|
|
25
40
|
void shutdown();
|
|
@@ -28,12 +43,20 @@ struct CesiumBridgeAndroid {
|
|
|
28
43
|
|
|
29
44
|
void updateIonAccessToken(const std::string& token, int64_t assetId);
|
|
30
45
|
void updateImageryAssetId(int64_t assetId);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
void
|
|
34
|
-
|
|
35
|
-
|
|
46
|
+
|
|
47
|
+
// ── Per-DoF camera demand setters ──────────────────────────────────────
|
|
48
|
+
void setPosition(double lat, double lon);
|
|
49
|
+
void setAltitude(double alt);
|
|
50
|
+
void setHeading(double headingDeg);
|
|
51
|
+
void setAttitude(double pitchDeg, double rollDeg);
|
|
52
|
+
void setViewCorrection(double qw, double qx, double qy, double qz);
|
|
53
|
+
void teleport(double lat, double lon, double alt,
|
|
54
|
+
double heading, double pitch, double roll, double vfov);
|
|
55
|
+
|
|
36
56
|
void setVerticalFovDeg(double degrees);
|
|
57
|
+
void setRateCaps(double yawDegSec, double pitchDegSec, double rollDegSec,
|
|
58
|
+
double climbMps, double groundMps);
|
|
59
|
+
|
|
37
60
|
void setMaximumScreenSpaceError(double v);
|
|
38
61
|
void setMaximumSimultaneousTileLoads(int32_t v);
|
|
39
62
|
void setLoadingDescendantLimit(int32_t v);
|
|
@@ -56,16 +79,27 @@ struct CesiumBridgeAndroid {
|
|
|
56
79
|
|
|
57
80
|
void markNeedsRender();
|
|
58
81
|
bool shouldRenderNextFrame();
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
double
|
|
65
|
-
double
|
|
66
|
-
double
|
|
67
|
-
double
|
|
68
|
-
double
|
|
82
|
+
// Wall-clock seconds (steady_clock), used by the integrator to extrapolate
|
|
83
|
+
// every DoF forward to the time we are about to render.
|
|
84
|
+
void renderFrame(double nowSeconds);
|
|
85
|
+
|
|
86
|
+
// Actual camera readback (post-integration; what was rendered).
|
|
87
|
+
double readActualLatitude();
|
|
88
|
+
double readActualLongitude();
|
|
89
|
+
double readActualAltitude();
|
|
90
|
+
double readActualHeading();
|
|
91
|
+
double readActualPitch();
|
|
92
|
+
double readActualRoll();
|
|
93
|
+
double readActualVerticalFovDeg();
|
|
94
|
+
// Demand camera readback (what the consumer last asked for).
|
|
95
|
+
double readDemandLatitude();
|
|
96
|
+
double readDemandLongitude();
|
|
97
|
+
double readDemandAltitude();
|
|
98
|
+
double readDemandHeading();
|
|
99
|
+
double readDemandPitch();
|
|
100
|
+
double readDemandRoll();
|
|
101
|
+
double readDemandVerticalFovDeg();
|
|
102
|
+
|
|
69
103
|
double readViewCorrectionW();
|
|
70
104
|
double readViewCorrectionX();
|
|
71
105
|
double readViewCorrectionY();
|
|
@@ -85,20 +119,29 @@ struct CesiumBridgeAndroid {
|
|
|
85
119
|
|
|
86
120
|
private:
|
|
87
121
|
void buildEngine();
|
|
88
|
-
// Push the current `config_` state to the live engine
|
|
89
|
-
// fields go through tileset_->getOptions(); token/asset id changes force
|
|
90
|
-
// a tileset rebuild).
|
|
122
|
+
// Push the current `config_` state to the live engine.
|
|
91
123
|
void applyEngineConfig();
|
|
92
124
|
|
|
93
|
-
std::unique_ptr<reactnativecesium::VulkanBackend>
|
|
94
|
-
std::unique_ptr<reactnativecesium::CesiumEngine>
|
|
95
|
-
std::unique_ptr<reactnativecesium::FrameResult>
|
|
125
|
+
std::unique_ptr<reactnativecesium::VulkanBackend> vulkanBackend_;
|
|
126
|
+
std::unique_ptr<reactnativecesium::CesiumEngine> engine_;
|
|
127
|
+
std::unique_ptr<reactnativecesium::FrameResult> frameResult_;
|
|
128
|
+
std::unique_ptr<reactnativecesium::CameraIntegrator> integrator_;
|
|
129
|
+
|
|
130
|
+
// ANativeWindow* acquired via ANativeWindow_fromSurface in init(). The
|
|
131
|
+
// bridge owns one strong reference and must release it in shutdown() once
|
|
132
|
+
// the Vulkan backend (which renders into it) is gone. Leaving this dangling
|
|
133
|
+
// leaks one ANativeWindow per view create/destroy cycle.
|
|
134
|
+
ANativeWindow* nativeWindow_ = nullptr;
|
|
96
135
|
|
|
97
136
|
int viewportWidth_ = 0;
|
|
98
137
|
int viewportHeight_ = 0;
|
|
99
138
|
bool initialized_ = false;
|
|
100
139
|
|
|
101
|
-
|
|
102
|
-
|
|
140
|
+
// Force-render flag — set on every demand change so the render loop knows
|
|
141
|
+
// to dispatch at least one frame.
|
|
142
|
+
std::atomic<bool> forceRender_{true};
|
|
143
|
+
|
|
144
|
+
reactnativecesium::EngineConfig config_;
|
|
103
145
|
reactnativecesium::MetricsAggregator metrics_;
|
|
146
|
+
double lastTickSeconds_ = 0.0;
|
|
104
147
|
};
|
|
@@ -23,22 +23,25 @@ class CesiumBridgeJNI {
|
|
|
23
23
|
fun resize(w: Int, h: Int) = nativeResize(nativePtr, w, h)
|
|
24
24
|
fun updateIonAccessToken(token: String, assetId: Long) = nativeUpdateIonAccessToken(nativePtr, token, assetId)
|
|
25
25
|
fun updateImageryAssetId(assetId: Long) = nativeUpdateImageryAssetId(nativePtr, assetId)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
fun
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
qz: Double,
|
|
40
|
-
) = nativeUpdateCameraQuaternion(nativePtr, lat, lon, alt, heading, pitch, roll, qw, qx, qy, qz)
|
|
26
|
+
|
|
27
|
+
// ── Per-DoF camera setters ───────────────────────────────────────────────
|
|
28
|
+
fun setPosition(lat: Double, lon: Double) = nativeSetPosition(nativePtr, lat, lon)
|
|
29
|
+
fun setAltitude(alt: Double) = nativeSetAltitude(nativePtr, alt)
|
|
30
|
+
fun setHeading(headingDeg: Double) = nativeSetHeading(nativePtr, headingDeg)
|
|
31
|
+
fun setAttitude(pitchDeg: Double, rollDeg: Double) = nativeSetAttitude(nativePtr, pitchDeg, rollDeg)
|
|
32
|
+
fun setViewCorrection(qw: Double, qx: Double, qy: Double, qz: Double) =
|
|
33
|
+
nativeSetViewCorrection(nativePtr, qw, qx, qy, qz)
|
|
34
|
+
fun teleport(
|
|
35
|
+
lat: Double, lon: Double, alt: Double,
|
|
36
|
+
heading: Double, pitch: Double, roll: Double, vfov: Double,
|
|
37
|
+
) = nativeTeleport(nativePtr, lat, lon, alt, heading, pitch, roll, vfov)
|
|
38
|
+
|
|
41
39
|
fun setVerticalFovDeg(deg: Double) = nativeSetVerticalFovDeg(nativePtr, deg)
|
|
40
|
+
fun setRateCaps(
|
|
41
|
+
yawDegSec: Double, pitchDegSec: Double, rollDegSec: Double,
|
|
42
|
+
climbMps: Double, groundMps: Double,
|
|
43
|
+
) = nativeSetRateCaps(nativePtr, yawDegSec, pitchDegSec, rollDegSec, climbMps, groundMps)
|
|
44
|
+
|
|
42
45
|
fun setMaxSSE(v: Double) = nativeSetMaxSSE(nativePtr, v)
|
|
43
46
|
fun setMaxSimLoads(v: Int) = nativeSetMaxSimLoads(nativePtr, v)
|
|
44
47
|
fun setLoadDescLim(v: Int) = nativeSetLoadDescLim(nativePtr, v)
|
|
@@ -46,15 +49,25 @@ class CesiumBridgeJNI {
|
|
|
46
49
|
|
|
47
50
|
fun markNeedsRender() = nativeMarkNeedsRender(nativePtr)
|
|
48
51
|
fun shouldRenderNextFrame(): Boolean = nativeShouldRenderNextFrame(nativePtr)
|
|
49
|
-
fun renderFrame(
|
|
52
|
+
fun renderFrame(nowSeconds: Double) = nativeRenderFrame(nativePtr, nowSeconds)
|
|
50
53
|
|
|
51
|
-
|
|
52
|
-
fun
|
|
53
|
-
fun
|
|
54
|
-
fun
|
|
55
|
-
fun
|
|
56
|
-
fun
|
|
57
|
-
fun
|
|
54
|
+
// ── Actual camera readback ───────────────────────────────────────────────
|
|
55
|
+
fun getActualLatitude(): Double = nativeGetActualLatitude(nativePtr)
|
|
56
|
+
fun getActualLongitude(): Double = nativeGetActualLongitude(nativePtr)
|
|
57
|
+
fun getActualAltitude(): Double = nativeGetActualAltitude(nativePtr)
|
|
58
|
+
fun getActualHeading(): Double = nativeGetActualHeading(nativePtr)
|
|
59
|
+
fun getActualPitch(): Double = nativeGetActualPitch(nativePtr)
|
|
60
|
+
fun getActualRoll(): Double = nativeGetActualRoll(nativePtr)
|
|
61
|
+
fun getActualVerticalFovDeg(): Double = nativeGetActualVerticalFovDeg(nativePtr)
|
|
62
|
+
|
|
63
|
+
// ── Demand camera readback ───────────────────────────────────────────────
|
|
64
|
+
fun getDemandLatitude(): Double = nativeGetDemandLatitude(nativePtr)
|
|
65
|
+
fun getDemandLongitude(): Double = nativeGetDemandLongitude(nativePtr)
|
|
66
|
+
fun getDemandAltitude(): Double = nativeGetDemandAltitude(nativePtr)
|
|
67
|
+
fun getDemandHeading(): Double = nativeGetDemandHeading(nativePtr)
|
|
68
|
+
fun getDemandPitch(): Double = nativeGetDemandPitch(nativePtr)
|
|
69
|
+
fun getDemandRoll(): Double = nativeGetDemandRoll(nativePtr)
|
|
70
|
+
fun getDemandVerticalFovDeg(): Double = nativeGetDemandVerticalFovDeg(nativePtr)
|
|
58
71
|
|
|
59
72
|
fun getViewCorrectionW(): Double = nativeGetViewCorrectionW(nativePtr)
|
|
60
73
|
fun getViewCorrectionX(): Double = nativeGetViewCorrectionX(nativePtr)
|
|
@@ -91,35 +104,46 @@ class CesiumBridgeJNI {
|
|
|
91
104
|
private external fun nativeResize(ptr: Long, w: Int, h: Int)
|
|
92
105
|
private external fun nativeUpdateIonAccessToken(ptr: Long, token: String, assetId: Long)
|
|
93
106
|
private external fun nativeUpdateImageryAssetId(ptr: Long, assetId: Long)
|
|
94
|
-
|
|
95
|
-
private external fun
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
roll: Double,
|
|
103
|
-
qw: Double,
|
|
104
|
-
qx: Double,
|
|
105
|
-
qy: Double,
|
|
106
|
-
qz: Double,
|
|
107
|
+
|
|
108
|
+
private external fun nativeSetPosition(ptr: Long, lat: Double, lon: Double)
|
|
109
|
+
private external fun nativeSetAltitude(ptr: Long, alt: Double)
|
|
110
|
+
private external fun nativeSetHeading(ptr: Long, headingDeg: Double)
|
|
111
|
+
private external fun nativeSetAttitude(ptr: Long, pitchDeg: Double, rollDeg: Double)
|
|
112
|
+
private external fun nativeSetViewCorrection(ptr: Long, qw: Double, qx: Double, qy: Double, qz: Double)
|
|
113
|
+
private external fun nativeTeleport(
|
|
114
|
+
ptr: Long, lat: Double, lon: Double, alt: Double,
|
|
115
|
+
heading: Double, pitch: Double, roll: Double, vfov: Double,
|
|
107
116
|
)
|
|
117
|
+
|
|
108
118
|
private external fun nativeSetVerticalFovDeg(ptr: Long, deg: Double)
|
|
119
|
+
private external fun nativeSetRateCaps(
|
|
120
|
+
ptr: Long, yawDegSec: Double, pitchDegSec: Double, rollDegSec: Double,
|
|
121
|
+
climbMps: Double, groundMps: Double,
|
|
122
|
+
)
|
|
109
123
|
private external fun nativeSetMaxSSE(ptr: Long, v: Double)
|
|
110
124
|
private external fun nativeSetMaxSimLoads(ptr: Long, v: Int)
|
|
111
125
|
private external fun nativeSetLoadDescLim(ptr: Long, v: Int)
|
|
112
126
|
private external fun nativeSetMsaa(ptr: Long, v: Int)
|
|
113
127
|
private external fun nativeMarkNeedsRender(ptr: Long)
|
|
114
128
|
private external fun nativeShouldRenderNextFrame(ptr: Long): Boolean
|
|
115
|
-
private external fun nativeRenderFrame(ptr: Long,
|
|
116
|
-
|
|
117
|
-
private external fun
|
|
118
|
-
private external fun
|
|
119
|
-
private external fun
|
|
120
|
-
private external fun
|
|
121
|
-
private external fun
|
|
122
|
-
private external fun
|
|
129
|
+
private external fun nativeRenderFrame(ptr: Long, nowSeconds: Double)
|
|
130
|
+
|
|
131
|
+
private external fun nativeGetActualLatitude(ptr: Long): Double
|
|
132
|
+
private external fun nativeGetActualLongitude(ptr: Long): Double
|
|
133
|
+
private external fun nativeGetActualAltitude(ptr: Long): Double
|
|
134
|
+
private external fun nativeGetActualHeading(ptr: Long): Double
|
|
135
|
+
private external fun nativeGetActualPitch(ptr: Long): Double
|
|
136
|
+
private external fun nativeGetActualRoll(ptr: Long): Double
|
|
137
|
+
private external fun nativeGetActualVerticalFovDeg(ptr: Long): Double
|
|
138
|
+
|
|
139
|
+
private external fun nativeGetDemandLatitude(ptr: Long): Double
|
|
140
|
+
private external fun nativeGetDemandLongitude(ptr: Long): Double
|
|
141
|
+
private external fun nativeGetDemandAltitude(ptr: Long): Double
|
|
142
|
+
private external fun nativeGetDemandHeading(ptr: Long): Double
|
|
143
|
+
private external fun nativeGetDemandPitch(ptr: Long): Double
|
|
144
|
+
private external fun nativeGetDemandRoll(ptr: Long): Double
|
|
145
|
+
private external fun nativeGetDemandVerticalFovDeg(ptr: Long): Double
|
|
146
|
+
|
|
123
147
|
private external fun nativeGetViewCorrectionW(ptr: Long): Double
|
|
124
148
|
private external fun nativeGetViewCorrectionX(ptr: Long): Double
|
|
125
149
|
private external fun nativeGetViewCorrectionY(ptr: Long): Double
|