gltf prefabs
This commit is contained in:
18
game/shared/src/animation_plugin.rs
Normal file
18
game/shared/src/animation_plugin.rs
Normal file
@@ -0,0 +1,18 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::prefab_defination::RotationAnimation;
|
||||
|
||||
pub struct SimpleAnimationPlugin;
|
||||
|
||||
impl Plugin for SimpleAnimationPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(Update, rotate);
|
||||
}
|
||||
}
|
||||
|
||||
fn rotate(mut query: Query<(&mut Transform, &RotationAnimation)>, time: Res<Time>) {
|
||||
for (mut transform, rot) in query.iter_mut() {
|
||||
let cur_rot = transform.rotation;
|
||||
transform.rotation = cur_rot * Quat::from_axis_angle(rot.axis, rot.speed.to_radians() * time.elapsed_seconds());
|
||||
}
|
||||
}
|
||||
20
game/shared/src/component_defination.rs
Normal file
20
game/shared/src/component_defination.rs
Normal file
@@ -0,0 +1,20 @@
|
||||
use bevy::{
|
||||
ecs::system::EntityCommands, math::{Quat, Vec3}, prelude::*
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::prefab_defination::AnimationComponent;
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct ComponentDefination {
|
||||
pub path: String,
|
||||
pub animations: Vec<AnimationComponent>,
|
||||
}
|
||||
|
||||
|
||||
impl ComponentDefination {
|
||||
pub fn apply(&self, commands: &mut EntityCommands){
|
||||
for c in &self.animations {
|
||||
c.apply(commands);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,8 @@ pub mod sets;
|
||||
pub mod states;
|
||||
pub mod tags;
|
||||
pub mod prefab_defination;
|
||||
pub mod component_defination;
|
||||
pub mod animation_plugin;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub enum Tier {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use bevy::{
|
||||
ecs::system::{EntityCommand, EntityCommands},
|
||||
gltf::{Gltf, GltfMesh},
|
||||
math::{Quat, Vec3},
|
||||
prelude::*,
|
||||
@@ -57,6 +58,23 @@ impl UnpackGltfMesh for GltfMesh {
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub enum AnimationComponent {
|
||||
Rotation,
|
||||
Rotation(RotationAnimation),
|
||||
Slider,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Component, Clone, Copy)]
|
||||
pub struct RotationAnimation {
|
||||
pub axis: Vec3,
|
||||
pub speed: f32,
|
||||
}
|
||||
|
||||
impl AnimationComponent {
|
||||
pub fn apply(&self, commands: &mut EntityCommands) {
|
||||
match self {
|
||||
AnimationComponent::Rotation(comp) => {
|
||||
commands.insert(comp.clone());
|
||||
}
|
||||
AnimationComponent::Slider => todo!(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user