/// <inheritdoc />
        public override Geometry BuildGeometry(GeometryBuildOptions buildOptions)
        {
            // Handle empty case
            if ((_generatedTriangles == null) ||
                (_generatedTriangles.Count == 0))
            {
                return(new Geometry(0));
            }

            var result  = new Geometry(this.TriangleCount * 3);
            var surface = result.CreateSurface(this.TriangleCount);

            var generatedTriangles = _generatedTriangles;

            foreach (var actTriangleArray in generatedTriangles)
            {
                foreach (var actTriangle in actTriangleArray)
                {
                    surface.BuildTriangle(
                        new Vector3(actTriangle.Point1.X, 0f, actTriangle.Point1.Y),
                        new Vector3(actTriangle.Point2.X, 0f, actTriangle.Point2.Y),
                        new Vector3(actTriangle.Point3.X, 0f, actTriangle.Point3.Y));
                }
            }

            return(result);
        }
        /// <summary>
        /// Builds the geometry for the given detail level.
        /// </summary>
        /// <param name="buildOptions">Some generic options for geometry building</param>
        public override Geometry BuildGeometry(GeometryBuildOptions buildOptions)
        {
            var geometryFromChild = _geometryToStack.BuildGeometry(buildOptions);

            geometryFromChild.EnsureNotNull(nameof(geometryFromChild));

            var childStructBox   = geometryFromChild.GenerateBoundingBox();
            var correctionVector = -childStructBox.GetBottomCenter();

            // Copy metadata information of the Geometry
            var result = geometryFromChild.Clone(
                false,
                _stackSize);

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

                var baseVertex = loop * geometryFromChild.CountVertices;

                foreach (var actVertex in geometryFromChild.Vertices)
                {
                    // Change vertex properties based on stack position
                    var changedVertex = actVertex;
                    changedVertex.Position = changedVertex.Position + localCorrection;

                    if (loop % 2 == 1)
                    {
                        var color = changedVertex.Color;
                        color.ChangeColorByLight(0.05f);
                        changedVertex.Color = color;
                    }

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

                // Clone all surfaces
                foreach (var actSurfaceFromChild in geometryFromChild.Surfaces)
                {
                    var newSurface = result.CreateSurface(actSurfaceFromChild.CountTriangles);

                    foreach (var actTriangle in actSurfaceFromChild.Triangles)
                    {
                        newSurface.AddTriangle(
                            baseVertex + actTriangle.Index1,
                            baseVertex + actTriangle.Index2,
                            baseVertex + actTriangle.Index3);
                    }
                }
            }

            return(result);
        }
        /// <summary>
        /// Builds the geometry.
        /// </summary>
        /// <param name="buildOptions">Some generic options for geometry building</param>
        public override Geometry BuildGeometry(GeometryBuildOptions buildOptions)
        {
            if (this.BuilderFunction != null)
            {
                return(this.BuilderFunction(buildOptions));
            }

            if (buildOptions.IsHighDetail)
            {
                return(this.Geometry !);
            }
            return(this.GeometryLowDetail !);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Builds the geometry.
        /// </summary>
        public override Geometry BuildGeometry(GeometryBuildOptions buildOptions)
        {
            var result = new Geometry();

            // Calculate half vector of total ground size.
            var totalHalfSize = new Vector2(_totalSizeWithoutBorder.X / 2f, _totalSizeWithoutBorder.Y / 2f);

            // Build all tiles
            foreach (var actTile in _groundTiles)
            {
                // Get the material of the tile
                var actMaterialIndex = actTile.MaterialIndex;
                if (actMaterialIndex < 0)
                {
                    actMaterialIndex = 0;
                }

                // Get surface object
                while (result.CountSurfaces <= actMaterialIndex)
                {
                    result.CreateSurface();
                }
                var actSurface = result.Surfaces[actMaterialIndex];

                // Get position of the tile
                var tilePosition = new Vector3(
                    actTile.XPos * _tileSize.X - totalHalfSize.X,
                    0f,
                    actTile.YPos * _tileSize.Y - totalHalfSize.Y);

                // AddObject tile information to current Geometry
                actSurface.BuildCubeTop(
                    new Vector3(tilePosition.X, 0, tilePosition.Z),
                    new Vector3(_tileSize.X, 0, _tileSize.Y));
            }

            // Return all generated Geometry
            return(result);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Builds the geometry
        /// </summary>
        public override Geometry BuildGeometry(GeometryBuildOptions buildOptions)
        {
            var result = new Geometry();

            // Calculate parameters
            var firstCoordinate = new Vector3(
                -(this.TilesX * this.TileWidth / 2f),
                0f,
                -(this.TilesZ * this.TileWidth / 2f));
            var tileWidthX = this.TileWidth;
            var tileWidthZ = this.TileWidth;

            var tileMiddleX = this.TilesX % 2 == 0 && this.HighlightXZLines ? this.TilesX / 2 : 1;
            var tileMiddleZ = this.TilesZ % 2 == 0 && this.HighlightXZLines ? this.TilesZ / 2 : 1;

            // Define line geometry
            var genSurfaceDefaultLine = result.CreateSurface();
            var genSurfaceGroupLine   = result.CreateSurface();

            for (var actTileX = 0; actTileX < this.TilesX + 1; actTileX++)
            {
                var localStart = firstCoordinate + new Vector3(actTileX * tileWidthX, 0f, 0f);
                var localEnd   = localStart + new Vector3(0f, 0f, tileWidthZ * this.TilesZ);

                var actLineColor = this.LineColor;
                var divider      = actTileX % this.GroupTileCount == 0 ? this.LineSmallDivider : this.LineBigDivider;

                if (this.HighlightXZLines && actTileX == tileMiddleX)
                {
                    actLineColor = this.ZLineHighlightColor;
                    divider      = this.LineSmallDivider;
                }

                var targetGeometry = actTileX % this.GroupTileCount == 0 ? genSurfaceGroupLine : genSurfaceDefaultLine;
                targetGeometry.BuildRect(
                    localStart - new Vector3(tileWidthX / divider, 0f, 0f),
                    localStart + new Vector3(tileWidthX / divider, 0f, 0f),
                    localEnd + new Vector3(tileWidthX / divider, 0f, 0f),
                    localEnd - new Vector3(tileWidthX / divider, 0f, 0f))
                .SetVertexColor(actLineColor);

                if (this.BuildBackFaces)
                {
                    targetGeometry.BuildRect(
                        localEnd - new Vector3(tileWidthX / divider, 0f, 0f),
                        localEnd + new Vector3(tileWidthX / divider, 0f, 0f),
                        localStart + new Vector3(tileWidthX / divider, 0f, 0f),
                        localStart - new Vector3(tileWidthX / divider, 0f, 0f))
                    .SetVertexColor(actLineColor);
                }
            }

            for (var actTileZ = 0; actTileZ < this.TilesZ + 1; actTileZ++)
            {
                var localStart = firstCoordinate + new Vector3(0f, 0f, actTileZ * tileWidthZ);
                var localEnd   = localStart + new Vector3(tileWidthX * this.TilesX, 0f, 0f);

                var actLineColor = this.LineColor;
                var divider      = actTileZ % this.GroupTileCount == 0 ? this.LineSmallDivider : this.LineBigDivider;

                if (this.HighlightXZLines && actTileZ == tileMiddleZ)
                {
                    actLineColor = this.XLineHighlightColor;
                    divider      = this.LineSmallDivider;
                }

                var targetGeometry = actTileZ % this.GroupTileCount == 0 ? genSurfaceGroupLine : genSurfaceDefaultLine;
                targetGeometry.BuildRect(
                    localStart + new Vector3(0f, 0f, tileWidthZ / divider),
                    localStart - new Vector3(0f, 0f, tileWidthZ / divider),
                    localEnd - new Vector3(0f, 0f, tileWidthZ / divider),
                    localEnd + new Vector3(0f, 0f, tileWidthZ / divider))
                .SetVertexColor(actLineColor);

                if (this.BuildBackFaces)
                {
                    targetGeometry.BuildRect(
                        localEnd + new Vector3(0f, 0f, tileWidthZ / divider),
                        localEnd - new Vector3(0f, 0f, tileWidthZ / divider),
                        localStart - new Vector3(0f, 0f, tileWidthZ / divider),
                        localStart + new Vector3(0f, 0f, tileWidthZ / divider))
                    .SetVertexColor(actLineColor);
                }
            }
            if (genSurfaceDefaultLine.CountTriangles == 0)
            {
                result.RemoveSurface(genSurfaceDefaultLine);
            }
            if (genSurfaceGroupLine.CountTriangles == 0)
            {
                result.RemoveSurface(genSurfaceGroupLine);
            }

            // Return the generated geometry
            return(result);
        }