MCPcopy Create free account
hub / github.com/StereoKit/StereoKit / ModelNodeCollection

Class ModelNodeCollection

StereoKit/Assets/Model.cs:810–857  ·  view source on GitHub ↗

An enumerable for Model's ModelNodes

Source from the content-addressed store, hash-verified

808
809 /// <summary>An enumerable for Model's ModelNodes</summary>
810 public class ModelNodeCollection : IEnumerable<ModelNode>
811 {
812 Model _model;
813 /// <summary>This is the total number of nodes in the Model.</summary>
814 public int Count => NativeAPI.model_node_count(_model._inst);
815 /// <summary>Allows you to retrieve a node from this collection via its
816 /// index.</summary>
817 /// <param name="index">This should be in the range of [0, Count).</param>
818 /// <returns>A ModelNode for the given index.</returns>
819 public ModelNode this[int index] => new ModelNode(_model, NativeAPI.model_node_index(_model._inst, index));
820
821 internal ModelNodeCollection(Model model) { _model = model; }
822
823 /// <summary>Gets an enumerator for the collection.</summary>
824 /// <returns>An enumerator.</returns>
825 public IEnumerator<ModelNode> GetEnumerator()
826 {
827 int count = Count;
828 for (int i = 0; i < count; i++)
829 yield return new ModelNode(_model, NativeAPI.model_node_index(_model._inst, i));
830 }
831 IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
832
833 /// <summary>This adds a root node to the `Model`'s node hierarchy! If
834 /// There is already an initial root node, this node will still be a
835 /// root node, but will be a `Sibling` of the `Model`'s `RootNode`. If
836 /// this is the first root node added, you'll be able to access it via
837 /// `RootNode`.</summary>
838 /// <param name="name">A text name to identify the node. If null is
839 /// provided, it will be auto named to "node"+index.</param>
840 /// <param name="modelTransform">A Matrix describing this node's
841 /// transform in Model space.</param>
842 /// <param name="mesh">The Mesh to attach to this Node's visual, if
843 /// this is null, then material must also be null.</param>
844 /// <param name="material">The Material to attach to this Node's
845 /// visual, if this is null, then mesh must also be null.</param>
846 /// <param name="solid">A flag that indicates the Mesh for this node
847 /// will be used in ray intersection tests. This flag is ignored if no
848 /// Mesh is attached.</param>
849 /// <returns>This returns the newly added ModelNode, or if there's an
850 /// issue with mesh and material being inconsistently null, then this
851 /// result will also be null.</returns>
852 public ModelNode Add(string name, Matrix modelTransform, Mesh mesh = null, Material material = null, bool solid = true)
853 {
854 return new ModelNode(_model,
855 NativeAPI.model_node_add(_model._inst, name, modelTransform, mesh != null ? mesh._inst : IntPtr.Zero, material != null ? material._inst : IntPtr.Zero, solid ? 1 : 0));
856 }
857 }
858
859 /// <summary>An enumerable for Model's visual ModelNodes</summary>
860 public class ModelVisualCollection : IEnumerable<ModelNode>

Callers

nothing calls this directly

Calls 2

model_node_countMethod · 0.80
model_node_indexMethod · 0.80

Tested by

no test coverage detected