diff --git a/Cargo.toml b/Cargo.toml index bd7f8f9..02e56b8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,8 @@ members = [ "crates/wgsparkl-testbed3d", "crates/wgsparkl2d", "crates/wgsparkl3d", + "examples3d", + "examples2d", ] resolver = "2" @@ -23,15 +25,32 @@ rust.unexpected_cfgs = { level = "warn", check-cfg = [ ] } [patch.crates-io] -parry2d = { path = "../parry/crates/parry2d" } -parry3d = { path = "../parry/crates/parry3d" } -encase = { path = "../encase" } -wgcore = { path = "../wgmath/crates/wgcore" } -wgebra = { path = "../wgmath/crates/wgebra" } -wgparry2d = { path = "../wgmath/crates/wgparry/crates/wgparry2d" } -wgparry3d = { path = "../wgmath/crates/wgparry/crates/wgparry3d" } -wgrapier2d = { path = "../wgmath/crates/wgrapier/crates/wgrapier2d" } -wgrapier3d = { path = "../wgmath/crates/wgrapier/crates/wgrapier3d" } +# parry2d = { path = "../parry/crates/parry2d" } +# parry3d = { path = "../parry/crates/parry3d" } +# encase = { path = "../encase" } +# wgcore = { path = "../wgmath/crates/wgcore" } +# wgebra = { path = "../wgmath/crates/wgebra" } +# wgparry2d = { path = "../wgmath/crates/wgparry/crates/wgparry2d" } +# wgparry3d = { path = "../wgmath/crates/wgparry/crates/wgparry3d" } +# wgrapier2d = { path = "../wgmath/crates/wgrapier/crates/wgrapier2d" } +# wgrapier3d = { path = "../wgmath/crates/wgrapier/crates/wgrapier3d" } + +parry2d = { git = "https://github.com/dimforge/parry.git", rev = "407fb449504dde7ba0a3d80a8de7e37ac991a77a" } +parry3d = { git = "https://github.com/dimforge/parry.git", rev = "407fb449504dde7ba0a3d80a8de7e37ac991a77a" } +encase = { git = "https://github.com/sebcrozet/encase.git", rev = "6755c1414c225cbeac9fde1ff9394b70d3b05404" } +# wgcore = { git = "https://github.com/dimforge/wgmath.git", rev = "32b54c802be6040c5f003e7d3def4a33e4730d92" } +wgcore = { git = "https://github.com/dimforge/wgmath.git", branch = "wgml-chat" } +wgcore-derive = { git = "https://github.com/dimforge/wgmath.git", branch = "wgml-chat" } +wgebra = { git = "https://github.com/dimforge/wgmath.git", branch = "wgml-chat" } +wgparry3d = { git = "https://github.com/dimforge/wgmath.git", branch = "wgml-chat" } +wgparry2d = { git = "https://github.com/dimforge/wgmath.git", branch = "wgml-chat" } +wgrapier3d = { git = "https://github.com/dimforge/wgmath.git", branch = "wgml-chat" } +wgrapier2d = { git = "https://github.com/dimforge/wgmath.git", branch = "wgml-chat" } +rapier3d = { git = "https://github.com/vrixyz/rapier.git", branch = "uber_physics_context" } +rapier2d = { git = "https://github.com/vrixyz/rapier.git", branch = "uber_physics_context" } [profile.release] opt-level = 'z' + +[profile.dev] +opt-level = 1 diff --git a/build_wasm.sh b/build_wasm.sh index 8b2f27d..42cdf7e 100755 --- a/build_wasm.sh +++ b/build_wasm.sh @@ -1,11 +1,11 @@ #!/bin/sh -cargo build --example elasticity2 --release --target wasm32-unknown-unknown --features dim2 -cargo build --example elasticity3 --release --target wasm32-unknown-unknown --features dim3 -wasm-bindgen --no-typescript --target web --out-dir dist2d --out-name elasticity2 ./target/wasm32-unknown-unknown/release/examples/elasticity2.wasm -wasm-bindgen --no-typescript --target web --out-dir dist3d --out-name elasticity3 ./target/wasm32-unknown-unknown/release/examples/elasticity3.wasm -wasm-opt -Oz -o ./dist2d/opt.wasm ./dist2d/elasticity2_bg.wasm && mv ./dist2d/opt.wasm ./dist2d/elasticity2_bg.wasm -wasm-opt -Oz -o ./dist3d/opt.wasm ./dist3d/elasticity3_bg.wasm && mv ./dist3d/opt.wasm ./dist3d/elasticity3_bg.wasm +# cargo build -p wgsparkl-examples-2d --release --target wasm32-unknown-unknown +cargo build -p wgsparkl-examples-3d --release --target wasm32-unknown-unknown +# wasm-bindgen --no-typescript --target web --out-dir dist2d --out-name wgsparkl-examples-2d ./target/wasm32-unknown-unknown/release/wgsparkl-examples-2d.wasm +wasm-bindgen --no-typescript --target web --out-dir dist3d --out-name wgsparkl-examples-3d ./target/wasm32-unknown-unknown/release/wgsparkl-examples-3d.wasm +# wasm-opt -Oz -o ./dist2d/opt.wasm ./dist2d/wgsparkl-examples-2d_bg.wasm && mv ./dist2d/opt.wasm ./dist2d/wgsparkl-examples-2d_bg.wasm +wasm-opt -Oz -o ./dist3d/opt.wasm ./dist3d/wgsparkl-examples-3d_bg.wasm && mv ./dist3d/opt.wasm ./dist3d/wgsparkl-examples-3d_bg.wasm -brotli ./dist2d/elasticity2_bg.wasm && mv ./dist2d/elasticity2_bg.wasm.br ./dist2d/elasticity2_bg.wasm -brotli ./dist3d/elasticity3_bg.wasm && mv ./dist3d/elasticity3_bg.wasm.br ./dist3d/elasticity3_bg.wasm \ No newline at end of file +# brotli ./dist2d/wgsparkl-examples-2d_bg.wasm && mv ./dist2d/wgsparkl-examples-2d_bg.wasm.br ./dist2d/wgsparkl-examples-2d_bg.wasm +brotli ./dist3d/wgsparkl-examples-3d_bg.wasm && mv ./dist3d/wgsparkl-examples-3d_bg.wasm.br ./dist3d/wgsparkl-examples-3d_bg.wasm \ No newline at end of file diff --git a/crates/wgsparkl-testbed2d/Cargo.toml b/crates/wgsparkl-testbed2d/Cargo.toml index a402a4c..483c7e8 100644 --- a/crates/wgsparkl-testbed2d/Cargo.toml +++ b/crates/wgsparkl-testbed2d/Cargo.toml @@ -13,8 +13,8 @@ path = "../../src_testbed/lib.rs" required-features = ["dim2"] [features] +default = ["dim2"] dim2 = [] -default_features = ["dim2"] [dependencies] nalgebra = { workspace = true, features = ["rand"] } @@ -31,10 +31,17 @@ futures-test = "0.3" serial_test = "3" approx = "0.5" async-std = { version = "1", features = ["attributes"] } -bevy = { version = "0.15.0", features = ["shader_format_glsl", "shader_format_spirv", "webgpu"] } +bevy = { version = "0.15.0", features = [ + "shader_format_glsl", + "shader_format_spirv", + "webgpu", +] } #bevy_wasm_window_resize = "0.4" bevy_editor_cam = "0.5" -bevy_egui = { version = "0.31", default-features = false, features = ["default_fonts", "render"] } +bevy_egui = { version = "0.31", default-features = false, features = [ + "default_fonts", + "render", +] } bevy_sprite = "0.15" wgsparkl2d = { path = "../wgsparkl2d" } -futures = "0.3" \ No newline at end of file +futures = "0.3" diff --git a/crates/wgsparkl-testbed3d/Cargo.toml b/crates/wgsparkl-testbed3d/Cargo.toml index 3eb114a..d652796 100644 --- a/crates/wgsparkl-testbed3d/Cargo.toml +++ b/crates/wgsparkl-testbed3d/Cargo.toml @@ -13,8 +13,8 @@ path = "../../src_testbed/lib.rs" required-features = ["dim3"] [features] +default = ["dim3"] dim3 = [] -default_features = ["dim3"] [dependencies] nalgebra = { workspace = true, features = ["rand"] } @@ -31,10 +31,17 @@ futures-test = "0.3" serial_test = "3" approx = "0.5" async-std = { version = "1", features = ["attributes"] } -bevy = { version = "0.15.0", features = ["shader_format_glsl", "shader_format_spirv", "webgpu"] } +bevy = { version = "0.15.0", features = [ + "shader_format_glsl", + "shader_format_spirv", + "webgpu", +] } bevy_editor_cam = "0.5" #bevy_mod_picking = { version = "0.20", default-features = false } #bevy_wasm_window_resize = "0.4" -bevy_egui = { version = "0.31", default-features = false, features = ["default_fonts", "render"] } +bevy_egui = { version = "0.31", default-features = false, features = [ + "default_fonts", + "render", +] } wgsparkl3d = { path = "../wgsparkl3d" } futures = "0.3" diff --git a/crates/wgsparkl2d/Cargo.toml b/crates/wgsparkl2d/Cargo.toml index 8645eba..8602b88 100644 --- a/crates/wgsparkl2d/Cargo.toml +++ b/crates/wgsparkl2d/Cargo.toml @@ -34,12 +34,3 @@ rapier2d = "0.23" # For wasm? getrandom = { version = "0.3.1", features = ["wasm_js"] } uuid = { version = "1", features = ["js"] } - -[dev-dependencies] -nalgebra = { version = "0.33", features = ["rand"] } -futures-test = "0.3" -serial_test = "3" -approx = "0.5" -async-std = { version = "1", features = ["attributes"] } -bevy = { version = "0.15.0", features = ["shader_format_glsl", "shader_format_spirv", "webgpu"] } -wgsparkl_testbed2d = { path = "../wgsparkl-testbed2d", features = ["dim2"] } diff --git a/crates/wgsparkl2d/examples/testbed2.rs b/crates/wgsparkl2d/examples/testbed2.rs deleted file mode 100644 index e5373f5..0000000 --- a/crates/wgsparkl2d/examples/testbed2.rs +++ /dev/null @@ -1,53 +0,0 @@ -use wgsparkl_testbed2d::{wgsparkl, RapierData}; - -use bevy::prelude::*; -use bevy::render::renderer::RenderDevice; -use nalgebra::{point, vector, Similarity2, Vector2}; -use rapier2d::prelude::{ColliderBuilder, RigidBodyBuilder}; -use wgebra::GpuSim2; -use wgparry2d::parry::shape::Cuboid; -use wgrapier2d::dynamics::{BodyDesc, GpuVelocity}; -use wgsparkl::models::DruckerPrager; -use wgsparkl::solver::ParticlePhase; -use wgsparkl::{ - models::ElasticCoefficients, - pipeline::MpmData, - solver::{Particle, SimulationParams}, -}; -use wgsparkl_testbed2d::{init_testbed, AppState, PhysicsContext, SceneInits}; - -mod elastic_cut2; -mod elasticity2; -mod sand2; - -pub fn main() { - let mut app = App::new(); - init_testbed(&mut app); - app.add_systems( - Startup, - (register_scenes, start_default_scene) - .chain() - .after(wgsparkl_testbed2d::startup::setup_app), - ); - app.run(); -} - -fn register_scenes(world: &mut World) { - let scenes = vec![ - ("sand".to_string(), world.register_system(sand2::sand_demo)), - ( - "elastic".to_string(), - world.register_system(elasticity2::elastic_demo), - ), - ( - "elastic cut".to_string(), - world.register_system(elastic_cut2::elastic_cut_demo), - ), - ]; - let mut inits = world.resource_mut::(); - inits.scenes = scenes; -} - -fn start_default_scene(mut commands: Commands, scenes: Res) { - scenes.init_scene(&mut commands, 0); -} diff --git a/crates/wgsparkl3d/Cargo.toml b/crates/wgsparkl3d/Cargo.toml index 6654d2e..e77cfac 100644 --- a/crates/wgsparkl3d/Cargo.toml +++ b/crates/wgsparkl3d/Cargo.toml @@ -15,6 +15,9 @@ required-features = ["dim3"] [features] default = ["dim3"] dim3 = [] +load_gltf = ["obj-rs", "image"] +load_obj = ["gltf", "image"] +load_bevy = ["bevy", "image"] [dependencies] nalgebra = { workspace = true } @@ -33,11 +36,19 @@ wgrapier3d = "0.2" # TODO: make rapier optional? rapier3d = "0.23" -[dev-dependencies] -nalgebra = { version = "0.33", features = ["rand"] } -futures-test = "0.3" -serial_test = "3" -approx = "0.5" -async-std = { version = "1", features = ["attributes"] } -bevy = { version = "0.15.0", features = ["shader_format_glsl", "shader_format_spirv", "webgpu"] } -wgsparkl_testbed3d = { path = "../wgsparkl-testbed3d" } \ No newline at end of file +# for loaders +# TODO: slim bevy features +bevy = { version = "0.15.0", features = [ + "shader_format_glsl", + "shader_format_spirv", + "webgpu", + "jpeg", +], optional = true } +gltf = { version = "1.3", features = [ + "KHR_materials_pbrSpecularGlossiness", +], optional = true } +obj-rs = { version = "0.7", default-features = false, optional = true } +image = { version = "0.25", optional = true } + +[package.metadata.docs.rs] +cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"] diff --git a/crates/wgsparkl3d/examples/sand3.rs b/crates/wgsparkl3d/examples/sand3.rs deleted file mode 100644 index f4eae09..0000000 --- a/crates/wgsparkl3d/examples/sand3.rs +++ /dev/null @@ -1,121 +0,0 @@ -use wgsparkl_testbed3d::{wgsparkl, RapierData}; - -use bevy::prelude::*; -use bevy::render::renderer::RenderDevice; -use nalgebra::{vector, Similarity3, Vector3}; -use rapier3d::prelude::{ColliderBuilder, RigidBodyBuilder}; -use wgebra::GpuSim3; -use wgparry3d::parry::shape::Cuboid; -use wgrapier3d::dynamics::BodyDesc; -use wgsparkl::models::DruckerPrager; -use wgsparkl::{ - models::ElasticCoefficients, - pipeline::MpmData, - solver::{Particle, ParticleDynamics, ParticlePhase, SimulationParams}, -}; -use wgsparkl_testbed3d::{init_testbed, AppState, PhysicsContext, SceneInits}; - -fn main() { - panic!("Run the `testbed3` example instead."); -} - -pub fn sand_demo( - mut commands: Commands, - device: Res, - mut app_state: ResMut, -) { - let mut rapier_data = RapierData::default(); - let device = device.wgpu_device(); - - let nxz = 45; - let cell_width = 1.0; - let mut particles = vec![]; - for i in 0..nxz { - for j in 0..100 { - for k in 0..nxz { - let position = vector![ - i as f32 + 0.5 - nxz as f32 / 2.0, - j as f32 + 0.5 + 10.0, - k as f32 + 0.5 - nxz as f32 / 2.0 - ] * cell_width - / 2.0; - let density = 2700.0; - let radius = cell_width / 4.0; - particles.push(Particle { - position, - dynamics: ParticleDynamics::with_density(radius, density), - model: ElasticCoefficients::from_young_modulus(2_000_000_000.0, 0.2), - plasticity: Some(DruckerPrager::new(2_000_000_000.0, 0.2)), - phase: None, - }); - } - } - } - - if !app_state.restarting { - app_state.num_substeps = 20; - app_state.gravity_factor = 1.0; - }; - - let params = SimulationParams { - gravity: vector![0.0, -9.81, 0.0] * app_state.gravity_factor, - dt: (1.0 / 60.0) / (app_state.num_substeps as f32), - }; - - let rb = RigidBodyBuilder::fixed().translation(vector![0.0, -4.0, 0.0]); - let rb_handle = rapier_data.bodies.insert(rb); - let co = ColliderBuilder::cuboid(100.0, 4.0, 100.0); - rapier_data - .colliders - .insert_with_parent(co, rb_handle, &mut rapier_data.bodies); - - let rb = RigidBodyBuilder::fixed().translation(vector![0.0, 5.0, -35.0]); - let rb_handle = rapier_data.bodies.insert(rb); - let co = ColliderBuilder::cuboid(35.0, 5.0, 0.5); - rapier_data - .colliders - .insert_with_parent(co, rb_handle, &mut rapier_data.bodies); - let rb = RigidBodyBuilder::fixed().translation(vector![0.0, 5.0, 35.0]); - let rb_handle = rapier_data.bodies.insert(rb); - let co = ColliderBuilder::cuboid(35.0, 5.0, 0.5); - rapier_data - .colliders - .insert_with_parent(co, rb_handle, &mut rapier_data.bodies); - let rb = RigidBodyBuilder::fixed().translation(vector![-35.0, 5.0, 0.0]); - let rb_handle = rapier_data.bodies.insert(rb); - let co = ColliderBuilder::cuboid(0.5, 5.0, 35.0); - rapier_data - .colliders - .insert_with_parent(co, rb_handle, &mut rapier_data.bodies); - let rb = RigidBodyBuilder::fixed().translation(vector![35.0, 5.0, 0.0]); - let rb_handle = rapier_data.bodies.insert(rb); - let co = ColliderBuilder::cuboid(0.5, 5.0, 35.0); - rapier_data - .colliders - .insert_with_parent(co, rb_handle, &mut rapier_data.bodies); - - let rb = RigidBodyBuilder::kinematic_velocity_based() - .translation(vector![0.0, 2.0, 0.0]) - .rotation(vector![0.0, 0.0, -0.5]) - .angvel(vector![0.0, -1.0, 0.0]); - let rb_handle = rapier_data.bodies.insert(rb); - let co = ColliderBuilder::cuboid(0.5, 2.0, 30.0); - rapier_data - .colliders - .insert_with_parent(co, rb_handle, &mut rapier_data.bodies); - - let data = MpmData::new( - device, - params, - &particles, - &rapier_data.bodies, - &rapier_data.colliders, - cell_width, - 60_000, - ); - commands.insert_resource(PhysicsContext { - data, - rapier_data, - particles, - }); -} diff --git a/dist2d/index.html b/dist2d/index.html index 0bb9815..3794f6a 100644 --- a/dist2d/index.html +++ b/dist2d/index.html @@ -3,7 +3,7 @@