feat(spatial): get spatial parent and get transform pose functions
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
use super::core::Node;
|
use super::core::Node;
|
||||||
use super::spatial::{get_spatial_parent, Spatial};
|
use super::spatial::{get_spatial_parent_flex, Spatial};
|
||||||
use crate::core::client::Client;
|
use crate::core::client::Client;
|
||||||
use anyhow::{anyhow, ensure, Result};
|
use anyhow::{anyhow, ensure, Result};
|
||||||
use glam::{swizzles::*, vec2, vec3, vec3a, Mat4, Vec3, Vec3A};
|
use glam::{swizzles::*, vec2, vec3, vec3a, Mat4, Vec3, Vec3A};
|
||||||
@@ -329,7 +329,7 @@ pub fn create_box_field_flex(_node: &Node, calling_client: Rc<Client>, data: &[u
|
|||||||
let root = flexbuffers::Reader::get_root(data)?;
|
let root = flexbuffers::Reader::get_root(data)?;
|
||||||
let flex_vec = root.get_vector()?;
|
let flex_vec = root.get_vector()?;
|
||||||
let node = Node::create("/field", flex_vec.idx(0).get_str()?, true);
|
let node = Node::create("/field", flex_vec.idx(0).get_str()?, true);
|
||||||
let parent = get_spatial_parent(&calling_client, flex_vec.idx(1).get_str()?)?;
|
let parent = get_spatial_parent_flex(&calling_client, flex_vec.idx(1).get_str()?)?;
|
||||||
let transform = Mat4::from_rotation_translation(
|
let transform = Mat4::from_rotation_translation(
|
||||||
flex_to_quat!(flex_vec.idx(3))
|
flex_to_quat!(flex_vec.idx(3))
|
||||||
.ok_or_else(|| anyhow!("Rotation not found"))?
|
.ok_or_else(|| anyhow!("Rotation not found"))?
|
||||||
@@ -353,7 +353,7 @@ pub fn create_cylinder_field_flex(
|
|||||||
let root = flexbuffers::Reader::get_root(data)?;
|
let root = flexbuffers::Reader::get_root(data)?;
|
||||||
let flex_vec = root.get_vector()?;
|
let flex_vec = root.get_vector()?;
|
||||||
let node = Node::create("/field", flex_vec.idx(0).get_str()?, true);
|
let node = Node::create("/field", flex_vec.idx(0).get_str()?, true);
|
||||||
let parent = get_spatial_parent(&calling_client, flex_vec.idx(1).get_str()?)?;
|
let parent = get_spatial_parent_flex(&calling_client, flex_vec.idx(1).get_str()?)?;
|
||||||
let transform = Mat4::from_rotation_translation(
|
let transform = Mat4::from_rotation_translation(
|
||||||
flex_to_quat!(flex_vec.idx(3))
|
flex_to_quat!(flex_vec.idx(3))
|
||||||
.ok_or_else(|| anyhow!("Rotation not found"))?
|
.ok_or_else(|| anyhow!("Rotation not found"))?
|
||||||
@@ -378,7 +378,7 @@ pub fn create_sphere_field_flex(
|
|||||||
let root = flexbuffers::Reader::get_root(data)?;
|
let root = flexbuffers::Reader::get_root(data)?;
|
||||||
let flex_vec = root.get_vector()?;
|
let flex_vec = root.get_vector()?;
|
||||||
let node = Node::create("/field", flex_vec.idx(0).get_str()?, true);
|
let node = Node::create("/field", flex_vec.idx(0).get_str()?, true);
|
||||||
let parent = get_spatial_parent(&calling_client, flex_vec.idx(1).get_str()?)?;
|
let parent = get_spatial_parent_flex(&calling_client, flex_vec.idx(1).get_str()?)?;
|
||||||
let transform = Mat4::from_translation(
|
let transform = Mat4::from_translation(
|
||||||
flex_to_vec3!(flex_vec.idx(2))
|
flex_to_vec3!(flex_vec.idx(2))
|
||||||
.ok_or_else(|| anyhow!("Position not found"))?
|
.ok_or_else(|| anyhow!("Position not found"))?
|
||||||
|
|||||||
@@ -151,7 +151,10 @@ impl Spatial {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_spatial_parent(calling_client: &Rc<Client>, node_path: &str) -> Result<Arc<Spatial>> {
|
pub fn get_spatial_parent_flex(
|
||||||
|
calling_client: &Rc<Client>,
|
||||||
|
node_path: &str,
|
||||||
|
) -> Result<Arc<Spatial>> {
|
||||||
Ok(calling_client
|
Ok(calling_client
|
||||||
.scenegraph
|
.scenegraph
|
||||||
.get_node(node_path)
|
.get_node(node_path)
|
||||||
@@ -161,6 +164,19 @@ pub fn get_spatial_parent(calling_client: &Rc<Client>, node_path: &str) -> Resul
|
|||||||
.ok_or_else(|| anyhow!("Spatial parent node is not a spatial"))?
|
.ok_or_else(|| anyhow!("Spatial parent node is not a spatial"))?
|
||||||
.clone())
|
.clone())
|
||||||
}
|
}
|
||||||
|
pub fn get_transform_pose_flex<B: flexbuffers::Buffer>(
|
||||||
|
translation: &flexbuffers::Reader<B>,
|
||||||
|
rotation: &flexbuffers::Reader<B>,
|
||||||
|
) -> Result<Mat4> {
|
||||||
|
Ok(Mat4::from_rotation_translation(
|
||||||
|
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: &Rc<Client>) {
|
pub fn create_interface(client: &Rc<Client>) {
|
||||||
let node = Node::create("", "spatial", false);
|
let node = Node::create("", "spatial", false);
|
||||||
@@ -172,7 +188,7 @@ pub fn create_spatial_flex(_node: &Node, calling_client: Rc<Client>, data: &[u8]
|
|||||||
let root = flexbuffers::Reader::get_root(data)?;
|
let root = flexbuffers::Reader::get_root(data)?;
|
||||||
let flex_vec = root.get_vector()?;
|
let flex_vec = root.get_vector()?;
|
||||||
let spatial = Node::create("/spatial/spatial", flex_vec.idx(0).get_str()?, true);
|
let spatial = Node::create("/spatial/spatial", flex_vec.idx(0).get_str()?, true);
|
||||||
let parent = get_spatial_parent(&calling_client, flex_vec.idx(1).get_str()?)?;
|
let parent = get_spatial_parent_flex(&calling_client, flex_vec.idx(1).get_str()?)?;
|
||||||
let transform = Mat4::from_scale_rotation_translation(
|
let transform = Mat4::from_scale_rotation_translation(
|
||||||
flex_to_vec3!(flex_vec.idx(4))
|
flex_to_vec3!(flex_vec.idx(4))
|
||||||
.ok_or_else(|| anyhow!("Scale not found"))?
|
.ok_or_else(|| anyhow!("Scale not found"))?
|
||||||
|
|||||||
Reference in New Issue
Block a user