Skip to content

Commit

Permalink
fix "unused" warnings when compiling with render feature but withou…
Browse files Browse the repository at this point in the history
…t `animation` (bevyengine#4714)

# Objective
When running `cargo check --no-default-features --features render` I get
```rust
warning: unused import: `Quat`
  --> crates/bevy_gltf/src/loader.rs:11:23
   |
11 | use bevy_math::{Mat4, Quat, Vec3};
   |                       ^^^^
   |
   = note: `#[warn(unused_imports)]` on by default

warning: function is never used: `paths_recur`
   --> crates/bevy_gltf/src/loader.rs:542:4
    |
542 | fn paths_recur(
    |    ^^^^^^^^^^^
    |
    = note: `#[warn(dead_code)]` on by default
```

## Solution

Put these items behind `#[cfg(feature = "animation")]`.
  • Loading branch information
jakobhellermann authored and robtfm committed May 17, 2022
1 parent f562869 commit 3233ecc
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions crates/bevy_gltf/src/loader.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use anyhow::Result;
#[cfg(feature = "bevy_animation")]
use bevy_animation::{AnimationClip, AnimationPlayer, EntityPath, Keyframes, VariableCurve};
use bevy_asset::{
AssetIoError, AssetLoader, AssetPath, BoxedFuture, Handle, LoadContext, LoadedAsset,
};
use bevy_core::Name;
use bevy_ecs::{entity::Entity, prelude::FromWorld, world::World};
use bevy_hierarchy::{BuildWorldChildren, WorldChildBuilder};
use bevy_log::warn;
use bevy_math::{Mat4, Quat, Vec3};
use bevy_math::{Mat4, Vec3};
use bevy_pbr::{
AlphaMode, DirectionalLight, DirectionalLightBundle, PbrBundle, PointLight, PointLightBundle,
StandardMaterial,
Expand Down Expand Up @@ -150,7 +148,7 @@ async fn load_gltf<'a, 'b>(
let mut named_animations = HashMap::default();
let mut animation_roots = HashSet::default();
for animation in gltf.animations() {
let mut animation_clip = AnimationClip::default();
let mut animation_clip = bevy_animation::AnimationClip::default();
for channel in animation.channels() {
match channel.sampler().interpolation() {
gltf::animation::Interpolation::Linear => (),
Expand All @@ -177,13 +175,15 @@ async fn load_gltf<'a, 'b>(
let keyframes = if let Some(outputs) = reader.read_outputs() {
match outputs {
gltf::animation::util::ReadOutputs::Translations(tr) => {
Keyframes::Translation(tr.map(Vec3::from).collect())
bevy_animation::Keyframes::Translation(tr.map(Vec3::from).collect())
}
gltf::animation::util::ReadOutputs::Rotations(rots) => {
Keyframes::Rotation(rots.into_f32().map(Quat::from_array).collect())
bevy_animation::Keyframes::Rotation(
rots.into_f32().map(bevy_math::Quat::from_array).collect(),
)
}
gltf::animation::util::ReadOutputs::Scales(scale) => {
Keyframes::Scale(scale.map(Vec3::from).collect())
bevy_animation::Keyframes::Scale(scale.map(Vec3::from).collect())
}
gltf::animation::util::ReadOutputs::MorphTargetWeights(_) => {
warn!("Morph animation property not yet supported");
Expand All @@ -198,10 +198,10 @@ async fn load_gltf<'a, 'b>(
if let Some((root_index, path)) = paths.get(&node.index()) {
animation_roots.insert(root_index);
animation_clip.add_curve_to_path(
EntityPath {
bevy_animation::EntityPath {
parts: path.clone(),
},
VariableCurve {
bevy_animation::VariableCurve {
keyframe_timestamps,
keyframes,
},
Expand Down Expand Up @@ -481,7 +481,7 @@ async fn load_gltf<'a, 'b>(
if animation_roots.contains(&node.index()) {
world
.entity_mut(*node_index_to_entity_map.get(&node.index()).unwrap())
.insert(AnimationPlayer::default());
.insert(bevy_animation::AnimationPlayer::default());
}
}
}
Expand Down Expand Up @@ -539,6 +539,7 @@ fn node_name(node: &Node) -> Name {
Name::new(name)
}

#[cfg(feature = "bevy_animation")]
fn paths_recur(
node: Node,
current_path: &[Name],
Expand Down

0 comments on commit 3233ecc

Please sign in to comment.