refactor: modularize getting nodes and aspects
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use super::{Field, FieldTrait, Node};
|
||||
use crate::core::client::Client;
|
||||
use crate::nodes::spatial::{get_spatial_parent_flex, parse_transform, Spatial};
|
||||
use crate::nodes::spatial::{find_spatial_parent, parse_transform, Spatial};
|
||||
use anyhow::{ensure, Result};
|
||||
use glam::{vec3, vec3a, Vec3, Vec3A};
|
||||
use mint::Vector3;
|
||||
@@ -73,7 +73,7 @@ pub fn create_box_field_flex(_node: &Node, calling_client: Arc<Client>, data: &[
|
||||
}
|
||||
let info: CreateFieldInfo = deserialize(data)?;
|
||||
let node = Node::create(&calling_client, "/field", info.name, true);
|
||||
let parent = get_spatial_parent_flex(&calling_client, info.parent_path)?;
|
||||
let parent = find_spatial_parent(&calling_client, info.parent_path)?;
|
||||
let transform = parse_transform(info.transform, true, true, false)?;
|
||||
let node = node.add_to_scenegraph();
|
||||
Spatial::add_to(&node, Some(parent), transform)?;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::{Field, FieldTrait, Node};
|
||||
use crate::core::client::Client;
|
||||
use crate::nodes::spatial::{get_spatial_parent_flex, parse_transform, Spatial};
|
||||
use crate::nodes::spatial::{find_spatial_parent, parse_transform, Spatial};
|
||||
use anyhow::{ensure, Result};
|
||||
use glam::{swizzles::*, vec2, Vec3A};
|
||||
use portable_atomic::AtomicF32;
|
||||
@@ -80,7 +80,7 @@ pub fn create_cylinder_field_flex(
|
||||
}
|
||||
let info: CreateFieldInfo = deserialize(data)?;
|
||||
let node = Node::create(&calling_client, "/field", info.name, true);
|
||||
let parent = get_spatial_parent_flex(&calling_client, info.parent_path)?;
|
||||
let parent = find_spatial_parent(&calling_client, info.parent_path)?;
|
||||
let transform = parse_transform(info.transform, true, true, false)?;
|
||||
let node = node.add_to_scenegraph();
|
||||
Spatial::add_to(&node, Some(parent), transform)?;
|
||||
|
||||
@@ -9,7 +9,8 @@ use self::sphere::{create_sphere_field_flex, SphereField};
|
||||
use super::spatial::Spatial;
|
||||
use super::Node;
|
||||
use crate::core::client::Client;
|
||||
use anyhow::{anyhow, Result};
|
||||
use crate::nodes::spatial::find_reference_space;
|
||||
use anyhow::Result;
|
||||
use glam::{vec2, vec3a, Vec3, Vec3A};
|
||||
use mint::Vector3;
|
||||
use serde::Deserialize;
|
||||
@@ -76,14 +77,7 @@ fn field_distance_flex(node: &Node, calling_client: Arc<Client>, data: &[u8]) ->
|
||||
point: Vector3<f32>,
|
||||
}
|
||||
let args: FieldInfoArgs = deserialize(data)?;
|
||||
let reference_space = calling_client
|
||||
.scenegraph
|
||||
.get_node(args.reference_space_path)
|
||||
.ok_or_else(|| anyhow!("Reference space node does not exist"))?
|
||||
.spatial
|
||||
.get()
|
||||
.ok_or_else(|| anyhow!("Reference space node does not have a spatial"))?
|
||||
.clone();
|
||||
let reference_space = find_reference_space(&calling_client, args.reference_space_path)?;
|
||||
|
||||
let distance = node
|
||||
.field
|
||||
@@ -100,14 +94,7 @@ fn field_normal_flex(node: &Node, calling_client: Arc<Client>, data: &[u8]) -> R
|
||||
radius: Option<f32>,
|
||||
}
|
||||
let args: FieldInfoArgs = deserialize(data)?;
|
||||
let reference_space = calling_client
|
||||
.scenegraph
|
||||
.get_node(args.reference_space_path)
|
||||
.ok_or_else(|| anyhow!("Reference space node does not exist"))?
|
||||
.spatial
|
||||
.get()
|
||||
.ok_or_else(|| anyhow!("Reference space node does not have a spatial"))?
|
||||
.clone();
|
||||
let reference_space = find_reference_space(&calling_client, args.reference_space_path)?;
|
||||
|
||||
let normal = node.field.get().as_ref().unwrap().normal(
|
||||
reference_space.as_ref(),
|
||||
@@ -128,14 +115,7 @@ fn field_closest_point_flex(
|
||||
radius: Option<f32>,
|
||||
}
|
||||
let args: FieldInfoArgs = deserialize(data)?;
|
||||
let reference_space = calling_client
|
||||
.scenegraph
|
||||
.get_node(args.reference_space_path)
|
||||
.ok_or_else(|| anyhow!("Reference space node does not exist"))?
|
||||
.spatial
|
||||
.get()
|
||||
.ok_or_else(|| anyhow!("Reference space node does not have a spatial"))?
|
||||
.clone();
|
||||
let reference_space = find_reference_space(&calling_client, args.reference_space_path)?;
|
||||
|
||||
let closest_point = node.field.get().as_ref().unwrap().closest_point(
|
||||
reference_space.as_ref(),
|
||||
@@ -224,3 +204,9 @@ pub fn ray_march(ray: Ray, field: &Field) -> RayMarchResult {
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
pub fn find_field(client: &Client, path: &str) -> Result<Arc<Field>> {
|
||||
Ok(client
|
||||
.get_node("Field", path)?
|
||||
.get_aspect("Field", "info", |n| &n.field)?)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::{Field, FieldTrait, Node};
|
||||
use crate::core::client::Client;
|
||||
use crate::nodes::spatial::{get_spatial_parent_flex, Spatial};
|
||||
use crate::nodes::spatial::{find_spatial_parent, Spatial};
|
||||
use anyhow::{ensure, Result};
|
||||
use glam::{Mat4, Vec3A};
|
||||
use mint::Vector3;
|
||||
@@ -77,7 +77,7 @@ pub fn create_sphere_field_flex(
|
||||
}
|
||||
let info: CreateFieldInfo = deserialize(data)?;
|
||||
let node = Node::create(&calling_client, "/field", info.name, true);
|
||||
let parent = get_spatial_parent_flex(&calling_client, info.parent_path)?;
|
||||
let parent = find_spatial_parent(&calling_client, info.parent_path)?;
|
||||
let transform = Mat4::from_translation(
|
||||
info.origin
|
||||
.unwrap_or_else(|| Vector3::from([0.0; 3]))
|
||||
|
||||
Reference in New Issue
Block a user