Add SetOutlineDepth component.
This commit is contained in:
parent
a792cca681
commit
8afc8f9d14
@ -6,7 +6,15 @@ pub struct ComputedOutlineDepth {
|
|||||||
pub(crate) origin: Vec3,
|
pub(crate) origin: Vec3,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A component which specifies that this entity lies at the same depth as its parent.
|
/// A component which specifies how the outline depth should be computed.
|
||||||
|
#[derive(Clone, Component)]
|
||||||
|
#[non_exhaustive]
|
||||||
|
pub enum SetOutlineDepth {
|
||||||
|
/// A flat plane facing the camera and intersecting the specified point in model-space.
|
||||||
|
Flat { model_origin: Vec3 },
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A component which specifies that this outline lies at the same depth as its parent.
|
||||||
#[derive(Clone, Component, Default)]
|
#[derive(Clone, Component, Default)]
|
||||||
pub struct InheritOutlineDepth;
|
pub struct InheritOutlineDepth;
|
||||||
|
|
||||||
@ -17,6 +25,7 @@ pub(crate) fn compute_outline_depth(
|
|||||||
&mut ComputedOutlineDepth,
|
&mut ComputedOutlineDepth,
|
||||||
&GlobalTransform,
|
&GlobalTransform,
|
||||||
Changed<GlobalTransform>,
|
Changed<GlobalTransform>,
|
||||||
|
Option<(&SetOutlineDepth, Changed<SetOutlineDepth>)>,
|
||||||
Option<(&Children, Changed<Children>)>,
|
Option<(&Children, Changed<Children>)>,
|
||||||
),
|
),
|
||||||
Without<InheritOutlineDepth>,
|
Without<InheritOutlineDepth>,
|
||||||
@ -24,17 +33,28 @@ pub(crate) fn compute_outline_depth(
|
|||||||
mut computed_query: Query<(&mut ComputedOutlineDepth, Changed<InheritOutlineDepth>)>,
|
mut computed_query: Query<(&mut ComputedOutlineDepth, Changed<InheritOutlineDepth>)>,
|
||||||
child_query: Query<(&Children, Changed<Children>)>,
|
child_query: Query<(&Children, Changed<Children>)>,
|
||||||
) {
|
) {
|
||||||
for (mut computed, transform, changed_transform, children) in root_query.iter_mut() {
|
for (mut computed, transform, changed_transform, set_depth, children) in root_query.iter_mut() {
|
||||||
if changed_transform {
|
let mut changed = changed_transform;
|
||||||
|
if changed {
|
||||||
|
let origin = if let Some((sd, sd_changed)) = set_depth {
|
||||||
|
changed |= sd_changed;
|
||||||
|
match sd {
|
||||||
|
SetOutlineDepth::Flat {
|
||||||
|
model_origin: origin,
|
||||||
|
} => *origin,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Vec3::ZERO
|
||||||
|
};
|
||||||
let matrix = transform.compute_matrix();
|
let matrix = transform.compute_matrix();
|
||||||
computed.origin = matrix.project_point3(Vec3::ZERO);
|
computed.origin = matrix.project_point3(origin);
|
||||||
}
|
}
|
||||||
if let Some((cs, changed_children)) = children {
|
if let Some((cs, changed_children)) = children {
|
||||||
let changed2 = changed_children || changed_transform;
|
changed |= changed_children;
|
||||||
for child in cs.iter() {
|
for child in cs.iter() {
|
||||||
propagate_outline_depth(
|
propagate_outline_depth(
|
||||||
&computed,
|
&computed,
|
||||||
changed2,
|
changed,
|
||||||
*child,
|
*child,
|
||||||
&mut computed_query,
|
&mut computed_query,
|
||||||
&child_query,
|
&child_query,
|
||||||
@ -46,21 +66,22 @@ pub(crate) fn compute_outline_depth(
|
|||||||
|
|
||||||
fn propagate_outline_depth(
|
fn propagate_outline_depth(
|
||||||
root_computed: &ComputedOutlineDepth,
|
root_computed: &ComputedOutlineDepth,
|
||||||
changed: bool,
|
mut changed: bool,
|
||||||
entity: Entity,
|
entity: Entity,
|
||||||
computed_query: &mut Query<(&mut ComputedOutlineDepth, Changed<InheritOutlineDepth>)>,
|
computed_query: &mut Query<(&mut ComputedOutlineDepth, Changed<InheritOutlineDepth>)>,
|
||||||
child_query: &Query<(&Children, Changed<Children>)>,
|
child_query: &Query<(&Children, Changed<Children>)>,
|
||||||
) {
|
) {
|
||||||
if let Ok((mut computed, changed_inherit)) = computed_query.get_mut(entity) {
|
if let Ok((mut computed, changed_inherit)) = computed_query.get_mut(entity) {
|
||||||
if changed_inherit || changed {
|
changed |= changed_inherit;
|
||||||
|
if changed {
|
||||||
*computed = root_computed.clone();
|
*computed = root_computed.clone();
|
||||||
}
|
}
|
||||||
if let Ok((cs, changed_children)) = child_query.get(entity) {
|
if let Ok((cs, changed_children)) = child_query.get(entity) {
|
||||||
let changed2 = changed_children || changed_inherit || changed;
|
changed |= changed_children;
|
||||||
for child in cs.iter() {
|
for child in cs.iter() {
|
||||||
propagate_outline_depth(
|
propagate_outline_depth(
|
||||||
root_computed,
|
root_computed,
|
||||||
changed2,
|
changed,
|
||||||
*child,
|
*child,
|
||||||
computed_query,
|
computed_query,
|
||||||
child_query,
|
child_query,
|
||||||
|
Loading…
Reference in New Issue
Block a user