react-native-cesium 1.0.1 → 1.0.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 +109 -19
- package/android/src/main/cpp/CesiumBridgeAndroid.cpp +88 -1
- package/android/src/main/cpp/CesiumBridgeAndroid.h +11 -1
- package/android/src/main/java/com/margelo/nitro/reactnativecesium/CesiumBridgeJNI.kt +35 -0
- package/android/src/main/java/com/margelo/nitro/reactnativecesium/HybridCesiumView.kt +55 -0
- package/cpp/engine/GlobeCamera.cpp +22 -0
- package/cpp/engine/GlobeCamera.hpp +3 -0
- package/ios/CesiumBridge.h +15 -0
- package/ios/CesiumBridge.mm +68 -7
- package/ios/HybridCesiumView.swift +56 -0
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/cesium-view.nitro.d.ts +21 -1
- package/lib/typescript/src/specs/cesium-view.nitro.d.ts.map +1 -1
- package/nitrogen/generated/android/c++/JHybridCesiumViewSpec.cpp +24 -0
- package/nitrogen/generated/android/c++/JHybridCesiumViewSpec.hpp +2 -0
- package/nitrogen/generated/android/c++/JQuaternion.hpp +69 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativecesium/HybridCesiumViewSpec.kt +8 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativecesium/Quaternion.kt +47 -0
- package/nitrogen/generated/ios/ReactNativeCesium+autolinking.rb +2 -0
- package/nitrogen/generated/ios/ReactNativeCesium-Swift-Cxx-Bridge.cpp +8 -0
- package/nitrogen/generated/ios/ReactNativeCesium-Swift-Cxx-Bridge.hpp +46 -0
- package/nitrogen/generated/ios/ReactNativeCesium-Swift-Cxx-Umbrella.hpp +3 -0
- package/nitrogen/generated/ios/c++/HybridCesiumViewSpecSwift.hpp +17 -0
- package/nitrogen/generated/ios/swift/Func_void_Quaternion.swift +46 -0
- package/nitrogen/generated/ios/swift/HybridCesiumViewSpec.swift +2 -0
- package/nitrogen/generated/ios/swift/HybridCesiumViewSpec_cxx.swift +30 -0
- package/nitrogen/generated/ios/swift/Quaternion.swift +44 -0
- package/nitrogen/generated/shared/c++/HybridCesiumViewSpec.cpp +2 -0
- package/nitrogen/generated/shared/c++/HybridCesiumViewSpec.hpp +5 -0
- package/nitrogen/generated/shared/c++/Quaternion.hpp +95 -0
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/specs/cesium-view.nitro.ts +22 -1
|
@@ -283,6 +283,36 @@ open class HybridCesiumViewSpec_cxx {
|
|
|
283
283
|
}
|
|
284
284
|
}
|
|
285
285
|
|
|
286
|
+
@inline(__always)
|
|
287
|
+
public final func setCameraQuaternion(camera: CameraState, viewCorrection: Quaternion) -> bridge.Result_void_ {
|
|
288
|
+
do {
|
|
289
|
+
try self.__implementation.setCameraQuaternion(camera: camera, viewCorrection: viewCorrection)
|
|
290
|
+
return bridge.create_Result_void_()
|
|
291
|
+
} catch (let __error) {
|
|
292
|
+
let __exceptionPtr = __error.toCpp()
|
|
293
|
+
return bridge.create_Result_void_(__exceptionPtr)
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
@inline(__always)
|
|
298
|
+
public final func getViewCorrection() -> bridge.Result_std__shared_ptr_Promise_Quaternion___ {
|
|
299
|
+
do {
|
|
300
|
+
let __result = try self.__implementation.getViewCorrection()
|
|
301
|
+
let __resultCpp = { () -> bridge.std__shared_ptr_Promise_Quaternion__ in
|
|
302
|
+
let __promise = bridge.create_std__shared_ptr_Promise_Quaternion__()
|
|
303
|
+
let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_Quaternion__(__promise)
|
|
304
|
+
__result
|
|
305
|
+
.then({ __result in __promiseHolder.resolve(__result) })
|
|
306
|
+
.catch({ __error in __promiseHolder.reject(__error.toCpp()) })
|
|
307
|
+
return __promise
|
|
308
|
+
}()
|
|
309
|
+
return bridge.create_Result_std__shared_ptr_Promise_Quaternion___(__resultCpp)
|
|
310
|
+
} catch (let __error) {
|
|
311
|
+
let __exceptionPtr = __error.toCpp()
|
|
312
|
+
return bridge.create_Result_std__shared_ptr_Promise_Quaternion___(__exceptionPtr)
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
286
316
|
public final func getView() -> UnsafeMutableRawPointer {
|
|
287
317
|
return Unmanaged.passRetained(__implementation.view).toOpaque()
|
|
288
318
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// 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
|
+
* Represents an instance of `Quaternion`, backed by a C++ struct.
|
|
12
|
+
*/
|
|
13
|
+
public typealias Quaternion = margelo.nitro.reactnativecesium.Quaternion
|
|
14
|
+
|
|
15
|
+
public extension Quaternion {
|
|
16
|
+
private typealias bridge = margelo.nitro.reactnativecesium.bridge.swift
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Create a new instance of `Quaternion`.
|
|
20
|
+
*/
|
|
21
|
+
init(w: Double, x: Double, y: Double, z: Double) {
|
|
22
|
+
self.init(w, x, y, z)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@inline(__always)
|
|
26
|
+
var w: Double {
|
|
27
|
+
return self.__w
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@inline(__always)
|
|
31
|
+
var x: Double {
|
|
32
|
+
return self.__x
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@inline(__always)
|
|
36
|
+
var y: Double {
|
|
37
|
+
return self.__y
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@inline(__always)
|
|
41
|
+
var z: Double {
|
|
42
|
+
return self.__z
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -36,6 +36,8 @@ namespace margelo::nitro::reactnativecesium {
|
|
|
36
36
|
prototype.registerHybridSetter("onMetrics", &HybridCesiumViewSpec::setOnMetrics);
|
|
37
37
|
prototype.registerHybridMethod("getCameraState", &HybridCesiumViewSpec::getCameraState);
|
|
38
38
|
prototype.registerHybridMethod("setCamera", &HybridCesiumViewSpec::setCamera);
|
|
39
|
+
prototype.registerHybridMethod("setCameraQuaternion", &HybridCesiumViewSpec::setCameraQuaternion);
|
|
40
|
+
prototype.registerHybridMethod("getViewCorrection", &HybridCesiumViewSpec::getViewCorrection);
|
|
39
41
|
});
|
|
40
42
|
}
|
|
41
43
|
|
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
namespace margelo::nitro::reactnativecesium { struct CameraState; }
|
|
18
18
|
// Forward declaration of `CesiumMetrics` to properly resolve imports.
|
|
19
19
|
namespace margelo::nitro::reactnativecesium { struct CesiumMetrics; }
|
|
20
|
+
// Forward declaration of `Quaternion` to properly resolve imports.
|
|
21
|
+
namespace margelo::nitro::reactnativecesium { struct Quaternion; }
|
|
20
22
|
|
|
21
23
|
#include <string>
|
|
22
24
|
#include "CameraState.hpp"
|
|
@@ -24,6 +26,7 @@ namespace margelo::nitro::reactnativecesium { struct CesiumMetrics; }
|
|
|
24
26
|
#include <functional>
|
|
25
27
|
#include <optional>
|
|
26
28
|
#include <NitroModules/Promise.hpp>
|
|
29
|
+
#include "Quaternion.hpp"
|
|
27
30
|
|
|
28
31
|
namespace margelo::nitro::reactnativecesium {
|
|
29
32
|
|
|
@@ -77,6 +80,8 @@ namespace margelo::nitro::reactnativecesium {
|
|
|
77
80
|
// Methods
|
|
78
81
|
virtual std::shared_ptr<Promise<CameraState>> getCameraState() = 0;
|
|
79
82
|
virtual void setCamera(const CameraState& camera) = 0;
|
|
83
|
+
virtual void setCameraQuaternion(const CameraState& camera, const Quaternion& viewCorrection) = 0;
|
|
84
|
+
virtual std::shared_ptr<Promise<Quaternion>> getViewCorrection() = 0;
|
|
80
85
|
|
|
81
86
|
protected:
|
|
82
87
|
// Hybrid Setup
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Quaternion.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
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
11
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
16
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
#if __has_include(<NitroModules/JSIHelpers.hpp>)
|
|
21
|
+
#include <NitroModules/JSIHelpers.hpp>
|
|
22
|
+
#else
|
|
23
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
|
+
#endif
|
|
25
|
+
#if __has_include(<NitroModules/PropNameIDCache.hpp>)
|
|
26
|
+
#include <NitroModules/PropNameIDCache.hpp>
|
|
27
|
+
#else
|
|
28
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
29
|
+
#endif
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
namespace margelo::nitro::reactnativecesium {
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A struct which can be represented as a JavaScript object (Quaternion).
|
|
39
|
+
*/
|
|
40
|
+
struct Quaternion final {
|
|
41
|
+
public:
|
|
42
|
+
double w SWIFT_PRIVATE;
|
|
43
|
+
double x SWIFT_PRIVATE;
|
|
44
|
+
double y SWIFT_PRIVATE;
|
|
45
|
+
double z SWIFT_PRIVATE;
|
|
46
|
+
|
|
47
|
+
public:
|
|
48
|
+
Quaternion() = default;
|
|
49
|
+
explicit Quaternion(double w, double x, double y, double z): w(w), x(x), y(y), z(z) {}
|
|
50
|
+
|
|
51
|
+
public:
|
|
52
|
+
friend bool operator==(const Quaternion& lhs, const Quaternion& rhs) = default;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
} // namespace margelo::nitro::reactnativecesium
|
|
56
|
+
|
|
57
|
+
namespace margelo::nitro {
|
|
58
|
+
|
|
59
|
+
// C++ Quaternion <> JS Quaternion (object)
|
|
60
|
+
template <>
|
|
61
|
+
struct JSIConverter<margelo::nitro::reactnativecesium::Quaternion> final {
|
|
62
|
+
static inline margelo::nitro::reactnativecesium::Quaternion fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
63
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
64
|
+
return margelo::nitro::reactnativecesium::Quaternion(
|
|
65
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "w"))),
|
|
66
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "x"))),
|
|
67
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "y"))),
|
|
68
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "z")))
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::reactnativecesium::Quaternion& arg) {
|
|
72
|
+
jsi::Object obj(runtime);
|
|
73
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "w"), JSIConverter<double>::toJSI(runtime, arg.w));
|
|
74
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "x"), JSIConverter<double>::toJSI(runtime, arg.x));
|
|
75
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "y"), JSIConverter<double>::toJSI(runtime, arg.y));
|
|
76
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "z"), JSIConverter<double>::toJSI(runtime, arg.z));
|
|
77
|
+
return obj;
|
|
78
|
+
}
|
|
79
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
80
|
+
if (!value.isObject()) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
jsi::Object obj = value.getObject(runtime);
|
|
84
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "w")))) return false;
|
|
88
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "x")))) return false;
|
|
89
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "y")))) return false;
|
|
90
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "z")))) return false;
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
} // namespace margelo::nitro
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -15,6 +15,17 @@ export interface CameraState {
|
|
|
15
15
|
verticalFovDeg: number
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Unit quaternion (w + xi + yj + zk). Used for camera-space view correction.
|
|
20
|
+
* Non-unit values are normalized on the native side.
|
|
21
|
+
*/
|
|
22
|
+
export interface Quaternion {
|
|
23
|
+
w: number
|
|
24
|
+
x: number
|
|
25
|
+
y: number
|
|
26
|
+
z: number
|
|
27
|
+
}
|
|
28
|
+
|
|
18
29
|
/** Throttled telemetry for dashboards (see `onMetrics` prop). */
|
|
19
30
|
export interface CesiumMetrics {
|
|
20
31
|
fps: number
|
|
@@ -44,8 +55,18 @@ export interface CesiumViewProps extends HybridViewProps {
|
|
|
44
55
|
export interface CesiumViewMethods extends HybridViewMethods {
|
|
45
56
|
/** Returns the current native camera state. */
|
|
46
57
|
getCameraState(): Promise<CameraState>
|
|
47
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* Runtime camera control (heading/pitch/roll + position + VFOV).
|
|
60
|
+
* Does not change the view-correction quaternion; use `setCameraQuaternion` to set that.
|
|
61
|
+
*/
|
|
48
62
|
setCamera(camera: CameraState): void
|
|
63
|
+
/**
|
|
64
|
+
* Same fields as `setCamera`, plus a camera-space rotation applied after HPR
|
|
65
|
+
* (e.g. boresight / HUD alignment). See README.
|
|
66
|
+
*/
|
|
67
|
+
setCameraQuaternion(camera: CameraState, viewCorrection: Quaternion): void
|
|
68
|
+
/** Current view-correction quaternion (identity if never set via `setCameraQuaternion`). */
|
|
69
|
+
getViewCorrection(): Promise<Quaternion>
|
|
49
70
|
}
|
|
50
71
|
|
|
51
72
|
export type CesiumView = HybridView<CesiumViewProps, CesiumViewMethods>
|