Skip to content

Commit

Permalink
physnet: initial project scaffold (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheButlah authored May 27, 2024
1 parent fa017af commit 308fca8
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
resolver = "2"
members = [
"apps/legacy_web/backend",
"apps/networked_physics_demo/client",
"apps/networked_physics_demo/server",
"apps/legacy_web/frontend",
"apps/rvid/client",
"apps/rvid/server",
Expand Down
15 changes: 15 additions & 0 deletions apps/networked_physics_demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Networked Physics in VR

An implementation of [this excellent GafferOnGames article][article] about
writing netcode for a distributed physics simulation in VR.

Unlike the original article, this demo will be utilizing WebTransport for its
networking and will not be as focused on hyper-optimized message payload sizes
like in the original article.


## Project Status

WIP / active development.

[article]: https://gafferongames.com/post/networked_physics_in_virtual_reality/
18 changes: 18 additions & 0 deletions apps/networked_physics_demo/client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "physnet_client"
version.workspace = true
license.workspace = true
repository.workspace = true
edition.workspace = true
rust-version.workspace = true
description = "A demo for Networked Physics in VR"
publish = false

[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
bevy.workspace = true
bevy_oxr.workspace = true
color-eyre.workspace = true
openxr.workspace = true
77 changes: 77 additions & 0 deletions apps/networked_physics_demo/client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
use bevy::{
app::{App, Startup},
asset::Assets,
core_pipeline::core_3d::Camera3dBundle,
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
ecs::system::{Commands, ResMut},
log::info,
math::{
primitives::{Cuboid, Plane3d},
Vec3,
},
pbr::{PbrBundle, PointLight, PointLightBundle, StandardMaterial},
prelude::{bevy_main, default},
render::{
color::Color,
mesh::{Mesh, Meshable},
},
transform::components::Transform,
};
use bevy_oxr::DefaultXrPlugins;

const APP_NAME: &str = env!("CARGO_PKG_NAME");

#[bevy_main]
pub fn main() {
color_eyre::install().unwrap();

info!("Running {}", APP_NAME);
App::new()
.add_plugins(DefaultXrPlugins {
app_info: bevy_oxr::graphics::XrAppInfo {
name: env!("CARGO_PKG_NAME").to_string(),
},
..default()
})
.add_plugins(LogDiagnosticsPlugin::default())
.add_plugins(FrameTimeDiagnosticsPlugin)
.add_systems(Startup, setup)
// .add_systems(Update, hands)
.run();
}

// set up a simple 3D scene
fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
// plane
commands.spawn(PbrBundle {
mesh: meshes.add(Plane3d::new(Vec3::Y).mesh().size(5.0, 5.0)),
material: materials.add(StandardMaterial::from(Color::rgb(0.3, 0.5, 0.3))),
..default()
});
// cube
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(Cuboid::from_size(Vec3::splat(0.1)))),
material: materials.add(StandardMaterial::from(Color::rgb(0.8, 0.7, 0.6))),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default()
});
// light
commands.spawn(PointLightBundle {
point_light: PointLight {
intensity: 1500.0,
shadows_enabled: true,
..default()
},
transform: Transform::from_xyz(4.0, 8.0, 4.0),
..default()
});
// camera
commands.spawn((Camera3dBundle {
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
},));
}
3 changes: 3 additions & 0 deletions apps/networked_physics_demo/client/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
physnet_client::main()
}
11 changes: 11 additions & 0 deletions apps/networked_physics_demo/server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "physnet_server"
version.workspace = true
license.workspace = true
repository.workspace = true
edition.workspace = true
rust-version.workspace = true
description = "A demo for Networked Physics in VR"
publish = false

[dependencies]
1 change: 1 addition & 0 deletions apps/networked_physics_demo/server/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

0 comments on commit 308fca8

Please sign in to comment.