// MonoGame - Copyright (C) The MonoGame Team // This file is subject to the terms and conditions defined in // file 'LICENSE.txt', which is part of this source code package. using System; using System.Collections; using System.Collections.Generic; namespace Microsoft.Xna.Framework.Content.Pipeline.Graphics { /// /// Provides methods for maintaining a list of vertex positions. /// /// /// This class is designed to collect the vertex positions for a VertexContent object. Use the contents /// of the PositionIndices property (of the contained VertexContent object) to index into the Positions /// property of the parent mesh. /// public sealed class IndirectPositionCollection : IList { private readonly VertexChannel _positionIndices; private readonly GeometryContent _geometry; /// /// Number of positions in the collection. /// /// Number of positions. public int Count { get { return _positionIndices.Count; } } /// /// Gets or sets the position at the specified index. /// /// Position located at index. public Vector3 this[int index] { get { var remap = _positionIndices[index]; return _geometry.Parent.Positions[remap]; } set { throw Readonly(); } } /// /// Gets a value indicating whether this object is read-only. /// /// true if this object is read-only; false otherwise. bool ICollection.IsReadOnly { get { return true; } } /// /// Initializes a new instance of IndirectPositionCollection. /// internal IndirectPositionCollection(GeometryContent geom, VertexChannel positionIndices) { _geometry = geom; _positionIndices = positionIndices; } /// /// Determines whether the specified position is in the collection. /// /// Position being searched for in the collection. /// true if the position was found; false otherwise. public bool Contains(Vector3 item) { return IndexOf(item) > -1; } /// /// Copies the specified positions to an array, starting at the specified index. /// /// Array of positions to be copied. /// Index of the first copied position. public void CopyTo(Vector3[] array, int arrayIndex) { foreach (var vec in this) array[arrayIndex++] = vec; } /// /// Gets an enumerator interface for reading the position values. /// /// Interface for enumerating the collection of position values. public IEnumerator GetEnumerator() { for (var i = 0; i < Count; i++) yield return this[i]; } /// /// Gets the index of the specified position in a collection. /// /// Position being searched for. /// Index of the specified position or -1 if not found. public int IndexOf(Vector3 item) { for (var i = 0; i < Count; i++) if (this[i] == item) return i; return -1; } internal Exception Readonly() { return new NotSupportedException("The collection is read only!"); } void ICollection.Add(Vector3 item) { throw Readonly(); } void ICollection.Clear() { throw Readonly(); } bool ICollection.Remove(Vector3 item) { throw Readonly(); } void IList.Insert(int index, Vector3 item) { throw Readonly(); } void IList.RemoveAt(int index) { throw Readonly(); } /// /// Returns an enumerator that can iterate through the collection. /// /// Enumerator that can iterate through the collection. IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } }