Skip to content
Open
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
86ca5c1
compiling 3d (from folder)
ThierryBerger Mar 3, 2025
1b23a23
add an example loading a mesh into a particle
ThierryBerger Mar 4, 2025
9da163f
attempt to sample vertex colors from material
ThierryBerger Mar 8, 2025
7e8d3da
attempt to load glb into particles ; not working
ThierryBerger Mar 10, 2025
57ec176
better model to showcase
ThierryBerger Mar 11, 2025
0d72d4f
correct color loading for gltf
ThierryBerger Mar 11, 2025
4377db0
wip loading banana and knife
ThierryBerger Mar 12, 2025
4fc0213
format credits
ThierryBerger Mar 12, 2025
e23815d
correctly load rigidbody coupling
ThierryBerger Mar 12, 2025
2a62ab9
knife cutting through banana (but cut is bugged)
ThierryBerger Mar 12, 2025
8ac05e0
knife with open blade correctly cuts :)
ThierryBerger Mar 12, 2025
1debc1f
better time management
ThierryBerger Mar 12, 2025
c20b71c
inside the banana is now white/yellow
ThierryBerger Mar 12, 2025
28aa807
attempt to use lib examples
ThierryBerger Mar 13, 2025
5118676
knif model follow its rigidbody
ThierryBerger Mar 14, 2025
9a886bd
add comment about sample_mesh
ThierryBerger Mar 14, 2025
5ed648a
use binary for examples 3d
ThierryBerger Mar 14, 2025
93c0e01
use binary for examples 2d
ThierryBerger Mar 14, 2025
9f849cb
fix wasm build
ThierryBerger Mar 14, 2025
92a4e19
better banana cut ; moved utils functions to wgsparkl behind a featur…
ThierryBerger Mar 17, 2025
53ef2db
less bevy specific examples
ThierryBerger Mar 18, 2025
f02b27a
independant example for loading a glb to point cloud
ThierryBerger Mar 18, 2025
9b39703
fix some slippy lints
ThierryBerger Mar 18, 2025
4e8e507
better banana cut
ThierryBerger Mar 18, 2025
d99ce1b
fix 2d examples
ThierryBerger Mar 24, 2025
bd31adc
removed notes
ThierryBerger Apr 7, 2025
1800d63
re-enable wasm build
ThierryBerger Apr 7, 2025
8a38ae8
fix some warnings
ThierryBerger Apr 7, 2025
c139889
fix clippy + use ticks rather than elapsed seconds
ThierryBerger Apr 11, 2025
133b990
fix doc example compilation
ThierryBerger Apr 14, 2025
e225c6a
add cargo test to CI
ThierryBerger Apr 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ members = [
"crates/wgsparkl-testbed3d",
"crates/wgsparkl2d",
"crates/wgsparkl3d",
"examples3d",
"examples2d",
]
resolver = "2"

Expand Down Expand Up @@ -32,6 +34,10 @@ wgparry2d = { git = "https://github.com/dimforge/wgmath.git", rev = "6d17942bd84
wgrapier3d = { git = "https://github.com/dimforge/wgmath.git", rev = "6d17942bd841efdfcc696d8455b22be3a8ddfe8d" }
wgrapier2d = { git = "https://github.com/dimforge/wgmath.git", rev = "6d17942bd841efdfcc696d8455b22be3a8ddfe8d" }
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
16 changes: 8 additions & 8 deletions build_wasm.sh
Original file line number Diff line number Diff line change
@@ -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
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
2 changes: 1 addition & 1 deletion crates/wgsparkl-testbed2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ path = "../../src_testbed/lib.rs"
required-features = ["dim2"]

[features]
dim2 = []
default = ["dim2"]
dim2 = []

[dependencies]
nalgebra = { workspace = true, features = ["rand"] }
Expand Down
2 changes: 1 addition & 1 deletion crates/wgsparkl-testbed3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ path = "../../src_testbed/lib.rs"
required-features = ["dim3"]

[features]
dim3 = []
default = ["dim3"]
dim3 = []

[dependencies]
nalgebra = { workspace = true, features = ["rand"] }
Expand Down
9 changes: 0 additions & 9 deletions crates/wgsparkl2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
27 changes: 19 additions & 8 deletions crates/wgsparkl3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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" }
# 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"]
2 changes: 1 addition & 1 deletion dist2d/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<body style="margin: 0px;">
<script type="module">
import init from './elasticity2.js'
import init from './wgsparkl-examples-2d.js'

init().catch((error) => {
if (!error.message.startsWith("Using exceptions for control flow, don't mind me. This isn't actually an error!")) {
Expand Down
2 changes: 1 addition & 1 deletion dist3d/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<body style="margin: 0px;">
<script type="module">
import init from './elasticity3.js'
import init from './wgsparkl-examples-3d.js'

init().catch((error) => {
if (!error.message.startsWith("Using exceptions for control flow, don't mind me. This isn't actually an error!")) {
Expand Down
24 changes: 24 additions & 0 deletions examples2d/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "wgsparkl-examples-2d"
version = "0.1.0"
license = "Apache-2.0 OR Custom"
edition = "2021"

[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",
"jpeg",
] }
wgsparkl_testbed2d = { path = "../crates/wgsparkl-testbed2d" }
wgsparkl2d = { path = "../crates/wgsparkl2d" }
rapier2d = "0.23"

[lints]
workspace = true
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use wgsparkl_testbed2d::{wgsparkl, RapierData};
use wgsparkl2d::rapier::prelude::{ColliderBuilder, RigidBodyBuilder};
use wgsparkl_testbed2d::{wgsparkl, Callbacks, RapierData};

use bevy::prelude::*;
use bevy::render::renderer::RenderDevice;
use nalgebra::{point, vector, Vector2};
use rapier2d::prelude::{ColliderBuilder, RigidBodyBuilder};
use wgsparkl::solver::ParticlePhase;
use wgsparkl::{
models::ElasticCoefficients,
Expand All @@ -13,16 +12,11 @@ use wgsparkl::{
use wgsparkl2d::solver::ParticleDynamics;
use wgsparkl_testbed2d::{AppState, PhysicsContext};

#[allow(dead_code)]
fn main() {
panic!("Run the `testbed3` example instead.");
}

pub fn elastic_cut_demo(
mut commands: Commands,
device: Res<RenderDevice>,
mut app_state: ResMut<AppState>,
) {
device: RenderDevice,
app_state: &mut AppState,
_callbacks: &mut Callbacks,
) -> PhysicsContext {
let mut rapier_data = RapierData::default();
let device = device.wgpu_device();

Expand All @@ -45,6 +39,7 @@ pub fn elastic_cut_demo(
phase: 1.0,
max_stretch: f32::MAX,
}),
color: None,
});
}
}
Expand All @@ -60,14 +55,12 @@ pub fn elastic_cut_demo(
padding: 0.0,
};

// const ANGVEL: f32 = 1.0; // 2.0;

/*
* Static platforms.
*/
let rb = RigidBodyBuilder::fixed().translation(vector![35.0, 20.0]);
let rb_handle = rapier_data.bodies.insert(rb);
let co = ColliderBuilder::cuboid(70.0, 1.0);
let co = wgsparkl2d::rapier::prelude::ColliderBuilder::cuboid(70.0, 1.0);
rapier_data
.colliders
.insert_with_parent(co, rb_handle, &mut rapier_data.bodies);
Expand Down Expand Up @@ -115,9 +108,9 @@ pub fn elastic_cut_demo(
cell_width,
60_000,
);
commands.insert_resource(PhysicsContext {
PhysicsContext {
data,
rapier_data,
particles,
});
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use wgsparkl_testbed2d::{wgsparkl, RapierData};
use wgsparkl2d::rapier::prelude::{ColliderBuilder, RigidBodyBuilder};
use wgsparkl_testbed2d::{wgsparkl, Callbacks, RapierData};

use bevy::prelude::*;
use bevy::render::renderer::RenderDevice;
use nalgebra::{vector, Vector2};
use rapier2d::prelude::{ColliderBuilder, RigidBodyBuilder};
use wgsparkl::solver::ParticlePhase;
use wgsparkl::{
models::ElasticCoefficients,
Expand All @@ -13,16 +12,11 @@ use wgsparkl::{
use wgsparkl2d::solver::ParticleDynamics;
use wgsparkl_testbed2d::{AppState, PhysicsContext};

#[allow(dead_code)]
fn main() {
panic!("Run the `testbed3` example instead.");
}

pub fn elastic_demo(
mut commands: Commands,
device: Res<RenderDevice>,
mut app_state: ResMut<AppState>,
) {
device: RenderDevice,
app_state: &mut AppState,
_callbacks: &mut Callbacks,
) -> PhysicsContext {
let device = device.wgpu_device();
let mut rapier_data = RapierData::default();

Expand All @@ -46,6 +40,7 @@ pub fn elastic_demo(
phase: 1.0,
max_stretch: f32::MAX,
}),
color: None,
});
}
}
Expand Down Expand Up @@ -95,9 +90,9 @@ pub fn elastic_demo(
cell_width,
60_000,
);
commands.insert_resource(PhysicsContext {
PhysicsContext {
data,
rapier_data,
particles,
});
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bevy::prelude::*;
use wgsparkl_testbed2d::{init_testbed, SceneInits};
use wgsparkl_testbed2d::{init_testbed, SceneInitFn, SceneInits};

mod elastic_cut2;
mod elasticity2;
Expand All @@ -18,15 +18,12 @@ pub fn main() {
}

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),
),
let scenes: Vec<(String, SceneInitFn)> = vec![
("sand".to_string(), Box::new(sand2::sand_demo)),
("elastic".to_string(), Box::new(elasticity2::elastic_demo)),
(
"elastic cut".to_string(),
world.register_system(elastic_cut2::elastic_cut_demo),
Box::new(elastic_cut2::elastic_cut_demo),
),
];
let mut inits = world.resource_mut::<SceneInits>();
Expand Down
23 changes: 9 additions & 14 deletions crates/wgsparkl2d/examples/sand2.rs → examples2d/src/sand2.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use wgsparkl_testbed2d::{wgsparkl, RapierData};
use wgsparkl2d::rapier::prelude::{ColliderBuilder, RigidBodyBuilder};
use wgsparkl_testbed2d::{wgsparkl, Callbacks, RapierData};

use bevy::prelude::*;
use bevy::render::renderer::RenderDevice;
use nalgebra::{vector, Vector2};
use rapier2d::prelude::{ColliderBuilder, RigidBodyBuilder};
use wgsparkl::models::DruckerPrager;
use wgsparkl::{
models::ElasticCoefficients,
Expand All @@ -13,16 +12,11 @@ use wgsparkl::{
use wgsparkl2d::solver::ParticleDynamics;
use wgsparkl_testbed2d::{AppState, PhysicsContext};

#[allow(dead_code)]
fn main() {
panic!("Run the `testbed3` example instead.");
}

pub fn sand_demo(
mut commands: Commands,
device: Res<RenderDevice>,
mut app_state: ResMut<AppState>,
) {
device: RenderDevice,
app_state: &mut AppState,
_callbacks: &mut Callbacks,
) -> PhysicsContext {
let mut rapier_data = RapierData::default();
let device = device.wgpu_device();

Expand All @@ -42,6 +36,7 @@ pub fn sand_demo(
model: ElasticCoefficients::from_young_modulus(10_000_000.0, 0.2),
plasticity: Some(DruckerPrager::new(10_000_000.0, 0.2)),
phase: None,
color: None,
});
}
}
Expand Down Expand Up @@ -173,9 +168,9 @@ pub fn sand_demo(
cell_width,
60_000,
);
commands.insert_resource(PhysicsContext {
PhysicsContext {
data,
rapier_data,
particles,
});
}
}
32 changes: 32 additions & 0 deletions examples3d/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[package]
name = "wgsparkl-examples-3d"
version = "0.1.0"
license = "Apache-2.0 OR Custom"
edition = "2021"

[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",
"jpeg",
] }
wgsparkl_testbed3d = { path = "../crates/wgsparkl-testbed3d" }
wgsparkl3d = { path = "../crates/wgsparkl3d", features = [
"load_gltf",
"load_bevy",
"load_obj",
] }
obj-rs = { version = "0.7", default-features = false }
bevy_editor_cam = "*"
image = "0.25"
gltf = { version = "1.3", features = ["KHR_materials_pbrSpecularGlossiness"] }
rapier3d = "0.23"

[lints]
workspace = true
Binary file added examples3d/assets/banana.glb
Binary file not shown.
Binary file added examples3d/assets/chefs_knife_open_blade.glb
Binary file not shown.
Loading
Loading