Skip to content
Open
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
15 changes: 8 additions & 7 deletions crates/bevy_gltf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ license = "MIT OR Apache-2.0"
keywords = ["bevy"]

[features]
pbr_transmission_textures = ["bevy_pbr/pbr_transmission_textures"]
pbr_transmission_textures = ["bevy_material/pbr_transmission_textures"]
pbr_multi_layer_material_textures = [
"bevy_pbr/pbr_multi_layer_material_textures",
"bevy_material/pbr_multi_layer_material_textures",
]
pbr_anisotropy_texture = ["bevy_pbr/pbr_anisotropy_texture"]
pbr_specular_textures = ["bevy_pbr/pbr_specular_textures"]
pbr_anisotropy_texture = ["bevy_material/pbr_anisotropy_texture"]
pbr_specular_textures = ["bevy_material/pbr_specular_textures"]

[dependencies]
# bevy
Expand All @@ -29,10 +29,11 @@ bevy_image = { path = "../bevy_image", version = "0.18.0-dev" }
bevy_light = { path = "../bevy_light", version = "0.18.0-dev" }
bevy_camera = { path = "../bevy_camera", version = "0.18.0-dev" }
bevy_math = { path = "../bevy_math", version = "0.18.0-dev" }
bevy_mesh = { path = "../bevy_mesh", version = "0.18.0-dev" }
bevy_pbr = { path = "../bevy_pbr", version = "0.18.0-dev" }
bevy_mesh = { path = "../bevy_mesh", version = "0.18.0-dev", features = [
"morph",
"bevy_mikktspace",
] }
bevy_reflect = { path = "../bevy_reflect", version = "0.18.0-dev" }
bevy_render = { path = "../bevy_render", version = "0.18.0-dev" }
bevy_material = { path = "../bevy_material", version = "0.18.0-dev" }
bevy_scene = { path = "../bevy_scene", version = "0.18.0-dev" }
bevy_transform = { path = "../bevy_transform", version = "0.18.0-dev" }
Expand Down
12 changes: 6 additions & 6 deletions crates/bevy_gltf/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use core::ops::Deref;
use bevy_animation::AnimationClip;
use bevy_asset::{Asset, Handle};
use bevy_ecs::{component::Component, reflect::ReflectComponent};
use bevy_material::pbr_material::ShortStandardMaterial;
use bevy_mesh::{skinning::SkinnedMeshInverseBindposes, Mesh};
use bevy_pbr::StandardMaterial;
use bevy_platform::collections::HashMap;
use bevy_reflect::{prelude::ReflectDefault, Reflect, TypePath};
use bevy_scene::Scene;
Expand All @@ -26,9 +26,9 @@ pub struct Gltf {
/// Named meshes loaded from the glTF file.
pub named_meshes: HashMap<Box<str>, Handle<GltfMesh>>,
/// All materials loaded from the glTF file.
pub materials: Vec<Handle<StandardMaterial>>,
pub materials: Vec<Handle<ShortStandardMaterial>>,
/// Named materials loaded from the glTF file.
pub named_materials: HashMap<Box<str>, Handle<StandardMaterial>>,
pub named_materials: HashMap<Box<str>, Handle<ShortStandardMaterial>>,
/// All nodes loaded from the glTF file.
pub nodes: Vec<Handle<GltfNode>>,
/// Named nodes loaded from the glTF file.
Expand Down Expand Up @@ -158,7 +158,7 @@ impl GltfNode {
}
}

/// Part of a [`GltfMesh`] that consists of a [`Mesh`], an optional [`StandardMaterial`] and [`GltfExtras`].
/// Part of a [`GltfMesh`] that consists of a [`Mesh`], an optional [`ShortStandardMaterial`] and [`GltfExtras`].
///
/// See [the relevant glTF specification section](https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-mesh-primitive).
#[derive(Asset, Debug, Clone, TypePath)]
Expand All @@ -172,7 +172,7 @@ pub struct GltfPrimitive {
/// Topology to be rendered.
pub mesh: Handle<Mesh>,
/// Material to apply to the `mesh`.
pub material: Option<Handle<StandardMaterial>>,
pub material: Option<Handle<ShortStandardMaterial>>,
/// Additional data.
pub extras: Option<GltfExtras>,
/// Additional data of the `material`.
Expand All @@ -185,7 +185,7 @@ impl GltfPrimitive {
gltf_mesh: &gltf::Mesh,
gltf_primitive: &gltf::Primitive,
mesh: Handle<Mesh>,
material: Option<Handle<StandardMaterial>>,
material: Option<Handle<ShortStandardMaterial>>,
extras: Option<GltfExtras>,
material_extras: Option<GltfExtras>,
) -> Self {
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_gltf/src/label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ pub enum GltfAssetLabel {
},
/// `Texture{}`: glTF Texture as a Bevy [`Image`](bevy_image::prelude::Image)
Texture(usize),
/// `Material{}`: glTF Material as a Bevy [`StandardMaterial`](bevy_pbr::StandardMaterial)
/// `Material{}`: glTF Material as a Bevy [`ShortStandardMaterial`](bevy_material::ShortStandardMaterial)
Material {
/// Index of this material
index: usize,
/// Used to set the [`Face`](bevy_render::render_resource::Face) of the material,
/// Used to set the [`Face`](bevy_material::render_resource::Face) of the material,
/// useful if it is used with negative scale
is_scale_inverted: bool,
},
/// `DefaultMaterial`: glTF's default Material as a
/// Bevy [`StandardMaterial`](bevy_pbr::StandardMaterial)
/// Bevy [`ShortStandardMaterial`](bevy_material::ShortStandardMaterial)
DefaultMaterial,
/// `Animation{}`: glTF Animation as Bevy [`AnimationClip`](bevy_animation::AnimationClip)
Animation(usize),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use {
/// `KHR_materials_specular` specification requirement that stems from the fact
/// that glTF is specified in terms of a specular strength model, not the
/// reflectance model that Filament and Bevy use. A workaround, which is noted
/// in the [`StandardMaterial`](bevy_pbr::StandardMaterial) documentation, is to set the reflectance value
/// in the [`ShortStandardMaterial`](bevy_material::ShortStandardMaterial) documentation, is to set the reflectance value
/// to 2.0, which spreads the specular map range from [0.0, 1.0] as normal.
///
/// See the specification:
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_gltf/src/loader/gltf_ext/material.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bevy_material::alpha::AlphaMode;
use bevy_material::UvChannel;
use bevy_math::Affine2;
use bevy_render::alpha::AlphaMode;

use gltf::{json::texture::Info, Material};

Expand Down
18 changes: 8 additions & 10 deletions crates/bevy_gltf/src/loader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ use bevy_image::{
ImageType, TextureError,
};
use bevy_light::{DirectionalLight, PointLight, SpotLight};
use bevy_material::pbr_material::{MarkerMeshMaterial3d, ShortStandardMaterial};
#[cfg(feature = "pbr_transmission_textures")]
use bevy_material::UvChannel;
use bevy_material::{mesh::skin::MAX_JOINTS, render_resource::Face};
use bevy_math::{Mat4, Vec3};
use bevy_mesh::{
morph::{MeshMorphWeights, MorphAttributes, MorphTargetImage, MorphWeights},
skinning::{SkinnedMesh, SkinnedMeshInverseBindposes},
Indices, Mesh, Mesh3d, MeshVertexAttribute, PrimitiveTopology,
};
use bevy_pbr::{MeshMaterial3d, StandardMaterial, MAX_JOINTS};
use bevy_platform::collections::{HashMap, HashSet};
use bevy_render::render_resource::Face;
use bevy_scene::Scene;
#[cfg(not(target_arch = "wasm32"))]
use bevy_tasks::IoTaskPool;
Expand Down Expand Up @@ -1143,13 +1143,13 @@ async fn load_image<'a, 'b>(
}
}

/// Loads a glTF material as a bevy [`StandardMaterial`] and returns it.
/// Loads a glTF material as a bevy [`ShortStandardMaterial`] and returns it.
fn load_material(
material: &Material,
load_context: &mut LoadContext,
document: &Document,
is_scale_inverted: bool,
) -> Handle<StandardMaterial> {
) -> Handle<ShortStandardMaterial> {
let material_label = material_label(material, is_scale_inverted);
load_context
.labeled_asset_scope::<_, ()>(material_label.to_string(), |load_context| {
Expand Down Expand Up @@ -1303,7 +1303,7 @@ fn load_material(
let base_emissive = LinearRgba::rgb(emissive[0], emissive[1], emissive[2]);
let emissive = base_emissive * material.emissive_strength().unwrap_or(1.0);

Ok(StandardMaterial {
Ok(ShortStandardMaterial {
base_color: Color::linear_rgba(color[0], color[1], color[2], color[3]),
base_color_channel,
base_color_texture,
Expand Down Expand Up @@ -1534,9 +1534,7 @@ fn load_node(
let mut mesh_entity = parent.spawn((
// TODO: handle missing label handle errors here?
Mesh3d(load_context.get_label_handle(primitive_label.to_string())),
MeshMaterial3d::<StandardMaterial>(
load_context.get_label_handle(&material_label),
),
MarkerMeshMaterial3d(load_context.get_label_handle(&material_label)),
));

let target_count = primitive.morph_targets().len();
Expand Down Expand Up @@ -1915,9 +1913,9 @@ mod test {
use bevy_ecs::{resource::Resource, world::World};
use bevy_image::{Image, ImageLoaderSettings};
use bevy_log::LogPlugin;
use bevy_material::ShortStandardMaterial;
use bevy_mesh::skinning::SkinnedMeshInverseBindposes;
use bevy_mesh::MeshPlugin;
use bevy_pbr::StandardMaterial;
use bevy_scene::ScenePlugin;

fn test_app(dir: Dir) -> App {
Expand Down Expand Up @@ -2408,7 +2406,7 @@ mod test {
fn reads_images_in_custom_asset_source() {
let (mut app, dir) = test_app_custom_asset_source();

app.init_asset::<StandardMaterial>();
app.init_asset::<ShortStandardMaterial>();

// Note: We need the material here since otherwise we don't store the texture handle, which
// can result in the image getting dropped leading to the gltf never being loaded with
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_internal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ bevy_ui_render = ["dep:bevy_ui_render", "bevy_sprite_render", "bevy_ui"]
bevy_solari = ["dep:bevy_solari", "bevy_pbr"]
bevy_gizmos = ["dep:bevy_gizmos", "bevy_camera"]
bevy_gizmos_render = ["dep:bevy_gizmos_render", "bevy_gizmos"]
bevy_gltf = ["dep:bevy_gltf", "bevy_scene", "bevy_pbr"]
bevy_gltf = ["dep:bevy_gltf", "bevy_material", "bevy_scene", "bevy_pbr"]

# Used to disable code that is unsupported when Bevy is dynamically linked
dynamic_linking = ["bevy_diagnostic/dynamic_linking"]
Expand Down
2 changes: 2 additions & 0 deletions crates/bevy_internal/src/default_plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ plugin_group! {
bevy_ui:::UiPlugin,
#[cfg(feature = "bevy_ui_render")]
bevy_ui_render:::UiRenderPlugin,
#[cfg(feature = "bevy_material")]
bevy_material::pbr_material:::ShortMaterialPlugin,
#[cfg(feature = "bevy_pbr")]
bevy_pbr:::PbrPlugin,
// NOTE: Load this after renderer initialization so that it knows about the supported
Expand Down
6 changes: 6 additions & 0 deletions crates/bevy_material/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ repository = "https://github.com/bevyengine/bevy"
license = "MIT OR Apache-2.0"
keywords = ["bevy"]

[features]
pbr_transmission_textures = []
pbr_multi_layer_material_textures = []
pbr_anisotropy_texture = []
pbr_specular_textures = []

[dependencies]
# bevy
bevy_app = { path = "../bevy_app", version = "0.18.0-dev" }
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_material/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ extern crate alloc;

pub mod alpha;
pub mod material;
pub mod mesh;
pub mod opaque;
pub mod pbr_material;
pub mod render;
Expand All @@ -16,7 +17,7 @@ pub mod render_resource;
/// This includes the most common types in this crate, re-exported for your convenience.
pub mod prelude {
#[doc(hidden)]
pub use crate::alpha::AlphaMode;
pub use crate::{alpha::AlphaMode, pbr_material::ShortMaterialPlugin};
}

pub use pbr_material::*;
1 change: 1 addition & 0 deletions crates/bevy_material/src/mesh/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod skin;
34 changes: 34 additions & 0 deletions crates/bevy_material/src/mesh/skin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use core::mem::size_of;

use bevy_math::Mat4;

/// Maximum number of joints supported for skinned meshes.
///
/// It is used to allocate buffers.
/// The correctness of the value depends on the GPU/platform.
/// The current value is chosen because it is guaranteed to work everywhere.
/// To allow for bigger values, a check must be made for the limits
/// of the GPU at runtime, which would mean not using consts anymore.
pub const MAX_JOINTS: usize = 256;

/// The total number of joints we support.
///
/// This is 256 GiB worth of joint matrices, which we will never hit under any
/// reasonable circumstances.
pub const MAX_TOTAL_JOINTS: u32 = 1024 * 1024 * 1024;

/// The number of joints that we allocate at a time.
///
/// Some hardware requires that uniforms be allocated on 256-byte boundaries, so
/// we need to allocate 4 64-byte matrices at a time to satisfy alignment
/// requirements.
pub const JOINTS_PER_ALLOCATION_UNIT: u32 = (256 / size_of::<Mat4>()) as u32;

/// The maximum ratio of the number of entities whose transforms changed to the
/// total number of joints before we re-extract all joints.
///
/// We use this as a heuristic to decide whether it's worth switching over to
/// fine-grained detection to determine which skins need extraction. If the
/// number of changed entities is over this threshold, we skip change detection
/// and simply re-extract the transforms of all joints.
pub const JOINT_EXTRACTION_THRESHOLD_FACTOR: f64 = 0.25;
Loading