diff --git a/src/nodes/data.rs b/src/nodes/data.rs index f2020e0..7cca182 100644 --- a/src/nodes/data.rs +++ b/src/nodes/data.rs @@ -287,7 +287,7 @@ pub fn create_pulse_receiver_flex( true, ); let parent = get_spatial_parent_flex(&calling_client, flex_vec.idx(1).get_str()?)?; - let transform = get_transform_pose_flex(&flex_vec.idx(2), &flex_vec.idx(3))?; + let transform = get_transform_pose_flex(flex_vec.idx(2), flex_vec.idx(3))?; let field = calling_client .scenegraph .get_node(flex_vec.idx(4).as_str()) diff --git a/src/nodes/drawable/model.rs b/src/nodes/drawable/model.rs index 8c59a77..0f227ea 100644 --- a/src/nodes/drawable/model.rs +++ b/src/nodes/drawable/model.rs @@ -3,16 +3,14 @@ use crate::core::client::Client; use crate::core::destroy_queue; use crate::core::registry::Registry; use crate::core::resource::{parse_resource_id, ResourceID}; -use crate::nodes::spatial::{get_spatial_parent_flex, Spatial}; +use crate::nodes::spatial::{get_spatial_parent_flex, get_transform_flex, Spatial}; use anyhow::{anyhow, bail, ensure, Result}; use flexbuffers::FlexBufferType; -use glam::Mat4; use once_cell::sync::OnceCell; use parking_lot::Mutex; use prisma::{Rgb, Rgba}; use rustc_hash::FxHashMap; use send_wrapper::SendWrapper; -use stardust_xr::{flex_to_quat, flex_to_vec3}; use std::fmt::Error; use std::path::PathBuf; use std::sync::Arc; @@ -175,17 +173,7 @@ pub fn create(_node: &Node, calling_client: Arc, data: &[u8]) -> Result< ); let parent = get_spatial_parent_flex(&calling_client, flex_vec.idx(1).get_str()?)?; let resource_id = parse_resource_id(flex_vec.idx(2))?; - let transform = Mat4::from_scale_rotation_translation( - flex_to_vec3!(flex_vec.idx(5)) - .ok_or_else(|| anyhow!("Scale not found"))? - .into(), - flex_to_quat!(flex_vec.idx(4)) - .ok_or_else(|| anyhow!("Rotation not found"))? - .into(), - flex_to_vec3!(flex_vec.idx(3)) - .ok_or_else(|| anyhow!("Position not found"))? - .into(), - ); + let transform = get_transform_flex(flex_vec.index(3)?, flex_vec.index(4)?, flex_vec.index(5)?)?; let node = node.add_to_scenegraph(); Spatial::add_to(&node, Some(parent), transform)?; Model::add_to(&node, resource_id)?; diff --git a/src/nodes/input/mod.rs b/src/nodes/input/mod.rs index 2a606d8..c286a3b 100644 --- a/src/nodes/input/mod.rs +++ b/src/nodes/input/mod.rs @@ -218,7 +218,7 @@ pub fn create_input_handler_flex( true, ); let parent = get_spatial_parent_flex(&calling_client, flex_vec.idx(1).get_str()?)?; - let transform = get_transform_pose_flex(&flex_vec.idx(2), &flex_vec.idx(3))?; + let transform = get_transform_pose_flex(flex_vec.idx(2), flex_vec.idx(3))?; let field = calling_client .scenegraph .get_node(flex_vec.idx(4).as_str()) diff --git a/src/nodes/items/mod.rs b/src/nodes/items/mod.rs index 1e6f155..b1462a2 100644 --- a/src/nodes/items/mod.rs +++ b/src/nodes/items/mod.rs @@ -352,7 +352,7 @@ pub fn create_environment_item_flex( true, ); let space = get_spatial_parent_flex(&calling_client, flex_vec.idx(1).get_str()?)?; - let transform = get_transform_pose_flex(&flex_vec.idx(2), &flex_vec.idx(3))?; + let transform = get_transform_pose_flex(flex_vec.idx(2), flex_vec.idx(3))?; let node = node.add_to_scenegraph(); Spatial::add_to(&node, None, transform * space.global_transform())?; EnvironmentItem::add_to(&node, flex_vec.idx(4).get_str()?.to_string()); @@ -372,7 +372,7 @@ pub fn create_item_acceptor_flex( let flex_vec = root.get_vector()?; let parent_name = format!("/item/{}/acceptor/", ITEM_TYPE_INFO_ENVIRONMENT.type_name); let space = get_spatial_parent_flex(&calling_client, flex_vec.idx(1).get_str()?)?; - let transform = get_transform_pose_flex(&flex_vec.idx(2), &flex_vec.idx(3))?; + let transform = get_transform_pose_flex(flex_vec.idx(2), flex_vec.idx(3))?; let field = calling_client .scenegraph .get_node(flex_vec.idx(4).get_str()?) diff --git a/src/nodes/spatial.rs b/src/nodes/spatial.rs index f7cda39..04998d7 100644 --- a/src/nodes/spatial.rs +++ b/src/nodes/spatial.rs @@ -267,8 +267,8 @@ pub fn get_spatial_parent_flex( .clone()) } pub fn get_transform_pose_flex( - translation: &flexbuffers::Reader, - rotation: &flexbuffers::Reader, + translation: flexbuffers::Reader, + rotation: flexbuffers::Reader, ) -> Result { Ok(Mat4::from_rotation_translation( flex_to_quat!(rotation) @@ -279,6 +279,23 @@ pub fn get_transform_pose_flex( .into(), )) } +pub fn get_transform_flex( + translation: flexbuffers::Reader, + rotation: flexbuffers::Reader, + scale: flexbuffers::Reader, +) -> Result { + Ok(Mat4::from_scale_rotation_translation( + flex_to_vec3!(scale) + .ok_or_else(|| anyhow!("Scale not found"))? + .into(), + flex_to_quat!(rotation) + .ok_or_else(|| anyhow!("Rotation not found"))? + .into(), + flex_to_vec3!(translation) + .ok_or_else(|| anyhow!("Position not found"))? + .into(), + )) +} pub fn create_interface(client: &Arc) { let node = Node::create(client, "", "spatial", false); @@ -294,18 +311,8 @@ pub fn create_spatial_flex(_node: &Node, calling_client: Arc, data: &[u8 flex_vec.idx(0).get_str()?, true, ); - let parent = get_spatial_parent_flex(&calling_client, flex_vec.idx(1).get_str()?)?; - let transform = Mat4::from_scale_rotation_translation( - flex_to_vec3!(flex_vec.idx(4)) - .ok_or_else(|| anyhow!("Scale not found"))? - .into(), - flex_to_quat!(flex_vec.idx(3)) - .ok_or_else(|| anyhow!("Rotation not found"))? - .into(), - flex_to_vec3!(flex_vec.idx(2)) - .ok_or_else(|| anyhow!("Position not found"))? - .into(), - ); + let parent = get_spatial_parent_flex(&calling_client, flex_vec.index(1)?.get_str()?)?; + let transform = get_transform_flex(flex_vec.index(2)?, flex_vec.index(3)?, flex_vec.index(4)?)?; let node = node.add_to_scenegraph(); Spatial::add_to(&node, Some(parent), transform)?; Ok(())