Exemple #1
0
        public void ImportWithEnlarge(MatrixWorld src, MatrixWorld dst, Terrains.Area area, StopToken stop)
        /// Takes a part of raw (src) and expands it to fill tile (dst)
        /// The new function, but doesn't work for some reason (no offset)
        {
            //finding read area - dst rect in src coordsys
            Vector2D worldRatio = (Vector2D)dst.worldSize / (Vector2D)src.worldSize;
            Vector2D rectRatio  = (Vector2D)dst.rect.size / (Vector2D)src.rect.size;

            Vector2D ratio    = worldRatio / rectRatio;
            Vector2D readPos  = (Vector2D)dst.rect.offset * ratio - (Vector2D)src.worldPos / src.PixelSize;
            Vector2D readSize = (Vector2D)dst.rect.size * ratio;             //was /ratio, but we need dst-1 for size

            //int pixelMarg = Mathf.Max((int)(0.5f/ratio.x), 2); //2 initially, but increases for big scale values  //can't rescale when src dst pixelsizes are about the same
            int       pixelMarg = (int)(0.5f / ratio.x);     //2 initially, but increases for big scale values
            CoordRect readRect  = new CoordRect(Coord.Floor(readPos) - pixelMarg, (Coord)readSize + pixelMarg * 2);

            if (stop != null && stop.stop)
            {
                return;
            }
            Matrix readMatrix = new Matrix(readRect);

            Matrix.ReadMatrix(src, readMatrix, wrapMode);

            if (stop != null && stop.stop)
            {
                return;
            }
            MatrixOps.Upsize(readMatrix, readPos, readSize, dst);
        }
Exemple #2
0
        public void ImportWithDownscale(Matrix src, MatrixWorld dst, Terrains.Area area)
        {
            CoordRect relRect = new CoordRect(
                Mathf.FloorToInt(offset.x / dst.PixelSize.x),
                Mathf.FloorToInt(offset.y / dst.PixelSize.z),
                Mathf.CeilToInt(scale * dst.rect.size.x),
                Mathf.CeilToInt(scale * dst.rect.size.z));

            //creating a small matrix
            Matrix smallMatrix = new Matrix(relRect);

            MatrixOps.Resize(matrixAsset.matrix, smallMatrix);

            //writing small matrix to dst
            Matrix.ReadMatrix(smallMatrix, dst, wrapMode);
        }
Exemple #3
0
        public void ImportWithEnlarge(Matrix src, MatrixWorld dst, Terrains.Area area)
        {
            //finding chunk rect on raw matrix
            Vector3 srcPixelSize = new Vector3(
                scale * dst.worldSize.x / src.rect.size.x,
                0,
                scale * dst.worldSize.z / src.rect.size.z);

            CoordRect relRect = new CoordRect(
                Mathf.FloorToInt((area.full.worldPos.x - offset.x) / srcPixelSize.x),                //taking full rect here
                Mathf.FloorToInt((area.full.worldPos.z - offset.y) / srcPixelSize.z),
                Mathf.CeilToInt(area.full.worldSize.x / srcPixelSize.x),
                Mathf.CeilToInt(area.full.worldSize.z / srcPixelSize.z));

            //creating a small matrix
            Matrix smallMatrix = new Matrix(relRect);

            Matrix.ReadMatrix(src, smallMatrix, wrapMode);

            //upscaling small matrix to dst
            MatrixOps.Resize(smallMatrix, dst);
        }
Exemple #4
0
        public void ImportWithDownscale(MatrixWorld src, MatrixWorld dst, Terrains.Area area, StopToken stop)
        /// Downsizes raw (src) and copies it to tile (dst)
        {
            //src (raw) rect in tile pixels coordsys
            CoordRect dstPartRect = dst.WorldRectToPixels((Vector2D)src.worldPos, (Vector2D)src.worldSize);
            //using matrix size = full area here

            //creating a small matrix
            Matrix smallMatrix = new Matrix(dstPartRect);

            if (stop != null && stop.stop)
            {
                return;
            }
            MatrixOps.Downsize(matrixAsset.matrix, smallMatrix);

            //writing small matrix to dst
            if (stop != null && stop.stop)
            {
                return;
            }
            Matrix.ReadMatrix(smallMatrix, dst, wrapMode);
        }