bevy 1.0.0
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.
- checksums.yaml +7 -0
- data/Cargo.lock +4279 -0
- data/Cargo.toml +36 -0
- data/README.md +226 -0
- data/crates/bevy/Cargo.toml +52 -0
- data/crates/bevy/src/app.rs +43 -0
- data/crates/bevy/src/component.rs +111 -0
- data/crates/bevy/src/entity.rs +30 -0
- data/crates/bevy/src/error.rs +32 -0
- data/crates/bevy/src/event.rs +190 -0
- data/crates/bevy/src/input_bridge.rs +300 -0
- data/crates/bevy/src/lib.rs +42 -0
- data/crates/bevy/src/mesh_renderer.rs +328 -0
- data/crates/bevy/src/query.rs +53 -0
- data/crates/bevy/src/render_app.rs +689 -0
- data/crates/bevy/src/resource.rs +28 -0
- data/crates/bevy/src/schedule.rs +186 -0
- data/crates/bevy/src/sprite_renderer.rs +355 -0
- data/crates/bevy/src/system.rs +44 -0
- data/crates/bevy/src/text_renderer.rs +258 -0
- data/crates/bevy/src/types/color.rs +114 -0
- data/crates/bevy/src/types/dynamic.rs +131 -0
- data/crates/bevy/src/types/math.rs +260 -0
- data/crates/bevy/src/types/mod.rs +9 -0
- data/crates/bevy/src/types/transform.rs +166 -0
- data/crates/bevy/src/world.rs +163 -0
- data/crates/bevy_ruby_render/Cargo.toml +22 -0
- data/crates/bevy_ruby_render/src/asset.rs +360 -0
- data/crates/bevy_ruby_render/src/audio.rs +511 -0
- data/crates/bevy_ruby_render/src/camera.rs +365 -0
- data/crates/bevy_ruby_render/src/gamepad.rs +398 -0
- data/crates/bevy_ruby_render/src/lib.rs +26 -0
- data/crates/bevy_ruby_render/src/material.rs +310 -0
- data/crates/bevy_ruby_render/src/mesh.rs +491 -0
- data/crates/bevy_ruby_render/src/sprite.rs +289 -0
- data/ext/bevy/Cargo.toml +20 -0
- data/ext/bevy/extconf.rb +6 -0
- data/ext/bevy/src/conversions.rs +137 -0
- data/ext/bevy/src/lib.rs +29 -0
- data/ext/bevy/src/ruby_app.rs +65 -0
- data/ext/bevy/src/ruby_color.rs +149 -0
- data/ext/bevy/src/ruby_component.rs +189 -0
- data/ext/bevy/src/ruby_entity.rs +33 -0
- data/ext/bevy/src/ruby_math.rs +384 -0
- data/ext/bevy/src/ruby_query.rs +64 -0
- data/ext/bevy/src/ruby_render_app.rs +779 -0
- data/ext/bevy/src/ruby_system.rs +122 -0
- data/ext/bevy/src/ruby_world.rs +107 -0
- data/lib/bevy/animation.rb +597 -0
- data/lib/bevy/app.rb +675 -0
- data/lib/bevy/asset.rb +613 -0
- data/lib/bevy/audio.rb +545 -0
- data/lib/bevy/audio_effects.rb +224 -0
- data/lib/bevy/camera.rb +412 -0
- data/lib/bevy/component.rb +91 -0
- data/lib/bevy/diagnostics.rb +227 -0
- data/lib/bevy/ecs_advanced.rb +296 -0
- data/lib/bevy/event.rb +199 -0
- data/lib/bevy/gizmos.rb +158 -0
- data/lib/bevy/gltf.rb +227 -0
- data/lib/bevy/hierarchy.rb +444 -0
- data/lib/bevy/input.rb +514 -0
- data/lib/bevy/lighting.rb +369 -0
- data/lib/bevy/material.rb +248 -0
- data/lib/bevy/mesh.rb +257 -0
- data/lib/bevy/navigation.rb +344 -0
- data/lib/bevy/networking.rb +335 -0
- data/lib/bevy/particle.rb +337 -0
- data/lib/bevy/physics.rb +396 -0
- data/lib/bevy/plugins/default_plugins.rb +34 -0
- data/lib/bevy/plugins/input_plugin.rb +49 -0
- data/lib/bevy/reflect.rb +361 -0
- data/lib/bevy/render_graph.rb +210 -0
- data/lib/bevy/resource.rb +185 -0
- data/lib/bevy/scene.rb +254 -0
- data/lib/bevy/shader.rb +319 -0
- data/lib/bevy/shape.rb +195 -0
- data/lib/bevy/skeletal.rb +248 -0
- data/lib/bevy/sprite.rb +152 -0
- data/lib/bevy/sprite_sheet.rb +444 -0
- data/lib/bevy/state.rb +277 -0
- data/lib/bevy/system.rb +206 -0
- data/lib/bevy/text.rb +99 -0
- data/lib/bevy/text_advanced.rb +455 -0
- data/lib/bevy/timer.rb +147 -0
- data/lib/bevy/transform.rb +158 -0
- data/lib/bevy/ui.rb +454 -0
- data/lib/bevy/ui_advanced.rb +568 -0
- data/lib/bevy/version.rb +5 -0
- data/lib/bevy/visibility.rb +250 -0
- data/lib/bevy/window.rb +302 -0
- data/lib/bevy.rb +390 -0
- metadata +150 -0
|
@@ -0,0 +1,491 @@
|
|
|
1
|
+
use bevy_color::Color;
|
|
2
|
+
use bevy_ecs::entity::Entity;
|
|
3
|
+
use bevy_ecs::world::World;
|
|
4
|
+
use bevy_math::{Vec2, Vec3};
|
|
5
|
+
use bevy_prototype_lyon::prelude::*;
|
|
6
|
+
use bevy_render::view::Visibility;
|
|
7
|
+
use bevy_transform::components::Transform;
|
|
8
|
+
use std::collections::HashMap;
|
|
9
|
+
|
|
10
|
+
#[derive(Debug, Clone, Copy, PartialEq)]
|
|
11
|
+
pub enum ShapeType {
|
|
12
|
+
Rectangle,
|
|
13
|
+
Circle,
|
|
14
|
+
RegularPolygon,
|
|
15
|
+
Line,
|
|
16
|
+
Ellipse,
|
|
17
|
+
Triangle,
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
#[derive(Debug, Clone)]
|
|
21
|
+
pub struct MeshData {
|
|
22
|
+
pub shape_type: ShapeType,
|
|
23
|
+
pub color_r: f32,
|
|
24
|
+
pub color_g: f32,
|
|
25
|
+
pub color_b: f32,
|
|
26
|
+
pub color_a: f32,
|
|
27
|
+
pub width: f32,
|
|
28
|
+
pub height: f32,
|
|
29
|
+
pub radius: f32,
|
|
30
|
+
pub sides: u32,
|
|
31
|
+
pub line_start_x: f32,
|
|
32
|
+
pub line_start_y: f32,
|
|
33
|
+
pub line_end_x: f32,
|
|
34
|
+
pub line_end_y: f32,
|
|
35
|
+
pub thickness: f32,
|
|
36
|
+
pub fill: bool,
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
impl Default for MeshData {
|
|
40
|
+
fn default() -> Self {
|
|
41
|
+
Self {
|
|
42
|
+
shape_type: ShapeType::Rectangle,
|
|
43
|
+
color_r: 1.0,
|
|
44
|
+
color_g: 1.0,
|
|
45
|
+
color_b: 1.0,
|
|
46
|
+
color_a: 1.0,
|
|
47
|
+
width: 100.0,
|
|
48
|
+
height: 100.0,
|
|
49
|
+
radius: 50.0,
|
|
50
|
+
sides: 6,
|
|
51
|
+
line_start_x: 0.0,
|
|
52
|
+
line_start_y: 0.0,
|
|
53
|
+
line_end_x: 100.0,
|
|
54
|
+
line_end_y: 0.0,
|
|
55
|
+
thickness: 2.0,
|
|
56
|
+
fill: true,
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
impl MeshData {
|
|
62
|
+
pub fn rectangle(width: f32, height: f32) -> Self {
|
|
63
|
+
Self {
|
|
64
|
+
shape_type: ShapeType::Rectangle,
|
|
65
|
+
width,
|
|
66
|
+
height,
|
|
67
|
+
..Default::default()
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
pub fn circle(radius: f32) -> Self {
|
|
72
|
+
Self {
|
|
73
|
+
shape_type: ShapeType::Circle,
|
|
74
|
+
radius,
|
|
75
|
+
..Default::default()
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
pub fn regular_polygon(radius: f32, sides: u32) -> Self {
|
|
80
|
+
Self {
|
|
81
|
+
shape_type: ShapeType::RegularPolygon,
|
|
82
|
+
radius,
|
|
83
|
+
sides,
|
|
84
|
+
..Default::default()
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
pub fn line(start: Vec2, end: Vec2, thickness: f32) -> Self {
|
|
89
|
+
Self {
|
|
90
|
+
shape_type: ShapeType::Line,
|
|
91
|
+
line_start_x: start.x,
|
|
92
|
+
line_start_y: start.y,
|
|
93
|
+
line_end_x: end.x,
|
|
94
|
+
line_end_y: end.y,
|
|
95
|
+
thickness,
|
|
96
|
+
..Default::default()
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
pub fn ellipse(width: f32, height: f32) -> Self {
|
|
101
|
+
Self {
|
|
102
|
+
shape_type: ShapeType::Ellipse,
|
|
103
|
+
width,
|
|
104
|
+
height,
|
|
105
|
+
..Default::default()
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
pub fn with_color(mut self, r: f32, g: f32, b: f32, a: f32) -> Self {
|
|
110
|
+
self.color_r = r;
|
|
111
|
+
self.color_g = g;
|
|
112
|
+
self.color_b = b;
|
|
113
|
+
self.color_a = a;
|
|
114
|
+
self
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
pub fn with_fill(mut self, fill: bool) -> Self {
|
|
118
|
+
self.fill = fill;
|
|
119
|
+
self
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
pub fn to_bevy_color(&self) -> Color {
|
|
123
|
+
Color::srgba(self.color_r, self.color_g, self.color_b, self.color_a)
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
#[derive(Debug, Clone)]
|
|
128
|
+
pub struct MeshTransformData {
|
|
129
|
+
pub translation_x: f32,
|
|
130
|
+
pub translation_y: f32,
|
|
131
|
+
pub translation_z: f32,
|
|
132
|
+
pub rotation_x: f32,
|
|
133
|
+
pub rotation_y: f32,
|
|
134
|
+
pub rotation_z: f32,
|
|
135
|
+
pub rotation_w: f32,
|
|
136
|
+
pub scale_x: f32,
|
|
137
|
+
pub scale_y: f32,
|
|
138
|
+
pub scale_z: f32,
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
impl Default for MeshTransformData {
|
|
142
|
+
fn default() -> Self {
|
|
143
|
+
Self {
|
|
144
|
+
translation_x: 0.0,
|
|
145
|
+
translation_y: 0.0,
|
|
146
|
+
translation_z: 0.0,
|
|
147
|
+
rotation_x: 0.0,
|
|
148
|
+
rotation_y: 0.0,
|
|
149
|
+
rotation_z: 0.0,
|
|
150
|
+
rotation_w: 1.0,
|
|
151
|
+
scale_x: 1.0,
|
|
152
|
+
scale_y: 1.0,
|
|
153
|
+
scale_z: 1.0,
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
impl MeshTransformData {
|
|
159
|
+
pub fn from_xyz(x: f32, y: f32, z: f32) -> Self {
|
|
160
|
+
Self {
|
|
161
|
+
translation_x: x,
|
|
162
|
+
translation_y: y,
|
|
163
|
+
translation_z: z,
|
|
164
|
+
..Default::default()
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
pub fn to_bevy_transform(&self) -> Transform {
|
|
169
|
+
Transform {
|
|
170
|
+
translation: Vec3::new(
|
|
171
|
+
self.translation_x,
|
|
172
|
+
self.translation_y,
|
|
173
|
+
self.translation_z,
|
|
174
|
+
),
|
|
175
|
+
rotation: bevy_math::Quat::from_xyzw(
|
|
176
|
+
self.rotation_x,
|
|
177
|
+
self.rotation_y,
|
|
178
|
+
self.rotation_z,
|
|
179
|
+
self.rotation_w,
|
|
180
|
+
),
|
|
181
|
+
scale: Vec3::new(self.scale_x, self.scale_y, self.scale_z),
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
#[derive(Debug, Clone)]
|
|
187
|
+
pub enum MeshOperation {
|
|
188
|
+
Sync {
|
|
189
|
+
ruby_entity_id: u64,
|
|
190
|
+
mesh_data: MeshData,
|
|
191
|
+
transform_data: MeshTransformData,
|
|
192
|
+
},
|
|
193
|
+
Remove {
|
|
194
|
+
ruby_entity_id: u64,
|
|
195
|
+
},
|
|
196
|
+
Clear,
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
struct EntityData {
|
|
200
|
+
bevy_entity: Entity,
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
pub struct MeshSync {
|
|
204
|
+
entity_map: HashMap<u64, EntityData>,
|
|
205
|
+
pub pending_operations: Vec<MeshOperation>,
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
impl MeshSync {
|
|
209
|
+
pub fn new() -> Self {
|
|
210
|
+
Self {
|
|
211
|
+
entity_map: HashMap::new(),
|
|
212
|
+
pending_operations: Vec::new(),
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
pub fn sync_mesh_standalone(
|
|
217
|
+
&mut self,
|
|
218
|
+
ruby_entity_id: u64,
|
|
219
|
+
mesh_data: &MeshData,
|
|
220
|
+
transform_data: &MeshTransformData,
|
|
221
|
+
) {
|
|
222
|
+
self.pending_operations.push(MeshOperation::Sync {
|
|
223
|
+
ruby_entity_id,
|
|
224
|
+
mesh_data: mesh_data.clone(),
|
|
225
|
+
transform_data: transform_data.clone(),
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
pub fn remove_mesh_standalone(&mut self, ruby_entity_id: u64) {
|
|
230
|
+
self.pending_operations
|
|
231
|
+
.push(MeshOperation::Remove { ruby_entity_id });
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
pub fn clear_standalone(&mut self) {
|
|
235
|
+
self.pending_operations.push(MeshOperation::Clear);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
pub fn apply_pending(&mut self, world: &mut World) {
|
|
239
|
+
let ops: Vec<_> = self.pending_operations.drain(..).collect();
|
|
240
|
+
for op in ops {
|
|
241
|
+
match op {
|
|
242
|
+
MeshOperation::Sync {
|
|
243
|
+
ruby_entity_id,
|
|
244
|
+
mesh_data,
|
|
245
|
+
transform_data,
|
|
246
|
+
} => {
|
|
247
|
+
self.sync_mesh(world, ruby_entity_id, &mesh_data, &transform_data);
|
|
248
|
+
}
|
|
249
|
+
MeshOperation::Remove { ruby_entity_id } => {
|
|
250
|
+
self.remove_mesh(world, ruby_entity_id);
|
|
251
|
+
}
|
|
252
|
+
MeshOperation::Clear => {
|
|
253
|
+
self.clear(world);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
pub fn sync_mesh(
|
|
260
|
+
&mut self,
|
|
261
|
+
world: &mut World,
|
|
262
|
+
ruby_entity_id: u64,
|
|
263
|
+
mesh_data: &MeshData,
|
|
264
|
+
transform_data: &MeshTransformData,
|
|
265
|
+
) {
|
|
266
|
+
let color = mesh_data.to_bevy_color();
|
|
267
|
+
let transform = transform_data.to_bevy_transform();
|
|
268
|
+
|
|
269
|
+
if let Some(entity_data) = self.entity_map.get(&ruby_entity_id) {
|
|
270
|
+
let bevy_entity = entity_data.bevy_entity;
|
|
271
|
+
if let Some(mut t) = world.get_mut::<Transform>(bevy_entity) {
|
|
272
|
+
*t = transform;
|
|
273
|
+
}
|
|
274
|
+
if let Some(mut fill) = world.get_mut::<Fill>(bevy_entity) {
|
|
275
|
+
fill.color = color;
|
|
276
|
+
}
|
|
277
|
+
if let Some(mut stroke) = world.get_mut::<Stroke>(bevy_entity) {
|
|
278
|
+
stroke.color = color;
|
|
279
|
+
}
|
|
280
|
+
} else {
|
|
281
|
+
let transparent = Color::srgba(0.0, 0.0, 0.0, 0.0);
|
|
282
|
+
let draw_mode = if mesh_data.fill {
|
|
283
|
+
(
|
|
284
|
+
Fill::color(color),
|
|
285
|
+
Stroke::new(color, mesh_data.thickness),
|
|
286
|
+
)
|
|
287
|
+
} else {
|
|
288
|
+
(
|
|
289
|
+
Fill::color(transparent),
|
|
290
|
+
Stroke::new(color, mesh_data.thickness),
|
|
291
|
+
)
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
let bevy_entity = match mesh_data.shape_type {
|
|
295
|
+
ShapeType::Rectangle => {
|
|
296
|
+
let shape = shapes::Rectangle {
|
|
297
|
+
extents: Vec2::new(mesh_data.width, mesh_data.height),
|
|
298
|
+
origin: RectangleOrigin::Center,
|
|
299
|
+
..Default::default()
|
|
300
|
+
};
|
|
301
|
+
world
|
|
302
|
+
.spawn((
|
|
303
|
+
ShapeBundle {
|
|
304
|
+
path: GeometryBuilder::build_as(&shape),
|
|
305
|
+
transform,
|
|
306
|
+
visibility: Visibility::Visible,
|
|
307
|
+
..Default::default()
|
|
308
|
+
},
|
|
309
|
+
draw_mode.0,
|
|
310
|
+
draw_mode.1,
|
|
311
|
+
))
|
|
312
|
+
.id()
|
|
313
|
+
}
|
|
314
|
+
ShapeType::Circle => {
|
|
315
|
+
let shape = shapes::Circle {
|
|
316
|
+
radius: mesh_data.radius,
|
|
317
|
+
center: Vec2::ZERO,
|
|
318
|
+
};
|
|
319
|
+
world
|
|
320
|
+
.spawn((
|
|
321
|
+
ShapeBundle {
|
|
322
|
+
path: GeometryBuilder::build_as(&shape),
|
|
323
|
+
transform,
|
|
324
|
+
visibility: Visibility::Visible,
|
|
325
|
+
..Default::default()
|
|
326
|
+
},
|
|
327
|
+
draw_mode.0,
|
|
328
|
+
draw_mode.1,
|
|
329
|
+
))
|
|
330
|
+
.id()
|
|
331
|
+
}
|
|
332
|
+
ShapeType::RegularPolygon => {
|
|
333
|
+
let shape = shapes::RegularPolygon {
|
|
334
|
+
sides: mesh_data.sides as usize,
|
|
335
|
+
feature: RegularPolygonFeature::Radius(mesh_data.radius),
|
|
336
|
+
..Default::default()
|
|
337
|
+
};
|
|
338
|
+
world
|
|
339
|
+
.spawn((
|
|
340
|
+
ShapeBundle {
|
|
341
|
+
path: GeometryBuilder::build_as(&shape),
|
|
342
|
+
transform,
|
|
343
|
+
visibility: Visibility::Visible,
|
|
344
|
+
..Default::default()
|
|
345
|
+
},
|
|
346
|
+
draw_mode.0,
|
|
347
|
+
draw_mode.1,
|
|
348
|
+
))
|
|
349
|
+
.id()
|
|
350
|
+
}
|
|
351
|
+
ShapeType::Triangle => {
|
|
352
|
+
let shape = shapes::RegularPolygon {
|
|
353
|
+
sides: 3,
|
|
354
|
+
feature: RegularPolygonFeature::Radius(mesh_data.radius),
|
|
355
|
+
..Default::default()
|
|
356
|
+
};
|
|
357
|
+
world
|
|
358
|
+
.spawn((
|
|
359
|
+
ShapeBundle {
|
|
360
|
+
path: GeometryBuilder::build_as(&shape),
|
|
361
|
+
transform,
|
|
362
|
+
visibility: Visibility::Visible,
|
|
363
|
+
..Default::default()
|
|
364
|
+
},
|
|
365
|
+
draw_mode.0,
|
|
366
|
+
draw_mode.1,
|
|
367
|
+
))
|
|
368
|
+
.id()
|
|
369
|
+
}
|
|
370
|
+
ShapeType::Line => {
|
|
371
|
+
let shape = shapes::Line(
|
|
372
|
+
Vec2::new(mesh_data.line_start_x, mesh_data.line_start_y),
|
|
373
|
+
Vec2::new(mesh_data.line_end_x, mesh_data.line_end_y),
|
|
374
|
+
);
|
|
375
|
+
world
|
|
376
|
+
.spawn((
|
|
377
|
+
ShapeBundle {
|
|
378
|
+
path: GeometryBuilder::build_as(&shape),
|
|
379
|
+
transform,
|
|
380
|
+
visibility: Visibility::Visible,
|
|
381
|
+
..Default::default()
|
|
382
|
+
},
|
|
383
|
+
Stroke::new(color, mesh_data.thickness),
|
|
384
|
+
))
|
|
385
|
+
.id()
|
|
386
|
+
}
|
|
387
|
+
ShapeType::Ellipse => {
|
|
388
|
+
let shape = shapes::Ellipse {
|
|
389
|
+
radii: Vec2::new(mesh_data.width / 2.0, mesh_data.height / 2.0),
|
|
390
|
+
center: Vec2::ZERO,
|
|
391
|
+
};
|
|
392
|
+
world
|
|
393
|
+
.spawn((
|
|
394
|
+
ShapeBundle {
|
|
395
|
+
path: GeometryBuilder::build_as(&shape),
|
|
396
|
+
transform,
|
|
397
|
+
visibility: Visibility::Visible,
|
|
398
|
+
..Default::default()
|
|
399
|
+
},
|
|
400
|
+
draw_mode.0,
|
|
401
|
+
draw_mode.1,
|
|
402
|
+
))
|
|
403
|
+
.id()
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
self.entity_map
|
|
408
|
+
.insert(ruby_entity_id, EntityData { bevy_entity });
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
pub fn remove_mesh(&mut self, world: &mut World, ruby_entity_id: u64) {
|
|
413
|
+
if let Some(entity_data) = self.entity_map.remove(&ruby_entity_id) {
|
|
414
|
+
world.despawn(entity_data.bevy_entity);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
pub fn clear(&mut self, world: &mut World) {
|
|
419
|
+
for (_, entity_data) in self.entity_map.drain() {
|
|
420
|
+
world.despawn(entity_data.bevy_entity);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
pub fn len(&self) -> usize {
|
|
425
|
+
self.entity_map.len()
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
pub fn is_empty(&self) -> bool {
|
|
429
|
+
self.entity_map.is_empty()
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
pub fn synced_entities(&self) -> Vec<u64> {
|
|
433
|
+
self.entity_map.keys().copied().collect()
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
impl Default for MeshSync {
|
|
438
|
+
fn default() -> Self {
|
|
439
|
+
Self::new()
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
pub struct MeshBuilder {
|
|
444
|
+
mesh_data: MeshData,
|
|
445
|
+
transform_data: MeshTransformData,
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
impl MeshBuilder {
|
|
449
|
+
pub fn new(shape_type: ShapeType) -> Self {
|
|
450
|
+
Self {
|
|
451
|
+
mesh_data: MeshData {
|
|
452
|
+
shape_type,
|
|
453
|
+
..Default::default()
|
|
454
|
+
},
|
|
455
|
+
transform_data: MeshTransformData::default(),
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
pub fn rectangle(width: f32, height: f32) -> Self {
|
|
460
|
+
Self {
|
|
461
|
+
mesh_data: MeshData::rectangle(width, height),
|
|
462
|
+
transform_data: MeshTransformData::default(),
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
pub fn circle(radius: f32) -> Self {
|
|
467
|
+
Self {
|
|
468
|
+
mesh_data: MeshData::circle(radius),
|
|
469
|
+
transform_data: MeshTransformData::default(),
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
pub fn color(mut self, r: f32, g: f32, b: f32, a: f32) -> Self {
|
|
474
|
+
self.mesh_data = self.mesh_data.with_color(r, g, b, a);
|
|
475
|
+
self
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
pub fn fill(mut self, fill: bool) -> Self {
|
|
479
|
+
self.mesh_data = self.mesh_data.with_fill(fill);
|
|
480
|
+
self
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
pub fn position(mut self, x: f32, y: f32, z: f32) -> Self {
|
|
484
|
+
self.transform_data = MeshTransformData::from_xyz(x, y, z);
|
|
485
|
+
self
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
pub fn build(self) -> (MeshData, MeshTransformData) {
|
|
489
|
+
(self.mesh_data, self.transform_data)
|
|
490
|
+
}
|
|
491
|
+
}
|