Skip to content
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

Rasmusgo/floor plane #438

Merged
merged 2 commits into from
Apr 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 22 additions & 1 deletion examples/simple-scene/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
use hotham::{
asset_importer::{self, add_model_to_world},
components::{hand::Handedness, physics::SharedShape, Collider, LocalTransform, RigidBody},
components::{
hand::Handedness,
physics::{BodyType, SharedShape},
Collider, LocalTransform, RigidBody,
},
hecs::World,
na,
systems::{
animation_system, debug::debug_system, grabbing_system, hands::add_hand, hands_system,
physics_system, rendering::rendering_system, skinning::skinning_system,
Expand Down Expand Up @@ -57,11 +62,13 @@ fn init(engine: &mut Engine) -> Result<(), hotham::HothamError> {
let world = &mut engine.world;

let mut glb_buffers: Vec<&[u8]> = vec![
include_bytes!("../../../test_assets/floor.glb"),
include_bytes!("../../../test_assets/left_hand.glb"),
include_bytes!("../../../test_assets/right_hand.glb"),
];
let models =
asset_importer::load_models_from_glb(&glb_buffers, vulkan_context, render_context)?;
add_floor(&models, world);
add_hand(&models, Handedness::Left, world);
add_hand(&models, Handedness::Right, world);

Expand All @@ -78,9 +85,23 @@ fn init(engine: &mut Engine) -> Result<(), hotham::HothamError> {
add_helmet(&models, world);
add_model_to_world("Cube", &models, world, None);

// Update global transforms from local transforms before physics_system gets confused
update_global_transform_system(engine);
update_global_transform_with_parent_system(engine);

Ok(())
}

fn add_floor(models: &std::collections::HashMap<String, World>, world: &mut World) {
let entity = add_model_to_world("Floor", models, world, None).expect("Could not find Floor");
let collider = Collider::new(SharedShape::halfspace(na::Vector3::y_axis()));
let rigid_body = RigidBody {
body_type: BodyType::Fixed,
..Default::default()
};
world.insert(entity, (collider, rigid_body)).unwrap();
}

fn add_helmet(models: &std::collections::HashMap<String, World>, world: &mut World) {
let helmet = add_model_to_world("Damaged Helmet", models, world, None)
.expect("Could not find Damaged Helmet");
Expand Down
1 change: 1 addition & 0 deletions hotham/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub use glam;
pub use hecs;
pub use hotham_error::HothamError;
pub use id_arena;
pub use rapier3d::na;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed for

let collider = Collider::new(SharedShape::halfspace(na::Vector3::y_axis()));


/// Components are data that are used to update the simulation and interact with the external world
pub mod components;
Expand Down
3 changes: 3 additions & 0 deletions test_assets/floor.glb
Git LFS file not shown