Ejemplo n.º 1
0
        /// <summary>
        /// Builds all vertex structures for the given detail level.
        /// </summary>
        /// <param name="buildOptions">Some generic options for structure building</param>
        public override VertexStructure BuildStructure(StructureBuildOptions buildOptions)
        {
            VertexStructure structureFromChild = m_objTypeToStack.BuildStructure(buildOptions);

            structureFromChild.EnsureNotNull(nameof(structureFromChild));

            BoundingBox childStructBox   = structureFromChild.GenerateBoundingBox();
            Vector3     correctionVector = -childStructBox.GetBottomCenter();

            // Copy metadata infomration of the VertexStructures
            VertexStructure result = structureFromChild.Clone(
                copyGeometryData: false,
                capacityMultiplier: m_stackSize);

            // Build geometry
            for (int loop = 0; loop < m_stackSize; loop++)
            {
                float   actYCorrection  = childStructBox.Height * loop;
                Vector3 localCorrection = new Vector3(correctionVector.X, correctionVector.Y + actYCorrection, correctionVector.Z);

                int baseVertex = loop * structureFromChild.CountVertices;
                foreach (Vertex actVertex in structureFromChild.Vertices)
                {
                    // Change vertex properties based on stack position
                    Vertex changedVertex = actVertex;
                    changedVertex.Position = changedVertex.Position + localCorrection;
                    if (loop % 2 == 1)
                    {
                        changedVertex.Color = changedVertex.Color.ChangeColorByLight(0.05f);
                    }

                    // Add the vertex
                    result.AddVertex(changedVertex);
                }

                // Clone all surfaces
                foreach (VertexStructureSurface actSurfaceFromChild in structureFromChild.Surfaces)
                {
                    VertexStructureSurface newSurface = result.CreateSurface(actSurfaceFromChild.CountTriangles);
                    foreach (Triangle actTriangle in actSurfaceFromChild.Triangles)
                    {
                        newSurface.AddTriangle(
                            baseVertex + actTriangle.Index1,
                            baseVertex + actTriangle.Index2,
                            baseVertex + actTriangle.Index3);
                    }
                }
            }

            return(result);
        }