Skip to content

Banana example #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]

env:
CARGO_TERM_COLOR: always
Expand Down Expand Up @@ -75,4 +75,18 @@ jobs:
sweep-cache: true

- name: Check documentation
run: cargo doc --locked --workspace --all-features --document-private-items --no-deps
run: cargo doc --locked --workspace --all-features --document-private-items --no-deps

test:
name: Test
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable

- name: Run cargo test
run: cargo test
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
5 changes: 0 additions & 5 deletions crates/wgsparkl2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,5 @@ 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"] }
26 changes: 21 additions & 5 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,24 @@ wgrapier3d = "0.2"
# TODO: make rapier optional?
rapier3d = "0.23"

# 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 }


[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" }

[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,
});
}
}
Loading
Loading