Skip to content

Commit

Permalink
set ecs transform values after script update
Browse files Browse the repository at this point in the history
  • Loading branch information
kayhhh committed Jun 26, 2024
1 parent aad7575 commit 9e0d0db
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions crates/unavi-scripting/src/execution.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bevy::{prelude::*, tasks::block_on};
use wasm_bridge::{component::ResourceAny, AsContextMut};

use crate::load::LoadedScript;
use crate::{host::wired_gltf::handler::NodeId, load::LoadedScript};

use super::load::Scripts;

Expand Down Expand Up @@ -53,6 +53,7 @@ pub fn update_scripts(
mut to_update: Query<(Entity, &ScriptResource)>,
scripts: NonSendMut<Scripts>,
time: Res<Time>,
mut nodes: Query<(&mut Transform, &NodeId)>,
) {
let now = time.elapsed_seconds();
let delta = now - *last_update;
Expand Down Expand Up @@ -81,7 +82,23 @@ pub fn update_scripts(
let transform = state.table.get(&node.transform)?;

if transform.clean(&state.table)? {
// TODO: Update ecs
let rep = res.rep();

let translation = state.table.get(&transform.translation)?;
let rotation = state.table.get(&transform.rotation)?;
let scale = state.table.get(&transform.scale)?;

if let Some(mut target) =
nodes
.iter_mut()
.find_map(|(t, id)| if id.0 == rep { Some(t) } else { None })
{
target.translation.clone_from(&translation.data);
target.rotation.clone_from(&rotation.data);
target.scale.clone_from(&scale.data);
} else {
warn!("Node {} not found", rep)
};
}
}

Expand Down

0 comments on commit 9e0d0db

Please sign in to comment.