Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bevyengine
GitHub Repository: bevyengine/bevy
Path: blob/main/crates/bevy_gizmos_render/src/retained.rs
9357 views
1
//! This module is for 'retained' alternatives to the 'immediate mode' [`Gizmos`](bevy_gizmos::gizmos::Gizmos) system parameter.
2
3
use crate::LineGizmoUniform;
4
use bevy_camera::visibility::RenderLayers;
5
use bevy_gizmos::retained::Gizmo;
6
use bevy_math::{Affine3, Affine3Ext};
7
use bevy_render::sync_world::{MainEntity, TemporaryRenderEntity};
8
use bevy_utils::once;
9
use tracing::warn;
10
use {
11
bevy_ecs::{
12
entity::Entity,
13
system::{Commands, Local, Query},
14
},
15
bevy_gizmos::config::GizmoLineJoint,
16
bevy_render::Extract,
17
bevy_transform::components::GlobalTransform,
18
};
19
20
use bevy_gizmos::config::GizmoLineStyle;
21
22
pub(crate) fn extract_linegizmos(
23
mut commands: Commands,
24
mut previous_len: Local<usize>,
25
query: Extract<Query<(Entity, &Gizmo, &GlobalTransform, Option<&RenderLayers>)>>,
26
) {
27
let mut values = Vec::with_capacity(*previous_len);
28
#[cfg_attr(
29
not(any(feature = "bevy_pbr", feature = "bevy_sprite_render")),
30
expect(
31
unused_variables,
32
reason = "`render_layers` is unused when bevy_pbr and bevy_sprite_render are both disabled."
33
)
34
)]
35
for (entity, gizmo, transform, render_layers) in &query {
36
let joints_resolution = if let GizmoLineJoint::Round(resolution) = gizmo.line_config.joints
37
{
38
resolution
39
} else {
40
0
41
};
42
let (gap_scale, line_scale) = if let GizmoLineStyle::Dashed {
43
gap_scale,
44
line_scale,
45
} = gizmo.line_config.style
46
{
47
if gap_scale <= 0.0 {
48
once!(warn!("when using gizmos with the line style `GizmoLineStyle::Dashed{{..}}` the gap scale should be greater than zero"));
49
}
50
if line_scale <= 0.0 {
51
once!(warn!("when using gizmos with the line style `GizmoLineStyle::Dashed{{..}}` the line scale should be greater than zero"));
52
}
53
(gap_scale, line_scale)
54
} else {
55
(1.0, 1.0)
56
};
57
58
values.push((
59
LineGizmoUniform {
60
world_from_local: Affine3::from(transform.affine()).to_transpose(),
61
line_width: gizmo.line_config.width,
62
depth_bias: gizmo.depth_bias,
63
joints_resolution,
64
gap_scale,
65
line_scale,
66
#[cfg(all(feature = "webgl", target_arch = "wasm32", not(feature = "webgpu")))]
67
_webgl2_padding: Default::default(),
68
},
69
#[cfg(any(feature = "bevy_pbr", feature = "bevy_sprite_render"))]
70
bevy_gizmos::config::GizmoMeshConfig {
71
line_perspective: gizmo.line_config.perspective,
72
line_style: gizmo.line_config.style,
73
line_joints: gizmo.line_config.joints,
74
render_layers: render_layers.cloned().unwrap_or_default(),
75
handle: gizmo.handle.clone(),
76
},
77
MainEntity::from(entity),
78
TemporaryRenderEntity,
79
));
80
}
81
*previous_len = values.len();
82
commands.spawn_batch(values);
83
}
84
85