-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port bevy_gltf to pipelined-rendering (#2537)
# Objective Port bevy_gltf to the pipelined-rendering branch. ## Solution crates/bevy_gltf has been copied and pasted into pipelined/bevy_gltf2 and modifications were made to work with the pipelined-rendering branch. Notably vertex tangents and vertex colours are not supported.
- Loading branch information
Showing
9 changed files
with
1,043 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<AssetServer>) { | ||
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<Time>, | ||
mut query: Query<&mut Transform, With<DirectionalLight>>, | ||
) { | ||
for mut transform in query.iter_mut() { | ||
transform.rotation = Quat::from_euler( | ||
EulerRot::ZYX, | ||
0.0, | ||
time.seconds_since_startup() as f32 * std::f32::consts::TAU / 10.0, | ||
-std::f32::consts::FRAC_PI_4, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
[package] | ||
name = "bevy_gltf2" | ||
version = "0.5.0" | ||
edition = "2018" | ||
authors = [ | ||
"Bevy Contributors <bevyengine@gmail.com>", | ||
"Carter Anderson <mcanders1@gmail.com>", | ||
] | ||
description = "Bevy Engine GLTF loading" | ||
homepage = "https://bevyengine.org" | ||
repository = "https://github.com/bevyengine/bevy" | ||
license = "MIT OR Apache-2.0" | ||
keywords = ["bevy"] | ||
|
||
[dependencies] | ||
# bevy | ||
bevy_app = { path = "../../crates/bevy_app", version = "0.5.0" } | ||
bevy_asset = { path = "../../crates/bevy_asset", version = "0.5.0" } | ||
bevy_core = { path = "../../crates/bevy_core", version = "0.5.0" } | ||
bevy_ecs = { path = "../../crates/bevy_ecs", version = "0.5.0" } | ||
bevy_pbr2 = { path = "../bevy_pbr2", version = "0.5.0" } | ||
bevy_reflect = { path = "../../crates/bevy_reflect", version = "0.5.0", features = ["bevy"] } | ||
bevy_render2 = { path = "../bevy_render2", version = "0.5.0" } | ||
bevy_transform = { path = "../../crates/bevy_transform", version = "0.5.0" } | ||
bevy_math = { path = "../../crates/bevy_math", version = "0.5.0" } | ||
bevy_scene = { path = "../../crates/bevy_scene", version = "0.5.0" } | ||
bevy_log = { path = "../../crates/bevy_log", version = "0.5.0" } | ||
|
||
# other | ||
gltf = { version = "0.16.0", default-features = false, features = ["utils", "names", "KHR_materials_unlit"] } | ||
thiserror = "1.0" | ||
anyhow = "1.0.4" | ||
base64 = "0.13.0" | ||
percent-encoding = "2.1" | ||
wgpu = "0.9" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use std::collections::HashMap; | ||
|
||
mod loader; | ||
pub use loader::*; | ||
|
||
use bevy_app::prelude::*; | ||
use bevy_asset::{AddAsset, Handle}; | ||
use bevy_pbr2::StandardMaterial; | ||
use bevy_reflect::TypeUuid; | ||
use bevy_render2::mesh::Mesh; | ||
use bevy_scene::Scene; | ||
|
||
/// Adds support for GLTF file loading to Apps | ||
#[derive(Default)] | ||
pub struct GltfPlugin; | ||
|
||
impl Plugin for GltfPlugin { | ||
fn build(&self, app: &mut App) { | ||
app.init_asset_loader::<GltfLoader>() | ||
.add_asset::<Gltf>() | ||
.add_asset::<GltfNode>() | ||
.add_asset::<GltfPrimitive>() | ||
.add_asset::<GltfMesh>(); | ||
} | ||
} | ||
|
||
#[derive(Debug, TypeUuid)] | ||
#[uuid = "5c7d5f8a-f7b0-4e45-a09e-406c0372fea2"] | ||
pub struct Gltf { | ||
pub scenes: Vec<Handle<Scene>>, | ||
pub named_scenes: HashMap<String, Handle<Scene>>, | ||
pub meshes: Vec<Handle<GltfMesh>>, | ||
pub named_meshes: HashMap<String, Handle<GltfMesh>>, | ||
pub materials: Vec<Handle<StandardMaterial>>, | ||
pub named_materials: HashMap<String, Handle<StandardMaterial>>, | ||
pub nodes: Vec<Handle<GltfNode>>, | ||
pub named_nodes: HashMap<String, Handle<GltfNode>>, | ||
pub default_scene: Option<Handle<Scene>>, | ||
} | ||
|
||
#[derive(Debug, Clone, TypeUuid)] | ||
#[uuid = "dad74750-1fd6-460f-ac51-0a7937563865"] | ||
pub struct GltfNode { | ||
pub children: Vec<GltfNode>, | ||
pub mesh: Option<Handle<GltfMesh>>, | ||
pub transform: bevy_transform::prelude::Transform, | ||
} | ||
|
||
#[derive(Debug, Clone, TypeUuid)] | ||
#[uuid = "8ceaec9a-926a-4f29-8ee3-578a69f42315"] | ||
pub struct GltfMesh { | ||
pub primitives: Vec<GltfPrimitive>, | ||
} | ||
|
||
#[derive(Debug, Clone, TypeUuid)] | ||
#[uuid = "cbfca302-82fd-41cb-af77-cab6b3d50af1"] | ||
pub struct GltfPrimitive { | ||
pub mesh: Handle<Mesh>, | ||
pub material: Option<Handle<StandardMaterial>>, | ||
} |
Oops, something went wrong.