コード例 #1
0
        /// <summary>
        /// Set the texture map for a point specified by sample coordinates.
        /// The 4-byte array is map.  The map can have 4 possible mappings associated
        /// with it with one byte per map.
        /// </summary>
        /// <param name="sampleX"></param>
        /// <param name="sampleZ"></param>
        /// <param name="textureMap"></param>
        /// <returns></returns>
        public void SetSampleTextureMap(int sampleX, int sampleZ, byte[] textureMap)
        {
            int tileX;
            int tileZ;

            int xOff;
            int zOff;

            SampleToTileCoords(sampleX, sampleZ, out tileX, out tileZ, out xOff, out zOff);

            if ((tileX < 0) || (tileX >= sizeXTiles) || (tileZ < 0) || (tileZ >= sizeZTiles))
            {
                return; // Ignore out-of-bounds modifications
            }

            TextureMosaicTile tile = tiles[tileX, tileZ] as TextureMosaicTile;

            if (tile == null)
            {
                // This shouldn't happen
                throw new Exception("Tile [" + tileX + "," + tileZ + "] not found for coord [" + sampleX + "," + sampleZ + "] while attempting to set textureMap to: " + textureMap);
            }

            tile.SetTextureMap(xOff, zOff, textureMap);
        }
コード例 #2
0
        public string GetTexture(int worldXMeters, int worldZMeters, int sizeXMeters, int sizeZMeters, out float u1, out float v1, out float u2, out float v2)
        {
            worldXMeters = worldXMeters + xWorldOffsetMeters;
            worldZMeters = worldZMeters + zWorldOffsetMeters;

            int tileX = worldXMeters >> (tileShift + desc.MPSShift);
            int tileZ = worldZMeters >> (tileShift + desc.MPSShift);

            int tileSizeWorld = desc.TileSizeSamples << desc.MPSShift;
            int tileMaskWorld = tileSizeWorld - 1;

            int xoff = worldXMeters & tileMaskWorld;
            int zoff = worldZMeters & tileMaskWorld;

            u1 = (float)xoff / tileSizeWorld;
            v1 = (float)zoff / tileSizeWorld;

            u2 = (float)(xoff + sizeXMeters) / tileSizeWorld;
            v2 = (float)(zoff + sizeZMeters) / tileSizeWorld;

            if (tileX < 0 || tileX >= sizeXTiles || tileZ < 0 || tileZ >= sizeZTiles)
            {
                return("red-zero-alpha.png");
            }

            TextureMosaicTile tile = tiles[tileX, tileZ] as TextureMosaicTile;

            if (tile == null)
            {
                throw new InvalidDataException("Unxpected state!");
            }
            return(tile.TextureName);
        }
コード例 #3
0
        private void FireTerrainSplatChanged(MosaicTile tile, int worldXMeters, int worldZMeters, int sizeXMeters, int sizeZMeters)
        {
            if (m_changeNotificationEnabled && TerrainSplatChanged != null)
            {
                TextureMosaicTile textile = tile as TextureMosaicTile;
                if (textile == null)
                {
                    // Refresh all textures within the mosaic
                    // that have dirty texture images
                    RefreshTextures();
                }
                else
                {
                    // Only refresh the given tile
                    textile.RefreshTexture();
                }

                TerrainSplatChanged(this, tile, worldXMeters, worldZMeters, sizeXMeters, sizeZMeters);
            }
        }
コード例 #4
0
        /// <summary>
        /// Get the texture map for a point specified by sample coordinates
        /// A 4-byte array is returned as the map.  The map can have 4 possible
        /// mappings associated with it with one byte per map.
        /// </summary>
        /// <param name="sampleX"></param>
        /// <param name="sampleZ"></param>
        /// <returns></returns>
        public byte[] GetSampleTextureMap(int sampleX, int sampleZ)
        {
            int tileX;
            int tileZ;

            int xOff;
            int zOff;

            SampleToTileCoords(sampleX, sampleZ, out tileX, out tileZ, out xOff, out zOff);

            if ((tileX < 0) || (tileX >= sizeXTiles) || (tileZ < 0) || (tileZ >= sizeZTiles))
            {
                return(new byte[4]);
            }

            TextureMosaicTile tile = tiles[tileX, tileZ] as TextureMosaicTile;

            if (tile == null)
            {
                return(new byte[4]);
            }

            return(tile.GetTextureMap(xOff, zOff));
        }