Exemple #1
0
        public ImageList( ContentReader R )
        {
            this.InitializeComponent();

            ReaderPage = R;
            SetTemplate();
        }
        protected internal override object Read(
			ContentReader input,
			object existingInstance
		)
        {
            return input.ReadExternalReference<object>();
        }
Exemple #3
0
 public BookmarkList( ContentReader MainReader )
     :this()
 {
     Reader = MainReader;
     Reader.ContentView.Reader.PropertyChanged += Reader_PropertyChanged;
     MainList.ItemsSource = Reader.ContentView.Reader.CustomAnchors;
 }
        public TableOfContents( ContentReader MainReader )
            :this()
        {
            Reader = MainReader;

            if( Reader.CurrentBook == null )
            {
                Logger.Log( ID, "Cannot init TOC: CurrentBook is null... is pages unloaded ?", LogType.WARNING );
                return;
            }

            TOC = new TOCPane( Reader.CurrentBook.GetVolumes() );

            TOCContext.DataContext = TOC;
            TOCList.SelectedItem = TOC.GetItem( Reader.CurrentChapter );
            TOCList.Loaded += TOCListLoaded;
            TOCList.SelectionChanged += TOCList_SelectionChanged;
        }
        protected override TiledMap Read(ContentReader input, TiledMap existingInstance)
        {
            TiledMap Map = null;

            return(Map);
        }
 public static GraphicsDevice GetGraphicsDevice(this ContentReader contentReader)
 {
     return((GraphicsDevice)ContentReaderGraphicsDeviceFieldInfo.GetValue(contentReader));
 }
Exemple #7
0
        public async Task <string> ExtraerkeyPhrasesFromPDF(TraceWriter log)
        {
            var    result     = new StringBuilder();
            string keyPhrases = string.Empty;

            string keyPhrasesGoogle    = string.Empty;
            string classifyTextGoogle  = string.Empty;
            int    numeroPagina        = 1;
            string separador           = ",";
            int    cantidadLlamadasAPI = 0;

            foreach (var page in doc.Pages)
            {
                ExtractText(ContentReader.ReadContent(page), result);
                Dictionary <int, string> subPaginas = splitPagina(result.ToString());

                foreach (KeyValuePair <int, string> entry in subPaginas)
                {
                    try
                    {
                        if (cantidadLlamadasAPI == 3)
                        {
                            Thread.Sleep(400);
                            cantidadLlamadasAPI = 0;
                        }
                        else
                        {
                            cantidadLlamadasAPI = cantidadLlamadasAPI + 1;
                            classifyTextGoogle  = AnalizadorTexto.Clasificador(entry.Value.ToString().Replace(".", ""));
                            keyPhrasesGoogle    = AnalizadorTexto.ProcesarGoogle(entry.Value.ToString().Replace(".", ""));
                            keyPhrases          = AnalizadorTexto.AnalizarTexto(entry.Value.ToString().Replace(".", ""), numeroPagina.ToString());
                            Thread.Sleep(400);
                        }
                    }
                    catch (Exception ex)
                    {
                        log.Info("exception 2 " + ex.Message + " // String Entry Value: " + entry.Value.ToString().Replace(".", ""));
                    }

                    log.Info("Se procesó el bloque : " + entry.Key.ToString() + " de la página " + numeroPagina.ToString() + ". Total de páginas: " + doc.PageCount.ToString());
                    log.Info(keyPhrases.Length.ToString());

                    var guardarKeys         = GuardarKeys(doc.Guid.ToString(), numeroPagina, entry.Key, keyPhrases, keyPhrasesGoogle.ToString(), log);
                    var guardarClasificador = GuardarClasificador(doc.Guid.ToString(), classifyTextGoogle, log);

                    if (guardarKeys && guardarClasificador)
                    {
                        log.Info("Guardó Ok");
                    }
                    else
                    {
                        log.Info("Error");
                    }
                }

                numeroPagina++;
            }



            // InsertarEnTxt(result1.ToString());

            return(result.ToString());
        }
Exemple #8
0
 /// <summary>
 /// Read
 /// </summary>
 protected override LDtkWorld Read(ContentReader input, LDtkWorld existingInstance)
 {
     return(existingInstance ?? System.Text.Json.JsonSerializer.Deserialize <LDtkWorld>(input.ReadString(), LDtkWorld.SerializeOptions));
 }
Exemple #9
0
        /// <summary>
        /// Reads a <see cref="JsonObject"/>.
        /// </summary>
        protected override JsonObject Read(ContentReader input, JsonObject existingInstance)
        {
            string json = input.ReadString();

            return(new JsonObject(json));
        }
Exemple #10
0
        protected override CpuAnimatedVertexBuffer Read(ContentReader input, CpuAnimatedVertexBuffer buffer)
        {
            IGraphicsDeviceService graphicsDeviceService = (IGraphicsDeviceService)input.ContentManager.ServiceProvider.GetService(typeof(IGraphicsDeviceService));
            var device = graphicsDeviceService.GraphicsDevice;

            // read standard VertexBuffer
            var declaration = input.ReadRawObject <VertexDeclaration>();
            var vertexCount = (int)input.ReadUInt32();
            // int dataSize = vertexCount * declaration.VertexStride;
            //byte[] data = new byte[dataSize];
            //input.Read(data, 0, dataSize);

            //read data
            var channels    = declaration.GetVertexElements();
            var cpuVertices = new VertexIndicesWeightsPositionNormal[vertexCount];
            var gpuVertices = new VertexPositionNormalTexture[vertexCount];

            for (int i = 0; i < vertexCount; i++)
            {
                foreach (var channel in channels)
                {
                    switch (channel.VertexElementUsage)
                    {
                    case VertexElementUsage.Position:
                        System.Diagnostics.Debug.Assert(channel.VertexElementFormat == VertexElementFormat.Vector3);
                        var pos = input.ReadVector3();
                        cpuVertices[i].Position = pos;
                        gpuVertices[i].Position = pos;
                        break;

                    case VertexElementUsage.Normal:
                        System.Diagnostics.Debug.Assert(channel.VertexElementFormat == VertexElementFormat.Vector3);
                        var nor = input.ReadVector3();
                        cpuVertices[i].Normal = nor;
                        gpuVertices[i].Normal = nor;
                        break;

                    case VertexElementUsage.TextureCoordinate:
                        System.Diagnostics.Debug.Assert(channel.VertexElementFormat == VertexElementFormat.Vector2);
                        var tex = input.ReadVector2();
                        gpuVertices[i].TextureCoordinate = tex;
                        break;

                    case VertexElementUsage.BlendWeight:
                        System.Diagnostics.Debug.Assert(channel.VertexElementFormat == VertexElementFormat.Vector4);
                        var wei = input.ReadVector4();
                        cpuVertices[i].BlendWeights = wei;
                        break;

                    case VertexElementUsage.BlendIndices:
                        System.Diagnostics.Debug.Assert(channel.VertexElementFormat == VertexElementFormat.Byte4);
                        var i0 = input.ReadByte();
                        var i1 = input.ReadByte();
                        var i2 = input.ReadByte();
                        var i3 = input.ReadByte();
                        cpuVertices[i].BlendIndex0 = i0;
                        cpuVertices[i].BlendIndex1 = i1;
                        cpuVertices[i].BlendIndex2 = i2;
                        cpuVertices[i].BlendIndex3 = i3;
                        break;

                    default:
                        throw new Exception();
                    }
                }
            }


            // read extras
            bool IsWriteOnly = input.ReadBoolean();

            if (buffer == null)
            {
                BufferUsage usage = (IsWriteOnly) ? BufferUsage.WriteOnly : BufferUsage.None;
                buffer = new CpuAnimatedVertexBuffer(device, VertexPositionNormalTexture.VertexDeclaration, vertexCount, usage);
            }

            buffer.SetData(gpuVertices, 0, vertexCount);
            buffer.SetGpuVertices(gpuVertices);
            buffer.SetCpuVertices(cpuVertices);

            return(buffer);
        }
Exemple #11
0
        protected override BitmapFont Read(ContentReader reader, BitmapFont existingInstance)
        {
            var hasEmbeddedTextures = reader.ReadBoolean();

            Texture2D[] textures;
            if (hasEmbeddedTextures)
            {
                var totalTextures = reader.ReadInt32();
                textures = new Texture2D[totalTextures];
                for (var i = 0; i < totalTextures; i++)
                {
                    textures[i] = reader.ReadObject <Texture2D>();
                }
            }
            else
            {
                var       totalTextureNames = reader.ReadInt32();
                Vector2[] atlasOrigins      = new Vector2[totalTextureNames];
                textures = new Texture2D[totalTextureNames];
                for (var i = 0; i < totalTextureNames; i++)
                {
                    var textureName = reader.ReadString();
                    atlasOrigins[i].X = reader.ReadSingle();
                    atlasOrigins[i].Y = reader.ReadSingle();
                    textures[i]       = reader.ContentManager.Load <Texture2D>(textureName);
                }
            }

            var lineHeight = reader.ReadInt32();
            var padTop     = reader.ReadInt32();
            var padLeft    = reader.ReadInt32();
            var padBottom  = reader.ReadInt32();
            var padRight   = reader.ReadInt32();

            reader.ReadInt32();             // was descent in old style format

            var regionCount = reader.ReadInt32();
            var characters  = new Dictionary <char, Character>();

            for (var r = 0; r < regionCount; r++)
            {
                var character = new Character();

                character.Char          = (char)reader.ReadInt32();
                character.TexturePage   = reader.ReadInt32();
                character.Bounds.X      = reader.ReadInt32();
                character.Bounds.Y      = reader.ReadInt32();
                character.Bounds.Width  = reader.ReadInt32();
                character.Bounds.Height = reader.ReadInt32();
                character.Offset.X      = reader.ReadInt32();
                character.Offset.Y      = reader.ReadInt32();
                character.XAdvance      = reader.ReadInt32();

                characters[character.Char] = character;
            }

            var font = new BitmapFont
            {
                Kernings   = new Dictionary <Kerning, int>(),
                Textures   = textures,
                LineHeight = lineHeight,
                Padding    = new Padding(padLeft, padTop, padRight, padBottom),
                Characters = characters
            };

            font.DefaultCharacter = font[' '];
            font._spaceWidth      = font.DefaultCharacter.Bounds.Width + font.DefaultCharacter.XAdvance;

            return(font);
        }
Exemple #12
0
 protected abstract T CreateAndPopulateObject(ContentReader input);
Exemple #13
0
 protected override Plane CreateAndPopulateObject(ContentReader input)
 {
     return(new Plane {
         Normal = input.ReadVector3(), Distance = input.ReadSingle()
     });
 }
 protected override SkinnedModelBone Read(ContentReader input, SkinnedModelBone existingInstance)
 {
     return(SkinnedModelBone.Read(input));
 }
Exemple #15
0
 protected internal override object Read(ContentReader input, object existingInstance)
 {
     throw new NotSupportedException();
 }
        /// <summary>
        /// initializes resources (mapDistanceSquaredFromWater, mapDistanceSquaredFromLocations, mapMultipliers) and smoothes small height map
        /// </summary>
        public static void InitImprovedWorldTerrain(ContentReader contentReader)
        {
            if (!init)
            {
                #if CREATE_PERSISTENT_LOCATION_RANGE_MAPS
                {
                    int width  = WoodsFile.mapWidthValue;
                    int height = WoodsFile.mapHeightValue;

                    mapLocationRangeX = new byte[width * height];
                    mapLocationRangeY = new byte[width * height];

                    //int y = 204;
                    //int x = 718;
                    for (int y = 0; y < height; y++)
                    {
                        for (int x = 0; x < width; x++)
                        {
                            //MapPixelData MapData = TerrainHelper.GetMapPixelData(contentReader, x, y);
                            //if (MapData.hasLocation)
                            //{
                            //    int locationRangeX = (int)MapData.locationRect.xMax - (int)MapData.locationRect.xMin;
                            //    int locationRangeY = (int)MapData.locationRect.yMax - (int)MapData.locationRect.yMin;
                            //}

                            ContentReader.MapSummary mapSummary;
                            int  regionIndex = -1, mapIndex = -1;
                            bool hasLocation = contentReader.HasLocation(x, y, out mapSummary);
                            if (hasLocation)
                            {
                                regionIndex = mapSummary.RegionIndex;
                                mapIndex    = mapSummary.MapIndex;
                                DFLocation location       = contentReader.MapFileReader.GetLocation(regionIndex, mapIndex);
                                byte       locationRangeX = location.Exterior.ExteriorData.Width;
                                byte       locationRangeY = location.Exterior.ExteriorData.Height;

                                mapLocationRangeX[y * width + x] = locationRangeX;
                                mapLocationRangeY[y * width + x] = locationRangeY;
                            }
                        }
                    }

                    // save to files
                    FileStream ostream;
                    ostream = new FileStream(Path.Combine(Application.dataPath, out_filepathMapLocationRangeX), FileMode.Create, FileAccess.Write);
                    BinaryWriter writerMapLocationRangeX = new BinaryWriter(ostream, Encoding.UTF8);
                    writerMapLocationRangeX.Write(mapLocationRangeX, 0, width * height);
                    writerMapLocationRangeX.Close();
                    ostream.Close();

                    ostream = new FileStream(Path.Combine(Application.dataPath, out_filepathMapLocationRangeY), FileMode.Create, FileAccess.Write);
                    BinaryWriter writerMapLocationRangeY = new BinaryWriter(ostream, Encoding.UTF8);
                    writerMapLocationRangeY.Write(mapLocationRangeY, 0, width * height);
                    writerMapLocationRangeY.Close();
                    ostream.Close();
                }
                #else
                {
                    int width  = WoodsFile.mapWidthValue;
                    int height = WoodsFile.mapHeightValue;

                    mapLocationRangeX = new byte[width * height];
                    mapLocationRangeY = new byte[width * height];

                    MemoryStream istream;
                    TextAsset    assetMapLocationRangeX = Resources.Load <TextAsset>(filenameMapLocationRangeX);
                    if (assetMapLocationRangeX != null)
                    {
                        istream = new MemoryStream(assetMapLocationRangeX.bytes);
                        BinaryReader readerMapLocationRangeX = new BinaryReader(istream, Encoding.UTF8);
                        readerMapLocationRangeX.Read(mapLocationRangeX, 0, width * height);
                        readerMapLocationRangeX.Close();
                        istream.Close();
                    }

                    TextAsset assetMapLocationRangeY = Resources.Load <TextAsset>(filenameMapLocationRangeY);
                    if (assetMapLocationRangeY)
                    {
                        istream = new MemoryStream(assetMapLocationRangeY.bytes);
                        BinaryReader readerMapLocationRangeY = new BinaryReader(istream, Encoding.UTF8);
                        readerMapLocationRangeY.Read(mapLocationRangeY, 0, width * height);
                        readerMapLocationRangeY.Close();
                        istream.Close();
                    }

                    //FileStream istream;
                    //istream = new FileStream(filepathMapLocationRangeX, FileMode.Open, FileAccess.Read);
                    //BinaryReader readerMapLocationRangeX = new BinaryReader(istream, Encoding.UTF8);
                    //readerMapLocationRangeX.Read(mapLocationRangeX, 0, width * height);
                    //readerMapLocationRangeX.Close();
                    //istream.Close();

                    //istream = new FileStream(filepathMapLocationRangeY, FileMode.Open, FileAccess.Read);
                    //BinaryReader readerMapLocationRangeY = new BinaryReader(istream, Encoding.UTF8);
                    //readerMapLocationRangeY.Read(mapLocationRangeY, 0, width * height);
                    //readerMapLocationRangeY.Close();
                    //istream.Close();
                }
                #endif

                if (mapDistanceSquaredFromWater == null)
                {
                    byte[] heightMapArray = contentReader.WoodsFileReader.Buffer.Clone() as byte[];
                    int    width          = WoodsFile.mapWidthValue;
                    int    height         = WoodsFile.mapHeightValue;
                    for (int y = 0; y < height; y++)
                    {
                        for (int x = 0; x < width; x++)
                        {
                            if (heightMapArray[y * width + x] <= 2)
                            {
                                heightMapArray[y * width + x] = 1;
                            }
                            else
                            {
                                heightMapArray[y * width + x] = 0;
                            }
                        }
                    }
                    //now set image borders to "water" (this is a workaround to prevent mountains to become too high in north-east and south-east edge of map)
                    for (int y = 0; y < height; y++)
                    {
                        heightMapArray[y * width + 0]         = 1;
                        heightMapArray[y * width + width - 1] = 1;
                    }
                    for (int x = 0; x < width; x++)
                    {
                        heightMapArray[0 * width + x]            = 1;
                        heightMapArray[(height - 1) * width + x] = 1;
                    }

                    mapDistanceSquaredFromWater = imageDistanceTransform(heightMapArray, width, height, 1);

                    heightMapArray = null;
                }

                if (mapDistanceSquaredFromLocations == null)
                {
                    int width  = WoodsFile.mapWidthValue;
                    int height = WoodsFile.mapHeightValue;
                    mapLocations = new byte[width * height];

                    for (int y = 0; y < height; y++)
                    {
                        for (int x = 0; x < width; x++)
                        {
                            ContentReader.MapSummary summary;
                            if (contentReader.HasLocation(x + 1, y + 1, out summary))
                            {
                                mapLocations[y * width + x] = 1;
                            }
                            else
                            {
                                mapLocations[y * width + x] = 0;
                            }
                        }
                    }
                    mapDistanceSquaredFromLocations = imageDistanceTransform(mapLocations, width, height, 1);
                }

                if (mapMultipliers == null)
                {
                    int width  = WoodsFile.mapWidthValue;
                    int height = WoodsFile.mapHeightValue;
                    mapMultipliers = new float[width * height];

                    // compute the multiplier and store it in mapMultipliers
                    for (int y = 0; y < height; y++)
                    {
                        for (int x = 0; x < width; x++)
                        {
                            float distanceFromWater    = (float)Math.Sqrt(mapDistanceSquaredFromWater[y * WoodsFile.mapWidthValue + x]);
                            float distanceFromLocation = (float)Math.Sqrt(mapDistanceSquaredFromLocations[y * WoodsFile.mapWidthValue + x]);
                            float multiplierLocation   = (distanceFromLocation * extraExaggerationFactorLocationDistance + 1.0f); // terrain distant from location gets extra exaggeration
                            if (distanceFromWater < minDistanceFromWaterForExtraExaggeration)                                     // except if it is near water
                            {
                                multiplierLocation = 1.0f;
                            }

                            // Seed random with terrain key
                            UnityEngine.Random.InitState(TerrainHelper.MakeTerrainKey(x, y));

                            float additionalHeightBasedOnClimate = GetAdditionalHeightBasedOnClimate(x, y);
                            float additionalHeightApplied        = UnityEngine.Random.Range(-additionalHeightBasedOnClimate * 0.5f, additionalHeightBasedOnClimate);
                            mapMultipliers[y * width + x] = (Math.Min(maxHeightsExaggerationMultiplier, additionalHeightApplied + /*multiplierLocation **/ Math.Max(1.0f, distanceFromWater * exaggerationFactorWaterDistance)));
                        }
                    }

                    // multipliedMap gets smoothed
                    float[] newmapMultipliers = mapMultipliers.Clone() as float[];
                    float[,] weights = { { 0.0625f, 0.125f, 0.0625f }, { 0.125f, 0.25f, 0.125f }, { 0.0625f, 0.125f, 0.0625f } };
                    for (int y = 1; y < height - 1; y++)
                    {
                        for (int x = 1; x < width - 1; x++)
                        {
                            if (mapDistanceSquaredFromLocations[y * width + x] <= 2) // at and around locations ( <= 2 ... only map pixels in 8-connected neighborhood (distanceFromLocationMaps stores squared distances...))
                            {
                                newmapMultipliers[y * width + x] =
                                    weights[0, 0] * mapMultipliers[(y - 1) * width + (x - 1)] + weights[0, 1] * mapMultipliers[(y - 1) * width + (x)] + weights[0, 2] * mapMultipliers[(y - 1) * width + (x + 1)] +
                                    weights[1, 0] * mapMultipliers[(y - 0) * width + (x - 1)] + weights[1, 1] * mapMultipliers[(y - 0) * width + (x)] + weights[1, 2] * mapMultipliers[(y - 0) * width + (x + 1)] +
                                    weights[2, 0] * mapMultipliers[(y + 1) * width + (x - 1)] + weights[2, 1] * mapMultipliers[(y + 1) * width + (x)] + weights[2, 2] * mapMultipliers[(y + 1) * width + (x + 1)];
                            }
                        }
                    }
                    mapMultipliers = newmapMultipliers;

                    newmapMultipliers = null;
                    weights           = null;
                }

                //the height map gets smoothed as well
                {
                    int    width           = WoodsFile.mapWidthValue;
                    int    height          = WoodsFile.mapHeightValue;
                    byte[] heightMapBuffer = contentReader.WoodsFileReader.Buffer.Clone() as byte[];
                    int[,] intWeights = { { 1, 2, 1 }, { 2, 4, 2 }, { 1, 2, 1 } };
                    for (int y = 1; y < height - 1; y++)
                    {
                        for (int x = 1; x < width - 1; x++)
                        {
                            if (mapDistanceSquaredFromWater[y * width + x] > 0) // check if squared distance from water is greater than zero -> if it is no water pixel
                            {
                                int value =
                                    intWeights[0, 0] * (int)heightMapBuffer[(y - 1) * width + (x - 1)] + intWeights[0, 1] * (int)heightMapBuffer[(y - 1) * width + (x)] + intWeights[0, 2] * (int)heightMapBuffer[(y - 1) * width + (x + 1)] +
                                    intWeights[1, 0] * (int)heightMapBuffer[(y - 0) * width + (x - 1)] + intWeights[1, 1] * (int)heightMapBuffer[(y - 0) * width + (x)] + intWeights[1, 2] * (int)heightMapBuffer[(y - 0) * width + (x + 1)] +
                                    intWeights[2, 0] * (int)heightMapBuffer[(y + 1) * width + (x - 1)] + intWeights[2, 1] * (int)heightMapBuffer[(y + 1) * width + (x)] + intWeights[2, 2] * (int)heightMapBuffer[(y + 1) * width + (x + 1)];

                                heightMapBuffer[y * width + x] = (byte)(value / 16);
                            }
                        }
                    }
                    contentReader.WoodsFileReader.Buffer = heightMapBuffer;

                    heightMapBuffer = null;
                    intWeights      = null;
                }

                // build tree coverage map
                if (mapTreeCoverage == null)
                {
                    int width  = WoodsFile.mapWidthValue;
                    int height = WoodsFile.mapHeightValue;
                    mapTreeCoverage = new byte[width * height];

                    #if !LOAD_TREE_COVERAGE_MAP
                    {
                        float startTreeCoverageAtElevation = ImprovedTerrainSampler.baseHeightScale * 2.0f; // ImprovedTerrainSampler.scaledBeachElevation;
                        float minTreeCoverageSaturated     = ImprovedTerrainSampler.baseHeightScale * 6.0f;
                        float maxTreeCoverageSaturated     = ImprovedTerrainSampler.baseHeightScale * 60.0f;
                        float endTreeCoverageAtElevation   = ImprovedTerrainSampler.baseHeightScale * 80.0f;
                        //float maxElevation = 0.0f;
                        for (int y = 0; y < height; y++)
                        {
                            for (int x = 0; x < width; x++)
                            {
                                int   readIndex = (height - 1 - y) * width + x;
                                float w         = 0.0f;

                                //float elevation = ((float)contentReader.WoodsFileReader.Buffer[(height - 1 - y) * width + x]) / 255.0f; // *mapMultipliers[index];
                                float elevation = ((float)contentReader.WoodsFileReader.Buffer[readIndex]) * mapMultipliers[readIndex];

                                //maxElevation = Math.Max(maxElevation, elevation);
                                if ((elevation > minTreeCoverageSaturated) && (elevation < maxTreeCoverageSaturated))
                                {
                                    w = 1.0f;
                                }
                                else if ((elevation >= startTreeCoverageAtElevation) && (elevation <= minTreeCoverageSaturated))
                                {
                                    w = (elevation - startTreeCoverageAtElevation) / (minTreeCoverageSaturated - startTreeCoverageAtElevation);
                                }
                                else if ((elevation >= maxTreeCoverageSaturated) && (elevation <= endTreeCoverageAtElevation))
                                {
                                    w = 1.0f - ((elevation - maxTreeCoverageSaturated) / (endTreeCoverageAtElevation - maxTreeCoverageSaturated));
                                }

                                //w = 0.65f * w + 0.35f * Math.Min(6.0f, (float)Math.Sqrt(mapDistanceSquaredFromLocations[y * width + x])) / 6.0f;

                                mapTreeCoverage[(y) * width + x] = Convert.ToByte(w * 255.0f);

                                //if (elevation>0.05f)
                                //    mapTreeCoverage[index] = Convert.ToByte(250); //w * 255.0f);
                                //else mapTreeCoverage[index] = Convert.ToByte(0);

                                //if (elevation >= startTreeCoverageAtElevation)
                                //{
                                //    mapTreeCoverage[(y) * width + x] = Convert.ToByte(255.0f);
                                //} else{
                                //    mapTreeCoverage[(y) * width + x] = Convert.ToByte(0.0f);
                                //}
                            }
                        }
                    }
                    #else
                    {
                        MemoryStream istream;
                        TextAsset    assetMapTreeCoverage = Resources.Load <TextAsset>(filenameTreeCoverageMap);
                        if (assetMapTreeCoverage)
                        {
                            istream = new MemoryStream(assetMapTreeCoverage.bytes);
                            BinaryReader readerMapTreeCoverage = new BinaryReader(istream, Encoding.UTF8);
                            readerMapTreeCoverage.Read(mapTreeCoverage, 0, width * height);
                            readerMapTreeCoverage.Close();
                            istream.Close();
                        }
                    }
                    #endif

                    #if CREATE_PERSISTENT_TREE_COVERAGE_MAP
                    {
                        FileStream   ostream = new FileStream(Path.Combine(Application.dataPath, out_filepathOutTreeCoverageMap), FileMode.Create, FileAccess.Write);
                        BinaryWriter writerMapTreeCoverage = new BinaryWriter(ostream, Encoding.UTF8);
                        writerMapTreeCoverage.Write(mapTreeCoverage, 0, width * height);
                        writerMapTreeCoverage.Close();
                        ostream.Close();
                    }
                    #endif
                    //Debug.Log(string.Format("max elevation: {0}", maxElevation));
                }

                init = true;
            }
        }
        protected override BodyContainer Read(ContentReader input, BodyContainer existingInstance)
        {
            BodyContainer bodies = existingInstance ?? new BodyContainer();

            int count = input.ReadInt32();

            for (int i = 0; i < count; i++)
            {
                string       name = input.ReadString();
                BodyTemplate body = new BodyTemplate
                {
                    Mass     = input.ReadSingle(),
                    BodyType = (BodyType)input.ReadInt32()
                };
                int fixtureCount = input.ReadInt32();
                for (int j = 0; j < fixtureCount; j++)
                {
                    FixtureTemplate fixture = new FixtureTemplate
                    {
                        Name        = input.ReadString(),
                        Restitution = input.ReadSingle(),
                        Friction    = input.ReadSingle()
                    };
                    ShapeType type = (ShapeType)input.ReadInt32();
                    switch (type)
                    {
                    case ShapeType.Circle:
                    {
                        float       density = input.ReadSingle();
                        float       radius  = input.ReadSingle();
                        CircleShape circle  = new CircleShape(radius, density);
                        circle.Position = input.ReadVector2();
                        fixture.Shape   = circle;
                    } break;

                    case ShapeType.Polygon:
                    {
                        Vertices verts        = new Vertices(Settings.MaxPolygonVertices);
                        float    density      = input.ReadSingle();
                        int      verticeCount = input.ReadInt32();
                        for (int k = 0; k < verticeCount; k++)
                        {
                            verts.Add(input.ReadVector2());
                        }
                        PolygonShape poly = new PolygonShape(verts, density);
                        poly.MassData.Centroid = input.ReadVector2();
                        fixture.Shape          = poly;
                    } break;

                    case ShapeType.Edge:
                    {
                        EdgeShape edge = new EdgeShape(input.ReadVector2(), input.ReadVector2());
                        edge.HasVertex0 = input.ReadBoolean();
                        if (edge.HasVertex0)
                        {
                            edge.Vertex0 = input.ReadVector2();
                        }
                        edge.HasVertex3 = input.ReadBoolean();
                        if (edge.HasVertex3)
                        {
                            edge.Vertex3 = input.ReadVector2();
                        }
                        fixture.Shape = edge;
                    } break;

                    case ShapeType.Chain:
                    {
                        Vertices verts        = new Vertices();
                        int      verticeCount = input.ReadInt32();
                        for (int k = 0; k < verticeCount; k++)
                        {
                            verts.Add(input.ReadVector2());
                        }
                        fixture.Shape = new ChainShape(verts);
                    } break;
                    }
                    body.Fixtures.Add(fixture);
                }
                bodies[name] = body;
            }
            return(bodies);
        }