From 8123735652d56c045fa141f4cd3be3e2172f6c8c Mon Sep 17 00:00:00 2001 From: Robert Swain Date: Sat, 24 Jul 2021 23:33:07 +0200 Subject: [PATCH 1/2] Add bevy_gltf2 --- Cargo.toml | 7 +- crates/bevy_internal/Cargo.toml | 1 + crates/bevy_internal/src/default_plugins.rs | 4 + crates/bevy_internal/src/lib.rs | 6 + examples/3d/load_gltf_pipelined.rs | 62 ++ examples/README.md | 1 + pipelined/bevy_gltf2/Cargo.toml | 35 + pipelined/bevy_gltf2/src/lib.rs | 60 ++ pipelined/bevy_gltf2/src/loader.rs | 868 ++++++++++++++++++++ 9 files changed, 1043 insertions(+), 1 deletion(-) create mode 100644 examples/3d/load_gltf_pipelined.rs create mode 100644 pipelined/bevy_gltf2/Cargo.toml create mode 100644 pipelined/bevy_gltf2/src/lib.rs create mode 100644 pipelined/bevy_gltf2/src/loader.rs diff --git a/Cargo.toml b/Cargo.toml index 84b9e1d5455e9..920153c08a953 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ default = [ "bevy_core_pipeline", "bevy_dynamic_plugin", "bevy_gilrs", - "bevy_gltf", + "bevy_gltf2", "bevy_wgpu", "bevy_sprite2", "bevy_render2", @@ -56,6 +56,7 @@ bevy_core_pipeline = ["bevy_internal/bevy_core_pipeline"] bevy_render2 = ["bevy_internal/bevy_render2"] bevy_sprite2 = ["bevy_internal/bevy_sprite2"] bevy_pbr2 = ["bevy_internal/bevy_pbr2"] +bevy_gltf2 = ["bevy_internal/bevy_gltf2"] trace_chrome = ["bevy_internal/trace_chrome"] trace = ["bevy_internal/trace"] @@ -156,6 +157,10 @@ path = "examples/3d/cornell_box_pipelined.rs" name = "load_gltf" path = "examples/3d/load_gltf.rs" +[[example]] +name = "load_gltf_pipelined" +path = "examples/3d/load_gltf_pipelined.rs" + [[example]] name = "msaa" path = "examples/3d/msaa.rs" diff --git a/crates/bevy_internal/Cargo.toml b/crates/bevy_internal/Cargo.toml index 036a053df4bee..8f7a1d2c2dd9e 100644 --- a/crates/bevy_internal/Cargo.toml +++ b/crates/bevy_internal/Cargo.toml @@ -68,6 +68,7 @@ bevy_tasks = { path = "../bevy_tasks", version = "0.5.0" } bevy_audio = { path = "../bevy_audio", optional = true, version = "0.5.0" } bevy_core_pipeline = { path = "../../pipelined/bevy_core_pipeline", optional = true, version = "0.5.0" } bevy_gltf = { path = "../bevy_gltf", optional = true, version = "0.5.0" } +bevy_gltf2 = { path = "../../pipelined/bevy_gltf2", optional = true, version = "0.5.0" } bevy_pbr = { path = "../bevy_pbr", optional = true, version = "0.5.0" } bevy_pbr2 = { path = "../../pipelined/bevy_pbr2", optional = true, version = "0.5.0" } bevy_render = { path = "../bevy_render", optional = true, version = "0.5.0" } diff --git a/crates/bevy_internal/src/default_plugins.rs b/crates/bevy_internal/src/default_plugins.rs index 6d506e5651b27..27e206d657af8 100644 --- a/crates/bevy_internal/src/default_plugins.rs +++ b/crates/bevy_internal/src/default_plugins.rs @@ -117,6 +117,7 @@ impl PluginGroup for PipelinedDefaultPlugins { group.add(bevy_input::InputPlugin::default()); group.add(bevy_window::WindowPlugin::default()); group.add(bevy_asset::AssetPlugin::default()); + group.add(bevy_scene::ScenePlugin::default()); #[cfg(feature = "bevy_render2")] { @@ -132,6 +133,9 @@ impl PluginGroup for PipelinedDefaultPlugins { #[cfg(feature = "bevy_pbr2")] group.add(bevy_pbr2::PbrPlugin::default()); + + #[cfg(feature = "bevy_gltf2")] + group.add(bevy_gltf2::GltfPlugin::default()); } #[cfg(feature = "bevy_winit")] diff --git a/crates/bevy_internal/src/lib.rs b/crates/bevy_internal/src/lib.rs index a47ee1984062a..932971b6f1046 100644 --- a/crates/bevy_internal/src/lib.rs +++ b/crates/bevy_internal/src/lib.rs @@ -99,6 +99,12 @@ pub mod gltf { pub use bevy_gltf::*; } +#[cfg(feature = "bevy_gltf2")] +pub mod gltf2 { + //! Support for GLTF file loading. + pub use bevy_gltf2::*; +} + #[cfg(feature = "bevy_pbr")] pub mod pbr { //! Physically based rendering. diff --git a/examples/3d/load_gltf_pipelined.rs b/examples/3d/load_gltf_pipelined.rs new file mode 100644 index 0000000000000..8b842095e92b5 --- /dev/null +++ b/examples/3d/load_gltf_pipelined.rs @@ -0,0 +1,62 @@ +use bevy::{ + core::Time, + ecs::prelude::*, + math::{EulerRot, Quat, Vec3}, + pbr2::{AmbientLight, DirectionalLight, DirectionalLightBundle}, + prelude::{App, AssetServer, SpawnSceneCommands, Transform}, + render2::{ + camera::{OrthographicProjection, PerspectiveCameraBundle}, + color::Color, + }, + PipelinedDefaultPlugins, +}; + +fn main() { + App::new() + .insert_resource(AmbientLight { + color: Color::WHITE, + brightness: 1.0 / 5.0f32, + }) + .add_plugins(PipelinedDefaultPlugins) + .add_startup_system(setup.system()) + .add_system(animate_light_direction.system()) + .run(); +} + +fn setup(mut commands: Commands, asset_server: Res) { + commands.spawn_scene(asset_server.load("models/FlightHelmet/FlightHelmet.gltf#Scene0")); + commands.spawn_bundle(PerspectiveCameraBundle { + transform: Transform::from_xyz(0.7, 0.7, 1.0).looking_at(Vec3::new(0.0, 0.3, 0.0), Vec3::Y), + ..Default::default() + }); + const HALF_SIZE: f32 = 1.0; + commands.spawn_bundle(DirectionalLightBundle { + directional_light: DirectionalLight { + shadow_projection: OrthographicProjection { + left: -HALF_SIZE, + right: HALF_SIZE, + bottom: -HALF_SIZE, + top: HALF_SIZE, + near: -10.0 * HALF_SIZE, + far: 10.0 * HALF_SIZE, + ..Default::default() + }, + ..Default::default() + }, + ..Default::default() + }); +} + +fn animate_light_direction( + time: Res