Path: blob/main/crates/bevy_gizmos_render/src/retained.rs
7228 views
//! This module is for 'retained' alternatives to the 'immediate mode' [`Gizmos`](bevy_gizmos::gizmos::Gizmos) system parameter.12use crate::LineGizmoUniform;3use bevy_camera::visibility::RenderLayers;4use bevy_gizmos::retained::Gizmo;5use bevy_math::Affine3;6use bevy_render::sync_world::{MainEntity, TemporaryRenderEntity};7use bevy_utils::once;8use tracing::warn;9use {10bevy_ecs::{11entity::Entity,12system::{Commands, Local, Query},13},14bevy_gizmos::config::GizmoLineJoint,15bevy_render::Extract,16bevy_transform::components::GlobalTransform,17};1819use bevy_gizmos::config::GizmoLineStyle;2021pub(crate) fn extract_linegizmos(22mut commands: Commands,23mut previous_len: Local<usize>,24query: Extract<Query<(Entity, &Gizmo, &GlobalTransform, Option<&RenderLayers>)>>,25) {26let mut values = Vec::with_capacity(*previous_len);27for (entity, gizmo, transform, render_layers) in &query {28let joints_resolution = if let GizmoLineJoint::Round(resolution) = gizmo.line_config.joints29{30resolution31} else {32033};34let (gap_scale, line_scale) = if let GizmoLineStyle::Dashed {35gap_scale,36line_scale,37} = gizmo.line_config.style38{39if gap_scale <= 0.0 {40once!(warn!("when using gizmos with the line style `GizmoLineStyle::Dashed{{..}}` the gap scale should be greater than zero"));41}42if line_scale <= 0.0 {43once!(warn!("when using gizmos with the line style `GizmoLineStyle::Dashed{{..}}` the line scale should be greater than zero"));44}45(gap_scale, line_scale)46} else {47(1.0, 1.0)48};4950values.push((51LineGizmoUniform {52world_from_local: Affine3::from(&transform.affine()).to_transpose(),53line_width: gizmo.line_config.width,54depth_bias: gizmo.depth_bias,55joints_resolution,56gap_scale,57line_scale,58#[cfg(feature = "webgl")]59_padding: Default::default(),60},61#[cfg(any(feature = "bevy_pbr", feature = "bevy_sprite_render"))]62bevy_gizmos::config::GizmoMeshConfig {63line_perspective: gizmo.line_config.perspective,64line_style: gizmo.line_config.style,65line_joints: gizmo.line_config.joints,66render_layers: render_layers.cloned().unwrap_or_default(),67handle: gizmo.handle.clone(),68},69MainEntity::from(entity),70TemporaryRenderEntity,71));72}73*previous_len = values.len();74commands.spawn_batch(values);75}767778