コード例 #1
0
        private static void GenerateHangingCornerFringe(
            RawPrimitive Into,
            Geo.TemplateFace Face,
            TerrainTileSheet TileSheet,
            SliceCache Cache,
            GrassType decalType,
            Geo.TemplateCorner Corner,
            Vector3 Sag)
        {
            var vertex = Cache.FaceGeometry[Corner.Vertex];

            Cache.TempVerticies[0] = new ExtendedVertex(
                vertex.Position,
                vertex.Color, vertex.VertColor,
                TileSheet.MapTileUVs(new Vector2(0.0f, 0.0f), decalType.FringeTiles[2]), TileSheet.GetTileBounds(decalType.FringeTiles[2]));

            Cache.TempVerticies[1] = new ExtendedVertex(
                Cache.EdgeFringeTempVerticies[Corner.EdgeA].Set ? Cache.EdgeFringeTempVerticies[Corner.EdgeA].End :
                (vertex.Position
                 + OrientationHelper.GetFaceNeighborOffset(Face.Edges[Corner.EdgeA].Orientation).AsVector3() * 0.5f
                 + Sag),
                vertex.Color, vertex.VertColor,
                TileSheet.MapTileUVs(new Vector2(0.5f, 0.0f), decalType.FringeTiles[2]), TileSheet.GetTileBounds(decalType.FringeTiles[2]));

            Cache.TempVerticies[2] = new ExtendedVertex(
                vertex.Position
                + OrientationHelper.GetFaceNeighborOffset(Face.Edges[Corner.EdgeA].Orientation).AsVector3() * 0.5f
                + OrientationHelper.GetFaceNeighborOffset(Face.Edges[Corner.EdgeB].Orientation).AsVector3() * 0.5f
                + Sag,
                vertex.Color, vertex.VertColor,
                TileSheet.MapTileUVs(new Vector2(0.5f, 0.5f), decalType.FringeTiles[2]), TileSheet.GetTileBounds(decalType.FringeTiles[2]));

            Cache.TempVerticies[3] = new ExtendedVertex(
                Cache.EdgeFringeTempVerticies[Corner.EdgeB].Set ? Cache.EdgeFringeTempVerticies[Corner.EdgeB].Start :
                (vertex.Position
                 + OrientationHelper.GetFaceNeighborOffset(Face.Edges[Corner.EdgeB].Orientation).AsVector3() * 0.5f
                 + Sag),
                vertex.Color, vertex.VertColor,
                TileSheet.MapTileUVs(new Vector2(0.0f, 0.5f), decalType.FringeTiles[2]), TileSheet.GetTileBounds(decalType.FringeTiles[2]));

            AddQuad(Into, Cache.TempVerticies, QuadIndicies);
        }
コード例 #2
0
        private static void GenerateEdgeFringe(
            RawPrimitive Into,
            Geo.TemplateFace Face,
            int EdgeIndex,
            TerrainTileSheet TileSheet,
            SliceCache Cache,
            GrassType decalType,
            Vector3 Sag,
            float Scale)
        {
            var start = Cache.FaceGeometry[Face.Edges[EdgeIndex].Start];
            var end   = Cache.FaceGeometry[Face.Edges[EdgeIndex].End];

            Cache.EdgeFringeTempVerticies[EdgeIndex].Set = true;

            Cache.TempVerticies[0] = new ExtendedVertex(
                start.Position,
                start.Color, start.VertColor,
                TileSheet.MapTileUVs(new Vector2(0.0f, 0.0f), decalType.FringeTiles[0]), TileSheet.GetTileBounds(decalType.FringeTiles[0]));

            Cache.TempVerticies[1] = new ExtendedVertex(
                end.Position,
                end.Color, end.VertColor,
                TileSheet.MapTileUVs(new Vector2(1.0f, 0.0f), decalType.FringeTiles[0]), TileSheet.GetTileBounds(decalType.FringeTiles[0]));

            Cache.EdgeFringeTempVerticies[EdgeIndex].End = end.Position + OrientationHelper.GetFaceNeighborOffset(Face.Edges[EdgeIndex].Orientation).AsVector3() * Scale + Sag;
            Cache.TempVerticies[2] = new ExtendedVertex(
                Cache.EdgeFringeTempVerticies[EdgeIndex].End,
                end.Color, end.VertColor,
                TileSheet.MapTileUVs(new Vector2(1.0f, 0.5f), decalType.FringeTiles[0]), TileSheet.GetTileBounds(decalType.FringeTiles[0]));

            Cache.EdgeFringeTempVerticies[EdgeIndex].Start = start.Position + OrientationHelper.GetFaceNeighborOffset(Face.Edges[EdgeIndex].Orientation).AsVector3() * Scale + Sag;
            Cache.TempVerticies[3] = new ExtendedVertex(
                Cache.EdgeFringeTempVerticies[EdgeIndex].Start,
                start.Color, start.VertColor,
                TileSheet.MapTileUVs(new Vector2(0.0f, 0.5f), decalType.FringeTiles[0]), TileSheet.GetTileBounds(decalType.FringeTiles[0]));

            AddQuad(Into, Cache.TempVerticies, QuadIndicies);
        }
コード例 #3
0
ファイル: GeometryBuilder.cs プロジェクト: sodomon2/dwarfcorp
        private static void PrepVerticies(
            WorldManager World,
            VoxelHandle Voxel,
            Geo.TemplateFace Face,
            SliceCache Cache,
            int ExploredVertexCount,
            TerrainTileSheet TileSheet,
            Point Tile,
            bool ApplyLighting,
            float explodeOffset)
        {
            for (var vertex = 0; vertex < Face.Mesh.VertexCount; ++vertex) // Blows up if face has more than 4 verticies.
            {
                var lighting = new VertexLighting.VertexColorInfo {
                    AmbientColor = 255, DynamicColor = 255, SunColor = 255
                };

                if (ApplyLighting)
                {
                    lighting = VertexLighting.CalculateVertexLight(Voxel, Face.Mesh.Verticies[vertex].LogicalVertex, World.ChunkManager, Cache);
                }

                var slopeOffset = Vector3.Zero;
                if (Face.Mesh.Verticies[vertex].ApplySlope && ShouldSlope(Face.Mesh.Verticies[vertex].LogicalVertex, Voxel))
                {
                    slopeOffset = new Vector3(0.0f, -0.5f, 0.0f);
                }

                var voxelPosition = Face.Mesh.Verticies[vertex].Position + slopeOffset + Voxel.WorldPosition;
                voxelPosition += VertexNoise.GetNoiseVectorFromRepeatingTexture(voxelPosition);
                voxelPosition += explodeOffset * OrientationHelper.GetFaceNeighborOffset(Face.Orientation).AsVector3();

                if (ExploredVertexCount == 0)
                {
                    Cache.FaceGeometry[vertex] = new ExtendedVertex
                    {
                        Position          = voxelPosition,
                        TextureCoordinate = TileSheet.MapTileUVs(Face.Mesh.Verticies[vertex].TextureCoordinate, BlackTile),
                        TextureBounds     = TileSheet.GetTileBounds(BlackTile),
                        VertColor         = new Color(0.0f, 0.0f, 0.0f, 1.0f),
                        Color             = new Color(0.0f, 0.0f, 0.0f, 1.0f)
                    };
                }
                else
                {
                    var anyNeighborExplored = true;
                    if (!Cache.ExploredCache.TryGetValue(SliceCache.GetCacheKey(Voxel, Face.Mesh.Verticies[vertex].LogicalVertex), out anyNeighborExplored))
                    {
                        anyNeighborExplored = true;
                    }

                    Cache.FaceGeometry[vertex] = new ExtendedVertex
                    {
                        Position          = voxelPosition,
                        TextureCoordinate = TileSheet.MapTileUVs(Face.Mesh.Verticies[vertex].TextureCoordinate, Tile),
                        TextureBounds     = TileSheet.GetTileBounds(Tile),
                        VertColor         = anyNeighborExplored ? new Color(1.0f, 1.0f, 1.0f, 1.0f) : new Color(0.0f, 0.0f, 0.0f, 1.0f),
                        Color             = lighting.AsColor()
                    };
                }
            }
        }