react-native-cesium 1.0.1 → 1.0.3

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 (34) hide show
  1. package/README.md +77 -9
  2. package/android/src/main/cpp/CesiumBridgeAndroid.cpp +88 -1
  3. package/android/src/main/cpp/CesiumBridgeAndroid.h +11 -1
  4. package/android/src/main/java/com/margelo/nitro/reactnativecesium/CesiumBridgeJNI.kt +35 -0
  5. package/android/src/main/java/com/margelo/nitro/reactnativecesium/HybridCesiumView.kt +55 -0
  6. package/cpp/engine/GlobeCamera.cpp +22 -0
  7. package/cpp/engine/GlobeCamera.hpp +3 -0
  8. package/ios/CesiumBridge.h +15 -0
  9. package/ios/CesiumBridge.mm +68 -7
  10. package/ios/HybridCesiumView.swift +56 -0
  11. package/lib/typescript/src/index.d.ts +1 -1
  12. package/lib/typescript/src/index.d.ts.map +1 -1
  13. package/lib/typescript/src/specs/cesium-view.nitro.d.ts +21 -1
  14. package/lib/typescript/src/specs/cesium-view.nitro.d.ts.map +1 -1
  15. package/nitrogen/generated/android/c++/JHybridCesiumViewSpec.cpp +24 -0
  16. package/nitrogen/generated/android/c++/JHybridCesiumViewSpec.hpp +2 -0
  17. package/nitrogen/generated/android/c++/JQuaternion.hpp +69 -0
  18. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativecesium/HybridCesiumViewSpec.kt +8 -0
  19. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativecesium/Quaternion.kt +47 -0
  20. package/nitrogen/generated/ios/ReactNativeCesium+autolinking.rb +2 -0
  21. package/nitrogen/generated/ios/ReactNativeCesium-Swift-Cxx-Bridge.cpp +8 -0
  22. package/nitrogen/generated/ios/ReactNativeCesium-Swift-Cxx-Bridge.hpp +46 -0
  23. package/nitrogen/generated/ios/ReactNativeCesium-Swift-Cxx-Umbrella.hpp +3 -0
  24. package/nitrogen/generated/ios/c++/HybridCesiumViewSpecSwift.hpp +17 -0
  25. package/nitrogen/generated/ios/swift/Func_void_Quaternion.swift +46 -0
  26. package/nitrogen/generated/ios/swift/HybridCesiumViewSpec.swift +2 -0
  27. package/nitrogen/generated/ios/swift/HybridCesiumViewSpec_cxx.swift +30 -0
  28. package/nitrogen/generated/ios/swift/Quaternion.swift +44 -0
  29. package/nitrogen/generated/shared/c++/HybridCesiumViewSpec.cpp +2 -0
  30. package/nitrogen/generated/shared/c++/HybridCesiumViewSpec.hpp +5 -0
  31. package/nitrogen/generated/shared/c++/Quaternion.hpp +95 -0
  32. package/package.json +1 -1
  33. package/src/index.ts +1 -0
  34. package/src/specs/cesium-view.nitro.ts +22 -1
@@ -4,6 +4,8 @@
4
4
  #include "engine/CesiumEngine.hpp"
5
5
  #include "metal/MetalBackend.h"
6
6
 
7
+ #include <glm/gtc/quaternion.hpp>
8
+
7
9
  #include <atomic>
8
10
  #include <cmath>
9
11
  #include <memory>
@@ -46,9 +48,15 @@ static const double kSmoothAlt = 25.0;
46
48
  static const double kSmoothHdg = 30.0;
47
49
  static const double kSmoothRoll = 50.0;
48
50
  static const double kSmoothPitch = 50.0;
51
+ static const double kSmoothViewCorr = 50.0;
49
52
  static const double kEpsLatLon = 1e-7;
50
53
  static const double kEpsAlt = 0.1;
51
54
  static const double kEpsAngleDeg = 0.05;
55
+ static const double kEpsQuatDot = 1e-8;
56
+
57
+ static double quatDotAbs(const glm::dquat& a, const glm::dquat& b) {
58
+ return std::abs(glm::dot(glm::normalize(a), glm::normalize(b)));
59
+ }
52
60
 
53
61
  @implementation CesiumBridge {
54
62
  std::unique_ptr<reactnativecesium::MetalBackend> _metalBackend;
@@ -182,17 +190,12 @@ static const double kEpsAngleDeg = 0.05;
182
190
  // Water mask textures are identical MTLTexture objects — createRasterTexture
183
191
  // is reused. On Metal, the binding slot (texture index 1) is set at draw
184
192
  // time so no separate factory is needed.
185
- NSLog(@"[WM-BRIDGE] Wiring up water mask texture creator/deleter");
186
193
  _engine->getResourcePreparer()->setWaterMaskTextureCreator(
187
194
  [backendPtr](const uint8_t* pixels, int32_t w, int32_t h) -> void* {
188
- NSLog(@"[WM-BRIDGE] waterMaskCreator called w=%d h=%d pixels=%p", w, h, pixels);
189
- void* tex = backendPtr->createRasterTexture(pixels, w, h);
190
- NSLog(@"[WM-BRIDGE] waterMaskCreator => tex=%p", tex);
191
- return tex;
195
+ return backendPtr->createRasterTexture(pixels, w, h);
192
196
  });
193
197
  _engine->getResourcePreparer()->setWaterMaskTextureDeleter(
194
198
  [](void* tex) {
195
- NSLog(@"[WM-BRIDGE] waterMaskDeleter called tex=%p", tex);
196
199
  if (tex) CFRelease(tex);
197
200
  });
198
201
  }
@@ -224,6 +227,36 @@ static const double kEpsAngleDeg = 0.05;
224
227
  _camTarget.heading = heading;
225
228
  _camTarget.pitch = pitch;
226
229
  _camTarget.roll = roll;
230
+ // Intentionally does not modify `_camTarget.viewCorrection`.
231
+ _forceRenderNextFrame = YES;
232
+ }
233
+
234
+ - (void)updateCameraQuaternionLatitude:(double)lat
235
+ longitude:(double)lon
236
+ altitude:(double)alt
237
+ heading:(double)heading
238
+ pitch:(double)pitch
239
+ roll:(double)roll
240
+ viewCorrectionW:(double)qw
241
+ x:(double)qx
242
+ y:(double)qy
243
+ z:(double)qz {
244
+ if (!_initialized) return;
245
+ _camTarget.latitude = lat;
246
+ _camTarget.longitude = lon;
247
+ _camTarget.altitude = alt;
248
+ _camTarget.heading = heading;
249
+ _camTarget.pitch = pitch;
250
+ _camTarget.roll = roll;
251
+ const double ql2 = qw * qw + qx * qx + qy * qy + qz * qz;
252
+ glm::dquat q;
253
+ if (ql2 < 1e-20) {
254
+ q = glm::dquat(1.0, 0.0, 0.0, 0.0);
255
+ } else {
256
+ const double inv = 1.0 / std::sqrt(ql2);
257
+ q = glm::dquat(qw * inv, qx * inv, qy * inv, qz * inv);
258
+ }
259
+ _camTarget.viewCorrection = q;
227
260
  _forceRenderNextFrame = YES;
228
261
  }
229
262
 
@@ -280,7 +313,8 @@ static const double kEpsAngleDeg = 0.05;
280
313
  std::abs(_camTarget.altitude - cur.altitude) > kEpsAlt ||
281
314
  angleDeltaAbsDeg(cur.heading, _camTarget.heading) > kEpsAngleDeg ||
282
315
  angleDeltaAbsDeg(cur.pitch, _camTarget.pitch) > kEpsAngleDeg ||
283
- angleDeltaAbsDeg(cur.roll, _camTarget.roll) > kEpsAngleDeg;
316
+ angleDeltaAbsDeg(cur.roll, _camTarget.roll) > kEpsAngleDeg ||
317
+ (1.0 - quatDotAbs(cur.viewCorrection, _camTarget.viewCorrection)) > kEpsQuatDot;
284
318
 
285
319
  return _forceRenderNextFrame ||
286
320
  _frameResult.tilesLoading > 0 ||
@@ -303,11 +337,18 @@ static const double kEpsAngleDeg = 0.05;
303
337
  const double aHdg = 1.0 - std::exp(-kSmoothHdg * dt);
304
338
  const double aPitch = 1.0 - std::exp(-kSmoothPitch * dt);
305
339
  const double aRoll = 1.0 - std::exp(-kSmoothRoll * dt);
340
+ const double aViewQ = 1.0 - std::exp(-kSmoothViewCorr * dt);
306
341
  cur.altitude = cur.altitude + aAlt * (_camTarget.altitude - cur.altitude);
307
342
  cur.heading = lerpAngleDeg(cur.heading, _camTarget.heading, aHdg);
308
343
  cur.pitch = lerpAngleDeg(cur.pitch, _camTarget.pitch, aPitch);
309
344
  cur.roll = lerpAngleDeg(cur.roll, _camTarget.roll, aRoll);
310
345
 
346
+ glm::dquat cq = glm::normalize(cur.viewCorrection);
347
+ glm::dquat tq = glm::normalize(_camTarget.viewCorrection);
348
+ if (glm::dot(cq, tq) < 0.0)
349
+ tq = -tq;
350
+ cur.viewCorrection = glm::normalize(glm::slerp(cq, tq, aViewQ));
351
+
311
352
  if (std::abs(_camTarget.altitude - cur.altitude) <= kEpsAlt) {
312
353
  cur.altitude = _camTarget.altitude;
313
354
  }
@@ -320,6 +361,9 @@ static const double kEpsAngleDeg = 0.05;
320
361
  if (angleDeltaAbsDeg(cur.roll, _camTarget.roll) <= kEpsAngleDeg) {
321
362
  cur.roll = _camTarget.roll;
322
363
  }
364
+ if ((1.0 - quatDotAbs(cur.viewCorrection, _camTarget.viewCorrection)) <= kEpsQuatDot) {
365
+ cur.viewCorrection = _camTarget.viewCorrection;
366
+ }
323
367
  _engine->camera().setParams(cur);
324
368
 
325
369
  _engine->updateFrame(_viewportWidth, _viewportHeight, _frameResult);
@@ -383,6 +427,23 @@ static const double kEpsAngleDeg = 0.05;
383
427
  - (double)readCameraRoll { return _engine ? _engine->camera().getParams().roll : 0.0; }
384
428
  - (double)readVerticalFovDeg { return _engine ? _engine->camera().getVerticalFovDegrees() : 60.0; }
385
429
 
430
+ - (double)readViewCorrectionW {
431
+ if (!_engine) return 1.0;
432
+ return _engine->camera().getParams().viewCorrection.w;
433
+ }
434
+ - (double)readViewCorrectionX {
435
+ if (!_engine) return 0.0;
436
+ return _engine->camera().getParams().viewCorrection.x;
437
+ }
438
+ - (double)readViewCorrectionY {
439
+ if (!_engine) return 0.0;
440
+ return _engine->camera().getParams().viewCorrection.y;
441
+ }
442
+ - (double)readViewCorrectionZ {
443
+ if (!_engine) return 0.0;
444
+ return _engine->camera().getParams().viewCorrection.z;
445
+ }
446
+
386
447
  - (void)shutdown {
387
448
  [[NSNotificationCenter defaultCenter] removeObserver:self];
388
449
  if (_engine) _engine->shutdown();
@@ -87,6 +87,26 @@ class HybridCesiumView: HybridCesiumViewSpec {
87
87
  pushCameraStateIfChanged(camera)
88
88
  }
89
89
 
90
+ func setCameraQuaternion(camera: CameraState, viewCorrection: Quaternion) throws {
91
+ initialCamera = camera
92
+ pushCameraQuaternionIfChanged(camera, viewCorrection: viewCorrection)
93
+ }
94
+
95
+ func getViewCorrection() throws -> Promise<Quaternion> {
96
+ guard let b = bridge else {
97
+ return Promise.resolved(
98
+ withResult: Quaternion(w: 1, x: 0, y: 0, z: 0)
99
+ )
100
+ }
101
+ let q = Quaternion(
102
+ w: b.readViewCorrectionW(),
103
+ x: b.readViewCorrectionX(),
104
+ y: b.readViewCorrectionY(),
105
+ z: b.readViewCorrectionZ()
106
+ )
107
+ return Promise.resolved(withResult: q)
108
+ }
109
+
90
110
  // MARK: - View
91
111
 
92
112
  private let metalView: MTKView
@@ -98,6 +118,8 @@ class HybridCesiumView: HybridCesiumViewSpec {
98
118
  private var usingLowRefreshRate = false
99
119
  private var hasConfiguredFrameRate = false
100
120
  private var lastPushedCameraState: CameraState?
121
+ /// Last quaternion pushed via `setCameraQuaternion`; `nil` if only `setCamera` has been used.
122
+ private var lastPushedViewCorrection: Quaternion?
101
123
  private var lastBridgePixelSize: CGSize = .zero
102
124
 
103
125
  var view: UIView { metalView }
@@ -220,6 +242,40 @@ class HybridCesiumView: HybridCesiumViewSpec {
220
242
  bridge?.setVerticalFovDeg(camera.verticalFovDeg)
221
243
  }
222
244
 
245
+ private func pushCameraQuaternionIfChanged(_ camera: CameraState, viewCorrection: Quaternion) {
246
+ guard bridge != nil else { return }
247
+ if let lastCam = lastPushedCameraState,
248
+ let lastQ = lastPushedViewCorrection,
249
+ lastCam.latitude == camera.latitude,
250
+ lastCam.longitude == camera.longitude,
251
+ lastCam.altitude == camera.altitude,
252
+ lastCam.heading == camera.heading,
253
+ lastCam.pitch == camera.pitch,
254
+ lastCam.roll == camera.roll,
255
+ lastCam.verticalFovDeg == camera.verticalFovDeg,
256
+ lastQ.w == viewCorrection.w,
257
+ lastQ.x == viewCorrection.x,
258
+ lastQ.y == viewCorrection.y,
259
+ lastQ.z == viewCorrection.z {
260
+ return
261
+ }
262
+ lastPushedCameraState = camera
263
+ lastPushedViewCorrection = viewCorrection
264
+ bridge?.updateCameraQuaternionLatitude(
265
+ camera.latitude,
266
+ longitude: camera.longitude,
267
+ altitude: camera.altitude,
268
+ heading: camera.heading,
269
+ pitch: camera.pitch,
270
+ roll: camera.roll,
271
+ viewCorrectionW: viewCorrection.w,
272
+ x: viewCorrection.x,
273
+ y: viewCorrection.y,
274
+ z: viewCorrection.z
275
+ )
276
+ bridge?.setVerticalFovDeg(camera.verticalFovDeg)
277
+ }
278
+
223
279
  // MARK: - Render Loop
224
280
 
225
281
  private func startRenderLoop() {
@@ -1,3 +1,3 @@
1
1
  export { CesiumView } from './CesiumView';
2
- export type { CameraState, CesiumMetrics, CesiumViewProps, CesiumViewMethods, } from './specs/cesium-view.nitro';
2
+ export type { CameraState, CesiumMetrics, CesiumViewProps, CesiumViewMethods, Quaternion, } from './specs/cesium-view.nitro';
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,YAAY,EACV,WAAW,EACX,aAAa,EACb,eAAe,EACf,iBAAiB,GAClB,MAAM,2BAA2B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,YAAY,EACV,WAAW,EACX,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,UAAU,GACX,MAAM,2BAA2B,CAAA"}
@@ -9,6 +9,16 @@ export interface CameraState {
9
9
  roll: number;
10
10
  verticalFovDeg: number;
11
11
  }
12
+ /**
13
+ * Unit quaternion (w + xi + yj + zk). Used for camera-space view correction.
14
+ * Non-unit values are normalized on the native side.
15
+ */
16
+ export interface Quaternion {
17
+ w: number;
18
+ x: number;
19
+ y: number;
20
+ z: number;
21
+ }
12
22
  /** Throttled telemetry for dashboards (see `onMetrics` prop). */
13
23
  export interface CesiumMetrics {
14
24
  fps: number;
@@ -36,8 +46,18 @@ export interface CesiumViewProps extends HybridViewProps {
36
46
  export interface CesiumViewMethods extends HybridViewMethods {
37
47
  /** Returns the current native camera state. */
38
48
  getCameraState(): Promise<CameraState>;
39
- /** Runtime camera control path after the view has been created. */
49
+ /**
50
+ * Runtime camera control (heading/pitch/roll + position + VFOV).
51
+ * Does not change the view-correction quaternion; use `setCameraQuaternion` to set that.
52
+ */
40
53
  setCamera(camera: CameraState): void;
54
+ /**
55
+ * Same fields as `setCamera`, plus a camera-space rotation applied after HPR
56
+ * (e.g. boresight / HUD alignment). See README.
57
+ */
58
+ setCameraQuaternion(camera: CameraState, viewCorrection: Quaternion): void;
59
+ /** Current view-correction quaternion (identity if never set via `setCameraQuaternion`). */
60
+ getViewCorrection(): Promise<Quaternion>;
41
61
  }
42
62
  export type CesiumView = HybridView<CesiumViewProps, CesiumViewMethods>;
43
63
  //# sourceMappingURL=cesium-view.nitro.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cesium-view.nitro.d.ts","sourceRoot":"","sources":["../../../../src/specs/cesium-view.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,eAAe,EACf,iBAAiB,EAClB,MAAM,4BAA4B,CAAA;AAEnC,6EAA6E;AAC7E,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,cAAc,EAAE,MAAM,CAAA;CACvB;AAED,iEAAiE;AACjE,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAA;IACX,aAAa,EAAE,MAAM,CAAA;IACrB,YAAY,EAAE,MAAM,CAAA;IACpB,YAAY,EAAE,MAAM,CAAA;IACpB,kBAAkB,EAAE,OAAO,CAAA;IAC3B,YAAY,EAAE,OAAO,CAAA;IACrB,gBAAgB,EAAE,MAAM,CAAA;CACzB;AAED,MAAM,WAAW,eAAgB,SAAQ,eAAe;IACtD,cAAc,EAAE,MAAM,CAAA;IACtB,UAAU,EAAE,MAAM,CAAA;IAClB,4EAA4E;IAC5E,aAAa,EAAE,WAAW,CAAA;IAC1B,cAAc,EAAE,OAAO,CAAA;IACvB,uBAAuB,EAAE,MAAM,CAAA;IAC/B,4BAA4B,EAAE,MAAM,CAAA;IACpC,sBAAsB,EAAE,MAAM,CAAA;IAC9B,6CAA6C;IAC7C,eAAe,EAAE,MAAM,CAAA;IACvB,iBAAiB,EAAE,MAAM,CAAA;IACzB,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,aAAa,KAAK,IAAI,CAAA;CAC7C;AAED,MAAM,WAAW,iBAAkB,SAAQ,iBAAiB;IAC1D,+CAA+C;IAC/C,cAAc,IAAI,OAAO,CAAC,WAAW,CAAC,CAAA;IACtC,mEAAmE;IACnE,SAAS,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,CAAA;CACrC;AAED,MAAM,MAAM,UAAU,GAAG,UAAU,CAAC,eAAe,EAAE,iBAAiB,CAAC,CAAA"}
1
+ {"version":3,"file":"cesium-view.nitro.d.ts","sourceRoot":"","sources":["../../../../src/specs/cesium-view.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,eAAe,EACf,iBAAiB,EAClB,MAAM,4BAA4B,CAAA;AAEnC,6EAA6E;AAC7E,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,cAAc,EAAE,MAAM,CAAA;CACvB;AAED;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;CACV;AAED,iEAAiE;AACjE,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAA;IACX,aAAa,EAAE,MAAM,CAAA;IACrB,YAAY,EAAE,MAAM,CAAA;IACpB,YAAY,EAAE,MAAM,CAAA;IACpB,kBAAkB,EAAE,OAAO,CAAA;IAC3B,YAAY,EAAE,OAAO,CAAA;IACrB,gBAAgB,EAAE,MAAM,CAAA;CACzB;AAED,MAAM,WAAW,eAAgB,SAAQ,eAAe;IACtD,cAAc,EAAE,MAAM,CAAA;IACtB,UAAU,EAAE,MAAM,CAAA;IAClB,4EAA4E;IAC5E,aAAa,EAAE,WAAW,CAAA;IAC1B,cAAc,EAAE,OAAO,CAAA;IACvB,uBAAuB,EAAE,MAAM,CAAA;IAC/B,4BAA4B,EAAE,MAAM,CAAA;IACpC,sBAAsB,EAAE,MAAM,CAAA;IAC9B,6CAA6C;IAC7C,eAAe,EAAE,MAAM,CAAA;IACvB,iBAAiB,EAAE,MAAM,CAAA;IACzB,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,aAAa,KAAK,IAAI,CAAA;CAC7C;AAED,MAAM,WAAW,iBAAkB,SAAQ,iBAAiB;IAC1D,+CAA+C;IAC/C,cAAc,IAAI,OAAO,CAAC,WAAW,CAAC,CAAA;IACtC;;;OAGG;IACH,SAAS,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,CAAA;IACpC;;;OAGG;IACH,mBAAmB,CAAC,MAAM,EAAE,WAAW,EAAE,cAAc,EAAE,UAAU,GAAG,IAAI,CAAA;IAC1E,4FAA4F;IAC5F,iBAAiB,IAAI,OAAO,CAAC,UAAU,CAAC,CAAA;CACzC;AAED,MAAM,MAAM,UAAU,GAAG,UAAU,CAAC,eAAe,EAAE,iBAAiB,CAAC,CAAA"}
@@ -11,6 +11,8 @@
11
11
  namespace margelo::nitro::reactnativecesium { struct CameraState; }
12
12
  // Forward declaration of `CesiumMetrics` to properly resolve imports.
13
13
  namespace margelo::nitro::reactnativecesium { struct CesiumMetrics; }
14
+ // Forward declaration of `Quaternion` to properly resolve imports.
15
+ namespace margelo::nitro::reactnativecesium { struct Quaternion; }
14
16
 
15
17
  #include <string>
16
18
  #include "CameraState.hpp"
@@ -23,6 +25,8 @@ namespace margelo::nitro::reactnativecesium { struct CesiumMetrics; }
23
25
  #include "JCesiumMetrics.hpp"
24
26
  #include <NitroModules/Promise.hpp>
25
27
  #include <NitroModules/JPromise.hpp>
28
+ #include "Quaternion.hpp"
29
+ #include "JQuaternion.hpp"
26
30
 
27
31
  namespace margelo::nitro::reactnativecesium {
28
32
 
@@ -174,5 +178,25 @@ namespace margelo::nitro::reactnativecesium {
174
178
  static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<JCameraState> /* camera */)>("setCamera");
175
179
  method(_javaPart, JCameraState::fromCpp(camera));
176
180
  }
181
+ void JHybridCesiumViewSpec::setCameraQuaternion(const CameraState& camera, const Quaternion& viewCorrection) {
182
+ static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<JCameraState> /* camera */, jni::alias_ref<JQuaternion> /* viewCorrection */)>("setCameraQuaternion");
183
+ method(_javaPart, JCameraState::fromCpp(camera), JQuaternion::fromCpp(viewCorrection));
184
+ }
185
+ std::shared_ptr<Promise<Quaternion>> JHybridCesiumViewSpec::getViewCorrection() {
186
+ static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>()>("getViewCorrection");
187
+ auto __result = method(_javaPart);
188
+ return [&]() {
189
+ auto __promise = Promise<Quaternion>::create();
190
+ __result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
191
+ auto __result = jni::static_ref_cast<JQuaternion>(__boxedResult);
192
+ __promise->resolve(__result->toCpp());
193
+ });
194
+ __result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
195
+ jni::JniException __jniError(__throwable);
196
+ __promise->reject(std::make_exception_ptr(__jniError));
197
+ });
198
+ return __promise;
199
+ }();
200
+ }
177
201
 
178
202
  } // namespace margelo::nitro::reactnativecesium
@@ -75,6 +75,8 @@ namespace margelo::nitro::reactnativecesium {
75
75
  // Methods
76
76
  std::shared_ptr<Promise<CameraState>> getCameraState() override;
77
77
  void setCamera(const CameraState& camera) override;
78
+ void setCameraQuaternion(const CameraState& camera, const Quaternion& viewCorrection) override;
79
+ std::shared_ptr<Promise<Quaternion>> getViewCorrection() override;
78
80
 
79
81
  private:
80
82
  jni::global_ref<JHybridCesiumViewSpec::JavaPart> _javaPart;
@@ -0,0 +1,69 @@
1
+ ///
2
+ /// JQuaternion.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #include <fbjni/fbjni.h>
11
+ #include "Quaternion.hpp"
12
+
13
+
14
+
15
+ namespace margelo::nitro::reactnativecesium {
16
+
17
+ using namespace facebook;
18
+
19
+ /**
20
+ * The C++ JNI bridge between the C++ struct "Quaternion" and the the Kotlin data class "Quaternion".
21
+ */
22
+ struct JQuaternion final: public jni::JavaClass<JQuaternion> {
23
+ public:
24
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/reactnativecesium/Quaternion;";
25
+
26
+ public:
27
+ /**
28
+ * Convert this Java/Kotlin-based struct to the C++ struct Quaternion by copying all values to C++.
29
+ */
30
+ [[maybe_unused]]
31
+ [[nodiscard]]
32
+ Quaternion toCpp() const {
33
+ static const auto clazz = javaClassStatic();
34
+ static const auto fieldW = clazz->getField<double>("w");
35
+ double w = this->getFieldValue(fieldW);
36
+ static const auto fieldX = clazz->getField<double>("x");
37
+ double x = this->getFieldValue(fieldX);
38
+ static const auto fieldY = clazz->getField<double>("y");
39
+ double y = this->getFieldValue(fieldY);
40
+ static const auto fieldZ = clazz->getField<double>("z");
41
+ double z = this->getFieldValue(fieldZ);
42
+ return Quaternion(
43
+ w,
44
+ x,
45
+ y,
46
+ z
47
+ );
48
+ }
49
+
50
+ public:
51
+ /**
52
+ * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
53
+ */
54
+ [[maybe_unused]]
55
+ static jni::local_ref<JQuaternion::javaobject> fromCpp(const Quaternion& value) {
56
+ using JSignature = JQuaternion(double, double, double, double);
57
+ static const auto clazz = javaClassStatic();
58
+ static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
59
+ return create(
60
+ clazz,
61
+ value.w,
62
+ value.x,
63
+ value.y,
64
+ value.z
65
+ );
66
+ }
67
+ };
68
+
69
+ } // namespace margelo::nitro::reactnativecesium
@@ -103,6 +103,14 @@ abstract class HybridCesiumViewSpec: HybridView() {
103
103
  @DoNotStrip
104
104
  @Keep
105
105
  abstract fun setCamera(camera: CameraState): Unit
106
+
107
+ @DoNotStrip
108
+ @Keep
109
+ abstract fun setCameraQuaternion(camera: CameraState, viewCorrection: Quaternion): Unit
110
+
111
+ @DoNotStrip
112
+ @Keep
113
+ abstract fun getViewCorrection(): Promise<Quaternion>
106
114
 
107
115
  // Default implementation of `HybridObject.toString()`
108
116
  override fun toString(): String {
@@ -0,0 +1,47 @@
1
+ ///
2
+ /// Quaternion.kt
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ package com.margelo.nitro.reactnativecesium
9
+
10
+ import androidx.annotation.Keep
11
+ import com.facebook.proguard.annotations.DoNotStrip
12
+
13
+
14
+ /**
15
+ * Represents the JavaScript object/struct "Quaternion".
16
+ */
17
+ @DoNotStrip
18
+ @Keep
19
+ data class Quaternion(
20
+ @DoNotStrip
21
+ @Keep
22
+ val w: Double,
23
+ @DoNotStrip
24
+ @Keep
25
+ val x: Double,
26
+ @DoNotStrip
27
+ @Keep
28
+ val y: Double,
29
+ @DoNotStrip
30
+ @Keep
31
+ val z: Double
32
+ ) {
33
+ /* primary constructor */
34
+
35
+ companion object {
36
+ /**
37
+ * Constructor called from C++
38
+ */
39
+ @DoNotStrip
40
+ @Keep
41
+ @Suppress("unused")
42
+ @JvmStatic
43
+ private fun fromCpp(w: Double, x: Double, y: Double, z: Double): Quaternion {
44
+ return Quaternion(w, x, y, z)
45
+ }
46
+ }
47
+ }
@@ -56,5 +56,7 @@ def add_nitrogen_files(spec)
56
56
  "SWIFT_OBJC_INTEROP_MODE" => "objcxx",
57
57
  # Enables stricter modular headers
58
58
  "DEFINES_MODULE" => "YES",
59
+ # Disable auto-generated ObjC header for Swift (Static linkage on Xcode 26.4 breaks here)
60
+ "SWIFT_INSTALL_OBJC_HEADER" => "NO",
59
61
  })
60
62
  end
@@ -38,6 +38,14 @@ namespace margelo::nitro::reactnativecesium::bridge::swift {
38
38
  };
39
39
  }
40
40
 
41
+ // pragma MARK: std::function<void(const Quaternion& /* result */)>
42
+ Func_void_Quaternion create_Func_void_Quaternion(void* NON_NULL swiftClosureWrapper) noexcept {
43
+ auto swiftClosure = ReactNativeCesium::Func_void_Quaternion::fromUnsafe(swiftClosureWrapper);
44
+ return [swiftClosure = std::move(swiftClosure)](const Quaternion& result) mutable -> void {
45
+ swiftClosure.call(result);
46
+ };
47
+ }
48
+
41
49
  // pragma MARK: std::shared_ptr<HybridCesiumViewSpec>
42
50
  std::shared_ptr<HybridCesiumViewSpec> create_std__shared_ptr_HybridCesiumViewSpec_(void* NON_NULL swiftUnsafePointer) noexcept {
43
51
  ReactNativeCesium::HybridCesiumViewSpec_cxx swiftPart = ReactNativeCesium::HybridCesiumViewSpec_cxx::fromUnsafe(swiftUnsafePointer);
@@ -14,6 +14,8 @@ namespace margelo::nitro::reactnativecesium { struct CameraState; }
14
14
  namespace margelo::nitro::reactnativecesium { struct CesiumMetrics; }
15
15
  // Forward declaration of `HybridCesiumViewSpec` to properly resolve imports.
16
16
  namespace margelo::nitro::reactnativecesium { class HybridCesiumViewSpec; }
17
+ // Forward declaration of `Quaternion` to properly resolve imports.
18
+ namespace margelo::nitro::reactnativecesium { struct Quaternion; }
17
19
 
18
20
  // Forward declarations of Swift defined types
19
21
  // Forward declaration of `HybridCesiumViewSpec_cxx` to properly resolve imports.
@@ -23,6 +25,7 @@ namespace ReactNativeCesium { class HybridCesiumViewSpec_cxx; }
23
25
  #include "CameraState.hpp"
24
26
  #include "CesiumMetrics.hpp"
25
27
  #include "HybridCesiumViewSpec.hpp"
28
+ #include "Quaternion.hpp"
26
29
  #include <NitroModules/Promise.hpp>
27
30
  #include <NitroModules/PromiseHolder.hpp>
28
31
  #include <NitroModules/Result.hpp>
@@ -131,6 +134,40 @@ namespace margelo::nitro::reactnativecesium::bridge::swift {
131
134
  return Func_void_std__exception_ptr_Wrapper(std::move(value));
132
135
  }
133
136
 
137
+ // pragma MARK: std::shared_ptr<Promise<Quaternion>>
138
+ /**
139
+ * Specialized version of `std::shared_ptr<Promise<Quaternion>>`.
140
+ */
141
+ using std__shared_ptr_Promise_Quaternion__ = std::shared_ptr<Promise<Quaternion>>;
142
+ inline std::shared_ptr<Promise<Quaternion>> create_std__shared_ptr_Promise_Quaternion__() noexcept {
143
+ return Promise<Quaternion>::create();
144
+ }
145
+ inline PromiseHolder<Quaternion> wrap_std__shared_ptr_Promise_Quaternion__(std::shared_ptr<Promise<Quaternion>> promise) noexcept {
146
+ return PromiseHolder<Quaternion>(std::move(promise));
147
+ }
148
+
149
+ // pragma MARK: std::function<void(const Quaternion& /* result */)>
150
+ /**
151
+ * Specialized version of `std::function<void(const Quaternion&)>`.
152
+ */
153
+ using Func_void_Quaternion = std::function<void(const Quaternion& /* result */)>;
154
+ /**
155
+ * Wrapper class for a `std::function<void(const Quaternion& / * result * /)>`, this can be used from Swift.
156
+ */
157
+ class Func_void_Quaternion_Wrapper final {
158
+ public:
159
+ explicit Func_void_Quaternion_Wrapper(std::function<void(const Quaternion& /* result */)>&& func): _function(std::make_unique<std::function<void(const Quaternion& /* result */)>>(std::move(func))) {}
160
+ inline void call(Quaternion result) const noexcept {
161
+ _function->operator()(result);
162
+ }
163
+ private:
164
+ std::unique_ptr<std::function<void(const Quaternion& /* result */)>> _function;
165
+ } SWIFT_NONCOPYABLE;
166
+ Func_void_Quaternion create_Func_void_Quaternion(void* NON_NULL swiftClosureWrapper) noexcept;
167
+ inline Func_void_Quaternion_Wrapper wrap_Func_void_Quaternion(Func_void_Quaternion value) noexcept {
168
+ return Func_void_Quaternion_Wrapper(std::move(value));
169
+ }
170
+
134
171
  // pragma MARK: std::shared_ptr<HybridCesiumViewSpec>
135
172
  /**
136
173
  * Specialized version of `std::shared_ptr<HybridCesiumViewSpec>`.
@@ -160,5 +197,14 @@ namespace margelo::nitro::reactnativecesium::bridge::swift {
160
197
  inline Result_void_ create_Result_void_(const std::exception_ptr& error) noexcept {
161
198
  return Result<void>::withError(error);
162
199
  }
200
+
201
+ // pragma MARK: Result<std::shared_ptr<Promise<Quaternion>>>
202
+ using Result_std__shared_ptr_Promise_Quaternion___ = Result<std::shared_ptr<Promise<Quaternion>>>;
203
+ inline Result_std__shared_ptr_Promise_Quaternion___ create_Result_std__shared_ptr_Promise_Quaternion___(const std::shared_ptr<Promise<Quaternion>>& value) noexcept {
204
+ return Result<std::shared_ptr<Promise<Quaternion>>>::withValue(value);
205
+ }
206
+ inline Result_std__shared_ptr_Promise_Quaternion___ create_Result_std__shared_ptr_Promise_Quaternion___(const std::exception_ptr& error) noexcept {
207
+ return Result<std::shared_ptr<Promise<Quaternion>>>::withError(error);
208
+ }
163
209
 
164
210
  } // namespace margelo::nitro::reactnativecesium::bridge::swift
@@ -14,11 +14,14 @@ namespace margelo::nitro::reactnativecesium { struct CameraState; }
14
14
  namespace margelo::nitro::reactnativecesium { struct CesiumMetrics; }
15
15
  // Forward declaration of `HybridCesiumViewSpec` to properly resolve imports.
16
16
  namespace margelo::nitro::reactnativecesium { class HybridCesiumViewSpec; }
17
+ // Forward declaration of `Quaternion` to properly resolve imports.
18
+ namespace margelo::nitro::reactnativecesium { struct Quaternion; }
17
19
 
18
20
  // Include C++ defined types
19
21
  #include "CameraState.hpp"
20
22
  #include "CesiumMetrics.hpp"
21
23
  #include "HybridCesiumViewSpec.hpp"
24
+ #include "Quaternion.hpp"
22
25
  #include <NitroModules/Promise.hpp>
23
26
  #include <NitroModules/Result.hpp>
24
27
  #include <exception>
@@ -16,6 +16,8 @@ namespace ReactNativeCesium { class HybridCesiumViewSpec_cxx; }
16
16
  namespace margelo::nitro::reactnativecesium { struct CameraState; }
17
17
  // Forward declaration of `CesiumMetrics` to properly resolve imports.
18
18
  namespace margelo::nitro::reactnativecesium { struct CesiumMetrics; }
19
+ // Forward declaration of `Quaternion` to properly resolve imports.
20
+ namespace margelo::nitro::reactnativecesium { struct Quaternion; }
19
21
 
20
22
  #include <string>
21
23
  #include "CameraState.hpp"
@@ -23,6 +25,7 @@ namespace margelo::nitro::reactnativecesium { struct CesiumMetrics; }
23
25
  #include <functional>
24
26
  #include <optional>
25
27
  #include <NitroModules/Promise.hpp>
28
+ #include "Quaternion.hpp"
26
29
 
27
30
  #include "ReactNativeCesium-Swift-Cxx-Umbrella.hpp"
28
31
 
@@ -149,6 +152,20 @@ namespace margelo::nitro::reactnativecesium {
149
152
  std::rethrow_exception(__result.error());
150
153
  }
151
154
  }
155
+ inline void setCameraQuaternion(const CameraState& camera, const Quaternion& viewCorrection) override {
156
+ auto __result = _swiftPart.setCameraQuaternion(std::forward<decltype(camera)>(camera), std::forward<decltype(viewCorrection)>(viewCorrection));
157
+ if (__result.hasError()) [[unlikely]] {
158
+ std::rethrow_exception(__result.error());
159
+ }
160
+ }
161
+ inline std::shared_ptr<Promise<Quaternion>> getViewCorrection() override {
162
+ auto __result = _swiftPart.getViewCorrection();
163
+ if (__result.hasError()) [[unlikely]] {
164
+ std::rethrow_exception(__result.error());
165
+ }
166
+ auto __value = std::move(__result.value());
167
+ return __value;
168
+ }
152
169
 
153
170
  private:
154
171
  ReactNativeCesium::HybridCesiumViewSpec_cxx _swiftPart;
@@ -0,0 +1,46 @@
1
+ ///
2
+ /// Func_void_Quaternion.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import NitroModules
9
+
10
+ /**
11
+ * Wraps a Swift `(_ value: Quaternion) -> Void` as a class.
12
+ * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
13
+ */
14
+ public final class Func_void_Quaternion {
15
+ public typealias bridge = margelo.nitro.reactnativecesium.bridge.swift
16
+
17
+ private let closure: (_ value: Quaternion) -> Void
18
+
19
+ public init(_ closure: @escaping (_ value: Quaternion) -> Void) {
20
+ self.closure = closure
21
+ }
22
+
23
+ @inline(__always)
24
+ public func call(value: Quaternion) -> Void {
25
+ self.closure(value)
26
+ }
27
+
28
+ /**
29
+ * Casts this instance to a retained unsafe raw pointer.
30
+ * This acquires one additional strong reference on the object!
31
+ */
32
+ @inline(__always)
33
+ public func toUnsafe() -> UnsafeMutableRawPointer {
34
+ return Unmanaged.passRetained(self).toOpaque()
35
+ }
36
+
37
+ /**
38
+ * Casts an unsafe pointer to a `Func_void_Quaternion`.
39
+ * The pointer has to be a retained opaque `Unmanaged<Func_void_Quaternion>`.
40
+ * This removes one strong reference from the object!
41
+ */
42
+ @inline(__always)
43
+ public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_Quaternion {
44
+ return Unmanaged<Func_void_Quaternion>.fromOpaque(pointer).takeRetainedValue()
45
+ }
46
+ }
@@ -24,6 +24,8 @@ public protocol HybridCesiumViewSpec_protocol: HybridObject, HybridView {
24
24
  // Methods
25
25
  func getCameraState() throws -> Promise<CameraState>
26
26
  func setCamera(camera: CameraState) throws -> Void
27
+ func setCameraQuaternion(camera: CameraState, viewCorrection: Quaternion) throws -> Void
28
+ func getViewCorrection() throws -> Promise<Quaternion>
27
29
  }
28
30
 
29
31
  public extension HybridCesiumViewSpec_protocol {