Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bevyengine
GitHub Repository: bevyengine/bevy
Path: blob/main/crates/bevy_gizmos_render/src/retained.rs
7228 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;
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
for (entity, gizmo, transform, render_layers) in &query {
29
let joints_resolution = if let GizmoLineJoint::Round(resolution) = gizmo.line_config.joints
30
{
31
resolution
32
} else {
33
0
34
};
35
let (gap_scale, line_scale) = if let GizmoLineStyle::Dashed {
36
gap_scale,
37
line_scale,
38
} = gizmo.line_config.style
39
{
40
if gap_scale <= 0.0 {
41
once!(warn!("when using gizmos with the line style `GizmoLineStyle::Dashed{{..}}` the gap scale should be greater than zero"));
42
}
43
if line_scale <= 0.0 {
44
once!(warn!("when using gizmos with the line style `GizmoLineStyle::Dashed{{..}}` the line scale should be greater than zero"));
45
}
46
(gap_scale, line_scale)
47
} else {
48
(1.0, 1.0)
49
};
50
51
values.push((
52
LineGizmoUniform {
53
world_from_local: Affine3::from(&transform.affine()).to_transpose(),
54
line_width: gizmo.line_config.width,
55
depth_bias: gizmo.depth_bias,
56
joints_resolution,
57
gap_scale,
58
line_scale,
59
#[cfg(feature = "webgl")]
60
_padding: Default::default(),
61
},
62
#[cfg(any(feature = "bevy_pbr", feature = "bevy_sprite_render"))]
63
bevy_gizmos::config::GizmoMeshConfig {
64
line_perspective: gizmo.line_config.perspective,
65
line_style: gizmo.line_config.style,
66
line_joints: gizmo.line_config.joints,
67
render_layers: render_layers.cloned().unwrap_or_default(),
68
handle: gizmo.handle.clone(),
69
},
70
MainEntity::from(entity),
71
TemporaryRenderEntity,
72
));
73
}
74
*previous_len = values.len();
75
commands.spawn_batch(values);
76
}
77
78