コード例 #1
0
ファイル: TextureGenerator.cs プロジェクト: 3Dmaps/3Dmaps
    public static ColorMap ColorMapForSatelliteImage(MapData mapData)
    {
        SatelliteImage satelliteImage = SatelliteImageService.getSatelliteImage();
        double         scale          = satelliteImage.getScale();

        int textureWidth  = (int)(mapData.GetWidth() * scale);
        int textureHeight = (int)(mapData.GetHeight() * scale);

        Color[] colorArray = new Color[textureWidth * textureHeight];
        if (!satelliteImage.hasSatelliteImage())
        {
            return(new ColorMap(colorArray, textureWidth, textureHeight));
        }

        MapDataSlice slice = mapData.AsSlice();

        for (int y = 0; y < textureHeight; y++)
        {
            int sliceY   = (int)(slice.GetY() * scale);
            int flippedY = satelliteImage.texture.height - (int)(sliceY + y) - 1;
            Array.ConstrainedCopy(satelliteImage.texture.GetPixels((int)(slice.GetX() * scale), flippedY, textureWidth, 1), 0, colorArray, (y * textureWidth), textureWidth);
        }

        return(new ColorMap(colorArray, textureWidth, textureHeight));
    }
コード例 #2
0
ファイル: MeshGeneratorTest.cs プロジェクト: 3Dmaps/3Dmaps
    public void MeshGeneratorTopLeftVerticeAltitudeCorrect()
    {
        float[,] heightMap = new float[3, 3];
        for (int x = 0; x < heightMap.GetLength(0); x++)
        {
            for (int y = 0; y < heightMap.GetLength(1); y++)
            {
                heightMap[x, y] = (x == 0) ? 2 : 5;
            }
        }

        float heightMultiplier = 1F;
        int   levelOfDetail    = 0;

        MapData mapData = MapData.ForTesting(heightMap);

        MeshData meshdata = MeshGenerator.GenerateTerrainMesh(mapData.AsSlice().AsDisplayReadySlice(0), heightMultiplier, levelOfDetail);

        Assert.True(meshdata.vertices[2].y == 1, "Meshdata vertice [2] altitude (y) not correct.");
        Assert.True(meshdata.vertices[0].y == 0, "Meshdata vertice [0] altitude (y) not correct.");
    }
コード例 #3
0
ファイル: TextureGenerator.cs プロジェクト: 3Dmaps/3Dmaps
    public static ColorMap ColorMapForHeightAndAreas(MapData mapData, int lod = 0)
    {
        lod = lod == 0 ? 1 : lod * 2;
        int          width  = mapData.GetWidth();
        int          height = mapData.GetHeight();
        MapDataSlice slice  = mapData.AsSlice();

        Color[] colorArray = new Color[width * height];
        if (areaDisplay == null)
        {
            areaDisplay = GameObject.FindObjectOfType <AreaDisplay>();
        }

        for (int y = 0; y < height; y += lod)
        {
            for (int x = 0; x < width; x += lod)
            {
                float currentHeight = mapData.GetSquished(x, y);
                float scaledPosX    = (slice.GetX() + x);
                float scaledPosY    = (slice.GetY() + y);
                Color areaColor     = areaDisplay.GetPointColor(scaledPosX, scaledPosY);
                Color regionColor   = GetRegionColour(currentHeight);

                if (areaColor != Color.clear)
                {
                    regionColor = Color.Lerp(areaColor, regionColor, colorLerpValue);
                }

                for (int actualY = y; actualY < y + lod && actualY < height; actualY++)
                {
                    for (int actualX = x; actualX < x + lod && actualX < width; actualX++)
                    {
                        colorArray[actualY * width + actualX] = regionColor;
                    }
                }
            }
        }
        return(new ColorMap(colorArray, width, height));
    }