mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
transform: immediately set localltransform value
This commit is contained in:
parent
ae30175e18
commit
19d24e92aa
5 changed files with 10 additions and 28 deletions
|
@ -15,6 +15,7 @@ This is the Bevy project's fork of hecs with changes that accommodate the needs
|
|||
* Entity indices are now queryable and are not returned in queries by default. This both improves ergonomics and significantly boosts performance in some cases.
|
||||
* Entity indices are now UUIDs and are no longer generational. This allows apps to use Entity ids as stable ids during serialization and networking. This also improves query performance because we don't need to look up entity generation information while iterating. It also removes ~300 lines of code dedicated to entity index maintenance. However this new model does come at a small cost: entity creation + `world.get::<Component>(entity)` lookup now requires hashing, which by our benchmarks is about 5x slower than the previous array indexing implementation. Given that this is an uncommon pattern and the major benefits the new design yields, we consider this small corner-case performance cost worth it.
|
||||
* Expose more interfaces as public so that we can build higher-level apis on top of the core hecs codebase (multithreading, functions-as-systems, world builders, schedules, etc)
|
||||
* Change Tracking
|
||||
|
||||
### Why ECS?
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#![allow(dead_code)]
|
||||
use crate::components::*;
|
||||
use bevy_ecs::{Commands, Entity, IntoQuerySystem, Query, System, Without};
|
||||
use smallvec::SmallVec;
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
#![allow(dead_code)]
|
||||
use crate::components::*;
|
||||
|
||||
use bevy_ecs::prelude::*;
|
||||
use bevy_math::{Mat4, Quat, Vec3};
|
||||
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
#![allow(dead_code)]
|
||||
use crate::components::*;
|
||||
use bevy_ecs::prelude::*;
|
||||
|
||||
pub fn transform_propagate_system(
|
||||
mut commands: Commands,
|
||||
mut root_query: Query<
|
||||
Without<Parent, (Option<&Children>, &mut Transform, Option<&LocalTransform>)>,
|
||||
>,
|
||||
mut children_query: Query<&Children>,
|
||||
mut local_transform_query: Query<&LocalTransform>,
|
||||
mut local_transform_query: Query<(&mut Transform, &LocalTransform, Option<&Children>)>,
|
||||
) {
|
||||
for (children, mut transform, local_transform) in &mut root_query.iter() {
|
||||
if let Some(local_transform) = local_transform {
|
||||
|
@ -17,13 +14,7 @@ pub fn transform_propagate_system(
|
|||
|
||||
if let Some(children) = children {
|
||||
for child in children.0.iter() {
|
||||
propagate_recursive(
|
||||
*transform,
|
||||
&mut children_query,
|
||||
&mut local_transform_query,
|
||||
*child,
|
||||
&mut commands,
|
||||
);
|
||||
propagate_recursive(*transform, &mut local_transform_query, *child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,10 +22,8 @@ pub fn transform_propagate_system(
|
|||
|
||||
fn propagate_recursive(
|
||||
parent_local_to_world: Transform,
|
||||
children_query: &mut Query<&Children>,
|
||||
local_transform_query: &mut Query<&LocalTransform>,
|
||||
local_transform_query: &mut Query<(&mut Transform, &LocalTransform, Option<&Children>)>,
|
||||
entity: Entity,
|
||||
commands: &mut Commands,
|
||||
) {
|
||||
log::trace!("Updating Transform for {:?}", entity);
|
||||
let local_transform = {
|
||||
|
@ -54,22 +43,19 @@ fn propagate_recursive(
|
|||
sync: true,
|
||||
};
|
||||
|
||||
commands.insert_one(entity, new_transform);
|
||||
{
|
||||
let mut transform = local_transform_query.get_mut::<Transform>(entity).unwrap();
|
||||
transform.value = new_transform.value;
|
||||
}
|
||||
|
||||
// Collect children
|
||||
let children = children_query
|
||||
let children = local_transform_query
|
||||
.get::<Children>(entity)
|
||||
.map(|e| e.0.iter().cloned().collect::<Vec<_>>())
|
||||
.unwrap_or_default();
|
||||
|
||||
for child in children {
|
||||
propagate_recursive(
|
||||
new_transform,
|
||||
children_query,
|
||||
local_transform_query,
|
||||
child,
|
||||
commands,
|
||||
);
|
||||
propagate_recursive(new_transform, local_transform_query, child);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
#![allow(dead_code)]
|
||||
use crate::components::*;
|
||||
|
||||
use bevy_ecs::prelude::*;
|
||||
use bevy_math::{Mat4, Quat, Vec3};
|
||||
|
||||
|
|
Loading…
Reference in a new issue