Exemple #1
0
        /// <summary>
        /// Creates a deep-copy of the current <see cref="IGraphicsStream"/>.
        /// </summary>
        /// <returns>A deep-copy of the current <see cref="IGraphicsStream"/>.</returns>
        public override IGraphicsStream Clone()
        {
            IGraphicsStream stream = new IndexStream16(this.Size);

            stream.Copy(this);
            return(stream);
        }
Exemple #2
0
        /// <summary>
        /// Creates an IndexStream from a certain number of vertices that are organised in quads.
        /// </summary>
        /// <param name="quadNum">The number of quads.</param>
        /// <returns>The created indexStream.</returns>
        public static IndexStream FromQuads(int quadNum)
        {
            IndexStream indexStream;

            if (quadNum * 6 > ushort.MaxValue)
            {
                indexStream = new IndexStream32(quadNum * 6);
            }
            else
            {
                indexStream = new IndexStream16(quadNum * 6);
            }

            int iIndex  = 0;
            int iVertex = 0;

            for (int i = 0; i < quadNum; i++, iIndex += 6, iVertex += 4)
            {
                indexStream[iIndex + 0] = iVertex;
                indexStream[iIndex + 1] = (iVertex + 1);
                indexStream[iIndex + 2] = (iVertex + 3);
                indexStream[iIndex + 3] = (iVertex + 3);
                indexStream[iIndex + 4] = (iVertex + 1);
                indexStream[iIndex + 5] = (iVertex + 2);
            }
            return(indexStream);
        }
Exemple #3
0
        //---------------------------------------------------------------
        #endregion
        //---------------------------------------------------------------

        //---------------------------------------------------------------
        #region Methods
        //---------------------------------------------------------------
        /// <summary>
        /// Creates an IndexStream from a list of triangles
        /// </summary>
        /// <param name="triangles"></param>
        public static IndexStream16 FromTriangles(System.Collections.ICollection triangles)
        {
            IndexStream16 index = new IndexStream16(triangles.Count * 3);
            int           i     = 0;

            foreach (Triangle tri in triangles)
            {
                index[i++] = tri.A;
                index[i++] = tri.B;
                index[i++] = tri.C;
            }
            return(index);
        }
Exemple #4
0
        /// <summary>
        /// creates an indexed vertexUnit and the indexStream from the current vertexUnit
        /// </summary>
        /// <param name="vertexUnit">created vertexUnit</param>
        /// <param name="indexStream">created indexStream</param>
        public void Indexify(out VertexUnit vertexUnit, out VertexStreams.IndexStream indexStream)
        {
            object[]  currentVertex = new object[StreamCount];
            Hashtable vertices      = new Hashtable();
            int       vertexNum     = 0;
            int       currentIndex  = 0;

            indexStream = new VertexStreams.IndexStream16(Size);
            // TODO: Size is much too high for vertexUnit
            // calc real size
            vertexUnit = new VertexUnit(format, Size);

            for (int i = 0; i < Size; i++)
            {
                // fill vertex
                for (int j = 0; j < StreamCount; j++)
                {
                    currentVertex[j] = this[j].Data.GetValue(i);
                }

                // calc current index
                if (vertices.Contains(currentVertex))
                {
                    currentIndex = (int)vertices[currentVertex];
                }
                else
                {
                    vertices.Add(currentVertex, vertexNum);
                    currentIndex = vertexNum;
                    vertexNum++;
                    // add new vertex to new streams
                    for (int j = 0; j < StreamCount; j++)
                    {
                        vertexUnit[j].Data.SetValue(currentVertex[j], j);
                    }
                }

                indexStream[i] = currentIndex;
            }
        }