示例#1
0
        /// <inheritdoc />
        public override List <int> GenerateIndexList(int resolutionU, int resolutionV, int indexOffset = 0)
        {
            // The index list of a model tells the GPU between which vertices to draw triangles. Each three consecutive
            // indices constitute a single triangle. Since the Capsule vertex array consists of several lists stitched
            // together, the indices of the shaft and endCap will have shifted by some amount. Therefore, calculate
            // this index offset for all submodels:
            int indexOffset2 = indexOffset + Hemisphere.CalculateVertexCount(resolutionU, resolutionU / 4) - resolutionU;
            int indexOffset3 = indexOffset2 + Cylinder.CalculateVertexCount(resolutionU, resolutionV) - resolutionU;
            int indexOffset4 = indexOffset3 + Hemisphere.CalculateVertexCount(resolutionU, resolutionU / 4) - resolutionU;

            // Generate the startCap indices as normal:
            List <int> startCapList = startCap.GenerateIndexList(resolutionU, resolutionU / 4, indexOffset);

            // Generate a shaft, using the last ring of the startCap to begin with. This is done by subtracting
            // `resolutionU` from indexOffset2. This automatically stitches the gap between the start cap and the shaft:
            List <int> shaftList = shaft.GenerateIndexList(resolutionU, resolutionV - 1, indexOffset2);

            // Generate the endCap indices as normal:
            List <int> endCapList = endCap.GenerateIndexList(resolutionU, resolutionU / 4, indexOffset3);

            // The final ring between the endCap and the shaft must be generated manually:
            List <int> stitchList = new List <int>(resolutionU);

            // Add a ring of triangles:
            for (int i = 1; i < resolutionU - 1; i++)
            {
                int invertedI = resolutionU - i;
                stitchList.Add(indexOffset + invertedI + indexOffset4);
                stitchList.Add(indexOffset + (i + 1) + indexOffset3 - resolutionU);
                stitchList.Add(indexOffset + i + indexOffset3 - resolutionU);

                stitchList.Add(indexOffset + (invertedI - 1) + indexOffset4);
                stitchList.Add(indexOffset + (i + 1) + indexOffset3 - resolutionU);
                stitchList.Add(indexOffset + invertedI + indexOffset4);
            }

            // Stitch the end of the ring of triangles:
            stitchList.Add(indexOffset + 1 + indexOffset4);
            stitchList.Add(indexOffset + indexOffset3 - resolutionU);
            stitchList.Add(indexOffset + resolutionU - 1 + indexOffset3 - resolutionU);

            stitchList.Add(indexOffset + indexOffset4);
            stitchList.Add(indexOffset + indexOffset3 - resolutionU);
            stitchList.Add(indexOffset + 1 + indexOffset4);

            stitchList.Add(indexOffset + resolutionU - 1 + indexOffset4);
            stitchList.Add(indexOffset + 1 + indexOffset3 - resolutionU);
            stitchList.Add(indexOffset + indexOffset3 - resolutionU);

            stitchList.Add(indexOffset + indexOffset4);
            stitchList.Add(indexOffset + resolutionU - 1 + indexOffset4);
            stitchList.Add(indexOffset + indexOffset3 - resolutionU);

            return(startCapList.Concat(shaftList).Concat(endCapList).Concat(stitchList).ToList());
        }
        public override List <int> GenerateIndexList(int resolutionU, int resolutionV, int indexOffset = 0)
        {
            int indexOffset2 = indexOffset + Hemisphere.CalculateVertexCount(resolutionU, resolutionU / 4);
            int indexOffset3 = indexOffset + indexOffset2 + Cylinder.CalculateVertexCount(resolutionU, resolutionV);

            List <int> startCapList = startCap.GenerateIndexList(resolutionU, resolutionU / 4, indexOffset);
            List <int> shaftList    = shaft.GenerateIndexList(resolutionU, resolutionV, indexOffset2);
            List <int> endCapList   = endCap.GenerateIndexList(resolutionU, resolutionU / 4, indexOffset3);

            return(startCapList.Concat(shaftList).Concat(endCapList).ToList());
        }