Esempio n. 1
0
        public static ushort[] Optimize(ushort[] triangles)
        {
            fixed(ushort *p = &triangles[0])
            {
                SetStitchStrips(true);

                PrimitiveGroup *pg  = null;
                ushort          num = 0;
                bool            rc  = GenerateStrips(p, (uint)triangles.Length, &pg, &num, false);

                if (!rc)
                {
                    throw new Exception();
                }

                try
                {
                    if (num != 1)
                    {
                        throw new Exception();
                    }
                    if (pg[0].type != PrimType.PT_STRIP)
                    {
                        throw new Exception();
                    }

                    ushort[] nidx = new ushort[pg[0].numIndices];

                    for (int i = 0; i < nidx.Length; ++i)
                    {
                        nidx[i] = pg[0].indices[i];
                    }

                    return(nidx);
                }
                finally
                {
                    DeletePrimitiveGroup(pg);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Generate triangle strips from the given triangle indices.
        /// </summary>
        /// <param name="triangles">The array containing the triangle indices.</param>
        /// <returns>Tri-stripped triangle indices</returns>
        public static ushort[] GenerateStrips(ushort[] triangles)
        {
            fixed(ushort *p = &triangles[0])
            {
                PrimitiveGroup *primGroup     = null;
                ushort          numPrimGroups = 0;
                bool            success       = GenerateStrips(p, (uint)triangles.Length, &primGroup, &numPrimGroups);

                if (!success)
                {
                    throw new Exception("Failed to generate triangle strips!");
                }

                try
                {
                    if (numPrimGroups != 1)
                    {
                        throw new Exception("More than 1 primitive group was returned");
                    }

                    if (primGroup[0].type != PrimType.PT_STRIP)
                    {
                        throw new Exception("Returned primitive group isn't triangle stripped!");
                    }

                    ushort[] strippedIndices = new ushort[primGroup[0].numIndices];

                    for (int i = 0; i < strippedIndices.Length; ++i)
                    {
                        strippedIndices[i] = primGroup[0].indices[i];
                    }

                    return(strippedIndices);
                }
                finally
                {
                    DeletePrimitiveGroups(primGroup, numPrimGroups);
                }
            }
        }
Esempio n. 3
0
 public extern static void DeletePrimitiveGroups(PrimitiveGroup *primGroups, ushort numGroups);
Esempio n. 4
0
 public extern static void RemapIndices(PrimitiveGroup *in_primGroups, ushort numGroups, ushort numVerts, PrimitiveGroup **remappedGroups);
Esempio n. 5
0
 public extern static void DeletePrimitiveGroup(PrimitiveGroup *primGroups);