1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
// ---------------------------------------------------------------------------
//! # rustial-renderer-bevy
//!
//! Bevy Engine renderer for the rustial 2.5D map engine.
//!
//! Provides [`RustialBevyPlugin`] -- a Bevy `Plugin` that synchronises
//! the engine's [`MapState`](rustial_engine::MapState) with Bevy's ECS
//! and rendering pipeline. Includes built-in viewport sync, default
//! input handling (pan / rotate / zoom), camera sync, and (with the
//! `http-tiles` feature) tile fetching + decoding.
//!
//! ## Crate layout
//!
//! ```text
//! lib.rs crate root -- re-exports, helpers, backend selection
//! plugin.rs RustialBevyPlugin, RustialBevyConfig, MapStateResource
//! components.rs ECS marker components (TileEntity, TerrainEntity, ...)
//! systems/
//! camera_sync.rs engine camera -> Bevy Transform + Projection
//! map_input.rs viewport sync + default input handling
//! tile_sync.rs spawn / despawn / reposition tile quad entities
//! terrain_sync.rs spawn / despawn / reposition terrain mesh entities
//! vector_sync.rs spawn / despawn / reposition vector geometry entities
//! model_sync.rs spawn / despawn / reposition 3D model entities
//! geo_entity_sync.rs reposition user-placed MapEntity + GeoTransform
//! texture_upload.rs decoded tile imagery -> Bevy Image + material
//! tile_fetch.rs (http-tiles) async HTTP fetch + decode -> cache
//! ```
//!
//! ## System schedule
//!
//! ```text
//! PreUpdate
//! sync_viewport read Bevy Window size -> engine viewport
//! handle_default_input mouse / keyboard -> engine InputEvent
//! update_map_state tick engine (after input)
//! sync_camera engine camera -> Bevy Transform (after update)
//! [http-tiles]
//! request_tiles spawn async fetch tasks (after update)
//! collect_tiles poll tasks -> TileImageCache (after request)
//! push_visible_tiles cache -> MapState visible tiles (after collect)
//!
//! Update
//! sync_tiles tile quad entities
//! sync_terrain terrain mesh entities
//! sync_vectors vector geometry entities
//! sync_models 3D model entities
//! sync_geo_entities user MapEntity + GeoTransform
//!
//! PostUpdate
//! upload_textures decoded imagery -> StandardMaterial textures
//! ```
//!
//! ## Feature flags
//!
//! | Flag | Default | Description |
//! |------|---------|-------------|
//! | `http-tiles` | **yes** | Built-in async tile fetcher (reqwest + tokio + image). Adds [`TileFetchConfig`]. |
//!
//! ## Quick start
//!
//! ```rust,no_run
//! use bevy::prelude::*;
//! use rustial_renderer_bevy::{RustialBevyPlugin, RustialBevyConfig};
//!
//! App::new()
//! .add_plugins(DefaultPlugins)
//! .insert_resource(RustialBevyConfig {
//! center: (51.1, 17.0),
//! zoom: 10,
//! ..default()
//! })
//! .add_plugins(RustialBevyPlugin)
//! .run();
//! ```
//!
//! ## Placing user entities on the map
//!
//! Attach [`components::MapEntity`] + [`components::GeoTransform`] to any
//! Bevy entity. The plugin automatically keeps its `Transform` in sync
//! with the map camera so the entity stays at the correct lat/lon.
//!
//! For manual coordinate conversion outside the ECS use [`geo_to_vec3`].
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// Top-level re-exports
// ---------------------------------------------------------------------------
pub use TerrainInteractionBuffersResource;
pub use ;
pub use MapInputEnabled;
pub use ;
// ---------------------------------------------------------------------------
// Imports
// ---------------------------------------------------------------------------
use ;
use Backends;
use GeoCoord;
// ---------------------------------------------------------------------------
// Coordinate helpers
// ---------------------------------------------------------------------------
/// Convert a geographic coordinate to a camera-relative Bevy [`Vec3`].
///
/// The returned position is in the same coordinate space used by all
/// map tile, terrain, vector, and model entities: **Web Mercator
/// metres relative to the current camera origin**
/// (`state.0.camera().target_world()`).
///
/// This is the function to call when you need to position your own
/// Bevy entities on the map from a system without using the
/// [`MapEntity`](components::MapEntity) + [`GeoTransform`](components::GeoTransform)
/// approach:
///
/// ```rust,ignore
/// use rustial_renderer_bevy::{geo_to_vec3, MapStateResource};
/// use rustial_engine::GeoCoord;
///
/// fn spawn_marker(
/// mut commands: Commands,
/// state: Res<MapStateResource>,
/// ) {
/// let pos = geo_to_vec3(
/// &state,
/// &GeoCoord::from_lat_lon(48.8566, 2.3522),
/// );
/// commands.spawn(Transform::from_translation(pos));
/// }
/// ```
///
/// # Note
///
/// The Z component is `GeoCoord.alt` converted to f32 (absolute
/// altitude, not camera-relative). For terrain-aware placement use
/// [`MapEntity`](components::MapEntity) with
/// [`GeoAltitudeMode`](components::GeoAltitudeMode) instead.
// ---------------------------------------------------------------------------
// GPU backend selection
// ---------------------------------------------------------------------------
/// Read the `RUSTIAL_BACKEND` environment variable and return the
/// corresponding [`Backends`] flags.
///
/// Supported values include common WGPU backend names such as:
///
/// - `vulkan`
/// - `metal`
/// - `dx12`
/// - `gl`
/// - `browser-webgpu`
/// - `all`
///
/// Unknown or missing values fall back to [`Backends::PRIMARY`].
/// Construct a convenient Bevy plugin group for rustial examples.
///
/// Uses [`backends_from_env`] so examples can switch graphics backend via the
/// `RUSTIAL_BACKEND` environment variable.