COLLIDERSSSS!!!!!!!

This commit is contained in:
Schrottkatze 2025-06-26 22:19:05 +02:00
parent 7e531d42a8
commit 643a16f008
Signed by: schrottkatze
SSH key fingerprint: SHA256:/raZeWZ2RLThYkX/nq26frnmA4Bi3qRM/hijRmDBa10
14 changed files with 541 additions and 33 deletions

243
Cargo.lock generated
View file

@ -120,6 +120,12 @@ version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4aa90d7ce82d4be67b64039a3d588d38dbcc6736577de4a847025ce5b0c468d1"
[[package]]
name = "allocator-api2"
version = "0.2.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923"
[[package]]
name = "alsa"
version = "0.9.1"
@ -1203,6 +1209,19 @@ version = "0.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df7370d0e46b60e071917711d0860721f5347bc958bf325975ae6913a5dfcf01"
[[package]]
name = "bevy_rapier3d"
version = "0.30.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdf74109573c2c82b05b217cb6101f7e71e6c53ad622aed6c370cc5783c59eb8"
dependencies = [
"bevy",
"bitflags 2.9.0",
"log",
"nalgebra",
"rapier3d",
]
[[package]]
name = "bevy_reflect"
version = "0.16.1"
@ -1653,7 +1672,7 @@ dependencies = [
"proc-macro2",
"quote",
"regex",
"rustc-hash",
"rustc-hash 1.1.0",
"shlex",
"syn 2.0.101",
]
@ -2105,7 +2124,7 @@ dependencies = [
"fontdb",
"log",
"rangemap",
"rustc-hash",
"rustc-hash 1.1.0",
"rustybuzz",
"self_cell",
"smol_str",
@ -2167,6 +2186,19 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b"
[[package]]
name = "crossbeam"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1137cd7e7fc0fb5d3c5a8678be38ec56e819125d8d7907411fe24ccb943faca8"
dependencies = [
"crossbeam-channel",
"crossbeam-deque",
"crossbeam-epoch",
"crossbeam-queue",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-channel"
version = "0.5.15"
@ -2373,6 +2405,15 @@ dependencies = [
"bytemuck",
]
[[package]]
name = "ena"
version = "0.14.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d248bdd43ce613d87415282f69b9bb99d947d290b10962dd6c56233312c2ad5"
dependencies = [
"log",
]
[[package]]
name = "encase"
version = "0.10.0"
@ -2984,6 +3025,7 @@ version = "0.15.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "84b26c544d002229e640969970a2e74021aadf6e2f96372b9c58eff97de08eb3"
dependencies = [
"allocator-api2",
"equivalent",
"foldhash",
"serde",
@ -3503,6 +3545,16 @@ dependencies = [
"regex-automata 0.1.10",
]
[[package]]
name = "matrixmultiply"
version = "0.3.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a06de3016e9fae57a36fd14dba131fccf49f74b40b7fbdb472f96e361ec71a08"
dependencies = [
"autocfg",
"rawpointer",
]
[[package]]
name = "maybe-rayon"
version = "0.1.1"
@ -3549,6 +3601,7 @@ version = "0.1.0"
dependencies = [
"bevy",
"bevy-inspector-egui",
"bevy_rapier3d",
"bevy_skein",
"bevy_third_person_camera",
"bevy_ui_text_input",
@ -3601,7 +3654,7 @@ dependencies = [
"indexmap",
"log",
"pp-rs",
"rustc-hash",
"rustc-hash 1.1.0",
"spirv",
"strum",
"termcolor",
@ -3623,12 +3676,40 @@ dependencies = [
"once_cell",
"regex",
"regex-syntax 0.8.5",
"rustc-hash",
"rustc-hash 1.1.0",
"thiserror 1.0.69",
"tracing",
"unicode-ident",
]
[[package]]
name = "nalgebra"
version = "0.33.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26aecdf64b707efd1310e3544d709c5c0ac61c13756046aaaba41be5c4f66a3b"
dependencies = [
"approx",
"glam",
"matrixmultiply",
"nalgebra-macros",
"num-complex",
"num-rational",
"num-traits",
"simba",
"typenum",
]
[[package]]
name = "nalgebra-macros"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "254a5372af8fc138e36684761d3c0cdb758a4410e938babcff1c860ce14ddbfc"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.101",
]
[[package]]
name = "ndk"
version = "0.8.0"
@ -3807,6 +3888,15 @@ dependencies = [
"num-traits",
]
[[package]]
name = "num-complex"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495"
dependencies = [
"num-traits",
]
[[package]]
name = "num-derive"
version = "0.4.2"
@ -4223,6 +4313,15 @@ dependencies = [
"num-traits",
]
[[package]]
name = "ordered-float"
version = "5.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2c1f9f56e534ac6a9b8a4600bdf0f530fb393b5f393e7b4d03489c3cf0c3f01"
dependencies = [
"num-traits",
]
[[package]]
name = "overload"
version = "0.1.1"
@ -4267,6 +4366,31 @@ dependencies = [
"windows-targets 0.52.6",
]
[[package]]
name = "parry3d"
version = "0.20.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bec55ce6f725367f8149f750575e79a8879d71b7257c02273259f9375822821f"
dependencies = [
"approx",
"arrayvec",
"bitflags 2.9.0",
"downcast-rs 2.0.1",
"either",
"ena",
"hashbrown",
"log",
"nalgebra",
"num-derive",
"num-traits",
"ordered-float 5.0.0",
"rstar",
"simba",
"slab",
"spade",
"thiserror 2.0.12",
]
[[package]]
name = "paste"
version = "1.0.15"
@ -4551,6 +4675,32 @@ version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f60fcc7d6849342eff22c4350c8b9a989ee8ceabc4b481253e8946b9fe83d684"
[[package]]
name = "rapier3d"
version = "0.25.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a35ec3d01c4f918675411442024a1fbfb7eafdd878a6e82479ff6e461a9092fc"
dependencies = [
"approx",
"arrayvec",
"bit-vec 0.8.0",
"bitflags 2.9.0",
"crossbeam",
"downcast-rs 2.0.1",
"log",
"nalgebra",
"num-derive",
"num-traits",
"ordered-float 5.0.0",
"parry3d",
"profiling",
"rayon",
"rustc-hash 2.1.1",
"simba",
"thiserror 2.0.12",
"vec_map",
]
[[package]]
name = "rav1e"
version = "0.7.1"
@ -4607,6 +4757,12 @@ version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20675572f6f24e9e76ef639bc5552774ed45f1c30e2951e1e99c59888861c539"
[[package]]
name = "rawpointer"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3"
[[package]]
name = "rayon"
version = "1.10.0"
@ -4717,6 +4873,12 @@ version = "0.8.50"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57397d16646700483b67d2dd6511d79318f9d057fdbd21a4066aeac8b41d310a"
[[package]]
name = "robust"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e27ee8bb91ca0adcf0ecb116293afa12d393f9c2b9b9cd54d33e8078fe19839"
[[package]]
name = "rodio"
version = "0.20.1"
@ -4745,6 +4907,17 @@ version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c20b6793b5c2fa6553b250154b78d6d0db37e72700ae35fad9387a46f487c97"
[[package]]
name = "rstar"
version = "0.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "421400d13ccfd26dfa5858199c30a5d76f9c54e0dba7575273025b43c5175dbb"
dependencies = [
"heapless",
"num-traits",
"smallvec",
]
[[package]]
name = "rustc-demangle"
version = "0.1.25"
@ -4757,6 +4930,12 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "rustc-hash"
version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d"
[[package]]
name = "rustc_version"
version = "0.2.3"
@ -4830,6 +5009,15 @@ version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
[[package]]
name = "safe_arch"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96b02de82ddbe1b636e6170c21be622223aea188ef2e139be0a5b219ec215323"
dependencies = [
"bytemuck",
]
[[package]]
name = "same-file"
version = "1.0.6"
@ -4947,6 +5135,19 @@ version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
name = "simba"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3a386a501cd104797982c15ae17aafe8b9261315b5d07e3ec803f2ea26be0fa"
dependencies = [
"approx",
"num-complex",
"num-traits",
"paste",
"wide",
]
[[package]]
name = "simd-adler32"
version = "0.3.7"
@ -5043,6 +5244,18 @@ dependencies = [
"serde",
]
[[package]]
name = "spade"
version = "2.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a14e31a007e9f85c32784b04f89e6e194bb252a4d41b4a8ccd9e77245d901c8c"
dependencies = [
"hashbrown",
"num-traits",
"robust",
"smallvec",
]
[[package]]
name = "spin"
version = "0.9.8"
@ -5476,6 +5689,12 @@ version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc7d623258602320d5c55d1bc22793b57daff0ec7efc270ea7d55ce1d5f5471c"
[[package]]
name = "typenum"
version = "1.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f"
[[package]]
name = "unicode-bidi"
version = "0.3.18"
@ -5875,7 +6094,7 @@ dependencies = [
"parking_lot",
"profiling",
"raw-window-handle",
"rustc-hash",
"rustc-hash 1.1.0",
"smallvec",
"thiserror 2.0.12",
"wgpu-hal",
@ -5912,13 +6131,13 @@ dependencies = [
"ndk-sys 0.5.0+25.2.9519653",
"objc",
"once_cell",
"ordered-float",
"ordered-float 4.6.0",
"parking_lot",
"profiling",
"range-alloc",
"raw-window-handle",
"renderdoc-sys",
"rustc-hash",
"rustc-hash 1.1.0",
"smallvec",
"thiserror 2.0.12",
"wasm-bindgen",
@ -5941,6 +6160,16 @@ dependencies = [
"web-sys",
]
[[package]]
name = "wide"
version = "0.7.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ce5da8ecb62bcd8ec8b7ea19f69a51275e91299be594ea5cc6ef7819e16cd03"
dependencies = [
"bytemuck",
"safe_arch",
]
[[package]]
name = "winapi"
version = "0.3.9"

View file

@ -14,6 +14,7 @@ bevy_skein = { git = "https://github.com/rust-adventure/skein.git" }
clap = { version = "4", features = ["derive"] }
shlex = "1.3.0"
bevy_ui_text_input = "0.5.2"
bevy_rapier3d = {version = "0.30.0", features = ["simd-stable", "debug-render", "parallel"]}
# Enable a small amount of optimization in the dev profile.
[profile.dev]

BIN
assets/gltf/test.bin Normal file

Binary file not shown.

Binary file not shown.

237
assets/gltf/test.gltf Normal file
View file

@ -0,0 +1,237 @@
{
"asset":{
"generator":"Khronos glTF Blender I/O v4.4.56",
"version":"2.0"
},
"scene":0,
"scenes":[
{
"extras":{
"skein_extension_properties":{
"enabled":1
}
},
"name":"Scene",
"nodes":[
0,
1
]
}
],
"nodes":[
{
"extras":{
"skein_two":[
{
"name":"TPCTarget",
"selected_type_path":"mgd2_demonic_posession::TPCTarget"
},
{
"name":"StaticColliderConfig",
"selected_type_path":"mgd2_demonic_posession::game::scene::StaticColliderConfig",
"mgd2_demonic_posession::game::scene::StaticColliderConfig":{
"x":10.0,
"y":5.0,
"z":1.0
}
}
],
"active_component_index":1,
"skein":[
{
"mgd2_demonic_posession::TPCTarget":{}
},
{
"mgd2_demonic_posession::game::scene::StaticColliderConfig":{
"x":10.0,
"y":5.0,
"z":1.0
}
}
]
},
"mesh":0,
"name":"Cube"
},
{
"extras":{
"skein_two":[
{
"name":"StaticColliderConfig",
"selected_type_path":"mgd2_demonic_posession::game::scene::StaticColliderConfig",
"mgd2_demonic_posession::game::scene::StaticColliderConfig":{
"y":2.0,
"z":2.0,
"x":2.0
}
}
],
"active_component_index":0,
"skein":[
{
"mgd2_demonic_posession::game::scene::StaticColliderConfig":{
"x":2.0,
"y":2.0,
"z":2.0
}
}
]
},
"mesh":1,
"name":"Cube.001",
"rotation":[
0,
0.3594704866409302,
0,
0.9331565499305725
],
"translation":[
0,
1.5,
0
]
}
],
"meshes":[
{
"name":"Cube.001",
"primitives":[
{
"attributes":{
"POSITION":0,
"NORMAL":1,
"TEXCOORD_0":2
},
"indices":3
}
]
},
{
"name":"Cube",
"primitives":[
{
"attributes":{
"POSITION":4,
"NORMAL":5,
"TEXCOORD_0":6
},
"indices":3
}
]
}
],
"accessors":[
{
"bufferView":0,
"componentType":5126,
"count":24,
"max":[
5,
0.5,
2.5
],
"min":[
-5,
-0.5,
-2.5
],
"type":"VEC3"
},
{
"bufferView":1,
"componentType":5126,
"count":24,
"type":"VEC3"
},
{
"bufferView":2,
"componentType":5126,
"count":24,
"type":"VEC2"
},
{
"bufferView":3,
"componentType":5123,
"count":36,
"type":"SCALAR"
},
{
"bufferView":4,
"componentType":5126,
"count":24,
"max":[
1,
1,
1
],
"min":[
-1,
-1,
-1
],
"type":"VEC3"
},
{
"bufferView":5,
"componentType":5126,
"count":24,
"type":"VEC3"
},
{
"bufferView":6,
"componentType":5126,
"count":24,
"type":"VEC2"
}
],
"bufferViews":[
{
"buffer":0,
"byteLength":288,
"byteOffset":0,
"target":34962
},
{
"buffer":0,
"byteLength":288,
"byteOffset":288,
"target":34962
},
{
"buffer":0,
"byteLength":192,
"byteOffset":576,
"target":34962
},
{
"buffer":0,
"byteLength":72,
"byteOffset":768,
"target":34963
},
{
"buffer":0,
"byteLength":288,
"byteOffset":840,
"target":34962
},
{
"buffer":0,
"byteLength":288,
"byteOffset":1128,
"target":34962
},
{
"buffer":0,
"byteLength":192,
"byteOffset":1416,
"target":34962
}
],
"buffers":[
{
"byteLength":1608,
"uri":"test.bin"
}
]
}

Binary file not shown.

View file

@ -3,6 +3,7 @@ use std::{fs, path::PathBuf};
use bevy::prelude::*;
use bevy_inspector_egui::{bevy_egui::EguiPlugin, quick::WorldInspectorPlugin};
use bevy_rapier3d::render::RapierDebugRenderPlugin;
use clap::Subcommand;
use console::exec_script;
@ -36,7 +37,11 @@ pub fn plugin(app: &mut App) {
.in_set(DebugSet),
)
.add_systems(Startup, startup_file.pipe(exec_script))
.add_plugins((console::plugin /* WorldInspectorPlugin::default() */,));
.add_plugins((
console::plugin,
WorldInspectorPlugin::default(),
RapierDebugRenderPlugin::default().disabled(),
));
}
fn start_game(

View file

@ -68,4 +68,8 @@ pub enum DebugEvent {
/// Despawn an entity by string id. Uniqueness of Ids isn't guaranteed.
Despawn { id: String },
/// Toggles rapier debug mode
#[command(aliases = ["rapier-debug", "rapier"])]
DebugRapier,
}

View file

@ -16,15 +16,9 @@ struct GameplaySet;
pub fn plugin(app: &mut App) {
app.add_systems(
OnEnter(AppState::Ingame),
scene::setup
.in_set(GameplaySet)
.run_if(in_state(DebugMode::Disabled)),
)
.add_systems(
OnExit(AppState::Ingame),
despawn::<cleanup::Scene>.in_set(GameplaySet),
)
.add_plugins((camera::plugin, debug::plugin));
.add_plugins((camera::plugin, scene::plugin, debug::plugin));
app.configure_sets(Update, GameplaySet.run_if(in_state(AppState::Ingame)));
}

View file

@ -4,6 +4,7 @@ use bevy::{
asset::{AssetPath, io::AssetSourceEvent},
prelude::*,
};
use bevy_rapier3d::render::DebugRenderContext;
use crate::debug::{ConsoleLog, DebugEvent, DebugMode};
@ -13,6 +14,7 @@ pub fn plugin(app: &mut App) {
(
handle_load_gltf.run_if(in_state(DebugMode::Enabled)),
handle_despawn,
handle_debug_rapier,
),
);
}
@ -74,3 +76,20 @@ fn handle_despawn(
}
}
}
fn handle_debug_rapier(
mut dbg_reader: EventReader<DebugEvent>,
mut logger: ResMut<ConsoleLog>,
mut rapier_ctx: ResMut<DebugRenderContext>,
) {
for ev in dbg_reader.read() {
if &DebugEvent::DebugRapier == ev {
rapier_ctx.enabled = !rapier_ctx.enabled;
logger.write(if rapier_ctx.enabled {
"Enabled Rapier debug rendering."
} else {
"Disabled Rapier debug rendering."
})
}
}
}

View file

@ -1,21 +1,32 @@
use bevy::prelude::*;
use bevy_rapier3d::prelude::{Collider, RigidBody};
use bevy_third_person_camera::ThirdPersonCameraTarget;
use log::info;
use crate::cleanup;
use crate::{AppState, cleanup};
pub fn setup(
mut c: Commands,
asset_server: Res<AssetServer>,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
let scene_handle = asset_server.load(GltfAssetLabel::Scene(0).from_asset("gltf/test.glb"));
c.spawn((
Mesh3d(meshes.add(Cuboid::new(1., 1., 1.))),
MeshMaterial3d(materials.add(Color::BLACK)),
ThirdPersonCameraTarget,
cleanup::Scene,
));
c.spawn(SceneRoot(scene_handle));
info!("Scene spawned!")
pub fn plugin(app: &mut App) {
app.register_type::<StaticColliderConfig>()
// .add_systems(OnEnter(AppState::Ingame), test_spawn_on_init)
.add_systems(Update, add_colliders_to_things_that_need_them);
}
// uses blender coords
#[derive(Component, Clone, Copy, Reflect)]
#[reflect(Component)]
pub struct StaticColliderConfig {
x: f32,
y: f32,
z: f32,
}
fn add_colliders_to_things_that_need_them(
mut c: Commands,
to_modify: Query<(Entity, &StaticColliderConfig), Without<Collider>>,
) {
for (entity, StaticColliderConfig { x, y, z }) in to_modify.iter() {
info!("meow");
c.entity(entity)
.insert(Collider::cuboid(*x / 2., *z / 2., -*y / 2.));
}
}

View file

@ -1,5 +1,6 @@
#![feature(iter_collect_into)]
use bevy::prelude::*;
use bevy_rapier3d::plugin::{NoUserData, RapierPhysicsPlugin};
use bevy_skein::SkeinPlugin;
use bevy_ui_text_input::TextInputPlugin;
use clap::ValueEnum;
@ -24,7 +25,12 @@ fn main() {
.register_type::<TPCTarget>()
.add_systems(Startup, camera::setup)
.add_plugins((DefaultPlugins, TextInputPlugin))
.add_plugins((game::plugin, menus::plugin, debug::plugin))
.add_plugins((
RapierPhysicsPlugin::<NoUserData>::default(),
game::plugin,
menus::plugin,
debug::plugin,
))
.add_plugins(SkeinPlugin::default())
.init_state::<AppState>()
.register_type::<AppState>()

View file

@ -2,4 +2,4 @@ log "hello from startup script!!"
enable-debug
start-game
load-scene gltf/test.glb test
load-scene gltf/test.gltf test

2
test.tx Normal file
View file

@ -0,0 +1,2 @@
despawn test
load-scene gltf/test.gltf test