pub struct ModelNode<'a> { /* private fields */ }
Expand description
This class is a link to a node in a Model’s internal hierarchy tree. It’s composed of node information, and links to the directly adjacent tree nodes. https://stereokit.net/Pages/StereoKit/ModelNode.html
§Examples
use stereokit_rust::{maths::{Vec3, Matrix}, model::Model, mesh::Mesh,
material::Material, util::named_colors};
let sphere = Mesh::generate_sphere(0.6, None);
let rounded_cube = Mesh::generate_rounded_cube(Vec3::ONE * 0.6, 0.2, None);
let cylinder = Mesh::generate_cylinder(0.25, 0.6, Vec3::Z, None);
let transform1 = Matrix::t( [-0.7,-0.5, 0.0]);
let transform2 = Matrix::t( [ 0.0, 0.0, 0.0]);
let transform3 = Matrix::t( [ 0.7, 0.5, 0.0]);
let trans_mini = Matrix::t_s([ 0.0, 0.0, 0.5].into(), Vec3::ONE * 0.15);
let material = Material::pbr();
let model = Model::new();
let mut nodes = model.get_nodes();
nodes.add("sphere", transform1 , Some(&sphere), Some(&material), true)
.add("cube", transform2 , Some(&rounded_cube), Some(&material), true)
.add("cylinder", transform3 , Some(&cylinder), Some(&material), true)
.add("mini", trans_mini, None, None, true);
let mut material = material.copy();
material.color_tint(named_colors::RED);
let mut mini = nodes.find("mini").expect("mini node should exist!");
mini.add_child("sphere", transform1 , Some(&sphere), Some(&material), true)
.add_child("cube", transform2 , Some(&rounded_cube), Some(&material), true)
.add_child("cylinder", transform3 , Some(&cylinder), Some(&material), true);
assert_eq!(nodes.get_visual_count(), 6);
assert_eq!(nodes.get_count(), 7);
filename_scr = "screenshots/model_node.jpeg";
test_screenshot!( // !!!! Get a proper main loop !!!!
model.draw(token, Matrix::IDENTITY, None, None);
);

Implementations§
Source§impl ModelNode<'_>
impl ModelNode<'_>
Sourcepub fn name<S: AsRef<str>>(&mut self, name: S) -> &mut Self
pub fn name<S: AsRef<str>>(&mut self, name: S) -> &mut Self
Set the name of the node https://stereokit.net/Pages/StereoKit/ModelNode/Name.html
see also model_node_set_name
§Examples
use stereokit_rust::{maths::Matrix, model::Model};
let model = Model::new();
let mut nodes = model.get_nodes();
nodes.add("root", Matrix::IDENTITY, None, None, false);
let mut node = nodes.find("root").expect("A node should exist!");
assert_eq!(node.get_name(), Some("root"));
node.name("my_root_node");
assert_eq!(node.get_name(), Some("my_root_node"));
let node = nodes.find("my_root_node").expect("A node should exist!");
assert!(nodes.find("root").is_none());
Sourcepub fn solid(&mut self, solid: bool) -> &mut Self
pub fn solid(&mut self, solid: bool) -> &mut Self
Set the solid of the node. A flag that indicates the Mesh for this node will be used in ray intersection tests. This flag is ignored if no Mesh is attached. https://stereokit.net/Pages/StereoKit/ModelNode/Solid.html
see also model_node_set_solid
Nodes::add
ModelNode::add_child
§Examples
use stereokit_rust::{maths::Matrix, model::Model, mesh::Mesh, material::Material};
let model = Model::new();
let mut nodes = model.get_nodes();
nodes.add("cube", Matrix::IDENTITY, Some(&Mesh::cube()), Some(&Material::pbr()), false);
let mut node = nodes.find("cube").expect("A node should exist!");
assert_eq!(node.get_solid(), false);
node.solid(true);
assert_eq!(node.get_solid(), true);
Sourcepub fn visible(&mut self, visible: bool) -> &mut Self
pub fn visible(&mut self, visible: bool) -> &mut Self
Is this node flagged as visible? By default, this is true for all nodes with visual elements attached. These nodes will not be drawn or skinned if you set this flag to false. If a ModelNode has no visual elements attached to it, it will always return false, and setting this value will have no effect. https://stereokit.net/Pages/StereoKit/ModelNode/Visible.html
see also model_node_set_visible
§Examples
use stereokit_rust::{maths::Matrix, model::Model, mesh::Mesh, material::Material};
let model = Model::new();
let mut nodes = model.get_nodes();
nodes.add("cube", Matrix::IDENTITY, Some(&Mesh::cube()), Some(&Material::pbr()), true);
let mut node = nodes.find("cube").expect("A node should exist!");
assert_eq!(node.get_visible(), true);
node.visible(false);
assert_eq!(node.get_visible(), false);
Sourcepub fn material<M: AsRef<Material>>(&mut self, material: M) -> &mut Self
pub fn material<M: AsRef<Material>>(&mut self, material: M) -> &mut Self
Set the material of the node https://stereokit.net/Pages/StereoKit/ModelNode/Material.html
see also model_node_set_material
§Examples
use stereokit_rust::{maths::Matrix, model::Model, mesh::Mesh, material::Material};
let model = Model::new();
let mut nodes = model.get_nodes();
nodes.add("cube", Matrix::IDENTITY, Some(&Mesh::cube()), Some(&Material::pbr()), true);
let mut node = nodes.find("cube").expect("A node should exist!");
assert_eq!(node.get_material(), Some(Material::pbr()));
node.material(Material::unlit());
assert_eq!(node.get_material(), Some(Material::unlit()));
Sourcepub fn mesh<M: AsRef<Mesh>>(&mut self, mesh: M) -> &mut Self
pub fn mesh<M: AsRef<Mesh>>(&mut self, mesh: M) -> &mut Self
Set the mesh of the node https://stereokit.net/Pages/StereoKit/ModelNode/Mesh.html
see also model_node_set_mesh
§Examples
use stereokit_rust::{maths::Matrix, model::Model, mesh::Mesh, material::Material};
let model = Model::new();
let mut nodes = model.get_nodes();
nodes.add("mesh", Matrix::IDENTITY, Some(&Mesh::cube()), Some(&Material::pbr()), true);
let mut node = nodes.find("mesh").expect("A node should exist!");
assert_eq!(node.get_mesh(), Some(Mesh::cube()));
node.mesh(Mesh::sphere());
assert_eq!(node.get_mesh(), Some(Mesh::sphere()));
Sourcepub fn model_transform(
&mut self,
transform_model_space: impl Into<Matrix>,
) -> &mut Self
pub fn model_transform( &mut self, transform_model_space: impl Into<Matrix>, ) -> &mut Self
Set the transform model of the node. The transform of this node relative to the Model itself. This incorporates transforms from all parent nodes. Setting this transform will update the LocalTransform, as well as all Child nodes below this one. https://stereokit.net/Pages/StereoKit/ModelNode/ModelTransform.html
see also model_node_set_transform_model
§Examples
use stereokit_rust::{maths::Matrix, model::Model, mesh::Mesh, material::Material};
let model = Model::new();
let mut nodes = model.get_nodes();
nodes.add("root_mesh", Matrix::t([1.0, 1.0, 1.0]), Some(&Mesh::cube()), Some(&Material::pbr()), true);
assert_eq!(model.get_bounds().center, [1.0, 1.0, 1.0].into());
assert_eq!(model.get_bounds().dimensions, [1.0, 1.0, 1.0].into());
let mut node = nodes.find("root_mesh").expect("A node should exist!");
node.add_child("child_mesh", Matrix::IDENTITY, Some(&Mesh::cube()), Some(&Material::pbr()), false);
assert_eq!(model.get_bounds().center, [1.0, 1.0, 1.0].into());
assert_eq!(model.get_bounds().dimensions, [1.0, 1.0, 1.0].into());
// Model_transform!!!
let mut node_child = nodes.find("child_mesh").expect("A node should exist!");
node_child.model_transform(Matrix::t([-2.0, -2.0, -2.0]));
assert_eq!(model.get_bounds().center, [-0.5, -0.5, -0.5].into());
assert_eq!(model.get_bounds().dimensions, [4.0, 4.0, 4.0].into());
// Local_transform!!!
let mut node_child = nodes.find("child_mesh").expect("A node should exist!");
node_child.local_transform(Matrix::t([-2.0, -2.0, -2.0]));
assert_eq!(model.get_bounds().center, [0.0, 0.0, 0.0].into());
assert_eq!(model.get_bounds().dimensions, [3.0, 3.0, 3.0].into());
Sourcepub fn local_transform(
&mut self,
transform_model_space: impl Into<Matrix>,
) -> &mut Self
pub fn local_transform( &mut self, transform_model_space: impl Into<Matrix>, ) -> &mut Self
Set the local transform of the node. The transform of this node relative to the Parent node. Setting this transform will update the ModelTransform, as well as all Child nodes below this one. https://stereokit.net/Pages/StereoKit/ModelNode/LocalTransform.html
see also model_node_set_transform_local
see example ModelNode::model_transform
Sourcepub fn add_child<S: AsRef<str>>(
&mut self,
name: S,
local_transform: impl Into<Matrix>,
mesh: Option<&Mesh>,
material: Option<&Material>,
solid: bool,
) -> &mut Self
pub fn add_child<S: AsRef<str>>( &mut self, name: S, local_transform: impl Into<Matrix>, mesh: Option<&Mesh>, material: Option<&Material>, solid: bool, ) -> &mut Self
Adds a Child node below this node, at the end of the child chain! The local transform of the child will have this node as reference https://stereokit.net/Pages/StereoKit/ModelNode/AddChild.html
name
- A text name to identify the node.local_transform
- A Matrix describing this node’s transform in local space relative to the currently selected node.mesh
- The Mesh to attach to this Node’s visual. If None, the material must also be None.material
- The Material to attach to this Node’s visual. If None, the mesh must also be None.solid
- A flag that indicates the Mesh for this node will be used in ray intersection tests. This flag is ignored if no Mesh is attached.
see also Nodes::add model_node_add_child
§Examples
use stereokit_rust::{maths::Matrix, model::Model, mesh::Mesh, material::Material};
let model = Model::new();
let cube = Mesh::generate_cube([0.1, 0.1, 0.1], None);
let sphere = Mesh::generate_sphere(0.15, None);
let material = Material::pbr();
let mut nodes = model.get_nodes();
nodes.add("root_mesh", Matrix::IDENTITY, Some(&cube), Some(&material), true);
let mut root_node = nodes.get_root_node().expect("A node should exist!");
root_node
.add_child("child_mesh2", Matrix::IDENTITY, Some(&sphere), Some(&material), true)
.add_child("child_no_mesh", Matrix::IDENTITY, None, None, false);
Sourcepub fn get_id(&self) -> ModelNodeId
pub fn get_id(&self) -> ModelNodeId
Get the node Id
§Examples
use stereokit_rust::{maths::Matrix, model::Model, mesh::Mesh, material::Material};
let model = Model::new();
let mut nodes = model.get_nodes();
nodes.add("mosh", Matrix::IDENTITY, Some(&Mesh::cube()), Some(&Material::pbr()), true);
nodes.add("mesh", Matrix::IDENTITY, Some(&Mesh::cube()), Some(&Material::pbr()), true);
nodes.add("mush", Matrix::IDENTITY, Some(&Mesh::cube()), Some(&Material::pbr()), true);
let node = nodes.find("mesh").expect("Node mesh should exist");
assert_eq!(node.get_id(), 1);
let node = nodes.find("mush").expect("Node mesh should exist");
assert_eq!(node.get_id(), 2);
Sourcepub fn get_name(&self) -> Option<&str>
pub fn get_name(&self) -> Option<&str>
Get the node Name https://stereokit.net/Pages/StereoKit/ModelNode/Name.html
see also model_node_get_name
see example ModelNode::name
Sourcepub fn get_solid(&self) -> bool
pub fn get_solid(&self) -> bool
Get the solid of the node. A flag that indicates if the Mesh for this node will be used in ray intersection tests. This flag is ignored if no Mesh is attached. https://stereokit.net/Pages/StereoKit/ModelNode/Solid.html
see also model_node_get_solid
see example ModelNode::solid
Sourcepub fn get_visible(&self) -> bool
pub fn get_visible(&self) -> bool
Get the visibility of the node https://stereokit.net/Pages/StereoKit/ModelNode/Visible.html
see also model_node_get_visible
see example ModelNode::visible
Sourcepub fn get_material(&self) -> Option<Material>
pub fn get_material(&self) -> Option<Material>
Get the material of the node https://stereokit.net/Pages/StereoKit/ModelNode/Material.html
see also model_node_get_material
see example ModelNode::material
Sourcepub fn get_mesh(&self) -> Option<Mesh>
pub fn get_mesh(&self) -> Option<Mesh>
Get the mesh of the node https://stereokit.net/Pages/StereoKit/ModelNode/Mesh.html
see also model_node_get_mesh
see example ModelNode::mesh
Sourcepub fn get_model_transform(&self) -> Matrix
pub fn get_model_transform(&self) -> Matrix
Get the transform matrix of the node https://stereokit.net/Pages/StereoKit/ModelNode/ModelTransform.html
see also model_node_get_transform_model
see example ModelNode::model_transform
Sourcepub fn get_local_transform(&self) -> Matrix
pub fn get_local_transform(&self) -> Matrix
Get the local transform matrix of the node https://stereokit.net/Pages/StereoKit/ModelNode/LocalTransform.html
see also model_node_get_transform_local
see example ModelNode::model_transform
Sourcepub fn iterate(&self) -> Option<ModelNode<'_>>
pub fn iterate(&self) -> Option<ModelNode<'_>>
Iterate to the next node https://stereokit.net/Pages/StereoKit/ModelNodeCollection.html
see also model_node_iterate
§Examples
use stereokit_rust::{maths::Matrix, model::Model, mesh::Mesh, material::Material};
let model = Model::new();
let mut nodes = model.get_nodes();
nodes.add("mosh", Matrix::IDENTITY, Some(&Mesh::cube()), Some(&Material::pbr()), true);
nodes.add("mesh", Matrix::IDENTITY, Some(&Mesh::cube()), Some(&Material::pbr()), true);
nodes.add("mush", Matrix::IDENTITY, Some(&Mesh::cube()), Some(&Material::pbr()), true);
let mut node = nodes.find("mosh").expect("Node mosh should exist");
let mut next_node = node.iterate().expect("Node should have a follower");
assert_eq!(next_node.get_name(), Some("mesh"));
next_node.add_child("mesh child", Matrix::IDENTITY, Some(&Mesh::cube()), Some(&Material::pbr()), true);
let next_node = next_node.iterate().expect("Node should have a follower");
assert_eq!(next_node.get_name(), Some("mesh child"));
let next_node = next_node.iterate().expect("Node should have a follower");
assert_eq!(next_node.get_name(), Some("mush"));
let next_node = next_node.iterate();
assert!(next_node.is_none());
Sourcepub fn get_child(&self) -> Option<ModelNode<'_>>
pub fn get_child(&self) -> Option<ModelNode<'_>>
Get the The first child node “below” on the hierarchy tree, or null if there are none. To see all children, get the Child and then iterate through its Siblings. https://stereokit.net/Pages/StereoKit/ModelNode/Child.html
see also model_node_child
§Examples
use stereokit_rust::{maths::Matrix, model::Model, mesh::Mesh, material::Material};
let model = Model::new();
let mut nodes = model.get_nodes();
nodes.add("mosh", Matrix::IDENTITY, Some(&Mesh::cube()), Some(&Material::pbr()), true);
nodes.add("mesh", Matrix::IDENTITY, Some(&Mesh::cube()), Some(&Material::pbr()), true);
nodes.add("mush", Matrix::IDENTITY, Some(&Mesh::cube()), Some(&Material::pbr()), true);
let mut node = nodes.find("mesh").expect("Node mosh should exist");
node.add_child("mesh child1", Matrix::IDENTITY, Some(&Mesh::cube()), Some(&Material::pbr()), true);
node.add_child("mesh child2", Matrix::IDENTITY, Some(&Mesh::cube()), Some(&Material::pbr()), true);
let child_node = node.get_child().expect("Node should have a child");
assert_eq!(child_node.get_name(), Some("mesh child1"));
Sourcepub fn get_sibling(&self) -> Option<ModelNode<'_>>
pub fn get_sibling(&self) -> Option<ModelNode<'_>>
The next ModelNode in the hierarchy, at the same level as this one. To the “right” on a hierarchy tree. None if there are no more ModelNodes in the tree there. https://stereokit.net/Pages/StereoKit/ModelNode/Sibling.html
see also model_node_sibling
§Examples
use stereokit_rust::{maths::Matrix, model::Model, mesh::Mesh, material::Material};
let model = Model::new();
let mut nodes = model.get_nodes();
nodes.add("mosh", Matrix::IDENTITY, Some(&Mesh::cube()), Some(&Material::pbr()), true);
nodes.add("mesh", Matrix::IDENTITY, Some(&Mesh::cube()), Some(&Material::pbr()), true);
nodes.add("mush", Matrix::IDENTITY, Some(&Mesh::cube()), Some(&Material::pbr()), true);
let mut node = nodes.find("mesh").expect("Node mosh should exist");
node.add_child("mesh child1", Matrix::IDENTITY, Some(&Mesh::cube()), Some(&Material::pbr()), true);
node.add_child("mesh child2", Matrix::IDENTITY, Some(&Mesh::cube()), Some(&Material::pbr()), true);
let child_node = node.get_child().expect("Node should have a child");
assert_eq!(child_node.get_name(), Some("mesh child1"));
let child_node = child_node.get_sibling().expect("Child_node should have a sibling");
assert_eq!(child_node.get_name(), Some("mesh child2"));
let sibling_node = node.get_sibling().expect("Node should have a sibling");
assert_eq!(sibling_node.get_name(), Some("mush"));
Sourcepub fn get_parent(&self) -> Option<ModelNode<'_>>
pub fn get_parent(&self) -> Option<ModelNode<'_>>
The ModelNode above this one (“up”) in the hierarchy tree, or None if this is a root node. https://stereokit.net/Pages/StereoKit/ModelNode/Parent.html
see also model_node_parent
§Examples
use stereokit_rust::{maths::Matrix, model::Model, mesh::Mesh, material::Material};
let model = Model::new();
let mut nodes = model.get_nodes();
nodes.add("mesh", Matrix::IDENTITY, Some(&Mesh::cube()), Some(&Material::pbr()), true);
nodes.add("mush", Matrix::IDENTITY, Some(&Mesh::cube()), Some(&Material::pbr()), true);
let mut node = nodes.find("mesh").expect("Node mosh should exist");
node.add_child("mesh child1", Matrix::IDENTITY, Some(&Mesh::cube()), Some(&Material::pbr()), true);
node.add_child("mesh child2", Matrix::IDENTITY, Some(&Mesh::cube()), Some(&Material::pbr()), true);
let child_node = node.get_child().expect("Node should have a child");
assert_eq!(child_node.get_name(), Some("mesh child1"));
assert_eq!(child_node.get_parent().unwrap().get_name(), Some("mesh"));
let child_node = child_node.get_sibling().expect("Child_node should have a sibling");
assert_eq!(child_node.get_name(), Some("mesh child2"));
assert_eq!(child_node.get_parent().unwrap().get_name(), Some("mesh"));
// Mesh is it's own parent.
assert_eq!(child_node.get_parent().unwrap().get_name(), Some("mesh"));
Sourcepub fn get_next(&self) -> Option<ModelNode<'_>>
pub fn get_next(&self) -> Option<ModelNode<'_>>
The next ModelNode in the hierarchy tree, or None if this is the last node. https://stereokit.net/Pages/StereoKit/Model/ModelNodeCollection.html
see also model_node_iterate
same as ModelNode::iterate
Sourcepub fn get_model(&self) -> &Model
pub fn get_model(&self) -> &Model
The whole model in which this node belongs https://stereokit.net/Pages/StereoKit/Model.html
see also Model
§Examples
use stereokit_rust::{maths::Matrix, model::Model, mesh::Mesh, material::Material};
let model = Model::new();
let mut nodes = model.get_nodes();
nodes.add("mesh", Matrix::IDENTITY, Some(&Mesh::cube()), Some(&Material::pbr()), true);
let node = nodes.get_root_node().expect("We should have a root node");
assert_eq!(node.get_name(), Some("mesh"));
assert_eq!(node.get_model(), &model);
Sourcepub fn get_infos(&self) -> Infos<'_> ⓘ
pub fn get_infos(&self) -> Infos<'_> ⓘ
Get Info for this node https://stereokit.net/Pages/StereoKit/ModelNodeInfoCollection.html
§Examples
use stereokit_rust::{maths::Matrix, model::{Model, Info}};
let model = Model::new();
let mut nodes = model.get_nodes();
nodes.add("some_info", Matrix::IDENTITY, None, None, false);
let mut node = nodes.get_root_node().expect("We should have a root node");
let mut infos = node.get_infos();
infos.set_info( "name1", "value1");
infos.set_info( "name2", "value2");
assert_eq!(infos.get_count(), 2);
for (item, info) in infos.enumerate() {
match item {
0 => assert_eq!(info, Info { name: "name2".to_string(), value: "value2".to_string() }),
_ => assert_eq!(info, Info { name: "name1".to_string(), value: "value1".to_string() }),
}
}
Trait Implementations§
impl<'a> Copy for ModelNode<'a>
impl<'a> StructuralPartialEq for ModelNode<'a>
Auto Trait Implementations§
impl<'a> Freeze for ModelNode<'a>
impl<'a> RefUnwindSafe for ModelNode<'a>
impl<'a> !Send for ModelNode<'a>
impl<'a> !Sync for ModelNode<'a>
impl<'a> Unpin for ModelNode<'a>
impl<'a> UnwindSafe for ModelNode<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.