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,444 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Bevy
|
|
4
|
+
class Parent
|
|
5
|
+
attr_reader :entity
|
|
6
|
+
|
|
7
|
+
def initialize(entity)
|
|
8
|
+
@entity = entity
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def type_name
|
|
12
|
+
'Parent'
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
class Children
|
|
17
|
+
attr_reader :entities
|
|
18
|
+
|
|
19
|
+
def initialize(entities = [])
|
|
20
|
+
@entities = entities.dup
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def add(entity)
|
|
24
|
+
@entities << entity unless @entities.include?(entity)
|
|
25
|
+
self
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def remove(entity)
|
|
29
|
+
@entities.delete(entity)
|
|
30
|
+
self
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def include?(entity)
|
|
34
|
+
@entities.include?(entity)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def count
|
|
38
|
+
@entities.size
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def empty?
|
|
42
|
+
@entities.empty?
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def each(&block)
|
|
46
|
+
@entities.each(&block)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def type_name
|
|
50
|
+
'Children'
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
module BuildChildren
|
|
55
|
+
def with_children(&block)
|
|
56
|
+
builder = ChildBuilder.new(self)
|
|
57
|
+
block.call(builder)
|
|
58
|
+
self
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def add_child(child_entity)
|
|
62
|
+
children_component = get_component(Children) rescue nil
|
|
63
|
+
if children_component
|
|
64
|
+
children_component.add(child_entity)
|
|
65
|
+
else
|
|
66
|
+
insert_component(Children.new([child_entity]))
|
|
67
|
+
end
|
|
68
|
+
self
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def remove_child(child_entity)
|
|
72
|
+
children_component = get_component(Children) rescue nil
|
|
73
|
+
children_component&.remove(child_entity)
|
|
74
|
+
self
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def set_parent(parent_entity)
|
|
78
|
+
insert_component(Parent.new(parent_entity))
|
|
79
|
+
self
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def remove_parent
|
|
83
|
+
remove_component(Parent)
|
|
84
|
+
self
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
class ChildBuilder
|
|
89
|
+
attr_reader :parent_entity
|
|
90
|
+
|
|
91
|
+
def initialize(parent_entity)
|
|
92
|
+
@parent_entity = parent_entity
|
|
93
|
+
@world = nil
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def spawn(*components)
|
|
97
|
+
entity = @world.spawn_entity(*components)
|
|
98
|
+
entity.set_parent(@parent_entity)
|
|
99
|
+
@parent_entity.add_child(entity)
|
|
100
|
+
entity
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def with_world(world)
|
|
104
|
+
@world = world
|
|
105
|
+
self
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
class GlobalTransform
|
|
110
|
+
attr_accessor :translation, :rotation, :scale
|
|
111
|
+
|
|
112
|
+
def initialize(translation: Vec3.zero, rotation: Quat.identity, scale: Vec3.one)
|
|
113
|
+
@translation = translation
|
|
114
|
+
@rotation = rotation
|
|
115
|
+
@scale = scale
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def self.identity
|
|
119
|
+
new
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def self.from_transform(transform)
|
|
123
|
+
new(
|
|
124
|
+
translation: Vec3.new(transform.translation.x, transform.translation.y, transform.translation.z),
|
|
125
|
+
rotation: transform.rotation,
|
|
126
|
+
scale: Vec3.new(transform.scale.x, transform.scale.y, transform.scale.z)
|
|
127
|
+
)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def to_matrix
|
|
131
|
+
Mat4.from_scale_rotation_translation(@scale, @rotation, @translation)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def transform_point(point)
|
|
135
|
+
rotated = @rotation.mul_vec3(Vec3.new(
|
|
136
|
+
point.x * @scale.x,
|
|
137
|
+
point.y * @scale.y,
|
|
138
|
+
point.z * @scale.z
|
|
139
|
+
))
|
|
140
|
+
Vec3.new(
|
|
141
|
+
rotated.x + @translation.x,
|
|
142
|
+
rotated.y + @translation.y,
|
|
143
|
+
rotated.z + @translation.z
|
|
144
|
+
)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def inverse_transform_point(point)
|
|
148
|
+
translated = Vec3.new(
|
|
149
|
+
point.x - @translation.x,
|
|
150
|
+
point.y - @translation.y,
|
|
151
|
+
point.z - @translation.z
|
|
152
|
+
)
|
|
153
|
+
inv_rotation = @rotation.inverse
|
|
154
|
+
rotated = inv_rotation.mul_vec3(translated)
|
|
155
|
+
Vec3.new(
|
|
156
|
+
rotated.x / @scale.x,
|
|
157
|
+
rotated.y / @scale.y,
|
|
158
|
+
rotated.z / @scale.z
|
|
159
|
+
)
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def type_name
|
|
163
|
+
'GlobalTransform'
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
class TransformBundle
|
|
168
|
+
attr_reader :local, :global
|
|
169
|
+
|
|
170
|
+
def initialize(transform: Transform.identity)
|
|
171
|
+
@local = transform
|
|
172
|
+
@global = GlobalTransform.from_transform(transform)
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def components
|
|
176
|
+
[@local, @global]
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def type_name
|
|
180
|
+
'TransformBundle'
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
class SpatialBundle
|
|
185
|
+
attr_reader :visibility, :inherited_visibility, :view_visibility
|
|
186
|
+
attr_reader :transform, :global_transform
|
|
187
|
+
|
|
188
|
+
def initialize(
|
|
189
|
+
transform: Transform.identity,
|
|
190
|
+
visibility: Visibility.new
|
|
191
|
+
)
|
|
192
|
+
@transform = transform
|
|
193
|
+
@global_transform = GlobalTransform.from_transform(transform)
|
|
194
|
+
@visibility = visibility
|
|
195
|
+
@inherited_visibility = InheritedVisibility.new
|
|
196
|
+
@view_visibility = ViewVisibility.new
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
def components
|
|
200
|
+
[@transform, @global_transform, @visibility, @inherited_visibility, @view_visibility]
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
def type_name
|
|
204
|
+
'SpatialBundle'
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
class Visibility
|
|
209
|
+
INHERITED = :inherited
|
|
210
|
+
VISIBLE = :visible
|
|
211
|
+
HIDDEN = :hidden
|
|
212
|
+
|
|
213
|
+
attr_accessor :value
|
|
214
|
+
|
|
215
|
+
def initialize(value = INHERITED)
|
|
216
|
+
@value = value
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
def visible?
|
|
220
|
+
@value == VISIBLE
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
def hidden?
|
|
224
|
+
@value == HIDDEN
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
def inherited?
|
|
228
|
+
@value == INHERITED
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
def type_name
|
|
232
|
+
'Visibility'
|
|
233
|
+
end
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
class InheritedVisibility
|
|
237
|
+
attr_reader :visible
|
|
238
|
+
|
|
239
|
+
def initialize(visible = true)
|
|
240
|
+
@visible = visible
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
def visible?
|
|
244
|
+
@visible
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
def type_name
|
|
248
|
+
'InheritedVisibility'
|
|
249
|
+
end
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
class ViewVisibility
|
|
253
|
+
attr_accessor :visible
|
|
254
|
+
|
|
255
|
+
def initialize(visible = true)
|
|
256
|
+
@visible = visible
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
def visible?
|
|
260
|
+
@visible
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
def type_name
|
|
264
|
+
'ViewVisibility'
|
|
265
|
+
end
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
module HierarchyQueryExt
|
|
269
|
+
def iter_descendants(entity, &block)
|
|
270
|
+
children = get_component(entity, Children) rescue nil
|
|
271
|
+
return unless children
|
|
272
|
+
|
|
273
|
+
children.each do |child|
|
|
274
|
+
block.call(child)
|
|
275
|
+
iter_descendants(child, &block)
|
|
276
|
+
end
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
def iter_ancestors(entity, &block)
|
|
280
|
+
parent = get_component(entity, Parent) rescue nil
|
|
281
|
+
return unless parent
|
|
282
|
+
|
|
283
|
+
block.call(parent.entity)
|
|
284
|
+
iter_ancestors(parent.entity, &block)
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
def root_ancestor(entity)
|
|
288
|
+
current = entity
|
|
289
|
+
loop do
|
|
290
|
+
parent = get_component(current, Parent) rescue nil
|
|
291
|
+
break current unless parent
|
|
292
|
+
current = parent.entity
|
|
293
|
+
end
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
def is_ancestor_of?(ancestor, descendant)
|
|
297
|
+
current = descendant
|
|
298
|
+
loop do
|
|
299
|
+
parent = get_component(current, Parent) rescue nil
|
|
300
|
+
return false unless parent
|
|
301
|
+
return true if parent.entity == ancestor
|
|
302
|
+
current = parent.entity
|
|
303
|
+
end
|
|
304
|
+
end
|
|
305
|
+
|
|
306
|
+
def is_descendant_of?(descendant, ancestor)
|
|
307
|
+
is_ancestor_of?(ancestor, descendant)
|
|
308
|
+
end
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
class TransformPropagation
|
|
312
|
+
def self.propagate(world)
|
|
313
|
+
propagator = new(world)
|
|
314
|
+
propagator.propagate_from_roots
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
def initialize(world)
|
|
318
|
+
@world = world
|
|
319
|
+
@processed = {}
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
def propagate_from_roots
|
|
323
|
+
roots = find_roots
|
|
324
|
+
roots.each do |root|
|
|
325
|
+
propagate_recursive(root, GlobalTransform.identity)
|
|
326
|
+
end
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
private
|
|
330
|
+
|
|
331
|
+
def find_roots
|
|
332
|
+
roots = []
|
|
333
|
+
@world.each(Transform) do |entity, _transform|
|
|
334
|
+
parent = @world.get_component(entity, Parent) rescue nil
|
|
335
|
+
roots << entity unless parent
|
|
336
|
+
end
|
|
337
|
+
roots
|
|
338
|
+
end
|
|
339
|
+
|
|
340
|
+
def propagate_recursive(entity, parent_global)
|
|
341
|
+
return if @processed[entity]
|
|
342
|
+
@processed[entity] = true
|
|
343
|
+
|
|
344
|
+
local_transform = @world.get_component(entity, Transform) rescue nil
|
|
345
|
+
return unless local_transform
|
|
346
|
+
|
|
347
|
+
global = compute_global_transform(parent_global, local_transform)
|
|
348
|
+
|
|
349
|
+
begin
|
|
350
|
+
@world.insert_component(entity, global)
|
|
351
|
+
rescue StandardError
|
|
352
|
+
# Entity may not support GlobalTransform
|
|
353
|
+
end
|
|
354
|
+
|
|
355
|
+
children = @world.get_component(entity, Children) rescue nil
|
|
356
|
+
return unless children
|
|
357
|
+
|
|
358
|
+
children.each do |child|
|
|
359
|
+
propagate_recursive(child, global)
|
|
360
|
+
end
|
|
361
|
+
end
|
|
362
|
+
|
|
363
|
+
def compute_global_transform(parent_global, local_transform)
|
|
364
|
+
parent_scale = parent_global.scale
|
|
365
|
+
parent_rotation = parent_global.rotation
|
|
366
|
+
|
|
367
|
+
scaled_local = Vec3.new(
|
|
368
|
+
local_transform.translation.x * parent_scale.x,
|
|
369
|
+
local_transform.translation.y * parent_scale.y,
|
|
370
|
+
local_transform.translation.z * parent_scale.z
|
|
371
|
+
)
|
|
372
|
+
|
|
373
|
+
rotated = parent_rotation.mul_vec3(scaled_local)
|
|
374
|
+
|
|
375
|
+
GlobalTransform.new(
|
|
376
|
+
translation: Vec3.new(
|
|
377
|
+
parent_global.translation.x + rotated.x,
|
|
378
|
+
parent_global.translation.y + rotated.y,
|
|
379
|
+
parent_global.translation.z + rotated.z
|
|
380
|
+
),
|
|
381
|
+
rotation: parent_rotation * local_transform.rotation,
|
|
382
|
+
scale: Vec3.new(
|
|
383
|
+
parent_global.scale.x * local_transform.scale.x,
|
|
384
|
+
parent_global.scale.y * local_transform.scale.y,
|
|
385
|
+
parent_global.scale.z * local_transform.scale.z
|
|
386
|
+
)
|
|
387
|
+
)
|
|
388
|
+
end
|
|
389
|
+
end
|
|
390
|
+
|
|
391
|
+
class DespawnRecursive
|
|
392
|
+
def self.despawn(world, entity)
|
|
393
|
+
despawner = new(world)
|
|
394
|
+
despawner.despawn_recursive(entity)
|
|
395
|
+
end
|
|
396
|
+
|
|
397
|
+
def initialize(world)
|
|
398
|
+
@world = world
|
|
399
|
+
end
|
|
400
|
+
|
|
401
|
+
def despawn_recursive(entity)
|
|
402
|
+
children = @world.get_component(entity, Children) rescue nil
|
|
403
|
+
if children
|
|
404
|
+
children.entities.dup.each do |child|
|
|
405
|
+
despawn_recursive(child)
|
|
406
|
+
end
|
|
407
|
+
end
|
|
408
|
+
|
|
409
|
+
parent = @world.get_component(entity, Parent) rescue nil
|
|
410
|
+
if parent
|
|
411
|
+
parent_children = @world.get_component(parent.entity, Children) rescue nil
|
|
412
|
+
parent_children&.remove(entity)
|
|
413
|
+
end
|
|
414
|
+
|
|
415
|
+
@world.despawn(entity)
|
|
416
|
+
end
|
|
417
|
+
end
|
|
418
|
+
|
|
419
|
+
class HierarchyEvent
|
|
420
|
+
CHILD_ADDED = :child_added
|
|
421
|
+
CHILD_REMOVED = :child_removed
|
|
422
|
+
CHILD_MOVED = :child_moved
|
|
423
|
+
|
|
424
|
+
attr_reader :event_type, :parent, :child
|
|
425
|
+
|
|
426
|
+
def initialize(event_type, parent:, child:)
|
|
427
|
+
@event_type = event_type
|
|
428
|
+
@parent = parent
|
|
429
|
+
@child = child
|
|
430
|
+
end
|
|
431
|
+
|
|
432
|
+
def child_added?
|
|
433
|
+
@event_type == CHILD_ADDED
|
|
434
|
+
end
|
|
435
|
+
|
|
436
|
+
def child_removed?
|
|
437
|
+
@event_type == CHILD_REMOVED
|
|
438
|
+
end
|
|
439
|
+
|
|
440
|
+
def child_moved?
|
|
441
|
+
@event_type == CHILD_MOVED
|
|
442
|
+
end
|
|
443
|
+
end
|
|
444
|
+
end
|