Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transform rewrite - initial draft #374

Merged
merged 25 commits into from
Sep 14, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
cfa64e8
initial draft
MarekLg Aug 27, 2020
6889524
replaced TransformBuilder, replaced e.g. Translation by Vec3
MarekLg Aug 28, 2020
dfced53
removed pass by reference in e.g. Transform::translate()
MarekLg Aug 28, 2020
03372ec
parenting working (see PR #374 for more info)
MarekLg Sep 1, 2020
8129f51
removed print_children system
MarekLg Sep 1, 2020
13b4f19
Merge branch 'master' into transform-rewrite
MarekLg Sep 4, 2020
f8a6d58
removed unused imports, kept commented code
MarekLg Sep 4, 2020
b75c2ab
added missing transformations
MarekLg Sep 11, 2020
86c8d63
removed unnecessary comments
MarekLg Sep 11, 2020
c757af2
removed unnecessary unit struct components
MarekLg Sep 11, 2020
fd439f2
removed unnecessary comments
MarekLg Sep 11, 2020
a949b70
removed registrations
MarekLg Sep 11, 2020
4025802
forgetting optimization by compute shader for now
MarekLg Sep 11, 2020
39e8b84
changed local_matrix().w_axis to local_transform
MarekLg Sep 11, 2020
4ea9cbd
removed unnecessary childs
MarekLg Sep 11, 2020
db6ab51
changed to set_local_translation()
MarekLg Sep 11, 2020
fe04ecf
removed unused imports
MarekLg Sep 11, 2020
e3936d3
changed to Vec3::new() constructor
MarekLg Sep 11, 2020
3e120cc
removed unnecessary asserts
MarekLg Sep 11, 2020
c0cccfc
Merge upstream/master into transform-rewrite
MarekLg Sep 11, 2020
7cc90b1
fix correct_children() test failing
MarekLg Sep 12, 2020
8329f96
split up local and global Transform
MarekLg Sep 12, 2020
79c898a
adapted 2D components to Transforms
MarekLg Sep 14, 2020
717f2b0
removed old Transform Components
MarekLg Sep 14, 2020
8a17481
forgot to add global_transform
MarekLg Sep 14, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
**/*.rs.bk
Cargo.lock
.cargo/config
/.idea
/.idea
/.vscode
10 changes: 1 addition & 9 deletions crates/bevy_pbr/src/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use bevy_render::{
pipeline::{DynamicBinding, PipelineSpecialization, RenderPipeline, RenderPipelines},
render_graph::base::MainPass,
};
use bevy_transform::prelude::{Rotation, Scale, Transform, Translation};
use bevy_transform::prelude::Transform;

/// A component bundle for "pbr mesh" entities
#[derive(Bundle)]
Expand All @@ -18,9 +18,6 @@ pub struct PbrComponents {
pub draw: Draw,
pub render_pipelines: RenderPipelines,
pub transform: Transform,
pub translation: Translation,
pub rotation: Rotation,
pub scale: Scale,
}

impl Default for PbrComponents {
Expand Down Expand Up @@ -49,9 +46,6 @@ impl Default for PbrComponents {
main_pass: Default::default(),
draw: Default::default(),
transform: Default::default(),
translation: Default::default(),
rotation: Default::default(),
scale: Default::default(),
}
}
}
Expand All @@ -61,6 +55,4 @@ impl Default for PbrComponents {
pub struct LightComponents {
pub light: Light,
pub transform: Transform,
pub translation: Translation,
pub rotation: Rotation,
}
9 changes: 4 additions & 5 deletions crates/bevy_pbr/src/light.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use bevy_core::Byteable;
use bevy_math::Mat4;
use bevy_property::Properties;
use bevy_render::{
camera::{CameraProjection, PerspectiveProjection},
color::Color,
};
use bevy_transform::components::Translation;
use bevy_transform::components::Transform;
use std::ops::Range;

/// A point light
Expand Down Expand Up @@ -37,16 +36,16 @@ pub(crate) struct LightRaw {
unsafe impl Byteable for LightRaw {}

impl LightRaw {
pub fn from(light: &Light, transform: &Mat4, translation: &Translation) -> LightRaw {
pub fn from(light: &Light, transform: &Transform) -> LightRaw {
let perspective = PerspectiveProjection {
fov: light.fov,
aspect_ratio: 1.0,
near: light.depth.start,
far: light.depth.end,
};

let proj = perspective.get_projection_matrix() * *transform;
let (x, y, z) = translation.0.into();
let proj = perspective.get_projection_matrix() * *transform.global_matrix();
let (x, y, z) = transform.global_translation().0.into();
LightRaw {
proj: proj.to_cols_array_2d(),
pos: [x, y, z, 1.0],
Expand Down
8 changes: 3 additions & 5 deletions crates/bevy_pbr/src/render_graph/lights_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub fn lights_node_system(
render_resource_context: Res<Box<dyn RenderResourceContext>>,
// TODO: this write on RenderResourceBindings will prevent this system from running in parallel with other systems that do the same
mut render_resource_bindings: ResMut<RenderResourceBindings>,
mut query: Query<(&Light, &Transform, &Translation)>,
mut query: Query<(&Light, &Transform)>,
) {
let state = &mut state;
let render_resource_context = &**render_resource_context;
Expand Down Expand Up @@ -132,14 +132,12 @@ pub fn lights_node_system(
data[0..light_count_size].copy_from_slice([light_count as u32, 0, 0, 0].as_bytes());

// light array
for ((light, transform, translation), slot) in query
for ((light, transform), slot) in query
.iter()
.iter()
.zip(data[light_count_size..current_light_uniform_size].chunks_exact_mut(size))
{
slot.copy_from_slice(
LightRaw::from(&light, &transform.value, &translation).as_bytes(),
);
slot.copy_from_slice(LightRaw::from(&light, &transform).as_bytes());
}
},
);
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_render/src/camera/visible_entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn visible_entities_system(
) {
for (camera, camera_transform, mut visible_entities) in &mut camera_query.iter() {
visible_entities.value.clear();
let camera_position = camera_transform.value.w_axis().truncate();
let camera_position = camera_transform.global_matrix().w_axis().truncate();

let mut no_transform_order = 0.0;
let mut transparent_entities = Vec::new();
Expand All @@ -40,7 +40,7 @@ pub fn visible_entities_system(
}

let order = if let Ok(transform) = draw_transform_query.get::<Transform>(entity) {
let position = transform.value.w_axis().truncate();
let position = transform.global_matrix().w_axis().truncate();
// smaller distances are sorted to lower indices by using the distance from the camera
FloatOrd(match camera.depth_calculation {
DepthCalculation::ZDifference => camera_position.z() - position.z(),
Expand Down
9 changes: 0 additions & 9 deletions crates/bevy_render/src/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ pub struct MeshComponents {
pub render_pipelines: RenderPipelines,
pub main_pass: MainPass,
pub transform: Transform,
pub translation: Translation,
pub rotation: Rotation,
pub scale: Scale,
}

/// A component bundle for "3d camera" entities
Expand All @@ -29,9 +26,6 @@ pub struct Camera3dComponents {
pub perspective_projection: PerspectiveProjection,
pub visible_entities: VisibleEntities,
pub transform: Transform,
pub translation: Translation,
pub rotation: Rotation,
pub scale: Scale,
}

impl Default for Camera3dComponents {
Expand All @@ -44,9 +38,6 @@ impl Default for Camera3dComponents {
perspective_projection: Default::default(),
visible_entities: Default::default(),
transform: Default::default(),
translation: Default::default(),
rotation: Default::default(),
scale: Default::default(),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_render/src/render_graph/nodes/camera_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub fn camera_node_system(

let matrix_size = std::mem::size_of::<[[f32; 4]; 4]>();
let camera_matrix: [f32; 16] =
(camera.projection_matrix * transform.value.inverse()).to_cols_array();
(camera.projection_matrix * transform.global_matrix().inverse()).to_cols_array();

render_resource_context.write_mapped_buffer(
staging_buffer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ impl RenderResources for bevy_transform::prelude::Transform {

fn get_render_resource(&self, index: usize) -> Option<&dyn RenderResource> {
if index == 0 {
Some(&self.value)
Some(self.global_matrix())
} else {
None
}
Expand Down
41 changes: 0 additions & 41 deletions crates/bevy_transform/src/components/local_transform.rs

This file was deleted.

2 changes: 0 additions & 2 deletions crates/bevy_transform/src/components/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
mod children;
mod local_transform;
mod non_uniform_scale;
mod parent;
mod rotation;
Expand All @@ -8,7 +7,6 @@ mod transform;
mod translation;

pub use children::Children;
pub use local_transform::*;
pub use non_uniform_scale::*;
pub use parent::{Parent, PreviousParent};
pub use rotation::*;
Expand Down
Loading