Struct Nodes

Source
pub struct Nodes<'a> { /* private fields */ }
Expand description

Nodes of a Model https://stereokit.net/Pages/StereoKit/ModelNodeCollection.html https://stereokit.net/Pages/StereoKit/ModelVisualCollection.html

see also Model::get_nodes

§Examples

use stereokit_rust::{maths::{Vec3, Matrix} ,model::Model, util::Color128};

let model = Model::from_file("center.glb", None)
                          .expect("Could not load model").copy();
let transform = Matrix::t_r_s(Vec3::NEG_Y * 0.40, [0.0, 190.0, 0.0], Vec3::ONE * 0.25);

let mut nodes = model.get_nodes();

// Duplicate Suzanne ModelNode 5 times at different positions.
let original_node = nodes.find("Suzanne").expect("Could not find Suzanne");
let mesh = original_node.get_mesh().expect("Could not get Suzanne's mesh");
let material_original = original_node.get_material().expect("Could not get Suzanne's material");

for i in -1..4 {
    let coord = i as f32 * 1.25;
    let color_idx = ((i+5) * 13694856) as u32;
    let position = Matrix::t([coord, coord, coord]);
    let name = format!("Suzanne_{}", i);
    let mut material = material_original.copy();
    material.color_tint(Color128::hex(color_idx));

    nodes.add(name, position, Some(&mesh), Some(&material), true);
}

filename_scr = "screenshots/model_nodes.jpeg";
test_screenshot!( // !!!! Get a proper main loop !!!!
    model.draw(token, transform, None, None);
);
screenshot

Implementations§

Source§

impl<'a> Nodes<'a>

Source

pub fn from(model: &'a impl AsRef<Model>) -> Nodes<'a>

Source

pub fn add<S: AsRef<str>>( &mut self, name: S, local_transform: impl Into<Matrix>, mesh: Option<&Mesh>, material: Option<&Material>, solid: bool, ) -> &mut Self

This adds a root node to the Model’s node hierarchy! If There is already an initial root node, this node will still be a root node, but will be a Sibling of the Model’s RootNode. If this is the first root node added, you’ll be able to access it via Nodes::get_root_node. https://stereokit.net/Pages/StereoKit/Model/AddNode.html

see also ModelNode::add_child model_node_add

§Examples
use stereokit_rust::{maths::{Vec3, Matrix}, model::Model, mesh::Mesh, material::Material};

let sphere =       Mesh::generate_sphere(0.6, 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 material = Material::pbr();

let model = Model::new();
let mut nodes = model.get_nodes();
nodes.add("sphere",   transform1 , Some(&sphere),       Some(&material), true)
     .add("cylinder", transform2 , Some(&cylinder),     Some(&material), true)
     .add("A matrix", Matrix::IDENTITY, None, None, false);

assert_eq!(nodes.get_count(), 3);
assert_eq!(nodes.get_root_node().unwrap().get_name(), Some("sphere"));
Source

pub fn all(&self) -> NodeIter<'_>

Get an iterator of all the nodes https://stereokit.net/Pages/StereoKit/ModelNodeCollection.html

see also NodeIter::all_from

§Examples
use stereokit_rust::{maths::{Vec3, Matrix}, model::Model, mesh::Mesh, material::Material};

let sphere =       Mesh::generate_sphere(0.6, 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 material = Material::pbr();

let model = Model::new();
let mut nodes = model.get_nodes();
nodes.add("sphere",   transform1 , Some(&sphere),       Some(&material), true)
     .add("cylinder", transform2 , Some(&cylinder),     Some(&material), true)
     .add("A matrix", Matrix::IDENTITY, None, None, false);

assert_eq!(nodes.get_count(), 3);
assert_eq!(nodes.all().count(), 3);

for (iter, node) in nodes.all().enumerate() {
    match iter {
        0 => assert_eq!(node.get_name(), Some("sphere")),
        1 => assert_eq!(node.get_name(), Some("cylinder")),
        _ => assert_eq!(node.get_name(), Some("A matrix")),
    }
}
Source

pub fn visuals(&self) -> NodeIter<'_>

Get an iterator of all the visual nodes https://stereokit.net/Pages/StereoKit/ModelVisualCollection.html

see also NodeIter::visuals_from

§Examples
use stereokit_rust::{maths::{Vec3, Matrix}, model::Model, mesh::Mesh, material::Material};

let sphere =       Mesh::generate_sphere(0.6, 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 material = Material::pbr();

let model = Model::new();
let mut nodes = model.get_nodes();
nodes.add("sphere",   transform1 , Some(&sphere),       Some(&material), true)
     .add("cylinder", transform2 , Some(&cylinder),     Some(&material), true)
     .add("A matrix", Matrix::IDENTITY, None, None, false);

assert_eq!(nodes.get_count(), 3);
assert_eq!(nodes.get_visual_count(), 2);
assert_eq!(nodes.visuals().count(), 2);

for (iter, node) in nodes.visuals().enumerate() {
    match iter {
        0 => assert_eq!(node.get_name(), Some("sphere")),
        _ => assert_eq!(node.get_name(), Some("cylinder")),
    }
}
Source

pub fn find<S: AsRef<str>>(&self, name: S) -> Option<ModelNode<'_>>

get node by name https://stereokit.net/Pages/StereoKit/Model/FindNode.html

  • name - Exact name to match against. ASCII only for now.

see also model_node_find

§Examples
use stereokit_rust::{maths::{Vec3, Matrix}, model::Model, mesh::Mesh, material::Material};

let sphere =      Mesh::generate_sphere(0.6, 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 material = Material::pbr();

let model = Model::new();
let mut nodes = model.get_nodes();
nodes.add("sphere",   transform1 , Some(&sphere),      Some(&material), true)
     .add("cylinder", transform2 , Some(&cylinder),    Some(&material), true)
     .add("A matrix", Matrix::IDENTITY, None, None, false);

let found_sphere = nodes.find("sphere");
assert!(found_sphere.is_some());
assert_eq!(found_sphere.unwrap().get_name(), Some("sphere"));

let found_non_existent = nodes.find("non_existent");
assert!(found_non_existent.is_none());
Source

pub fn get_count(&self) -> i32

Get the number of node. https://stereokit.net/Pages/StereoKit/ModelNodeCollection.html

see also NodeIter model_node_count

§Examples
use stereokit_rust::{maths::Matrix, model::Model};

let model = Model::new();

let mut nodes = model.get_nodes();
assert_eq!(nodes.get_count(), 0);

nodes.add("root", Matrix::IDENTITY, None, None, false);
assert_eq!(nodes.get_count(), 1);
Source

pub fn get_visual_count(&self) -> i32

Get the number of visual node https://stereokit.net/Pages/StereoKit/ModelVisualCollection.html

see also NodeIter model_node_visual_count

§Examples
use stereokit_rust::{maths::Matrix, model::Model};

let model = Model::new();

let mut nodes = model.get_nodes();
assert_eq!(nodes.get_count(), 0);
assert_eq!(nodes.get_visual_count(), 0);

nodes.add("root", Matrix::IDENTITY, None, None, false);
assert_eq!(nodes.get_count(), 1);
assert_eq!(nodes.get_visual_count(), 0);
Source

pub fn get_index(&self, index: i32) -> Option<ModelNode<'_>>

Get the node at index https://stereokit.net/Pages/StereoKit/ModelNodeCollection.html

see also NodeIter model_node_index

§Examples
use stereokit_rust::{maths::Matrix, model::Model};

let model = Model::new();

let mut nodes = model.get_nodes();
let node = nodes.get_index(0);
assert!(node.is_none());

nodes.add("root", Matrix::IDENTITY, None, None, false);
let node = nodes.get_index(0).expect("Node should exist");
assert_eq!(node.get_name(), Some("root"));
Source

pub fn get_visual_index(&self, index: i32) -> Option<ModelNode<'_>>

Get the visual node at index https://stereokit.net/Pages/StereoKit/ModelVisualCollection.html

see also NodeIter model_node_visual_index

§Examples
use stereokit_rust::{maths::Matrix, model::Model};

let model = Model::new();

let mut nodes = model.get_nodes();
let node = nodes.get_visual_index(0);
assert!(node.is_none());

nodes.add("root", Matrix::IDENTITY, None, None, false);
let node = nodes.get_visual_index(0);
assert!(node.is_none());
Source

pub fn get_root_node(&self) -> Option<ModelNode<'_>>

Get the root node https://stereokit.net/Pages/StereoKit/Model/RootNode.html

see also model_node_get_root

§Examples
use stereokit_rust::{maths::Matrix, model::Model};

let model = Model::new();

let mut nodes = model.get_nodes();
let node = nodes.get_root_node();
assert!(node.is_none());

nodes.add("root", Matrix::IDENTITY, None, None, false);
let node = nodes.get_root_node().expect("Node should exist");
assert_eq!(node.get_name(), Some("root"));

Trait Implementations§

Source§

impl<'a> Clone for Nodes<'a>

Source§

fn clone(&self) -> Nodes<'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 Nodes<'a>

Source§

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

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

impl<'a> Copy for Nodes<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Nodes<'a>

§

impl<'a> RefUnwindSafe for Nodes<'a>

§

impl<'a> !Send for Nodes<'a>

§

impl<'a> !Sync for Nodes<'a>

§

impl<'a> Unpin for Nodes<'a>

§

impl<'a> UnwindSafe for Nodes<'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