react-native-cesium 1.0.1
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/LICENSE +21 -0
- package/NOTICE +12 -0
- package/README.md +308 -0
- package/ReactNativeCesium.podspec +54 -0
- package/android/CMakeLists.txt +146 -0
- package/android/build.gradle +178 -0
- package/android/fix-prefab.gradle +51 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +5 -0
- package/android/src/main/assets/cacert.pem +3529 -0
- package/android/src/main/cpp/CesiumBridgeAndroid.cpp +487 -0
- package/android/src/main/cpp/CesiumBridgeAndroid.h +94 -0
- package/android/src/main/cpp/cpp-adapter.cpp +17 -0
- package/android/src/main/cpp/vulkan/VulkanBackend.cpp +1781 -0
- package/android/src/main/cpp/vulkan/VulkanBackend.h +190 -0
- package/android/src/main/cpp/vulkan/shaders/sky.frag +86 -0
- package/android/src/main/cpp/vulkan/shaders/sky.vert +9 -0
- package/android/src/main/cpp/vulkan/shaders/terrain.frag +144 -0
- package/android/src/main/cpp/vulkan/shaders/terrain.vert +25 -0
- package/android/src/main/java/com/margelo/nitro/reactnativecesium/CesiumBridgeJNI.kt +84 -0
- package/android/src/main/java/com/margelo/nitro/reactnativecesium/HybridCesiumView.kt +225 -0
- package/android/src/main/java/com/reactnativecesium/ReactNativeCesiumPackage.kt +28 -0
- package/cpp/engine/CesiumEngine.cpp +413 -0
- package/cpp/engine/CesiumEngine.hpp +90 -0
- package/cpp/engine/DeletionQueue.cpp +28 -0
- package/cpp/engine/DeletionQueue.hpp +28 -0
- package/cpp/engine/GlobeCamera.cpp +181 -0
- package/cpp/engine/GlobeCamera.hpp +64 -0
- package/cpp/engine/GltfToMesh.cpp +154 -0
- package/cpp/engine/GltfToMesh.hpp +20 -0
- package/cpp/engine/ResourcePreparer.cpp +224 -0
- package/cpp/engine/ResourcePreparer.hpp +96 -0
- package/cpp/engine/TaskProcessor.cpp +61 -0
- package/cpp/engine/TaskProcessor.hpp +43 -0
- package/cpp/engine/TileLifecycleManager.cpp +30 -0
- package/cpp/engine/TileLifecycleManager.hpp +25 -0
- package/cpp/fmt/format.h +9 -0
- package/cpp/renderer/IGPUBackend.hpp +22 -0
- package/cpp/renderer/RenderTypes.hpp +112 -0
- package/cpp/renderer/ShaderTypes.hpp +29 -0
- package/example/README.md +43 -0
- package/example/react-native-cesium-example.jpg +0 -0
- package/ios/CesiumBridge.h +55 -0
- package/ios/CesiumBridge.mm +393 -0
- package/ios/HybridCesiumView.swift +299 -0
- package/ios/ReactNativeCesium-umbrella.h +16 -0
- package/ios/metal/MetalBackend.h +82 -0
- package/ios/metal/MetalBackend.mm +839 -0
- package/ios/react_native_cesium_ensure_native.rb +12 -0
- package/ios/react_native_cesium_post_install.rb +30 -0
- package/lib/commonjs/CesiumView.js +13 -0
- package/lib/commonjs/CesiumView.js.map +1 -0
- package/lib/commonjs/index.js +13 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/specs/cesium-view.nitro.js +6 -0
- package/lib/commonjs/specs/cesium-view.nitro.js.map +1 -0
- package/lib/module/CesiumView.js +9 -0
- package/lib/module/CesiumView.js.map +1 -0
- package/lib/module/index.js +4 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/specs/cesium-view.nitro.js +4 -0
- package/lib/module/specs/cesium-view.nitro.js.map +1 -0
- package/lib/typescript/src/CesiumView.d.ts +5 -0
- package/lib/typescript/src/CesiumView.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +3 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/specs/cesium-view.nitro.d.ts +43 -0
- package/lib/typescript/src/specs/cesium-view.nitro.d.ts.map +1 -0
- package/nitro.json +30 -0
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/android/ReactNativeCesium+autolinking.cmake +83 -0
- package/nitrogen/generated/android/ReactNativeCesium+autolinking.gradle +27 -0
- package/nitrogen/generated/android/ReactNativeCesiumOnLoad.cpp +58 -0
- package/nitrogen/generated/android/ReactNativeCesiumOnLoad.hpp +34 -0
- package/nitrogen/generated/android/c++/JCameraState.hpp +81 -0
- package/nitrogen/generated/android/c++/JCesiumMetrics.hpp +81 -0
- package/nitrogen/generated/android/c++/JFunc_void_CesiumMetrics.hpp +78 -0
- package/nitrogen/generated/android/c++/JHybridCesiumViewSpec.cpp +178 -0
- package/nitrogen/generated/android/c++/JHybridCesiumViewSpec.hpp +83 -0
- package/nitrogen/generated/android/c++/views/JHybridCesiumViewStateUpdater.cpp +92 -0
- package/nitrogen/generated/android/c++/views/JHybridCesiumViewStateUpdater.hpp +49 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativecesium/CameraState.kt +56 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativecesium/CesiumMetrics.kt +56 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativecesium/Func_void_CesiumMetrics.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativecesium/HybridCesiumViewSpec.kt +126 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativecesium/ReactNativeCesiumOnLoad.kt +35 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativecesium/views/HybridCesiumViewManager.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativecesium/views/HybridCesiumViewStateUpdater.kt +23 -0
- package/nitrogen/generated/ios/ReactNativeCesium+autolinking.rb +60 -0
- package/nitrogen/generated/ios/ReactNativeCesium-Swift-Cxx-Bridge.cpp +57 -0
- package/nitrogen/generated/ios/ReactNativeCesium-Swift-Cxx-Bridge.hpp +164 -0
- package/nitrogen/generated/ios/ReactNativeCesium-Swift-Cxx-Umbrella.hpp +53 -0
- package/nitrogen/generated/ios/ReactNativeCesiumAutolinking.mm +33 -0
- package/nitrogen/generated/ios/ReactNativeCesiumAutolinking.swift +26 -0
- package/nitrogen/generated/ios/c++/HybridCesiumViewSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridCesiumViewSpecSwift.hpp +157 -0
- package/nitrogen/generated/ios/c++/views/HybridCesiumViewComponent.mm +167 -0
- package/nitrogen/generated/ios/swift/CameraState.swift +59 -0
- package/nitrogen/generated/ios/swift/CesiumMetrics.swift +59 -0
- package/nitrogen/generated/ios/swift/Func_void_CameraState.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_CesiumMetrics.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +46 -0
- package/nitrogen/generated/ios/swift/HybridCesiumViewSpec.swift +65 -0
- package/nitrogen/generated/ios/swift/HybridCesiumViewSpec_cxx.swift +306 -0
- package/nitrogen/generated/shared/c++/CameraState.hpp +107 -0
- package/nitrogen/generated/shared/c++/CesiumMetrics.hpp +107 -0
- package/nitrogen/generated/shared/c++/HybridCesiumViewSpec.cpp +42 -0
- package/nitrogen/generated/shared/c++/HybridCesiumViewSpec.hpp +90 -0
- package/nitrogen/generated/shared/c++/views/HybridCesiumViewComponent.cpp +182 -0
- package/nitrogen/generated/shared/c++/views/HybridCesiumViewComponent.hpp +122 -0
- package/nitrogen/generated/shared/json/CesiumViewConfig.json +19 -0
- package/package.json +140 -0
- package/react-native.config.js +16 -0
- package/scripts/cesium/build.mjs +901 -0
- package/scripts/cesium/clean.mjs +35 -0
- package/scripts/cesium/clone.mjs +32 -0
- package/scripts/cesium/ensure-native.mjs +116 -0
- package/scripts/cesium/vcpkg-ports/zstd/fix-emscripten-and-clang-cl.patch +31 -0
- package/scripts/cesium/vcpkg-ports/zstd/fix-windows-rc-compile.patch +13 -0
- package/scripts/cesium/vcpkg-ports/zstd/no-static-suffix.patch +13 -0
- package/scripts/cesium/vcpkg-ports/zstd/portfile.cmake +77 -0
- package/scripts/cesium/vcpkg-ports/zstd/usage +4 -0
- package/scripts/cesium/vcpkg-ports/zstd/vcpkg.json +23 -0
- package/scripts/cesium/vcpkg-triplets/arm64-ios-simulator.cmake +10 -0
- package/scripts/cesium/vcpkg-triplets/arm64-ios.cmake +14 -0
- package/src/CesiumView.tsx +13 -0
- package/src/index.ts +7 -0
- package/src/specs/cesium-view.nitro.ts +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Darren Yeates
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Third-party notices
|
|
2
|
+
===================
|
|
3
|
+
|
|
4
|
+
This package uses libraries and headers produced from
|
|
5
|
+
Cesium Native (https://github.com/CesiumGS/cesium-native).
|
|
6
|
+
|
|
7
|
+
Cesium Native is licensed under the Apache License, Version 2.0.
|
|
8
|
+
You may obtain a copy of the License at:
|
|
9
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
See also the upstream repository for copyright notices and third-party
|
|
12
|
+
dependencies bundled by Cesium Native and vcpkg.
|
package/README.md
ADDED
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
# react-native-cesium
|
|
2
|
+
|
|
3
|
+
> [!WARNING]
|
|
4
|
+
> This library is under development and may not work correctly in all cases yet.
|
|
5
|
+
>
|
|
6
|
+
|
|
7
|
+
Experimental Cesium rendering for React Native using [Nitro Modules](https://github.com/mrousavy/nitro), with the native Metal/Vulkan renderer powered by [Cesium Native](https://github.com/CesiumGS/cesium-native).
|
|
8
|
+
|
|
9
|
+

|
|
10
|
+
|
|
11
|
+
## Status
|
|
12
|
+
|
|
13
|
+
- Platform maturity: **under development**
|
|
14
|
+
- Supported renderers: Metal (iOS) and Vulkan (Android)
|
|
15
|
+
- Native engine: **Cesium Native**
|
|
16
|
+
- React Native integration: **Nitro host component + imperative hybrid ref API**
|
|
17
|
+
|
|
18
|
+
## Requirements
|
|
19
|
+
|
|
20
|
+
- React Native **new architecture**
|
|
21
|
+
- Follow the native build instructions below: additional setup is required by you.
|
|
22
|
+
- A valid Cesium Ion access token and asset IDs for your content (get these from https://ion.cesium.com)
|
|
23
|
+
- **Disk and time:** building Cesium Native pulls **vcpkg** dependencies, can use **several GB** of disk, and often takes a long time on first build.
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
Add the package to your app:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
yarn add react-native-cesium
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
or:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install react-native-cesium
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
## Building Cesium Native locally
|
|
41
|
+
|
|
42
|
+
The package **does not include** the required iOS or Android Cesium Native libraries. Generate them locally by compiling **Cesium Native** with the required toolchains.
|
|
43
|
+
|
|
44
|
+
### System dependencies
|
|
45
|
+
|
|
46
|
+
These are **not** installed by `yarn add` / `pod install`. Install them on your local machine first.
|
|
47
|
+
|
|
48
|
+
#### Shared (both iOS and Android)
|
|
49
|
+
|
|
50
|
+
| Tool | Typical install (macOS) | Why |
|
|
51
|
+
| --- | --- | --- |
|
|
52
|
+
| **CMake** | `brew install cmake` | Configures and drives the native build |
|
|
53
|
+
| **Ninja** | `brew install ninja` | Required generator on macOS for the bundled build script |
|
|
54
|
+
| **Git** | Xcode includes `/usr/bin/git` | Clones Cesium Native and vcpkg |
|
|
55
|
+
| **Python 3** | Usually present on macOS; `brew install python@3` if needed | Some vcpkg/port steps expect a working `python3` |
|
|
56
|
+
|
|
57
|
+
Optional but recommended for faster or more reliable builds (see [Cesium Native developer setup](https://github.com/CesiumGS/cesium-native/blob/main/doc/topics/developer-setup.md)):
|
|
58
|
+
|
|
59
|
+
- **`nasm`** — `brew install nasm` (speeds some JPEG-related builds in dependency trees)
|
|
60
|
+
|
|
61
|
+
Ensure Homebrew’s binary directory is on your **`PATH`** when you run the build (typically `/opt/homebrew/bin` on Apple Silicon or `/usr/local/bin` on Intel Macs). The build script also tries to prepend common Homebrew paths for nested CMake/vcpkg processes.
|
|
62
|
+
|
|
63
|
+
<details>
|
|
64
|
+
<summary><strong>Additional iOS specific requirements</strong></summary>
|
|
65
|
+
|
|
66
|
+
- **Xcode** or Command Line Tools: `xcode-select --install` (or install Xcode from the App Store)
|
|
67
|
+
- Needed for Apple `clang`, SDKs, and `xcodebuild` (XCFramework assembly)
|
|
68
|
+
|
|
69
|
+
</details>
|
|
70
|
+
|
|
71
|
+
<details>
|
|
72
|
+
<summary><strong>Additional Android specific requirements</strong></summary>
|
|
73
|
+
|
|
74
|
+
- Install **Android Studio**
|
|
75
|
+
- In SDK Manager, install:
|
|
76
|
+
- **Android SDK**
|
|
77
|
+
- **NDK** (the project currently uses `27.1.12297006`)
|
|
78
|
+
- Ensure **Java 17 (JDK)** is available (Android Studio bundled JDK is fine)
|
|
79
|
+
|
|
80
|
+
For Android builds, make sure one of these is set so the NDK can be discovered:
|
|
81
|
+
|
|
82
|
+
- `ANDROID_NDK_HOME` (explicit NDK path), or
|
|
83
|
+
- `ANDROID_SDK_ROOT` / `ANDROID_HOME` with an installed NDK under `ndk/`
|
|
84
|
+
|
|
85
|
+
If `ANDROID_NDK_HOME` is unset, the build script will try to auto-detect the latest installed NDK from your SDK directory.
|
|
86
|
+
|
|
87
|
+
</details>
|
|
88
|
+
|
|
89
|
+
### Required Podfile hooks (iOS)
|
|
90
|
+
|
|
91
|
+
Your app **`ios/Podfile`** must **`require`** two helpers from this package and call them in **`pre_install`** and **`post_install`**.
|
|
92
|
+
|
|
93
|
+
**Top of the Podfile** (paths assume the default `node_modules` layout):
|
|
94
|
+
|
|
95
|
+
```ruby
|
|
96
|
+
require_relative "../node_modules/react-native-cesium/ios/react_native_cesium_ensure_native"
|
|
97
|
+
require_relative "../node_modules/react-native-cesium/ios/react_native_cesium_post_install"
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
**`pre_install`** (runs before pods resolve; triggers automatic Cesium Native clone/build when the XCFramework is missing):
|
|
101
|
+
|
|
102
|
+
```ruby
|
|
103
|
+
pre_install do |installer|
|
|
104
|
+
react_native_cesium_ensure_native
|
|
105
|
+
end
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
**`post_install`** (header search paths and simulator arch exclusions):
|
|
109
|
+
|
|
110
|
+
```ruby
|
|
111
|
+
post_install do |installer|
|
|
112
|
+
react_native_post_install(
|
|
113
|
+
installer,
|
|
114
|
+
config[:reactNativePath],
|
|
115
|
+
:mac_catalyst_enabled => false
|
|
116
|
+
)
|
|
117
|
+
react_native_cesium_post_install(installer)
|
|
118
|
+
end
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
The **post-install** helper is currently needed to:
|
|
122
|
+
|
|
123
|
+
- prepend this package's `cpp/` headers before the locally built XCFramework headers
|
|
124
|
+
- exclude `x86_64` iOS simulator builds, because the simulator slice is Apple Silicon `arm64` only
|
|
125
|
+
|
|
126
|
+
### Building
|
|
127
|
+
|
|
128
|
+
**Automatic (default):** assuming you have done the above and have all the required dependencies in place, when the native output is missing, the package tries to build it for you:
|
|
129
|
+
|
|
130
|
+
- **iOS:** add **`pre_install`** in your app **`Podfile`** (one-time; see [Required Podfile hooks](#required-podfile-hooks-ios)) so **`pod install`** runs **`scripts/cesium/ensure-native.mjs --ios`**, which runs **`npm run update`** / **`yarn run update`** (if needed) and then **`CESIUM_BUILD_ONLY=ios`** build. The first run can take **a long time** and needs the same **system dependencies** as a manual build (CMake, Ninja, Xcode, disk space, etc.).
|
|
131
|
+
- **Android:** the library’s Gradle **`preBuild`** runs **`ensure-native.mjs --android`** if **`vendor/android`** is incomplete, which runs **`CESIUM_BUILD_ONLY=android`** build. Requires **ANDROID_NDK_HOME** (or an NDK the build script can find).
|
|
132
|
+
|
|
133
|
+
**Manual (optional):** from the package directory (e.g. `node_modules/react-native-cesium`):
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
yarn run update # fetches Cesium Native source locally from GitHub
|
|
137
|
+
yarn run build # builds iOS and Android artifacts; can take a long time
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
- `npm run update` / `yarn run update` checks out **Cesium Native `v0.59.0`** into `vendor/cesium-native` (created next to the package files; typically ignored in app repos).
|
|
141
|
+
- `npm run build` / `yarn run build` runs `scripts/cesium/build.mjs` (**CMake**, **vcpkg** under `vendor/vcpkg` unless **`VCPKG_ROOT`** is set, **Ninja** on macOS) and writes **`vendor/ios/CesiumNative.xcframework`** and/or **`vendor/android`** depending on **`CESIUM_BUILD_ONLY`**.
|
|
142
|
+
|
|
143
|
+
Then install pods (iOS):
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
cd ios && pod install && cd ..
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Usage
|
|
150
|
+
|
|
151
|
+
The public JS surface is exported from `react-native-cesium`:
|
|
152
|
+
|
|
153
|
+
- `CesiumView`
|
|
154
|
+
- `CameraState`
|
|
155
|
+
- `CesiumMetrics`
|
|
156
|
+
- `CesiumViewProps`
|
|
157
|
+
- `CesiumViewMethods`
|
|
158
|
+
|
|
159
|
+
Minimal usage:
|
|
160
|
+
|
|
161
|
+
```tsx
|
|
162
|
+
import React, { useRef } from 'react'
|
|
163
|
+
import { StyleSheet, View } from 'react-native'
|
|
164
|
+
import { callback } from 'react-native-nitro-modules'
|
|
165
|
+
import {
|
|
166
|
+
CesiumView,
|
|
167
|
+
type CameraState,
|
|
168
|
+
type CesiumMetrics,
|
|
169
|
+
type CesiumViewMethods,
|
|
170
|
+
} from 'react-native-cesium'
|
|
171
|
+
|
|
172
|
+
const initialCamera: CameraState = {
|
|
173
|
+
latitude: 46.02,
|
|
174
|
+
longitude: 7.6,
|
|
175
|
+
altitude: 5800,
|
|
176
|
+
heading: 220,
|
|
177
|
+
pitch: -20,
|
|
178
|
+
roll: 0,
|
|
179
|
+
verticalFovDeg: 60,
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function GlobeScreen() {
|
|
183
|
+
const cesiumRef = useRef<CesiumViewMethods | null>(null)
|
|
184
|
+
|
|
185
|
+
return (
|
|
186
|
+
<View style={styles.container}>
|
|
187
|
+
<CesiumView
|
|
188
|
+
hybridRef={callback((ref: CesiumViewMethods | null) => {
|
|
189
|
+
cesiumRef.current = ref
|
|
190
|
+
})}
|
|
191
|
+
style={styles.fill}
|
|
192
|
+
ionAccessToken="YOUR_CESIUM_ION_ACCESS_TOKEN"
|
|
193
|
+
ionAssetId={1}
|
|
194
|
+
initialCamera={initialCamera}
|
|
195
|
+
pauseRendering={false}
|
|
196
|
+
maximumScreenSpaceError={16}
|
|
197
|
+
maximumSimultaneousTileLoads={8}
|
|
198
|
+
loadingDescendantLimit={20}
|
|
199
|
+
msaaSampleCount={1}
|
|
200
|
+
ionImageryAssetId={2}
|
|
201
|
+
onMetrics={callback((metrics: CesiumMetrics) => {
|
|
202
|
+
console.log('Cesium FPS:', metrics.fps)
|
|
203
|
+
})}
|
|
204
|
+
/>
|
|
205
|
+
</View>
|
|
206
|
+
)
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const styles = StyleSheet.create({
|
|
210
|
+
container: { flex: 1 },
|
|
211
|
+
fill: { flex: 1 },
|
|
212
|
+
})
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### Nitro `hybridRef` requirement
|
|
216
|
+
|
|
217
|
+
When you pass a callback ref to `CesiumView`, wrap it with `callback(...)` from `react-native-nitro-modules`. Plain callback functions do not make it across the React Native bridge correctly for this component.
|
|
218
|
+
|
|
219
|
+
## API
|
|
220
|
+
|
|
221
|
+
### `CesiumViewProps`
|
|
222
|
+
|
|
223
|
+
`CesiumView` is a Nitro host component. In addition to standard view props like `style`, it currently expects these Cesium-specific props:
|
|
224
|
+
|
|
225
|
+
**Consumer-required props (TypeScript)**
|
|
226
|
+
|
|
227
|
+
| Prop | Type | Default | Description |
|
|
228
|
+
| --- | --- | --- |--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
229
|
+
| `ionAccessToken` | `string` | _none_ | Cesium Ion token for authenticated asset/imagery requests. An invalid token usually leaves the globe empty or partially loaded due to 401/403 responses. |
|
|
230
|
+
| `ionAssetId` | `number` | _none_ | Main Ion asset to render (tileset/terrain). |
|
|
231
|
+
| `initialCamera` | `CameraState` | _none_ | Initial camera used when the view is created. This is only used for initial camera; use `setCamera()` for runtime moves. |
|
|
232
|
+
| `pauseRendering` | `boolean` | `false` | Pauses the native render loop. Set `true` to stop rendering and reduce GPU/CPU usage. |
|
|
233
|
+
| `maximumScreenSpaceError` | `number` | `32` | Quality/performance trade-off for tile refinement. Lower values are sharper (more work); higher values are faster/blurrier. |
|
|
234
|
+
| `maximumSimultaneousTileLoads` | `number` | `12` | Max concurrent tile fetch/decode operations. Raising `8 -> 16` can improve fast camera moves on good networks but may increase memory/bandwidth spikes. |
|
|
235
|
+
| `loadingDescendantLimit` | `number` | `20` | Caps descendant tile fan-out during traversal. Lower values like `10` smooth bursts on low-end devices; higher values like `40` can fill detail faster. |
|
|
236
|
+
| `msaaSampleCount` | `number` | `1` | Anti-aliasing sample count. iOS uses `1`, `2`, or `4` (`>=4 -> 4`, `>=2 -> 2`, otherwise `1`); Android currently renders at `1` (MSAA setting is currently ignored in Vulkan backend). |
|
|
237
|
+
| `ionImageryAssetId` | `number` | `1` | Imagery layer to drape over terrain/tiles. Use a satellite imagery asset for a photoreal look, or switch to a streets/map layer for legibility. See your Cesium Ion Asset IDs. |
|
|
238
|
+
|
|
239
|
+
**Consumer-optional props (TypeScript)**
|
|
240
|
+
|
|
241
|
+
| Prop | Type | Default | Description |
|
|
242
|
+
| --- | --- | --- | --- |
|
|
243
|
+
| `onMetrics` | `(metrics: CesiumMetrics) => void` | `undefined` | Receives throttled runtime stats and credits text. |
|
|
244
|
+
|
|
245
|
+
### `CameraState`
|
|
246
|
+
|
|
247
|
+
```ts
|
|
248
|
+
type CameraState = {
|
|
249
|
+
latitude: number
|
|
250
|
+
longitude: number
|
|
251
|
+
altitude: number
|
|
252
|
+
heading: number
|
|
253
|
+
pitch: number
|
|
254
|
+
roll: number
|
|
255
|
+
verticalFovDeg: number
|
|
256
|
+
}
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
| Field | Type | Valid range / format | Description |
|
|
260
|
+
| --- | --- | --- |---------------------------------------------------------------------------------------------------------------------------------|
|
|
261
|
+
| `latitude` | `number` | `-90..90` | Camera latitude in degrees. |
|
|
262
|
+
| `longitude` | `number` | `-180..180` | Camera longitude in degrees. |
|
|
263
|
+
| `altitude` | `number` | Meters above ellipsoid | Camera height in meters. |
|
|
264
|
+
| `heading` | `number` | Degrees | Compass direction the camera faces. Example: `0` faces north, `90` faces east. |
|
|
265
|
+
| `pitch` | `number` | Degrees | Tilt angle. Negative values look downward toward terrain; positive values tilt up toward horizon/sky. |
|
|
266
|
+
| `roll` | `number` | Degrees | Bank/rotation around forward axis. Positive right bank, negative left bank. |
|
|
267
|
+
| `verticalFovDeg` | `number` | `20..100` (clamped) | Vertical field of view. Example: `30` zooms in/narrows view; `90` gives wider peripheral view with more perspective distortion. |
|
|
268
|
+
|
|
269
|
+
### `CesiumViewMethods`
|
|
270
|
+
|
|
271
|
+
| Method | Signature | Description |
|
|
272
|
+
| --- | --- |-----------------------------------------------------------------------------------------------------------------------------------------------|
|
|
273
|
+
| `setCamera` | `(camera: CameraState) => void` | Applies a new camera state at runtime. Example: animate route steps by calling `setCamera(...)` on each step. |
|
|
274
|
+
| `getCameraState` | `() => Promise<CameraState>` | Returns the current native camera snapshot. |
|
|
275
|
+
|
|
276
|
+
### `CesiumMetrics`
|
|
277
|
+
|
|
278
|
+
| Field | Type | Description |
|
|
279
|
+
| --- | --- |---------------------------------------------------------------------------------------------------------------------------------------------|
|
|
280
|
+
| `fps` | `number` | Smoothed frames-per-second estimate from the native render loop. |
|
|
281
|
+
| `tilesRendered` | `number` | Number of tiles currently rendered in the frame. |
|
|
282
|
+
| `tilesLoading` | `number` | Number of tiles still loading. If this stays high for long periods, reduce load pressure (`maximumSimultaneousTileLoads`) or check network. |
|
|
283
|
+
| `tilesVisited` | `number` | Number of tiles visited during traversal/culling. |
|
|
284
|
+
| `ionTokenConfigured` | `boolean` | Whether a non-empty Ion token is configured natively. `false` is a quick signal to check `ionAccessToken`. |
|
|
285
|
+
| `tilesetReady` | `boolean` | Whether the primary tileset is initialized and ready. |
|
|
286
|
+
| `creditsPlainText` | `string` | Plain-text attribution/credits from Cesium data sources. Display this in your app footer to satisfy attribution requirements. |
|
|
287
|
+
|
|
288
|
+
## Example App
|
|
289
|
+
|
|
290
|
+
The example app in [`example/App.tsx`](./example/App.tsx) is the best current integration reference. It shows:
|
|
291
|
+
|
|
292
|
+
- creating and storing a Nitro `hybridRef`
|
|
293
|
+
- driving camera updates with `setCamera(...)`
|
|
294
|
+
- listening to `onMetrics`
|
|
295
|
+
- switching imagery layers
|
|
296
|
+
- presenting Cesium attribution from `creditsPlainText`
|
|
297
|
+
|
|
298
|
+
Before running the example, copy `example/.env_example` to `example/.env` and set `CESIUM_ION_ACCESS_TOKEN` to your own token. Restart Metro after editing `.env` so the env transform is reapplied.
|
|
299
|
+
|
|
300
|
+
The example project currently links this library locally via `link:..`.
|
|
301
|
+
|
|
302
|
+
## Credits
|
|
303
|
+
|
|
304
|
+
- Native rendering is built on [Cesium Native](https://github.com/CesiumGS/cesium-native)
|
|
305
|
+
- Cesium Native is licensed under Apache 2.0; see [`NOTICE`](./NOTICE)
|
|
306
|
+
- React Native integration is built with [Nitro Modules](https://github.com/mrousavy/nitro)
|
|
307
|
+
|
|
308
|
+
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = "ReactNativeCesium"
|
|
7
|
+
s.version = package["version"]
|
|
8
|
+
s.summary = package["description"]
|
|
9
|
+
s.homepage = package["homepage"]
|
|
10
|
+
s.license = package["license"]
|
|
11
|
+
s.authors = package["author"]
|
|
12
|
+
|
|
13
|
+
s.platforms = { :ios => min_ios_version_supported, :visionos => 1.0 }
|
|
14
|
+
s.source = { :git => "https://github.com/sensorworks/react-native-cesium.git", :tag => "#{s.version}" }
|
|
15
|
+
|
|
16
|
+
s.vendored_frameworks = "vendor/ios/CesiumNative.xcframework"
|
|
17
|
+
|
|
18
|
+
cpp_include = File.join(__dir__, "cpp")
|
|
19
|
+
ios_include = File.join(__dir__, "ios")
|
|
20
|
+
nitro_cpp = File.join(__dir__, "nitrogen", "generated", "shared", "c++")
|
|
21
|
+
s.pod_target_xcconfig = {
|
|
22
|
+
# cpp/ must precede XCFramework Headers for <fmt/format.h>; CocoaPods merges $(inherited)
|
|
23
|
+
# first, so apps should call react_native_cesium_post_install from ios/react_native_cesium_post_install.rb.
|
|
24
|
+
# nitrogen/shared/c++ holds HybridCesiumViewSpec.hpp includes (CesiumMetrics.hpp, CameraState.hpp).
|
|
25
|
+
"HEADER_SEARCH_PATHS" => "$(inherited) \"#{cpp_include}\" \"#{ios_include}\" \"#{nitro_cpp}\"",
|
|
26
|
+
"CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
|
|
27
|
+
"GCC_PREPROCESSOR_DEFINITIONS" => "$(inherited) GLM_FORCE_DEPTH_ZERO_TO_ONE=1",
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
s.frameworks = "Metal", "MetalKit", "Network", "QuartzCore"
|
|
31
|
+
|
|
32
|
+
s.source_files = [
|
|
33
|
+
"ios/**/*.{swift}",
|
|
34
|
+
"ios/**/*.{h,m,mm}",
|
|
35
|
+
"cpp/**/*.{hpp,cpp,h,mm}",
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
s.public_header_files = [
|
|
39
|
+
"ios/ReactNativeCesium-umbrella.h",
|
|
40
|
+
"ios/CesiumBridge.h",
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
# cacert.pem must land in the app's main bundle so that
|
|
44
|
+
# [NSBundle mainBundle] pathForResource:@"cacert" ofType:@"pem"] resolves it.
|
|
45
|
+
# resource_bundles would put it in a sub-bundle; s.resources copies it to root.
|
|
46
|
+
s.resources = ["ios/cacert.pem"]
|
|
47
|
+
|
|
48
|
+
load 'nitrogen/generated/ios/ReactNativeCesium+autolinking.rb'
|
|
49
|
+
add_nitrogen_files(s)
|
|
50
|
+
|
|
51
|
+
s.dependency 'React-jsi'
|
|
52
|
+
s.dependency 'React-callinvoker'
|
|
53
|
+
install_modules_dependencies(s)
|
|
54
|
+
end
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
project(ReactNativeCesium)
|
|
2
|
+
cmake_minimum_required(VERSION 3.15.0)
|
|
3
|
+
|
|
4
|
+
set (PACKAGE_NAME ReactNativeCesium)
|
|
5
|
+
set (CMAKE_VERBOSE_MAKEFILE ON)
|
|
6
|
+
set (CMAKE_CXX_STANDARD 20)
|
|
7
|
+
|
|
8
|
+
# Enable Raw Props parsing in react-native (for Nitro Views)
|
|
9
|
+
add_compile_options(-DRN_SERIALIZABLE_STATE=1)
|
|
10
|
+
|
|
11
|
+
# ── SPIR-V shader compilation ──────────────────────────────────────────────────
|
|
12
|
+
# NDK ships glslc in shader-tools; find it automatically.
|
|
13
|
+
find_program(GLSLC glslc
|
|
14
|
+
HINTS "${ANDROID_NDK}/shader-tools/${CMAKE_HOST_SYSTEM_PROCESSOR}-${CMAKE_HOST_SYSTEM_NAME}"
|
|
15
|
+
"${ANDROID_NDK}/shader-tools/darwin-x86_64"
|
|
16
|
+
"${ANDROID_NDK}/shader-tools/linux-x86_64"
|
|
17
|
+
"${ANDROID_NDK}/shader-tools/windows-x86_64"
|
|
18
|
+
)
|
|
19
|
+
if (NOT GLSLC)
|
|
20
|
+
message(FATAL_ERROR "glslc not found in NDK shader-tools. Ensure ANDROID_NDK points to a valid NDK (>=r21).")
|
|
21
|
+
endif()
|
|
22
|
+
|
|
23
|
+
set(SHADER_DIR "${CMAKE_SOURCE_DIR}/src/main/cpp/vulkan/shaders")
|
|
24
|
+
set(SPIRV_OUTPUT_DIR "${CMAKE_BINARY_DIR}/shaders")
|
|
25
|
+
file(MAKE_DIRECTORY "${SPIRV_OUTPUT_DIR}")
|
|
26
|
+
|
|
27
|
+
set(SHADER_SOURCES
|
|
28
|
+
"${SHADER_DIR}/terrain.vert"
|
|
29
|
+
"${SHADER_DIR}/terrain.frag"
|
|
30
|
+
"${SHADER_DIR}/sky.vert"
|
|
31
|
+
"${SHADER_DIR}/sky.frag"
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
foreach(SHADER ${SHADER_SOURCES})
|
|
35
|
+
get_filename_component(SHADER_NAME ${SHADER} NAME)
|
|
36
|
+
set(SPV_FILE "${SPIRV_OUTPUT_DIR}/${SHADER_NAME}.spv")
|
|
37
|
+
set(SPV_HEADER "${SPIRV_OUTPUT_DIR}/${SHADER_NAME}.spv.h")
|
|
38
|
+
string(REGEX REPLACE "[^a-zA-Z0-9]" "_" ARRAY_NAME "spv_${SHADER_NAME}")
|
|
39
|
+
|
|
40
|
+
add_custom_command(
|
|
41
|
+
OUTPUT "${SPV_FILE}"
|
|
42
|
+
COMMAND "${GLSLC}" -O -o "${SPV_FILE}" "${SHADER}"
|
|
43
|
+
DEPENDS "${SHADER}"
|
|
44
|
+
COMMENT "Compiling ${SHADER_NAME} -> SPIR-V"
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
# Generate a C header embedding the SPIR-V as a uint32_t array
|
|
48
|
+
add_custom_command(
|
|
49
|
+
OUTPUT "${SPV_HEADER}"
|
|
50
|
+
COMMAND ${CMAKE_COMMAND}
|
|
51
|
+
-DSPV_FILE=${SPV_FILE}
|
|
52
|
+
-DSPV_HEADER=${SPV_HEADER}
|
|
53
|
+
-DARRAY_NAME=${ARRAY_NAME}
|
|
54
|
+
-P "${CMAKE_SOURCE_DIR}/cmake/spv_to_header.cmake"
|
|
55
|
+
DEPENDS "${SPV_FILE}"
|
|
56
|
+
COMMENT "Embedding ${SHADER_NAME}.spv -> header"
|
|
57
|
+
)
|
|
58
|
+
list(APPEND SPIRV_HEADERS "${SPV_HEADER}")
|
|
59
|
+
endforeach()
|
|
60
|
+
|
|
61
|
+
add_custom_target(compile_shaders DEPENDS ${SPIRV_HEADERS})
|
|
62
|
+
|
|
63
|
+
# Define C++ library and add all sources
|
|
64
|
+
add_library(${PACKAGE_NAME} SHARED
|
|
65
|
+
src/main/cpp/cpp-adapter.cpp
|
|
66
|
+
# Engine (shared with iOS)
|
|
67
|
+
../cpp/engine/CesiumEngine.cpp
|
|
68
|
+
../cpp/engine/TaskProcessor.cpp
|
|
69
|
+
../cpp/engine/ResourcePreparer.cpp
|
|
70
|
+
../cpp/engine/GltfToMesh.cpp
|
|
71
|
+
../cpp/engine/GlobeCamera.cpp
|
|
72
|
+
../cpp/engine/DeletionQueue.cpp
|
|
73
|
+
../cpp/engine/TileLifecycleManager.cpp
|
|
74
|
+
# Vulkan backend
|
|
75
|
+
src/main/cpp/vulkan/VulkanBackend.cpp
|
|
76
|
+
# JNI bridge
|
|
77
|
+
src/main/cpp/CesiumBridgeAndroid.cpp
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
add_dependencies(${PACKAGE_NAME} compile_shaders)
|
|
81
|
+
|
|
82
|
+
# Add Nitrogen specs :)
|
|
83
|
+
include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/ReactNativeCesium+autolinking.cmake)
|
|
84
|
+
|
|
85
|
+
# Set up local includes
|
|
86
|
+
include_directories(
|
|
87
|
+
BEFORE
|
|
88
|
+
"../cpp"
|
|
89
|
+
"src/main/cpp"
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
# Generated SPIR-V headers
|
|
93
|
+
target_include_directories(${PACKAGE_NAME} PRIVATE "${SPIRV_OUTPUT_DIR}")
|
|
94
|
+
|
|
95
|
+
find_library(LOG_LIB log)
|
|
96
|
+
find_library(VULKAN_LIB vulkan)
|
|
97
|
+
|
|
98
|
+
# Cesium Native (vendor/android from `yarn run build` or Gradle ensure-native — see README)
|
|
99
|
+
set(CESIUM_PREFIX "${CMAKE_SOURCE_DIR}/../vendor/android")
|
|
100
|
+
if (NOT EXISTS "${CESIUM_PREFIX}/share/cesium-native/cmake/cesium-nativeConfig.cmake")
|
|
101
|
+
message(FATAL_ERROR "Cesium Native Android artifacts missing under vendor/android. Gradle should run ensure-native.mjs before CMake; or run `npm run update` and `CESIUM_BUILD_ONLY=android npm run build` from the package root. Expected: ${CESIUM_PREFIX}/share/cesium-native/cmake/cesium-nativeConfig.cmake")
|
|
102
|
+
endif()
|
|
103
|
+
list(APPEND CMAKE_PREFIX_PATH "${CESIUM_PREFIX}")
|
|
104
|
+
list(APPEND CMAKE_FIND_ROOT_PATH "${CESIUM_PREFIX}")
|
|
105
|
+
|
|
106
|
+
# cesium-native ships Find modules and header-only shim targets that aren't
|
|
107
|
+
# always resolved by the default CMake search paths.
|
|
108
|
+
list(APPEND CMAKE_MODULE_PATH "${CESIUM_PREFIX}/share/cesium-native/cmake")
|
|
109
|
+
|
|
110
|
+
# modp_b64 has a static lib + Find module
|
|
111
|
+
find_package(modp_b64 REQUIRED)
|
|
112
|
+
|
|
113
|
+
# Header-only shim targets referenced by cesium-native cmake configs but not
|
|
114
|
+
# shipped with their own Config.cmake in the vcpkg install.
|
|
115
|
+
if (NOT TARGET picosha2::picosha2)
|
|
116
|
+
add_library(picosha2::picosha2 INTERFACE IMPORTED)
|
|
117
|
+
set_target_properties(picosha2::picosha2 PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CESIUM_PREFIX}/include")
|
|
118
|
+
endif()
|
|
119
|
+
if (NOT TARGET nonstd::expected-lite)
|
|
120
|
+
add_library(nonstd::expected-lite INTERFACE IMPORTED)
|
|
121
|
+
set_target_properties(nonstd::expected-lite PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CESIUM_PREFIX}/include")
|
|
122
|
+
endif()
|
|
123
|
+
|
|
124
|
+
find_package(cesium-native CONFIG REQUIRED)
|
|
125
|
+
|
|
126
|
+
# Link all libraries together
|
|
127
|
+
target_link_libraries(
|
|
128
|
+
${PACKAGE_NAME}
|
|
129
|
+
${LOG_LIB}
|
|
130
|
+
${VULKAN_LIB}
|
|
131
|
+
android
|
|
132
|
+
# Cesium Native libraries
|
|
133
|
+
Cesium3DTilesSelection
|
|
134
|
+
Cesium3DTilesContent
|
|
135
|
+
CesiumGltf
|
|
136
|
+
CesiumGltfReader
|
|
137
|
+
CesiumGltfContent
|
|
138
|
+
CesiumGeospatial
|
|
139
|
+
CesiumGeometry
|
|
140
|
+
CesiumAsync
|
|
141
|
+
CesiumIonClient
|
|
142
|
+
CesiumRasterOverlays
|
|
143
|
+
CesiumCurl
|
|
144
|
+
CesiumJsonReader
|
|
145
|
+
CesiumUtility
|
|
146
|
+
)
|