Skip to content

Commit

Permalink
feat: multi timestep schedule layer
Browse files Browse the repository at this point in the history
  • Loading branch information
ten3roberts committed Nov 3, 2024
1 parent 33654f1 commit 600bd09
Show file tree
Hide file tree
Showing 18 changed files with 376 additions and 102 deletions.
7 changes: 5 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ serde = [
"ivy-core/serde",
"ivy-physics/serde",
"ivy-wgpu/serde",
"ivy-wgpu-types/serde",
"ivy-assets/serde",
]
profile = [ "ivy-core/profile" ]
Expand Down
9 changes: 6 additions & 3 deletions examples/physics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ use ivy_physics::{ColliderBundle, PhysicsPlugin};
use ivy_postprocessing::preconfigured::{SurfacePbrPipeline, SurfacePbrPipelineDesc};
use ivy_wgpu::{
components::{
cast_shadow, environment_data, forward_pass, light_data, light_kind, projection_matrix,
cast_shadow, environment_data, forward_pass, light_kind, light_params, projection_matrix,
},
driver::WinitDriver,
events::ResizedEvent,
layer::GraphicsLayer,
light::{LightData, LightKind},
light::{LightKind, LightParams},
material_desc::{MaterialData, MaterialDesc},
mesh_desc::MeshDesc,
primitives::CapsulePrimitive,
Expand Down Expand Up @@ -178,7 +178,10 @@ fn setup_objects(world: &mut World, assets: AssetCache) -> anyhow::Result<()> {
1.0,
0.0,
)))
.set(light_data(), LightData::new(Srgb::new(1.0, 1.0, 1.0), 0.4))
.set(
light_params(),
LightParams::new(Srgb::new(1.0, 1.0, 1.0), 0.4),
)
.set(light_kind(), LightKind::Directional)
.set_default(cast_shadow())
.spawn(world);
Expand Down
14 changes: 6 additions & 8 deletions examples/physics_stacking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use ivy_wgpu::{
driver::WinitDriver,
events::ResizedEvent,
layer::GraphicsLayer,
light::{LightData, LightKind},
light::{LightKind, LightParams},
material_desc::{MaterialData, MaterialDesc},
mesh_desc::MeshDesc,
primitives::{CapsulePrimitive, CubePrimitive, UvSpherePrimitive},
Expand Down Expand Up @@ -67,7 +67,6 @@ pub fn main() -> anyhow::Result<()> {
gpu,
surface,
SurfacePbrPipelineDesc {
// hdri: None,
hdri: Some(Box::new(
"hdris/kloofendal_48d_partly_cloudy_puresky_2k.hdr",
)),
Expand All @@ -80,11 +79,7 @@ pub fn main() -> anyhow::Result<()> {
.with_layer(ScheduledLayer::new(PerTick).with_plugin(FreeCameraPlugin))
.with_layer(
ScheduledLayer::new(FixedTimeStep::new(0.02))
.with_plugin(
PhysicsPlugin::new()
// .with_gizmos(ivy_physics::GizmoSettings { rigidbody: true })
.with_gravity(-Vec3::Y * 9.81),
)
.with_plugin(PhysicsPlugin::new().with_gravity(-Vec3::Y * 9.81))
.with_plugin(RayPickingPlugin),
)
.run()
Expand Down Expand Up @@ -215,7 +210,10 @@ fn setup_objects(world: &mut World, assets: AssetCache) -> anyhow::Result<()> {
-1.0,
0.0,
)))
.set(light_data(), LightData::new(Srgb::new(1.0, 1.0, 1.0), 1.0))
.set(
light_params(),
LightParams::new(Srgb::new(1.0, 1.0, 1.0), 1.0),
)
.set(light_kind(), LightKind::Directional)
.set_default(cast_shadow())
.spawn(world);
Expand Down
53 changes: 39 additions & 14 deletions ivy-core/src/gizmos/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use dashmap::DashMap;
use glam::Vec3;
use glam::{Mat4, Vec3};
use itertools::Itertools;

use crate::{Color, ColorExt};
Expand Down Expand Up @@ -117,14 +117,31 @@ pub struct Cube {
pub max: Vec3,
pub line_radius: f32,
pub color: Color,
pub transform: Mat4,
}

impl Cube {
pub fn new(min: Vec3, max: Vec3, line_radius: f32, color: Color) -> Self {
Self {
min,
max,
line_radius,
color,
transform: Mat4::IDENTITY,
}
}

/// Set the color
pub fn with_color(mut self, color: Color) -> Self {
self.color = color;
self
}

/// Set the transform
pub fn with_transform(mut self, transform: Mat4) -> Self {
self.transform = transform;
self
}
}

impl Default for Cube {
Expand All @@ -134,6 +151,7 @@ impl Default for Cube {
max: Vec3::ZERO,
line_radius: 0.02,
color: Color::green(),
transform: Mat4::IDENTITY,
}
}
}
Expand All @@ -160,22 +178,29 @@ impl DrawGizmos for Cube {
let midpoint = (self.max + self.min) / 2.0;
let extent = (self.max - self.min) / 2.0;

let lines = sides.iter().map(|side| {
for side in sides.iter() {
let mid = midpoint + (side.0 + side.1) * extent;
let dir = side.0.cross(side.1).normalize() * (extent + self.line_radius) * 2.0;

let pos = mid - dir * 0.5;

GizmoPrimitive::Line {
origin: pos,
dir,
corner_radius: 1.0,
color: self.color,
radius: self.line_radius,
}
});

gizmos.extend(lines)
let start = mid - dir * 0.5;

let end = start + dir;

Line::from_points(
self.transform.transform_point3(start),
self.transform.transform_point3(end),
self.line_radius,
self.color,
)
.draw_primitives(gizmos);
// GizmoPrimitive::Line {
// origin: pos,
// dir,
// corner_radius: 1.0,
// color: self.color,
// radius: self.line_radius,
// }
}
}
}

Expand Down
Loading

0 comments on commit 600bd09

Please sign in to comment.