refactor(spatial): get_transform_flex
This commit is contained in:
@@ -287,7 +287,7 @@ pub fn create_pulse_receiver_flex(
|
|||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
let parent = get_spatial_parent_flex(&calling_client, flex_vec.idx(1).get_str()?)?;
|
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
|
let field = calling_client
|
||||||
.scenegraph
|
.scenegraph
|
||||||
.get_node(flex_vec.idx(4).as_str())
|
.get_node(flex_vec.idx(4).as_str())
|
||||||
|
|||||||
@@ -3,16 +3,14 @@ use crate::core::client::Client;
|
|||||||
use crate::core::destroy_queue;
|
use crate::core::destroy_queue;
|
||||||
use crate::core::registry::Registry;
|
use crate::core::registry::Registry;
|
||||||
use crate::core::resource::{parse_resource_id, ResourceID};
|
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 anyhow::{anyhow, bail, ensure, Result};
|
||||||
use flexbuffers::FlexBufferType;
|
use flexbuffers::FlexBufferType;
|
||||||
use glam::Mat4;
|
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use prisma::{Rgb, Rgba};
|
use prisma::{Rgb, Rgba};
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use send_wrapper::SendWrapper;
|
use send_wrapper::SendWrapper;
|
||||||
use stardust_xr::{flex_to_quat, flex_to_vec3};
|
|
||||||
use std::fmt::Error;
|
use std::fmt::Error;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@@ -175,17 +173,7 @@ pub fn create(_node: &Node, calling_client: Arc<Client>, data: &[u8]) -> Result<
|
|||||||
);
|
);
|
||||||
let parent = get_spatial_parent_flex(&calling_client, flex_vec.idx(1).get_str()?)?;
|
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 resource_id = parse_resource_id(flex_vec.idx(2))?;
|
||||||
let transform = Mat4::from_scale_rotation_translation(
|
let transform = get_transform_flex(flex_vec.index(3)?, flex_vec.index(4)?, flex_vec.index(5)?)?;
|
||||||
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 node = node.add_to_scenegraph();
|
let node = node.add_to_scenegraph();
|
||||||
Spatial::add_to(&node, Some(parent), transform)?;
|
Spatial::add_to(&node, Some(parent), transform)?;
|
||||||
Model::add_to(&node, resource_id)?;
|
Model::add_to(&node, resource_id)?;
|
||||||
|
|||||||
@@ -218,7 +218,7 @@ pub fn create_input_handler_flex(
|
|||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
let parent = get_spatial_parent_flex(&calling_client, flex_vec.idx(1).get_str()?)?;
|
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
|
let field = calling_client
|
||||||
.scenegraph
|
.scenegraph
|
||||||
.get_node(flex_vec.idx(4).as_str())
|
.get_node(flex_vec.idx(4).as_str())
|
||||||
|
|||||||
@@ -352,7 +352,7 @@ pub fn create_environment_item_flex(
|
|||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
let space = get_spatial_parent_flex(&calling_client, flex_vec.idx(1).get_str()?)?;
|
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();
|
let node = node.add_to_scenegraph();
|
||||||
Spatial::add_to(&node, None, transform * space.global_transform())?;
|
Spatial::add_to(&node, None, transform * space.global_transform())?;
|
||||||
EnvironmentItem::add_to(&node, flex_vec.idx(4).get_str()?.to_string());
|
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 flex_vec = root.get_vector()?;
|
||||||
let parent_name = format!("/item/{}/acceptor/", ITEM_TYPE_INFO_ENVIRONMENT.type_name);
|
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 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
|
let field = calling_client
|
||||||
.scenegraph
|
.scenegraph
|
||||||
.get_node(flex_vec.idx(4).get_str()?)
|
.get_node(flex_vec.idx(4).get_str()?)
|
||||||
|
|||||||
@@ -267,8 +267,8 @@ pub fn get_spatial_parent_flex(
|
|||||||
.clone())
|
.clone())
|
||||||
}
|
}
|
||||||
pub fn get_transform_pose_flex<B: flexbuffers::Buffer>(
|
pub fn get_transform_pose_flex<B: flexbuffers::Buffer>(
|
||||||
translation: &flexbuffers::Reader<B>,
|
translation: flexbuffers::Reader<B>,
|
||||||
rotation: &flexbuffers::Reader<B>,
|
rotation: flexbuffers::Reader<B>,
|
||||||
) -> Result<Mat4> {
|
) -> Result<Mat4> {
|
||||||
Ok(Mat4::from_rotation_translation(
|
Ok(Mat4::from_rotation_translation(
|
||||||
flex_to_quat!(rotation)
|
flex_to_quat!(rotation)
|
||||||
@@ -279,6 +279,23 @@ pub fn get_transform_pose_flex<B: flexbuffers::Buffer>(
|
|||||||
.into(),
|
.into(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
pub fn get_transform_flex<B: flexbuffers::Buffer>(
|
||||||
|
translation: flexbuffers::Reader<B>,
|
||||||
|
rotation: flexbuffers::Reader<B>,
|
||||||
|
scale: flexbuffers::Reader<B>,
|
||||||
|
) -> Result<Mat4> {
|
||||||
|
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<Client>) {
|
pub fn create_interface(client: &Arc<Client>) {
|
||||||
let node = Node::create(client, "", "spatial", false);
|
let node = Node::create(client, "", "spatial", false);
|
||||||
@@ -294,18 +311,8 @@ pub fn create_spatial_flex(_node: &Node, calling_client: Arc<Client>, data: &[u8
|
|||||||
flex_vec.idx(0).get_str()?,
|
flex_vec.idx(0).get_str()?,
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
let parent = get_spatial_parent_flex(&calling_client, flex_vec.idx(1).get_str()?)?;
|
let parent = get_spatial_parent_flex(&calling_client, flex_vec.index(1)?.get_str()?)?;
|
||||||
let transform = Mat4::from_scale_rotation_translation(
|
let transform = get_transform_flex(flex_vec.index(2)?, flex_vec.index(3)?, flex_vec.index(4)?)?;
|
||||||
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 node = node.add_to_scenegraph();
|
let node = node.add_to_scenegraph();
|
||||||
Spatial::add_to(&node, Some(parent), transform)?;
|
Spatial::add_to(&node, Some(parent), transform)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Reference in New Issue
Block a user