Beispiel #1
0
        public void ApplyBrush(IBrushShape brushshape, int brushsize, double brushcentre_x, double brushcentre_y, bool israising, double milliseconds)
        {
            TerrainModel terrain = MetaverseClient.GetInstance().worldstorage.terrainmodel;

            double[,] mesh = terrain.Map;

            int x = (int)(brushcentre_x);
            int y = (int)(brushcentre_y);

            double timemultiplier = milliseconds * speed;
            int    meshsize       = mesh.GetUpperBound(0) + 1;

            for (int i = -brushsize; i <= brushsize; i++)
            {
                for (int j = -brushsize; j <= brushsize; j++)
                {
                    int thisx = x + i;
                    int thisy = y + j;
                    if (thisx >= 0 && thisy >= 0 && thisx < meshsize &&
                        thisy < meshsize)
                    {
                        double brushshapecontribution = brushshape.GetStrength((double)i / brushsize, (double)j / brushsize);
                        if (brushshapecontribution > 0)
                        {
                            mesh[thisx, thisy] = mesh[thisx, thisy] + (mesh[x, y] - mesh[thisx, thisy]) * brushshapecontribution * timemultiplier / 50;
                        }
                    }
                }
            }
            terrain.OnHeightMapInPlaceEdited(x - brushsize, y - brushsize, x + brushsize, y + brushsize);
        }
Beispiel #2
0
        public void ApplyBrush(IBrushShape brushshape, int brushsize, double brushcentrex, double brushcentrey, bool israising, double milliseconds)
        {
            if (thistexture != null && maptexturestage != null)
            {
                double timemultiplier = milliseconds * speed;

                double directionmultiplier = 1.0;
                if (!israising)
                {
                    directionmultiplier = -1.0;
                }

                int mapx               = (int)(brushcentrex / Terrain.SquareSize);
                int mapy               = (int)(brushcentrey / Terrain.SquareSize);
                int mapwidth           = Terrain.GetInstance().HeightMapWidth - 1;
                int mapheight          = Terrain.GetInstance().HeightMapHeight - 1;
                int texturex           = (int)(texturewidth * mapx / mapwidth);
                int texturey           = (int)(textureheight * mapy / mapheight);
                int texturebrushwidth  = (int)(texturewidth * brushsize / mapwidth);
                int texturebrushheight = (int)(textureheight * brushsize / mapheight);
                for (int i = -texturebrushwidth; i <= texturebrushwidth; i++)
                {
                    for (int j = -texturebrushheight; j <= texturebrushheight; j++)
                    {
                        double brushshapecontribution = brushshape.GetStrength((double)i / texturebrushwidth,
                                                                               (double)j / texturebrushheight);
                        if (brushshapecontribution > 0)
                        {
                            int thisx = texturex + i;
                            int thisy = texturey + j;
                            //      Console.WriteLine(thisx + " " + thisy);
                            if (thisx >= 0 && thisy >= 0 && thisx < texturewidth &&
                                thisy < textureheight)
                            {
                                // we update our double array then set the int array iwthin ITexture itself
                                alphadata[thisx, thisy] += speed * directionmultiplier * timemultiplier * brushshapecontribution;
                                if (alphadata[thisx, thisy] >= 255)
                                {
                                    alphadata[thisx, thisy] = 255;
                                }
                                else if (alphadata[thisx, thisy] < 0)
                                {
                                    alphadata[thisx, thisy] = 0;
                                }
                                thistexture.AlphaData[thisx, thisy] = (byte)alphadata[thisx, thisy];
                                //  Console.WriteLine(thisx + " " + thisy + " " + (byte)alphadata[thisx, thisy]);
                            }
                        }
                    }
                }
                thistexture.ReloadAlpha();
                thistexture.Modified = true;
                Terrain.GetInstance().OnBlendMapInPlaceEdited(maptexturestage, mapx - brushsize, mapy - brushsize, mapx + brushsize, mapy + brushsize);
            }
        }
Beispiel #3
0
        public void ApplyBrush(IBrushShape brushshape, int brushsize, double brushcentre_x, double brushcentre_y, bool israising, double timespanmilliseconds)
        {
            Terrain terrain = Terrain.GetInstance();

            double[,] mesh = terrain.Map;

            int x = (int)(brushcentre_x / Terrain.SquareSize);
            int y = (int)(brushcentre_y / Terrain.SquareSize);

            double timemultiplier = timespanmilliseconds * speed;
            int    meshsize       = mesh.GetUpperBound(0) + 1;

            for (int i = -brushsize; i <= brushsize; i++)
            {
                for (int j = -brushsize; j <= brushsize; j++)
                {
                    int thisx = x + i;
                    int thisy = y + j;
                    if (thisx >= 0 && thisy >= 0 && thisx < meshsize &&
                        thisy < meshsize)
                    {
                        double brushshapecontribution = brushshape.GetStrength((double)i / brushsize, (double)j / brushsize);
                        if (brushshapecontribution > 0)
                        {
                            double directionmultiplier = 1.0;
                            if (!israising)
                            {
                                directionmultiplier = -1.0;
                            }
                            mesh[thisx, thisy] += (brushshapecontribution * directionmultiplier * timemultiplier);
                            if (mesh[thisx, thisy] >= terrain.MaxHeight)
                            {
                                mesh[thisx, thisy] = terrain.MaxHeight;
                            }
                            else if (mesh[thisx, thisy] < terrain.MinHeight)
                            {
                                mesh[thisx, thisy] = terrain.MinHeight;
                            }
                        }
                    }
                }
            }
            terrain.OnHeightMapInPlaceEdited(x - brushsize, y - brushsize, x + brushsize, y + brushsize);
        }
Beispiel #4
0
        public void ApplyBrush(IBrushShape brushshape, int brushsize, double brushcentrex, double brushcentrey, bool israising, double milliseconds)
        {
            if (heightscale == null)
            {
                return;
            }
            double targetheight = heightscale.Value;

            Console.WriteLine("height scale value: " + targetheight);
            int x = (int)(brushcentrex / Terrain.SquareSize);
            int y = (int)(brushcentrey / Terrain.SquareSize);

            for (int i = -brushsize; i <= brushsize; i++)
            {
                for (int j = -brushsize; j <= brushsize; j++)
                {
                    double brushcontribution = brushshape.GetStrength(
                        (double)i / brushsize, (double)j / brushsize);
                    if (brushcontribution > 0)
                    {
                        int thisx = x + i;
                        int thisy = y + j;
                        if (thisx >= 0 && thisy >= 0 &&
                            thisx < Terrain.GetInstance().HeightMapWidth&&
                            thisy < Terrain.GetInstance().HeightMapHeight)
                        {
                            double oldheight = Terrain.GetInstance().Map[thisx, thisy];
                            double newheight = oldheight + (targetheight - oldheight) *
                                               speed * milliseconds / 50 * brushcontribution;
                            Terrain.GetInstance().Map[thisx, thisy] = newheight;
                        }
                    }
                }
            }
            Terrain.GetInstance().OnHeightMapInPlaceEdited(x - brushsize, y - brushsize, x + brushsize, y + brushsize);
        }
        public void ApplyBrush( IBrushShape brushshape, int brushsize, double brushcentre_x, double brushcentre_y, bool israising, double milliseconds )
        {
            Terrain terrain = Terrain.GetInstance();
            double[,] mesh = terrain.Map;

            int x = (int)( brushcentre_x / Terrain.SquareSize );
            int y = (int)(brushcentre_y / Terrain.SquareSize);

            double timemultiplier = milliseconds * speed;
            int meshsize = mesh.GetUpperBound( 0 ) + 1;
            for (int i = -brushsize; i <= brushsize; i++)
            {
                for (int j = -brushsize; j <= brushsize; j++)
                {
                    int thisx = x + i;
                    int thisy = y + j;
                    if (thisx >= 0 && thisy >= 0 && thisx < meshsize &&
                        thisy < meshsize)
                    {
                        double brushshapecontribution = brushshape.GetStrength( (double)i / brushsize, (double)j / brushsize );
                        if (brushshapecontribution > 0)
                        {
                            mesh[thisx, thisy] = mesh[thisx, thisy] + (mesh[x, y] - mesh[thisx, thisy]) * brushshapecontribution * timemultiplier / 50;
                        }
                    }
                }
            }
            terrain.OnHeightMapInPlaceEdited( x - brushsize, y - brushsize, x + brushsize, y + brushsize );
        }
Beispiel #6
0
        public void ApplyBrush( IBrushShape brushshape, int brushsize, double brushcentre_x, double brushcentre_y, bool israising, double timespanmilliseconds )
        {
            TerrainModel terrain = MetaverseClient.GetInstance().worldstorage.terrainmodel;
            double[,] mesh = terrain.Map;

            int x = (int)(brushcentre_x );
            int y = (int)(brushcentre_y );

            double timemultiplier = timespanmilliseconds * speed;
            int meshsize = mesh.GetUpperBound( 0 ) + 1;
            for (int i = -brushsize; i <= brushsize; i++)
            {
                for (int j = -brushsize; j <= brushsize; j++)
                {
                    int thisx = x + i;
                    int thisy = y + j;
                    if (thisx >= 0 && thisy >= 0 && thisx < meshsize &&
                        thisy < meshsize)
                    {
                        double brushshapecontribution = brushshape.GetStrength( (double)i / brushsize, (double)j / brushsize );
                        if (brushshapecontribution > 0)
                        {
                            double directionmultiplier = 1.0;
                            if (!israising)
                            {
                                directionmultiplier = -1.0;
                            }
                            mesh[thisx, thisy] += (brushshapecontribution * directionmultiplier * timemultiplier);
                            if (mesh[thisx, thisy] >= terrain.MaxHeight)
                            {
                                mesh[thisx, thisy] = terrain.MaxHeight;
                            }
                            else if (mesh[thisx, thisy] < terrain.MinHeight)
                            {
                                mesh[thisx, thisy] = terrain.MinHeight;
                            }
                        }
                    }
                }
            }
            terrain.OnHeightMapInPlaceEdited( x - brushsize, y - brushsize, x + brushsize, y + brushsize );
        }
        public void ApplyBrush( IBrushShape brushshape, int brushsize, double brushcentrex, double brushcentrey, bool israising, double milliseconds )
        {
            if (heightscale == null)
            {
                return;
            }
            double targetheight = heightscale.Value;
            Console.WriteLine( "height scale value: " + targetheight );
            int x = (int)( brushcentrex / Terrain.SquareSize );
            int y = (int)(brushcentrey / Terrain.SquareSize);

            for (int i = -brushsize; i <= brushsize; i++)
            {
                for (int j = -brushsize; j <= brushsize; j++)
                {
                    double brushcontribution = brushshape.GetStrength(
                        (double)i / brushsize, (double)j / brushsize );
                    if (brushcontribution > 0)
                    {
                        int thisx = x + i;
                        int thisy = y + j;
                        if (thisx >= 0 && thisy >= 0 &&
                            thisx < Terrain.GetInstance().HeightMapWidth &&
                            thisy < Terrain.GetInstance().HeightMapHeight)
                        {
                            double oldheight = Terrain.GetInstance().Map[thisx, thisy];
                            double newheight = oldheight + (targetheight - oldheight) *
                                speed * milliseconds / 50 * brushcontribution;
                            Terrain.GetInstance().Map[thisx, thisy] = newheight;
                        }
                    }
                }
            }
            Terrain.GetInstance().OnHeightMapInPlaceEdited( x - brushsize, y - brushsize, x + brushsize, y + brushsize );
        }
Beispiel #8
0
        public void ApplyBrush( IBrushShape brushshape, int brushsize, double brushcentrex, double brushcentrey, bool israising, double milliseconds )
        {
            if ( thistexture != null && maptexturestage != null )
            {
                double timemultiplier = milliseconds * speed;

                double directionmultiplier = 1.0;
                if (!israising)
                {
                    directionmultiplier = -1.0;
                }

                int mapx = (int)(brushcentrex );
                int mapy = (int)(brushcentrey );
                int mapwidth = MetaverseClient.GetInstance().worldstorage.terrainmodel.HeightMapWidth - 1;
                int mapheight = MetaverseClient.GetInstance().worldstorage.terrainmodel.HeightMapHeight - 1;
                int texturex = (int)(texturewidth * mapx / mapwidth);
                int texturey = (int)(textureheight * mapy / mapheight);
                int texturebrushwidth = (int)(texturewidth * brushsize / mapwidth);
                int texturebrushheight = (int)(textureheight * brushsize / mapheight);
                for (int i = -texturebrushwidth; i <= texturebrushwidth; i++)
                {
                    for (int j = -texturebrushheight; j <= texturebrushheight; j++)
                    {
                        double brushshapecontribution = brushshape.GetStrength( (double)i / texturebrushwidth,
                           (double)j / texturebrushheight );
                        if (brushshapecontribution > 0)
                        {
                            int thisx = texturex + i;
                            int thisy = texturey + j;
                            //      Console.WriteLine(thisx + " " + thisy);
                            if (thisx >= 0 && thisy >= 0 && thisx < texturewidth &&
                                thisy < textureheight)
                            {
                                // we update our double array then set the int array iwthin ITexture itself
                                //LogFile.WriteLine( speed + " " + directionmultiplier + " " + timemultiplier + " " + brushshapecontribution );
                                alphadata[thisx, thisy] += speed * directionmultiplier * timemultiplier * brushshapecontribution;
                                if (alphadata[thisx, thisy] >= 255)
                                {
                                    alphadata[thisx, thisy] = 255;
                                }
                                else if (alphadata[thisx, thisy] < 0)
                                {
                                    alphadata[thisx, thisy] = 0;
                                }
                                thistexture.SetPixel( thisx, thisy, (byte)alphadata[thisx, thisy], (byte)alphadata[thisx, thisy], (byte)alphadata[thisx, thisy], 255 );
                                //LogFile.WriteLine( "setting pixel " + thisx + " " + thisy + " to " + (byte)alphadata[thisx, thisy] );
                                //thistexture.AlphaData[thisx, thisy] = (byte)alphadata[thisx, thisy];
                                //  Console.WriteLine(thisx + " " + thisy + " " + (byte)alphadata[thisx, thisy]);
                            }
                        }
                    }
                }

                thistexture.Save( "editedblend.jpg" );

                //thistexture.ReloadAlpha();
                maptexturestage.onChanged();
                //thistexture.Modified = true;
                MetaverseClient.GetInstance().worldstorage.terrainmodel.OnBlendMapInPlaceEdited( maptexturestage, mapx - brushsize, mapy - brushsize, mapx + brushsize, mapy + brushsize );
            }
        }
Beispiel #9
0
        public void ApplyBrush(IBrushShape brushshape, int brushsize, double brushcentrex, double brushcentrey, bool israising, double milliseconds)
        {
            if (thistexture != null && maptexturestage != null)
            {
                double timemultiplier = milliseconds * speed;

                double directionmultiplier = 1.0;
                if (!israising)
                {
                    directionmultiplier = -1.0;
                }

                int mapx               = (int)(brushcentrex);
                int mapy               = (int)(brushcentrey);
                int mapwidth           = MetaverseClient.GetInstance().worldstorage.terrainmodel.HeightMapWidth - 1;
                int mapheight          = MetaverseClient.GetInstance().worldstorage.terrainmodel.HeightMapHeight - 1;
                int texturex           = (int)(texturewidth * mapx / mapwidth);
                int texturey           = (int)(textureheight * mapy / mapheight);
                int texturebrushwidth  = (int)(texturewidth * brushsize / mapwidth);
                int texturebrushheight = (int)(textureheight * brushsize / mapheight);
                for (int i = -texturebrushwidth; i <= texturebrushwidth; i++)
                {
                    for (int j = -texturebrushheight; j <= texturebrushheight; j++)
                    {
                        double brushshapecontribution = brushshape.GetStrength((double)i / texturebrushwidth,
                                                                               (double)j / texturebrushheight);
                        if (brushshapecontribution > 0)
                        {
                            int thisx = texturex + i;
                            int thisy = texturey + j;
                            //      Console.WriteLine(thisx + " " + thisy);
                            if (thisx >= 0 && thisy >= 0 && thisx < texturewidth &&
                                thisy < textureheight)
                            {
                                // we update our double array then set the int array iwthin ITexture itself
                                //LogFile.WriteLine( speed + " " + directionmultiplier + " " + timemultiplier + " " + brushshapecontribution );
                                alphadata[thisx, thisy] += speed * directionmultiplier * timemultiplier * brushshapecontribution;
                                if (alphadata[thisx, thisy] >= 255)
                                {
                                    alphadata[thisx, thisy] = 255;
                                }
                                else if (alphadata[thisx, thisy] < 0)
                                {
                                    alphadata[thisx, thisy] = 0;
                                }
                                thistexture.SetPixel(thisx, thisy, (byte)alphadata[thisx, thisy], (byte)alphadata[thisx, thisy], (byte)alphadata[thisx, thisy], 255);
                                //LogFile.WriteLine( "setting pixel " + thisx + " " + thisy + " to " + (byte)alphadata[thisx, thisy] );
                                //thistexture.AlphaData[thisx, thisy] = (byte)alphadata[thisx, thisy];
                                //  Console.WriteLine(thisx + " " + thisy + " " + (byte)alphadata[thisx, thisy]);
                            }
                        }
                    }
                }

                thistexture.Save("editedblend.jpg");

                //thistexture.ReloadAlpha();
                maptexturestage.onChanged();
                //thistexture.Modified = true;
                MetaverseClient.GetInstance().worldstorage.terrainmodel.OnBlendMapInPlaceEdited(maptexturestage, mapx - brushsize, mapy - brushsize, mapx + brushsize, mapy + brushsize);
            }
        }