rename LocalToWorld -> Transform and LocalToParent -> LocalTransform

This commit is contained in:
Carter Anderson 2020-06-07 13:39:50 -07:00
parent d0298a4f89
commit 5add29f8cf
36 changed files with 131 additions and 166 deletions

View file

@ -7,7 +7,7 @@ pub use bevy_derive::Bytes;
use bevy_app::{stage, AppBuilder, AppPlugin}; use bevy_app::{stage, AppBuilder, AppPlugin};
use bevy_transform::{ use bevy_transform::{
components::{ components::{
Children, LocalToParent, LocalToWorld, NonUniformScale, Rotation, Scale, Translation, Children, LocalTransform, Transform, NonUniformScale, Rotation, Scale, Translation,
}, },
transform_system_bundle, transform_system_bundle,
}; };
@ -27,8 +27,8 @@ impl AppPlugin for CorePlugin {
app.init_resource::<Time>() app.init_resource::<Time>()
.register_component::<Children>() .register_component::<Children>()
.register_component::<LocalToParent>() .register_component::<LocalTransform>()
.register_component::<LocalToWorld>() .register_component::<Transform>()
.register_component::<Translation>() .register_component::<Translation>()
.register_component::<Rotation>() .register_component::<Rotation>()
.register_component::<Scale>() .register_component::<Scale>()

View file

@ -1,5 +1,5 @@
use bevy_app::EntityArchetype; use bevy_app::EntityArchetype;
use bevy_transform::components::{LocalToParent, Parent}; use bevy_transform::components::{LocalTransform, Parent};
use legion::{ use legion::{
filter::{ChunksetFilterData, Filter}, filter::{ChunksetFilterData, Filter},
prelude::*, prelude::*,
@ -90,7 +90,7 @@ impl<'a> WorldBuilder<'a> {
.add_component(current_entity, Parent(parent_entity)); .add_component(current_entity, Parent(parent_entity));
let _ = self let _ = self
.world .world
.add_component(current_entity, LocalToParent::identity()); .add_component(current_entity, LocalTransform::identity());
} }
} }
} }
@ -179,7 +179,7 @@ impl<'a> CommandBufferBuilder<'a> {
.add_component(current_entity, Parent(parent_entity)); .add_component(current_entity, Parent(parent_entity));
let _ = self let _ = self
.command_buffer .command_buffer
.add_component(current_entity, LocalToParent::identity()); .add_component(current_entity, LocalTransform::identity());
} }
} }
} }

View file

@ -2,7 +2,7 @@ use crate::{light::Light, material::StandardMaterial};
use bevy_asset::Handle; use bevy_asset::Handle;
use bevy_derive::EntityArchetype; use bevy_derive::EntityArchetype;
use bevy_render::{mesh::Mesh, Renderable}; use bevy_render::{mesh::Mesh, Renderable};
use bevy_transform::prelude::{LocalToWorld, Rotation, Scale, Translation}; use bevy_transform::prelude::{Transform, Rotation, Scale, Translation};
#[derive(EntityArchetype, Default)] #[derive(EntityArchetype, Default)]
pub struct MeshEntity { pub struct MeshEntity {
@ -11,7 +11,7 @@ pub struct MeshEntity {
// #[tag] // #[tag]
pub material: Handle<StandardMaterial>, pub material: Handle<StandardMaterial>,
pub renderable: Renderable, pub renderable: Renderable,
pub local_to_world: LocalToWorld, pub transform: Transform,
pub translation: Translation, pub translation: Translation,
pub rotation: Rotation, pub rotation: Rotation,
pub scale: Scale, pub scale: Scale,
@ -20,7 +20,7 @@ pub struct MeshEntity {
#[derive(EntityArchetype, Default)] #[derive(EntityArchetype, Default)]
pub struct LightEntity { pub struct LightEntity {
pub light: Light, pub light: Light,
pub local_to_world: LocalToWorld, pub transform: Transform,
pub translation: Translation, pub translation: Translation,
pub rotation: Rotation, pub rotation: Rotation,
} }

View file

@ -10,11 +10,11 @@ use bevy_render::{
}, },
shader::Shader, shader::Shader,
}; };
use bevy_transform::prelude::LocalToWorld; use bevy_transform::prelude::Transform;
use legion::prelude::Resources; use legion::prelude::Resources;
pub mod node { pub mod node {
pub const LOCAL_TO_WORLD: &str = "local_to_world"; pub const TRANSFORM: &str = "transform";
pub const STANDARD_MATERIAL: &str = "standard_material"; pub const STANDARD_MATERIAL: &str = "standard_material";
pub const LIGHTS: &str = "lights"; pub const LIGHTS: &str = "lights";
} }
@ -29,7 +29,7 @@ pub trait ForwardPbrRenderGraphBuilder {
impl ForwardPbrRenderGraphBuilder for RenderGraph { impl ForwardPbrRenderGraphBuilder for RenderGraph {
fn add_pbr_graph(&mut self, resources: &Resources) -> &mut Self { fn add_pbr_graph(&mut self, resources: &Resources) -> &mut Self {
self.add_system_node(node::LOCAL_TO_WORLD, UniformNode::<LocalToWorld>::new(true)); self.add_system_node(node::TRANSFORM, UniformNode::<Transform>::new(true));
self.add_system_node( self.add_system_node(
node::STANDARD_MATERIAL, node::STANDARD_MATERIAL,
AssetUniformNode::<StandardMaterial>::new(true), AssetUniformNode::<StandardMaterial>::new(true),
@ -50,7 +50,7 @@ impl ForwardPbrRenderGraphBuilder for RenderGraph {
// TODO: replace these with "autowire" groups // TODO: replace these with "autowire" groups
self.add_node_edge(node::STANDARD_MATERIAL, base_render_graph::node::MAIN_PASS) self.add_node_edge(node::STANDARD_MATERIAL, base_render_graph::node::MAIN_PASS)
.unwrap(); .unwrap();
self.add_node_edge(node::LOCAL_TO_WORLD, base_render_graph::node::MAIN_PASS) self.add_node_edge(node::TRANSFORM, base_render_graph::node::MAIN_PASS)
.unwrap(); .unwrap();
self.add_node_edge(node::LIGHTS, base_render_graph::node::MAIN_PASS) self.add_node_edge(node::LIGHTS, base_render_graph::node::MAIN_PASS)
.unwrap(); .unwrap();

View file

@ -4,7 +4,6 @@ use bevy_render::{texture::Texture, Color};
#[derive(Uniforms)] #[derive(Uniforms)]
pub struct StandardMaterial { pub struct StandardMaterial {
#[uniform(instance)]
pub albedo: Color, pub albedo: Color,
#[uniform(shader_def)] #[uniform(shader_def)]
pub albedo_texture: Option<Handle<Texture>>, pub albedo_texture: Option<Handle<Texture>>,

View file

@ -63,7 +63,7 @@ impl SystemNode for LightsNode {
render_resources: Res<RenderResources>, render_resources: Res<RenderResources>,
// TODO: this write on RenderResourceAssignments will prevent this system from running in parallel with other systems that do the same // TODO: this write on RenderResourceAssignments will prevent this system from running in parallel with other systems that do the same
mut render_resource_assignments: ResMut<RenderResourceAssignments>, mut render_resource_assignments: ResMut<RenderResourceAssignments>,
query: &mut Query<(Read<Light>, Read<LocalToWorld>, Read<Translation>)>| { query: &mut Query<(Read<Light>, Read<Transform>, Read<Translation>)>| {
if !lights_are_dirty { if !lights_are_dirty {
return; return;
} }
@ -117,11 +117,11 @@ impl SystemNode for LightsNode {
..Default::default() ..Default::default()
}, },
&mut |data, _renderer| { &mut |data, _renderer| {
for ((light, local_to_world, translation), slot) in for ((light, transform, translation), slot) in
query.iter(world).zip(data.chunks_exact_mut(size)) query.iter(world).zip(data.chunks_exact_mut(size))
{ {
slot.copy_from_slice( slot.copy_from_slice(
LightRaw::from(&light, &local_to_world.value, &translation).as_bytes(), LightRaw::from(&light, &transform.value, &translation).as_bytes(),
); );
} }
}, },

View file

@ -4,13 +4,6 @@ layout(location = 0) in vec3 Vertex_Position;
layout(location = 1) in vec3 Vertex_Normal; layout(location = 1) in vec3 Vertex_Normal;
layout(location = 2) in vec2 Vertex_Uv; layout(location = 2) in vec2 Vertex_Uv;
# ifdef INSTANCING
layout(location = 3) in vec4 I_Object_Model_0;
layout(location = 4) in vec4 I_Object_Model_1;
layout(location = 5) in vec4 I_Object_Model_2;
layout(location = 6) in vec4 I_Object_Model_3;
# endif
layout(location = 0) out vec3 v_Position; layout(location = 0) out vec3 v_Position;
layout(location = 1) out vec3 v_Normal; layout(location = 1) out vec3 v_Normal;
layout(location = 2) out vec2 v_Uv; layout(location = 2) out vec2 v_Uv;
@ -19,22 +12,11 @@ layout(set = 0, binding = 0) uniform Camera {
mat4 ViewProj; mat4 ViewProj;
}; };
# ifndef INSTANCING layout(set = 1, binding = 0) uniform Transform {
layout(set = 1, binding = 0) uniform Object {
mat4 Model; mat4 Model;
}; };
# endif
void main() { void main() {
# ifdef INSTANCING
mat4 Model = mat4(
I_Object_Model_0,
I_Object_Model_1,
I_Object_Model_2,
I_Object_Model_3
);
# endif
v_Normal = (Model * vec4(Vertex_Normal, 1.0)).xyz; v_Normal = (Model * vec4(Vertex_Normal, 1.0)).xyz;
v_Normal = mat3(Model) * Vertex_Normal; v_Normal = mat3(Model) * Vertex_Normal;
v_Position = (Model * vec4(Vertex_Position, 1.0)).xyz; v_Position = (Model * vec4(Vertex_Position, 1.0)).xyz;

View file

@ -4,14 +4,14 @@ use crate::{
}; };
use bevy_asset::Handle; use bevy_asset::Handle;
use bevy_derive::EntityArchetype; use bevy_derive::EntityArchetype;
use bevy_transform::components::{LocalToWorld, Rotation, Scale, Translation}; use bevy_transform::components::{Transform, Rotation, Scale, Translation};
#[derive(EntityArchetype, Default)] #[derive(EntityArchetype, Default)]
pub struct MeshMaterialEntity<T: Default + Send + Sync + 'static> { pub struct MeshMaterialEntity<T: Default + Send + Sync + 'static> {
pub mesh: Handle<Mesh>, pub mesh: Handle<Mesh>,
pub material: Handle<T>, pub material: Handle<T>,
pub renderable: Renderable, pub renderable: Renderable,
pub local_to_world: LocalToWorld, pub transform: Transform,
pub translation: Translation, pub translation: Translation,
pub rotation: Rotation, pub rotation: Rotation,
pub scale: Scale, pub scale: Scale,
@ -21,7 +21,7 @@ pub struct MeshMaterialEntity<T: Default + Send + Sync + 'static> {
pub struct PerspectiveCameraEntity { pub struct PerspectiveCameraEntity {
pub camera: Camera, pub camera: Camera,
pub perspective_projection: PerspectiveProjection, pub perspective_projection: PerspectiveProjection,
pub local_to_world: LocalToWorld, pub transform: Transform,
pub translation: Translation, pub translation: Translation,
pub rotation: Rotation, pub rotation: Rotation,
} }
@ -34,7 +34,7 @@ impl Default for PerspectiveCameraEntity {
..Default::default() ..Default::default()
}, },
perspective_projection: Default::default(), perspective_projection: Default::default(),
local_to_world: Default::default(), transform: Default::default(),
translation: Default::default(), translation: Default::default(),
rotation: Default::default(), rotation: Default::default(),
} }
@ -45,7 +45,7 @@ impl Default for PerspectiveCameraEntity {
pub struct OrthographicCameraEntity { pub struct OrthographicCameraEntity {
pub camera: Camera, pub camera: Camera,
pub orthographic_projection: OrthographicProjection, pub orthographic_projection: OrthographicProjection,
pub local_to_world: LocalToWorld, pub transform: Transform,
pub translation: Translation, pub translation: Translation,
pub rotation: Rotation, pub rotation: Rotation,
} }
@ -61,7 +61,7 @@ impl OrthographicCameraEntity {
window_origin: WindowOrigin::BottomLeft, window_origin: WindowOrigin::BottomLeft,
..Default::default() ..Default::default()
}, },
local_to_world: Default::default(), transform: Default::default(),
translation: Default::default(), translation: Default::default(),
rotation: Default::default(), rotation: Default::default(),
} }
@ -76,7 +76,7 @@ impl Default for OrthographicCameraEntity {
..Default::default() ..Default::default()
}, },
orthographic_projection: Default::default(), orthographic_projection: Default::default(),
local_to_world: Default::default(), transform: Default::default(),
translation: Default::default(), translation: Default::default(),
rotation: Default::default(), rotation: Default::default(),
} }

View file

@ -430,7 +430,7 @@ pub fn mesh_resource_provider_system(resources: &mut Resources) -> Box<dyn Sched
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::{Mesh, VertexAttribute}; use super::{Mesh, VertexAttribute, AsVertexBufferDescriptor};
use crate::{pipeline::state_descriptors::PrimitiveTopology, shader::Uniforms, Vertex}; use crate::{pipeline::state_descriptors::PrimitiveTopology, shader::Uniforms, Vertex};
use bevy_core::bytes::AsBytes; use bevy_core::bytes::AsBytes;

View file

@ -52,7 +52,7 @@ impl SystemNode for CameraNode {
// PERF: this write on RenderResourceAssignments will prevent this system from running in parallel // PERF: this write on RenderResourceAssignments will prevent this system from running in parallel
// with other systems that do the same // with other systems that do the same
mut render_resource_assignments: ResMut<RenderResourceAssignments>, mut render_resource_assignments: ResMut<RenderResourceAssignments>,
query: &mut Query<(Read<Camera>, Read<LocalToWorld>)>| { query: &mut Query<(Read<Camera>, Read<Transform>)>| {
let render_resources = &render_resources.context; let render_resources = &render_resources.context;
if camera_buffer.is_none() { if camera_buffer.is_none() {
let size = std::mem::size_of::<[[f32; 4]; 4]>(); let size = std::mem::size_of::<[[f32; 4]; 4]>();
@ -72,12 +72,12 @@ impl SystemNode for CameraNode {
camera_buffer = Some(buffer); camera_buffer = Some(buffer);
} }
let matrix_size = std::mem::size_of::<[[f32; 4]; 4]>(); let matrix_size = std::mem::size_of::<[[f32; 4]; 4]>();
if let Some((camera, local_to_world)) = query if let Some((camera, transform)) = query
.iter(world) .iter(world)
.find(|(camera, _)| camera.name.as_ref().map(|n| n.as_str()) == Some(&uniform_name)) .find(|(camera, _)| camera.name.as_ref().map(|n| n.as_str()) == Some(&uniform_name))
{ {
let camera_matrix: [f32; 16] = let camera_matrix: [f32; 16] =
(camera.view_matrix * local_to_world.value).to_cols_array(); (camera.view_matrix * transform.value).to_cols_array();
let tmp_buffer = render_resources.create_buffer_mapped( let tmp_buffer = render_resources.create_buffer_mapped(
BufferInfo { BufferInfo {

View file

@ -14,19 +14,6 @@ use spirv_reflect::{
ShaderModule, ShaderModule,
}; };
use std::collections::HashSet; use std::collections::HashSet;
// use rspirv::{binary::Parser, dr::Loader, lift::LiftContext};
// TODO: use rspirv when structured representation is ready. this way we can remove spirv_reflect, which is a non-rust dependency
// pub fn get_shader_layout(spirv_data: &[u32]) {
// let mut loader = Loader::new(); // You can use your own consumer here.
// {
// let p = Parser::new(spirv_data.as_bytes(), &mut loader);
// p.parse().unwrap();
// }
// let module = loader.module();
// let structured = LiftContext::convert(&module).unwrap();
// println!("{:?}", structured.types);
// }
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
pub struct ShaderLayout { pub struct ShaderLayout {

View file

@ -5,16 +5,16 @@ use crate::{
use bevy_asset::Handle; use bevy_asset::Handle;
use bevy_core::bytes::Bytes; use bevy_core::bytes::Bytes;
static LOCAL_TO_WORLD_FIELD_INFOS: &[FieldInfo] = &[FieldInfo { static TRANSFORM_FIELD_INFOS: &[FieldInfo] = &[FieldInfo {
name: "object", name: "transform",
uniform_name: "Object", uniform_name: "Transform",
texture_name: "", texture_name: "",
sampler_name: "", sampler_name: "",
}]; }];
impl Uniforms for bevy_transform::prelude::LocalToWorld { impl Uniforms for bevy_transform::prelude::Transform {
fn get_field_infos() -> &'static [FieldInfo] { fn get_field_infos() -> &'static [FieldInfo] {
LOCAL_TO_WORLD_FIELD_INFOS TRANSFORM_FIELD_INFOS
} }
fn get_shader_defs(&self) -> Option<Vec<String>> { fn get_shader_defs(&self) -> Option<Vec<String>> {
@ -22,7 +22,7 @@ impl Uniforms for bevy_transform::prelude::LocalToWorld {
} }
fn get_field_bind_type(&self, name: &str) -> Option<FieldBindType> { fn get_field_bind_type(&self, name: &str) -> Option<FieldBindType> {
match name { match name {
"object" => self.value.get_bind_type(), "transform" => self.value.get_bind_type(),
_ => None, _ => None,
} }
} }
@ -32,13 +32,13 @@ impl Uniforms for bevy_transform::prelude::LocalToWorld {
fn write_uniform_bytes(&self, name: &str, buffer: &mut [u8]) { fn write_uniform_bytes(&self, name: &str, buffer: &mut [u8]) {
match name { match name {
"Object" => self.value.write_bytes(buffer), "Transform" => self.value.write_bytes(buffer),
_ => {} _ => {}
} }
} }
fn uniform_byte_len(&self, name: &str) -> usize { fn uniform_byte_len(&self, name: &str) -> usize {
match name { match name {
"Object" => self.value.byte_len(), "Transform" => self.value.byte_len(),
_ => 0, _ => 0,
} }
} }

View file

@ -1,3 +0,0 @@
mod local_to_world;
pub use local_to_world::*;

View file

@ -36,7 +36,7 @@ pub struct SpriteSheetEntity {
pub texture_atlas: Handle<TextureAtlas>, pub texture_atlas: Handle<TextureAtlas>,
pub renderable: Renderable, pub renderable: Renderable,
pub mesh: Handle<Mesh>, // TODO: maybe abstract this out pub mesh: Handle<Mesh>, // TODO: maybe abstract this out
// pub local_to_world: LocalToWorld, // pub transform: Transform,
// pub translation: Translation, // pub translation: Translation,
// pub rotation: Rotation, // pub rotation: Rotation,
// pub scale: Scale, // pub scale: Scale,
@ -52,7 +52,7 @@ impl Default for SpriteSheetEntity {
..Default::default() ..Default::default()
}, },
mesh: QUAD_HANDLE, mesh: QUAD_HANDLE,
// local_to_world: Default::default(), // transform: Default::default(),
// translation: Default::default(), // translation: Default::default(),
// rotation: Default::default(), // rotation: Default::default(),
// scale: Default::default(), // scale: Default::default(),

View file

@ -3,15 +3,15 @@
// extern crate test; // extern crate test;
// use legion::prelude::*; // use legion::prelude::*;
// use bevy_transform::{local_to_world_system, prelude::*}; // use bevy_transform::{transform_system, prelude::*};
// use test::Bencher; // use test::Bencher;
// #[bench] // #[bench]
// fn local_to_world_update_without_change(b: &mut Bencher) { // fn transform_update_without_change(b: &mut Bencher) {
// let _ = env_logger::builder().is_test(true).try_init(); // let _ = env_logger::builder().is_test(true).try_init();
// let mut world = Universe::new().create_world(); // let mut world = Universe::new().create_world();
// let system = local_to_world_system::build(&mut world); // let system = transform_system::build(&mut world);
// let ltw = LocalToWorld::identity(); // let ltw = LocalToWorld::identity();
// let t = Translation::new(1.0, 2.0, 3.0); // let t = Translation::new(1.0, 2.0, 3.0);

View file

@ -85,10 +85,10 @@ fn main() {}
// // At this point all `LocalToWorld` components have correct values in them. Running the system // // At this point all `LocalToWorld` components have correct values in them. Running the system
// // again will result in a short-circuit as only changed components are considered for update. // // again will result in a short-circuit as only changed components are considered for update.
// let mut query = <Read<LocalToWorld>>::query(); // let mut query = <Read<LocalToWorld>>::query();
// for (entity, local_to_world) in query.iter_entities(&mut world) { // for (entity, transform) in query.iter_entities(&mut world) {
// println!( // println!(
// "Entity {} and a LocalToWorld matrix: {}", // "Entity {} and a LocalToWorld matrix: {}",
// entity, *local_to_world // entity, *transform
// ); // );
// } // }
// } // }

View file

@ -5,21 +5,21 @@ use std::fmt;
#[derive(Shrinkwrap, Debug, PartialEq, Clone, Copy, Properties)] #[derive(Shrinkwrap, Debug, PartialEq, Clone, Copy, Properties)]
#[shrinkwrap(mutable)] #[shrinkwrap(mutable)]
pub struct LocalToParent(pub Mat4); pub struct LocalTransform(pub Mat4);
impl LocalToParent { impl LocalTransform {
pub fn identity() -> Self { pub fn identity() -> Self {
Self(Mat4::identity()) Self(Mat4::identity())
} }
} }
impl Default for LocalToParent { impl Default for LocalTransform {
fn default() -> Self { fn default() -> Self {
Self::identity() Self::identity()
} }
} }
impl fmt::Display for LocalToParent { impl fmt::Display for LocalTransform {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.0) write!(f, "{}", self.0)
} }

View file

@ -1,6 +1,6 @@
mod children; mod children;
mod local_to_parent; mod local_transform;
mod local_to_world; mod transform;
mod non_uniform_scale; mod non_uniform_scale;
mod parent; mod parent;
mod rotation; mod rotation;
@ -8,8 +8,8 @@ mod scale;
mod translation; mod translation;
pub use children::Children; pub use children::Children;
pub use local_to_parent::*; pub use local_transform::*;
pub use local_to_world::*; pub use transform::*;
pub use non_uniform_scale::*; pub use non_uniform_scale::*;
pub use parent::{Parent, PreviousParent}; pub use parent::{Parent, PreviousParent};
pub use rotation::*; pub use rotation::*;

View file

@ -3,17 +3,17 @@ use bevy_property::Properties;
use std::fmt; use std::fmt;
#[derive(Debug, PartialEq, Clone, Copy, Properties)] #[derive(Debug, PartialEq, Clone, Copy, Properties)]
pub struct LocalToWorld { pub struct Transform {
pub value: Mat4, pub value: Mat4,
pub sync: bool, // NOTE: this is hopefully a temporary measure to allow setting the transform directly. pub sync: bool, // NOTE: this is hopefully a temporary measure to allow setting the transform directly.
// ideally setting the transform automatically propagates back to position / translation / rotation, // ideally setting the transform automatically propagates back to position / translation / rotation,
// but right now they are always considered the source of truth // but right now they are always considered the source of truth
} }
impl LocalToWorld { impl Transform {
#[inline(always)] #[inline(always)]
pub fn identity() -> Self { pub fn identity() -> Self {
LocalToWorld { Transform {
value: Mat4::identity(), value: Mat4::identity(),
sync: true, sync: true,
} }
@ -21,7 +21,7 @@ impl LocalToWorld {
#[inline(always)] #[inline(always)]
pub fn new(value: Mat4) -> Self { pub fn new(value: Mat4) -> Self {
LocalToWorld { value, sync: true } Transform { value, sync: true }
} }
/// This creates a new `LocalToWorld` transform with the `sync` field set to `false`. /// This creates a new `LocalToWorld` transform with the `sync` field set to `false`.
@ -29,17 +29,17 @@ impl LocalToWorld {
/// This is helpful if you want to manually set the transform to a value (ex: Mat4::look_at_rh) /// This is helpful if you want to manually set the transform to a value (ex: Mat4::look_at_rh)
#[inline(always)] #[inline(always)]
pub fn new_sync_disabled(value: Mat4) -> Self { pub fn new_sync_disabled(value: Mat4) -> Self {
LocalToWorld { value, sync: false } Transform { value, sync: false }
} }
} }
impl Default for LocalToWorld { impl Default for Transform {
fn default() -> Self { fn default() -> Self {
Self::identity() Self::identity()
} }
} }
impl fmt::Display for LocalToWorld { impl fmt::Display for Transform {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.value) write!(f, "{}", self.value)
} }

View file

@ -4,13 +4,13 @@ pub use legion as ecs;
pub mod components; pub mod components;
pub mod hierarchy_maintenance_system; pub mod hierarchy_maintenance_system;
pub mod local_to_parent_system; pub mod local_to_parent_system;
pub mod local_to_world_propagate_system; pub mod transform_propagate_system;
pub mod local_to_world_system; pub mod transform_system;
pub mod transform_system_bundle; pub mod transform_system_bundle;
pub mod prelude { pub mod prelude {
pub use crate::{ pub use crate::{
components::*, hierarchy_maintenance_system, local_to_parent_system, components::*, hierarchy_maintenance_system, local_to_parent_system,
local_to_world_propagate_system, local_to_world_system, transform_system_bundle, transform_propagate_system, transform_system, transform_system_bundle,
}; };
} }

View file

@ -8,21 +8,21 @@ use crate::{
pub fn build(_: &mut World) -> Box<dyn Schedulable> { pub fn build(_: &mut World) -> Box<dyn Schedulable> {
SystemBuilder::<()>::new("LocalToParentUpdateSystem") SystemBuilder::<()>::new("LocalToParentUpdateSystem")
// Translation // Translation
.with_query(<(Write<LocalToParent>, Read<Translation>)>::query().filter( .with_query(<(Write<LocalTransform>, Read<Translation>)>::query().filter(
!component::<Rotation>() !component::<Rotation>()
& !component::<Scale>() & !component::<Scale>()
& !component::<NonUniformScale>() & !component::<NonUniformScale>()
& (changed::<Translation>()), & (changed::<Translation>()),
)) ))
// Rotation // Rotation
.with_query(<(Write<LocalToParent>, Read<Rotation>)>::query().filter( .with_query(<(Write<LocalTransform>, Read<Rotation>)>::query().filter(
!component::<Translation>() !component::<Translation>()
& !component::<Scale>() & !component::<Scale>()
& !component::<NonUniformScale>() & !component::<NonUniformScale>()
& (changed::<Rotation>()), & (changed::<Rotation>()),
)) ))
// Scale // Scale
.with_query(<(Write<LocalToParent>, Read<Scale>)>::query().filter( .with_query(<(Write<LocalTransform>, Read<Scale>)>::query().filter(
!component::<Translation>() !component::<Translation>()
& !component::<Rotation>() & !component::<Rotation>()
& !component::<NonUniformScale>() & !component::<NonUniformScale>()
@ -30,7 +30,7 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
)) ))
// NonUniformScale // NonUniformScale
.with_query( .with_query(
<(Write<LocalToParent>, Read<NonUniformScale>)>::query().filter( <(Write<LocalTransform>, Read<NonUniformScale>)>::query().filter(
!component::<Translation>() !component::<Translation>()
& !component::<Rotation>() & !component::<Rotation>()
& !component::<Scale>() & !component::<Scale>()
@ -39,7 +39,7 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
) )
// Translation + Rotation // Translation + Rotation
.with_query( .with_query(
<(Write<LocalToParent>, Read<Translation>, Read<Rotation>)>::query().filter( <(Write<LocalTransform>, Read<Translation>, Read<Rotation>)>::query().filter(
!component::<Scale>() !component::<Scale>()
& !component::<NonUniformScale>() & !component::<NonUniformScale>()
& (changed::<Translation>() | changed::<Rotation>()), & (changed::<Translation>() | changed::<Rotation>()),
@ -47,7 +47,7 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
) )
// Translation + Scale // Translation + Scale
.with_query( .with_query(
<(Write<LocalToParent>, Read<Translation>, Read<Scale>)>::query().filter( <(Write<LocalTransform>, Read<Translation>, Read<Scale>)>::query().filter(
!component::<Rotation>() !component::<Rotation>()
& !component::<NonUniformScale>() & !component::<NonUniformScale>()
& (changed::<Translation>() | changed::<Scale>()), & (changed::<Translation>() | changed::<Scale>()),
@ -56,7 +56,7 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
// Translation + NonUniformScale // Translation + NonUniformScale
.with_query( .with_query(
<( <(
Write<LocalToParent>, Write<LocalTransform>,
Read<Translation>, Read<Translation>,
Read<NonUniformScale>, Read<NonUniformScale>,
)>::query() )>::query()
@ -68,7 +68,7 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
) )
// Rotation + Scale // Rotation + Scale
.with_query( .with_query(
<(Write<LocalToParent>, Read<Rotation>, Read<Scale>)>::query().filter( <(Write<LocalTransform>, Read<Rotation>, Read<Scale>)>::query().filter(
!component::<Translation>() !component::<Translation>()
& !component::<NonUniformScale>() & !component::<NonUniformScale>()
& (changed::<Rotation>() | changed::<Scale>()), & (changed::<Rotation>() | changed::<Scale>()),
@ -76,7 +76,7 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
) )
// Rotation + NonUniformScale // Rotation + NonUniformScale
.with_query( .with_query(
<(Write<LocalToParent>, Read<Rotation>, Read<NonUniformScale>)>::query().filter( <(Write<LocalTransform>, Read<Rotation>, Read<NonUniformScale>)>::query().filter(
!component::<Translation>() !component::<Translation>()
& !component::<Scale>() & !component::<Scale>()
& (changed::<Rotation>() | changed::<NonUniformScale>()), & (changed::<Rotation>() | changed::<NonUniformScale>()),
@ -85,7 +85,7 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
// Translation + Rotation + Scale // Translation + Rotation + Scale
.with_query( .with_query(
<( <(
Write<LocalToParent>, Write<LocalTransform>,
Read<Translation>, Read<Translation>,
Read<Rotation>, Read<Rotation>,
Read<Scale>, Read<Scale>,
@ -98,7 +98,7 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
// Translation + Rotation + NonUniformScale // Translation + Rotation + NonUniformScale
.with_query( .with_query(
<( <(
Write<LocalToParent>, Write<LocalTransform>,
Read<Translation>, Read<Translation>,
Read<Rotation>, Read<Rotation>,
Read<NonUniformScale>, Read<NonUniformScale>,
@ -111,38 +111,38 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
), ),
) )
// Just to issue warnings: Scale + NonUniformScale // Just to issue warnings: Scale + NonUniformScale
.with_query(<(Read<LocalToParent>, Read<Scale>, Read<NonUniformScale>)>::query()) .with_query(<(Read<LocalTransform>, Read<Scale>, Read<NonUniformScale>)>::query())
.build(move |_commands, world, _, queries| { .build(move |_commands, world, _, queries| {
let (a, b, c, d, e, f, g, h, i, j, k, l) = queries; let (a, b, c, d, e, f, g, h, i, j, k, l) = queries;
rayon::scope(|s| { rayon::scope(|s| {
s.spawn(|_| unsafe { s.spawn(|_| unsafe {
// Translation // Translation
a.for_each_unchecked(world, |(mut ltw, translation)| { a.for_each_unchecked(world, |(mut ltw, translation)| {
*ltw = LocalToParent(Mat4::from_translation(translation.0)); *ltw = LocalTransform(Mat4::from_translation(translation.0));
}); });
}); });
s.spawn(|_| unsafe { s.spawn(|_| unsafe {
// Rotation // Rotation
b.for_each_unchecked(world, |(mut ltw, rotation)| { b.for_each_unchecked(world, |(mut ltw, rotation)| {
*ltw = LocalToParent(Mat4::from_quat(rotation.0)); *ltw = LocalTransform(Mat4::from_quat(rotation.0));
}); });
}); });
s.spawn(|_| unsafe { s.spawn(|_| unsafe {
// Scale // Scale
c.for_each_unchecked(world, |(mut ltw, scale)| { c.for_each_unchecked(world, |(mut ltw, scale)| {
*ltw = *ltw =
LocalToParent(Mat4::from_scale(Vec3::new(scale.0, scale.0, scale.0))); LocalTransform(Mat4::from_scale(Vec3::new(scale.0, scale.0, scale.0)));
}); });
}); });
s.spawn(|_| unsafe { s.spawn(|_| unsafe {
// NonUniformScale // NonUniformScale
d.for_each_unchecked(world, |(mut ltw, non_uniform_scale)| { d.for_each_unchecked(world, |(mut ltw, non_uniform_scale)| {
*ltw = LocalToParent(Mat4::from_scale(non_uniform_scale.0)); *ltw = LocalTransform(Mat4::from_scale(non_uniform_scale.0));
}); });
// Translation + Rotation // Translation + Rotation
e.for_each_unchecked(world, |(mut ltw, translation, rotation)| { e.for_each_unchecked(world, |(mut ltw, translation, rotation)| {
*ltw = LocalToParent(Mat4::from_rotation_translation( *ltw = LocalTransform(Mat4::from_rotation_translation(
rotation.0, rotation.0,
translation.0, translation.0,
)); ));
@ -151,7 +151,7 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
s.spawn(|_| unsafe { s.spawn(|_| unsafe {
// Translation + Scale // Translation + Scale
f.for_each_unchecked(world, |(mut ltw, translation, scale)| { f.for_each_unchecked(world, |(mut ltw, translation, scale)| {
*ltw = LocalToParent(Mat4::from_scale_rotation_translation( *ltw = LocalTransform(Mat4::from_scale_rotation_translation(
Vec3::new(scale.0, scale.0, scale.0), Vec3::new(scale.0, scale.0, scale.0),
Quat::default(), Quat::default(),
translation.0, translation.0,
@ -160,7 +160,7 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
// Translation + NonUniformScale // Translation + NonUniformScale
g.for_each_unchecked(world, |(mut ltw, translation, non_uniform_scale)| { g.for_each_unchecked(world, |(mut ltw, translation, non_uniform_scale)| {
*ltw = LocalToParent(Mat4::from_scale_rotation_translation( *ltw = LocalTransform(Mat4::from_scale_rotation_translation(
non_uniform_scale.0, non_uniform_scale.0,
Quat::default(), Quat::default(),
translation.0, translation.0,
@ -170,7 +170,7 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
s.spawn(|_| unsafe { s.spawn(|_| unsafe {
// Rotation + Scale // Rotation + Scale
h.for_each_unchecked(world, |(mut ltw, rotation, scale)| { h.for_each_unchecked(world, |(mut ltw, rotation, scale)| {
*ltw = LocalToParent(Mat4::from_scale_rotation_translation( *ltw = LocalTransform(Mat4::from_scale_rotation_translation(
Vec3::new(scale.0, scale.0, scale.0), Vec3::new(scale.0, scale.0, scale.0),
rotation.0, rotation.0,
Vec3::default(), Vec3::default(),
@ -180,7 +180,7 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
s.spawn(|_| unsafe { s.spawn(|_| unsafe {
// Rotation + NonUniformScale // Rotation + NonUniformScale
i.for_each_unchecked(world, |(mut ltw, rotation, non_uniform_scale)| { i.for_each_unchecked(world, |(mut ltw, rotation, non_uniform_scale)| {
*ltw = LocalToParent(Mat4::from_scale_rotation_translation( *ltw = LocalTransform(Mat4::from_scale_rotation_translation(
non_uniform_scale.0, non_uniform_scale.0,
rotation.0, rotation.0,
Vec3::default(), Vec3::default(),
@ -190,7 +190,7 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
s.spawn(|_| unsafe { s.spawn(|_| unsafe {
// Translation + Rotation + Scale // Translation + Rotation + Scale
j.for_each_unchecked(world, |(mut ltw, translation, rotation, scale)| { j.for_each_unchecked(world, |(mut ltw, translation, rotation, scale)| {
*ltw = LocalToParent(Mat4::from_scale_rotation_translation( *ltw = LocalTransform(Mat4::from_scale_rotation_translation(
Vec3::new(scale.0, scale.0, scale.0), Vec3::new(scale.0, scale.0, scale.0),
rotation.0, rotation.0,
translation.0, translation.0,
@ -202,7 +202,7 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
k.for_each_unchecked( k.for_each_unchecked(
world, world,
|(mut ltw, translation, rotation, non_uniform_scale)| { |(mut ltw, translation, rotation, non_uniform_scale)| {
*ltw = LocalToParent(Mat4::from_scale_rotation_translation( *ltw = LocalTransform(Mat4::from_scale_rotation_translation(
non_uniform_scale.0, non_uniform_scale.0,
rotation.0, rotation.0,
translation.0, translation.0,

View file

@ -8,9 +8,9 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
SystemBuilder::<()>::new("LocalToWorldPropagateSystem") SystemBuilder::<()>::new("LocalToWorldPropagateSystem")
// Entities with a `Children` and `LocalToWorld` but NOT a `Parent` (ie those that are // Entities with a `Children` and `LocalToWorld` but NOT a `Parent` (ie those that are
// roots of a hierarchy). // roots of a hierarchy).
.with_query(<(Read<Children>, Read<LocalToWorld>)>::query().filter(!component::<Parent>())) .with_query(<(Read<Children>, Read<Transform>)>::query().filter(!component::<Parent>()))
.read_component::<Children>() .read_component::<Children>()
.read_component::<LocalToParent>() .read_component::<LocalTransform>()
.build(move |commands, world, _resource, query| { .build(move |commands, world, _resource, query| {
for (children, local_to_world) in query.iter(world) { for (children, local_to_world) in query.iter(world) {
for child in children.0.iter() { for child in children.0.iter() {
@ -21,14 +21,14 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
} }
fn propagate_recursive( fn propagate_recursive(
parent_local_to_world: LocalToWorld, parent_local_to_world: Transform,
world: &mut SubWorld, world: &mut SubWorld,
entity: Entity, entity: Entity,
commands: &mut CommandBuffer, commands: &mut CommandBuffer,
) { ) {
log::trace!("Updating LocalToWorld for {}", entity); log::trace!("Updating LocalToWorld for {}", entity);
let local_to_parent = { let local_to_parent = {
if let Some(local_to_parent) = world.get_component::<LocalToParent>(entity) { if let Some(local_to_parent) = world.get_component::<LocalTransform>(entity) {
*local_to_parent *local_to_parent
} else { } else {
log::warn!( log::warn!(
@ -39,7 +39,7 @@ fn propagate_recursive(
} }
}; };
let new_local_to_world = LocalToWorld { let new_local_to_world = Transform {
value: parent_local_to_world.value * local_to_parent.0, value: parent_local_to_world.value * local_to_parent.0,
sync: true, sync: true,
}; };

View file

@ -8,7 +8,7 @@ use crate::{
pub fn build(_: &mut World) -> Box<dyn Schedulable> { pub fn build(_: &mut World) -> Box<dyn Schedulable> {
SystemBuilder::<()>::new("LocalToWorldUpdateSystem") SystemBuilder::<()>::new("LocalToWorldUpdateSystem")
// Translation // Translation
.with_query(<(Write<LocalToWorld>, Read<Translation>)>::query().filter( .with_query(<(Write<Transform>, Read<Translation>)>::query().filter(
!component::<Parent>() !component::<Parent>()
& !component::<Rotation>() & !component::<Rotation>()
& !component::<Scale>() & !component::<Scale>()
@ -16,7 +16,7 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
& (changed::<Translation>()), & (changed::<Translation>()),
)) ))
// Rotation // Rotation
.with_query(<(Write<LocalToWorld>, Read<Rotation>)>::query().filter( .with_query(<(Write<Transform>, Read<Rotation>)>::query().filter(
!component::<Parent>() !component::<Parent>()
& !component::<Translation>() & !component::<Translation>()
& !component::<Scale>() & !component::<Scale>()
@ -24,7 +24,7 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
& (changed::<Rotation>()), & (changed::<Rotation>()),
)) ))
// Scale // Scale
.with_query(<(Write<LocalToWorld>, Read<Scale>)>::query().filter( .with_query(<(Write<Transform>, Read<Scale>)>::query().filter(
!component::<Parent>() !component::<Parent>()
& !component::<Translation>() & !component::<Translation>()
& !component::<Rotation>() & !component::<Rotation>()
@ -33,7 +33,7 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
)) ))
// NonUniformScale // NonUniformScale
.with_query( .with_query(
<(Write<LocalToWorld>, Read<NonUniformScale>)>::query().filter( <(Write<Transform>, Read<NonUniformScale>)>::query().filter(
!component::<Parent>() !component::<Parent>()
& !component::<Translation>() & !component::<Translation>()
& !component::<Rotation>() & !component::<Rotation>()
@ -43,7 +43,7 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
) )
// Translation + Rotation // Translation + Rotation
.with_query( .with_query(
<(Write<LocalToWorld>, Read<Translation>, Read<Rotation>)>::query().filter( <(Write<Transform>, Read<Translation>, Read<Rotation>)>::query().filter(
!component::<Parent>() !component::<Parent>()
& !component::<Scale>() & !component::<Scale>()
& !component::<NonUniformScale>() & !component::<NonUniformScale>()
@ -52,7 +52,7 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
) )
// Translation + Scale // Translation + Scale
.with_query( .with_query(
<(Write<LocalToWorld>, Read<Translation>, Read<Scale>)>::query().filter( <(Write<Transform>, Read<Translation>, Read<Scale>)>::query().filter(
!component::<Parent>() !component::<Parent>()
& !component::<Rotation>() & !component::<Rotation>()
& !component::<NonUniformScale>() & !component::<NonUniformScale>()
@ -62,7 +62,7 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
// Translation + NonUniformScale // Translation + NonUniformScale
.with_query( .with_query(
<( <(
Write<LocalToWorld>, Write<Transform>,
Read<Translation>, Read<Translation>,
Read<NonUniformScale>, Read<NonUniformScale>,
)>::query() )>::query()
@ -75,7 +75,7 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
) )
// Rotation + Scale // Rotation + Scale
.with_query( .with_query(
<(Write<LocalToWorld>, Read<Rotation>, Read<Scale>)>::query().filter( <(Write<Transform>, Read<Rotation>, Read<Scale>)>::query().filter(
!component::<Parent>() !component::<Parent>()
& !component::<Translation>() & !component::<Translation>()
& !component::<NonUniformScale>() & !component::<NonUniformScale>()
@ -84,7 +84,7 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
) )
// Rotation + NonUniformScale // Rotation + NonUniformScale
.with_query( .with_query(
<(Write<LocalToWorld>, Read<Rotation>, Read<NonUniformScale>)>::query().filter( <(Write<Transform>, Read<Rotation>, Read<NonUniformScale>)>::query().filter(
!component::<Parent>() !component::<Parent>()
& !component::<Translation>() & !component::<Translation>()
& !component::<Scale>() & !component::<Scale>()
@ -94,7 +94,7 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
// Translation + Rotation + Scale // Translation + Rotation + Scale
.with_query( .with_query(
<( <(
Write<LocalToWorld>, Write<Transform>,
Read<Translation>, Read<Translation>,
Read<Rotation>, Read<Rotation>,
Read<Scale>, Read<Scale>,
@ -108,7 +108,7 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
// Translation + Rotation + NonUniformScale // Translation + Rotation + NonUniformScale
.with_query( .with_query(
<( <(
Write<LocalToWorld>, Write<Transform>,
Read<Translation>, Read<Translation>,
Read<Rotation>, Read<Rotation>,
Read<NonUniformScale>, Read<NonUniformScale>,
@ -123,7 +123,7 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
) )
// Just to issue warnings: Scale + NonUniformScale // Just to issue warnings: Scale + NonUniformScale
.with_query( .with_query(
<(Read<LocalToWorld>, Read<Scale>, Read<NonUniformScale>)>::query() <(Read<Transform>, Read<Scale>, Read<NonUniformScale>)>::query()
.filter(!component::<Parent>()), .filter(!component::<Parent>()),
) )
.build(move |_commands, world, _, queries| { .build(move |_commands, world, _, queries| {
@ -135,7 +135,7 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
if !ltw.sync { if !ltw.sync {
return; return;
} }
*ltw = LocalToWorld::new(Mat4::from_translation(translation.0)); *ltw = Transform::new(Mat4::from_translation(translation.0));
}); });
}); });
s.spawn(|_| unsafe { s.spawn(|_| unsafe {
@ -144,7 +144,7 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
if !ltw.sync { if !ltw.sync {
return; return;
} }
*ltw = LocalToWorld::new(Mat4::from_quat(rotation.0)); *ltw = Transform::new(Mat4::from_quat(rotation.0));
}); });
}); });
s.spawn(|_| unsafe { s.spawn(|_| unsafe {
@ -153,7 +153,7 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
if !ltw.sync { if !ltw.sync {
return; return;
} }
*ltw = LocalToWorld::new(Mat4::from_scale(Vec3::new( *ltw = Transform::new(Mat4::from_scale(Vec3::new(
scale.0, scale.0, scale.0, scale.0, scale.0, scale.0,
))); )));
}); });
@ -164,7 +164,7 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
if !ltw.sync { if !ltw.sync {
return; return;
} }
*ltw = LocalToWorld::new(Mat4::from_scale(non_uniform_scale.0)); *ltw = Transform::new(Mat4::from_scale(non_uniform_scale.0));
}); });
}); });
s.spawn(|_| unsafe { s.spawn(|_| unsafe {
@ -173,7 +173,7 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
if !ltw.sync { if !ltw.sync {
return; return;
} }
*ltw = LocalToWorld::new(Mat4::from_rotation_translation( *ltw = Transform::new(Mat4::from_rotation_translation(
rotation.0, rotation.0,
translation.0, translation.0,
)); ));
@ -185,7 +185,7 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
if !ltw.sync { if !ltw.sync {
return; return;
} }
*ltw = LocalToWorld::new(Mat4::from_scale_rotation_translation( *ltw = Transform::new(Mat4::from_scale_rotation_translation(
Vec3::new(scale.0, scale.0, scale.0), Vec3::new(scale.0, scale.0, scale.0),
Quat::default(), Quat::default(),
translation.0, translation.0,
@ -198,7 +198,7 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
if !ltw.sync { if !ltw.sync {
return; return;
} }
*ltw = LocalToWorld::new(Mat4::from_scale_rotation_translation( *ltw = Transform::new(Mat4::from_scale_rotation_translation(
non_uniform_scale.0, non_uniform_scale.0,
Quat::default(), Quat::default(),
translation.0, translation.0,
@ -211,7 +211,7 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
if !ltw.sync { if !ltw.sync {
return; return;
} }
*ltw = LocalToWorld::new(Mat4::from_scale_rotation_translation( *ltw = Transform::new(Mat4::from_scale_rotation_translation(
Vec3::new(scale.0, scale.0, scale.0), Vec3::new(scale.0, scale.0, scale.0),
rotation.0, rotation.0,
Vec3::default(), Vec3::default(),
@ -224,7 +224,7 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
if !ltw.sync { if !ltw.sync {
return; return;
} }
*ltw = LocalToWorld::new(Mat4::from_scale_rotation_translation( *ltw = Transform::new(Mat4::from_scale_rotation_translation(
non_uniform_scale.0, non_uniform_scale.0,
rotation.0, rotation.0,
Vec3::default(), Vec3::default(),
@ -237,7 +237,7 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
if !ltw.sync { if !ltw.sync {
return; return;
} }
*ltw = LocalToWorld::new(Mat4::from_scale_rotation_translation( *ltw = Transform::new(Mat4::from_scale_rotation_translation(
Vec3::new(scale.0, scale.0, scale.0), Vec3::new(scale.0, scale.0, scale.0),
rotation.0, rotation.0,
translation.0, translation.0,
@ -252,7 +252,7 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
if !ltw.sync { if !ltw.sync {
return; return;
} }
*ltw = LocalToWorld::new(Mat4::from_scale_rotation_translation( *ltw = Transform::new(Mat4::from_scale_rotation_translation(
non_uniform_scale.0, non_uniform_scale.0,
rotation.0, rotation.0,
translation.0, translation.0,

View file

@ -1,6 +1,6 @@
use crate::{ use crate::{
ecs::prelude::*, hierarchy_maintenance_system, local_to_parent_system, ecs::prelude::*, hierarchy_maintenance_system, local_to_parent_system,
local_to_world_propagate_system, local_to_world_system, transform_propagate_system, transform_system,
}; };
pub fn build(world: &mut World) -> Vec<Box<dyn Schedulable>> { pub fn build(world: &mut World) -> Vec<Box<dyn Schedulable>> {
@ -8,13 +8,13 @@ pub fn build(world: &mut World) -> Vec<Box<dyn Schedulable>> {
let mut hierarchy_maintenance_systems = hierarchy_maintenance_system::build(world); let mut hierarchy_maintenance_systems = hierarchy_maintenance_system::build(world);
let local_to_parent_system = local_to_parent_system::build(world); let local_to_parent_system = local_to_parent_system::build(world);
let local_to_world_system = local_to_world_system::build(world); let transform_system = transform_system::build(world);
let local_to_world_propagate_system = local_to_world_propagate_system::build(world); let transform_propagate_system = transform_propagate_system::build(world);
all_systems.append(&mut hierarchy_maintenance_systems); all_systems.append(&mut hierarchy_maintenance_systems);
all_systems.push(local_to_parent_system); all_systems.push(local_to_parent_system);
all_systems.push(local_to_world_system); all_systems.push(transform_system);
all_systems.push(local_to_world_propagate_system); all_systems.push(transform_propagate_system);
all_systems all_systems
} }

View file

@ -50,7 +50,7 @@ fn setup(
}) })
// camera // camera
.add_entity(PerspectiveCameraEntity { .add_entity(PerspectiveCameraEntity {
local_to_world: LocalToWorld::new_sync_disabled(Mat4::look_at_rh( transform: Transform::new_sync_disabled(Mat4::look_at_rh(
Vec3::new(3.0, 8.0, 5.0), Vec3::new(3.0, 8.0, 5.0),
Vec3::new(0.0, 0.0, 0.0), Vec3::new(0.0, 0.0, 0.0),
Vec3::new(0.0, 0.0, 1.0), Vec3::new(0.0, 0.0, 1.0),

View file

@ -39,7 +39,7 @@ fn setup(
}) })
// camera // camera
.add_entity(PerspectiveCameraEntity { .add_entity(PerspectiveCameraEntity {
local_to_world: LocalToWorld::new_sync_disabled(Mat4::look_at_rh( transform: Transform::new_sync_disabled(Mat4::look_at_rh(
Vec3::new(2.0, -6.0, 2.0), Vec3::new(2.0, -6.0, 2.0),
Vec3::new(0.0, 0.0, 0.0), Vec3::new(0.0, 0.0, 0.0),
Vec3::new(0.0, 0.0, 1.0), Vec3::new(0.0, 0.0, 1.0),

View file

@ -53,7 +53,7 @@ fn setup(
}) })
// camera // camera
.add_entity(PerspectiveCameraEntity { .add_entity(PerspectiveCameraEntity {
local_to_world: LocalToWorld::new_sync_disabled(Mat4::look_at_rh( transform: Transform::new_sync_disabled(Mat4::look_at_rh(
Vec3::new(5.0, 10.0, 10.0), Vec3::new(5.0, 10.0, 10.0),
Vec3::new(0.0, 0.0, 0.0), Vec3::new(0.0, 0.0, 0.0),
Vec3::new(0.0, 0.0, 1.0), Vec3::new(0.0, 0.0, 1.0),

View file

@ -63,7 +63,7 @@ fn setup(
}) })
// camera // camera
.add_entity(PerspectiveCameraEntity { .add_entity(PerspectiveCameraEntity {
local_to_world: LocalToWorld::new_sync_disabled(Mat4::look_at_rh( transform: Transform::new_sync_disabled(Mat4::look_at_rh(
Vec3::new(3.0, 8.0, 5.0), Vec3::new(3.0, 8.0, 5.0),
Vec3::new(0.0, 0.0, 0.0), Vec3::new(0.0, 0.0, 0.0),
Vec3::new(0.0, 0.0, 1.0), Vec3::new(0.0, 0.0, 1.0),

View file

@ -67,7 +67,7 @@ fn setup(
}) })
// camera // camera
.add_entity(PerspectiveCameraEntity { .add_entity(PerspectiveCameraEntity {
local_to_world: LocalToWorld::new_sync_disabled(Mat4::look_at_rh( transform: Transform::new_sync_disabled(Mat4::look_at_rh(
Vec3::new(3.0, -8.0, 5.0), Vec3::new(3.0, -8.0, 5.0),
Vec3::new(0.0, 0.0, 0.0), Vec3::new(0.0, 0.0, 0.0),
Vec3::new(0.0, 0.0, 1.0), Vec3::new(0.0, 0.0, 1.0),

View file

@ -35,7 +35,7 @@ fn setup(
}) })
// camera // camera
.add_entity(PerspectiveCameraEntity { .add_entity(PerspectiveCameraEntity {
local_to_world: LocalToWorld::new_sync_disabled(Mat4::look_at_rh( transform: Transform::new_sync_disabled(Mat4::look_at_rh(
Vec3::new(3.0, 8.0, 5.0), Vec3::new(3.0, 8.0, 5.0),
Vec3::new(0.0, 0.0, 0.0), Vec3::new(0.0, 0.0, 0.0),
Vec3::new(0.0, 0.0, 1.0), Vec3::new(0.0, 0.0, 1.0),

View file

@ -72,7 +72,7 @@ fn setup(
}) })
// camera // camera
.add_entity(PerspectiveCameraEntity { .add_entity(PerspectiveCameraEntity {
local_to_world: LocalToWorld::new_sync_disabled(Mat4::look_at_rh( transform: Transform::new_sync_disabled(Mat4::look_at_rh(
Vec3::new(0.0, -10.0, 3.0), Vec3::new(0.0, -10.0, 3.0),
Vec3::new(0.0, 0.0, 0.0), Vec3::new(0.0, 0.0, 0.0),
Vec3::new(0.0, 0.0, 1.0), Vec3::new(0.0, 0.0, 1.0),

View file

@ -47,7 +47,7 @@ fn setup(
}) })
// camera // camera
.add_entity(PerspectiveCameraEntity { .add_entity(PerspectiveCameraEntity {
local_to_world: LocalToWorld::new_sync_disabled(Mat4::look_at_rh( transform: Transform::new_sync_disabled(Mat4::look_at_rh(
Vec3::new(2.0, -6.0, 2.0), Vec3::new(2.0, -6.0, 2.0),
Vec3::new(0.0, 0.0, 0.0), Vec3::new(0.0, 0.0, 0.0),
Vec3::new(0.0, 0.0, 1.0), Vec3::new(0.0, 0.0, 1.0),

View file

@ -19,7 +19,7 @@ layout(location = 0) in vec3 Vertex_Position;
layout(set = 0, binding = 0) uniform Camera { layout(set = 0, binding = 0) uniform Camera {
mat4 ViewProj; mat4 ViewProj;
}; };
layout(set = 1, binding = 0) uniform Object { layout(set = 1, binding = 0) uniform Transform {
mat4 Model; mat4 Model;
}; };
void main() { void main() {
@ -83,7 +83,7 @@ fn setup(
}) })
// camera // camera
.add_entity(PerspectiveCameraEntity { .add_entity(PerspectiveCameraEntity {
local_to_world: LocalToWorld::new_sync_disabled(Mat4::look_at_rh( transform: Transform::new_sync_disabled(Mat4::look_at_rh(
Vec3::new(3.0, 8.0, 5.0), Vec3::new(3.0, 8.0, 5.0),
Vec3::new(0.0, 0.0, 0.0), Vec3::new(0.0, 0.0, 0.0),
Vec3::new(0.0, 0.0, 1.0), Vec3::new(0.0, 0.0, 1.0),

View file

@ -25,7 +25,7 @@ layout(location = 0) in vec3 Vertex_Position;
layout(set = 0, binding = 0) uniform Camera { layout(set = 0, binding = 0) uniform Camera {
mat4 ViewProj; mat4 ViewProj;
}; };
layout(set = 1, binding = 0) uniform Object { layout(set = 1, binding = 0) uniform Transform {
mat4 Model; mat4 Model;
}; };
void main() { void main() {
@ -110,7 +110,7 @@ fn setup(
}) })
// camera // camera
.add_entity(PerspectiveCameraEntity { .add_entity(PerspectiveCameraEntity {
local_to_world: LocalToWorld::new_sync_disabled(Mat4::look_at_rh( transform: Transform::new_sync_disabled(Mat4::look_at_rh(
Vec3::new(3.0, 8.0, 5.0), Vec3::new(3.0, 8.0, 5.0),
Vec3::new(0.0, 0.0, 0.0), Vec3::new(0.0, 0.0, 0.0),
Vec3::new(0.0, 0.0, 1.0), Vec3::new(0.0, 0.0, 1.0),

View file

@ -50,7 +50,7 @@ fn setup(
// }) // })
// // 3d camera // // 3d camera
// .add_entity(CameraEntity { // .add_entity(CameraEntity {
// local_to_world: LocalToWorld(Mat4::look_at_rh( // transform: Transform(Mat4::look_at_rh(
// Vec3::new(3.0, 8.0, 5.0), // Vec3::new(3.0, 8.0, 5.0),
// Vec3::new(0.0, 0.0, 0.0), // Vec3::new(0.0, 0.0, 0.0),
// Vec3::new(0.0, 0.0, 1.0), // Vec3::new(0.0, 0.0, 1.0),

View file

@ -25,7 +25,7 @@ pub use crate::{
}, },
RenderGraph, RenderGraph,
}, },
shader::{Shader, ShaderDefSuffixProvider, ShaderStage, ShaderStages}, shader::{Shader, ShaderDefSuffixProvider, ShaderStage, ShaderStages, Uniforms},
texture::Texture, texture::Texture,
Camera, Color, ColorSource, OrthographicProjection, PerspectiveProjection, Renderable, Camera, Color, ColorSource, OrthographicProjection, PerspectiveProjection, Renderable,
}, },