Struct ModelNode

Source
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);
);
screenshot

Implementations§

Source§

impl ModelNode<'_>

Source

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());
Source

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);
Source

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);
Source

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()));
Source

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()));
Source

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());
Source

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

Source

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);
Source

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);
Source

pub fn get_name(&self) -> Option<&str>

Source

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

Source

pub fn get_visible(&self) -> bool

Source

pub fn get_material(&self) -> Option<Material>

Source

pub fn get_mesh(&self) -> Option<Mesh>

Source

pub fn get_model_transform(&self) -> Matrix

Source

pub fn get_local_transform(&self) -> Matrix

Source

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());
Source

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"));
Source

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"));
Source

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"));
Source

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

Source

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);
Source

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§

Source§

impl<'a> Clone for ModelNode<'a>

Source§

fn clone(&self) -> ModelNode<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for ModelNode<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> PartialEq for ModelNode<'a>

Source§

fn eq(&self, other: &ModelNode<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> Copy for ModelNode<'a>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more