mirror of
https://github.com/storytold/storyteller-bevy.git
synced 2026-11-02 18:08:19 +00:00
Perf improvement
This commit is contained in:
@@ -5,6 +5,8 @@ use bevy::{
|
|||||||
render::render_resource::{AsBindGroup, ShaderRef},
|
render::render_resource::{AsBindGroup, ShaderRef},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use crate::orbit_cam::{self, OrbitCam};
|
||||||
|
|
||||||
pub struct TestScenePlugin;
|
pub struct TestScenePlugin;
|
||||||
|
|
||||||
impl Plugin for TestScenePlugin {
|
impl Plugin for TestScenePlugin {
|
||||||
@@ -14,10 +16,17 @@ impl Plugin for TestScenePlugin {
|
|||||||
prepass_enabled: true,
|
prepass_enabled: true,
|
||||||
..default()
|
..default()
|
||||||
})
|
})
|
||||||
.add_systems(Startup, spawn_scene);
|
.add_systems(Startup, spawn_scene)
|
||||||
|
.add_systems(
|
||||||
|
Update,
|
||||||
|
move_plane_with_camera.after(orbit_cam::pan_orbit_camera),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
struct WorldGridPlane;
|
||||||
|
|
||||||
fn spawn_scene(
|
fn spawn_scene(
|
||||||
mut cmd: Commands,
|
mut cmd: Commands,
|
||||||
mut meshes: ResMut<Assets<Mesh>>,
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
@@ -53,16 +62,28 @@ fn spawn_scene(
|
|||||||
cmd.spawn((
|
cmd.spawn((
|
||||||
MaterialMeshBundle {
|
MaterialMeshBundle {
|
||||||
mesh: meshes.add(Mesh::from(shape::Plane {
|
mesh: meshes.add(Mesh::from(shape::Plane {
|
||||||
size: 10_000.0,
|
size: 200.0,
|
||||||
subdivisions: 0,
|
subdivisions: 0,
|
||||||
})),
|
})),
|
||||||
material: mat_proc_grid.add(ProceduralGridMaterial {}),
|
material: mat_proc_grid.add(ProceduralGridMaterial {}),
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
NotShadowCaster,
|
NotShadowCaster,
|
||||||
|
WorldGridPlane,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn move_plane_with_camera(
|
||||||
|
mut plane: Query<(&WorldGridPlane, &mut Transform)>,
|
||||||
|
camera: Query<&OrbitCam>,
|
||||||
|
) {
|
||||||
|
let &OrbitCam { focus, .. } = camera.single();
|
||||||
|
let (_, mut xform) = plane.single_mut();
|
||||||
|
|
||||||
|
xform.translation.x = focus.x;
|
||||||
|
xform.translation.z = focus.z;
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(AsBindGroup, Clone, TypePath, TypeUuid)]
|
#[derive(AsBindGroup, Clone, TypePath, TypeUuid)]
|
||||||
#[uuid = "CE331A13-F247-4F5B-A75E-670B2BD5776A"]
|
#[uuid = "CE331A13-F247-4F5B-A75E-670B2BD5776A"]
|
||||||
struct ProceduralGridMaterial {}
|
struct ProceduralGridMaterial {}
|
||||||
|
|||||||
Reference in New Issue
Block a user