Exemple #1
0
        static private DepthSlice MakeBaseDepthSlice(Heightmap heightmap)
        {
            RawDepthData rawDepthData = GetRawDepthData(heightmap, 0, heightmap.StartX - 1, heightmap.Width + 2); // <- Guarantuee missing ranges on each end (for extrapolation)

            if (rawDepthData.IsBlank)
            {
                return(DepthSlice.CreateBlank(heightmap.StartX, heightmap.StartZ));
            }

            // Fill in missing data and do extrapolation:
            rawDepthData.RepairMissingRanges();
            int dataStart = rawDepthData.missingDataRanges[0].index + rawDepthData.missingDataRanges[0].count;
            int dataEnd   = rawDepthData.missingDataRanges[rawDepthData.missingDataRanges.Count - 1].index;

            // Bring extrapolations into the legitimate data range:
            if (rawDepthData.depthFront[dataStart - 1] == rawDepthData.depthBack[dataStart - 1])
            {
                dataStart--;
            }
            if (rawDepthData.depthFront[dataEnd] == rawDepthData.depthBack[dataEnd])
            {
                dataEnd++;
            }


            return(PackDepthSlice(ref rawDepthData, dataStart, dataEnd));
        }
Exemple #2
0
        static DepthSlice MakeNonBaseDepthSlice(Heightmap heightmap, int yOffset, DepthSlice previousSlice)
        {
            Debug.Assert(yOffset != 0);
            Debug.Assert(previousSlice != null);

            RawDepthData rawDepthData = GetRawDepthData(heightmap, yOffset, previousSlice.xOffset, previousSlice.Width);

            if (rawDepthData.IsBlank)
            {
                return(DepthSlice.CreateBlank(previousSlice.xOffset, previousSlice.zOffset));
            }

            DepthSlice depthSlice = PackDepthSlice(ref rawDepthData, 0, previousSlice.Width);

            // Pull up missing data from previous layers:
            foreach (var missingRange in rawDepthData.missingDataRanges)
            {
                for (int j = 0; j < missingRange.count; j++)
                {
                    int i           = j + missingRange.index;
                    var belowBounds = previousSlice.depths[i];

                    if (belowBounds.front == belowBounds.back && missingRange.count == 1) // <- Indicates the lower layer is an extrapolation (keep it that way)
                    {
                        depthSlice.depths[i] = belowBounds;
                    }
                    else // Lower bounds is a surface, encode an "above" bounds
                    {
                        depthSlice.depths[i] = new FrontBack {
                            back = belowBounds.back, front = (byte)System.Math.Min(byte.MaxValue, (int)belowBounds.back + 1)
                        }
                    };
                }
            }

            return(depthSlice);
        }

        #endregion
    }