コード例 #1
0
ファイル: Quadrant.cs プロジェクト: Dyzalonius/MapCommander
    public void BuildColorMaps()
    {
        if (bottomLeft.colorMap == null)
        {
            bottomLeft.BuildColorMaps();
        }
        if (bottomRight.colorMap == null)
        {
            bottomRight.BuildColorMaps();
        }
        if (topLeft.colorMap == null)
        {
            topLeft.BuildColorMaps();
        }
        if (topRight.colorMap == null)
        {
            topRight.BuildColorMaps();
        }

        // Create colorMap of all children
        Color[] combinedColorMap = new Color[textureSize * textureSize * 4];
        for (int i = 0; i < bottomLeft.colorMap.Length; i++)
        {
            combinedColorMap[((Mathf.FloorToInt(i / textureSize)) * textureSize * 2) + (i % textureSize)] = bottomLeft.colorMap[i];
        }
        for (int i = 0; i < bottomRight.colorMap.Length; i++)
        {
            combinedColorMap[((Mathf.FloorToInt(i / textureSize)) * textureSize * 2) + textureSize + (i % textureSize)] = bottomRight.colorMap[i];
        }
        for (int i = 0; i < topLeft.colorMap.Length; i++)
        {
            combinedColorMap[((textureSize + Mathf.FloorToInt(i / textureSize)) * textureSize * 2) + (i % textureSize)] = topLeft.colorMap[i];
        }
        for (int i = 0; i < topRight.colorMap.Length; i++)
        {
            combinedColorMap[((textureSize + Mathf.FloorToInt(i / textureSize)) * textureSize * 2) + textureSize + (i % textureSize)] = topRight.colorMap[i];
        }

        // Shrink colorMap by combining pixels
        colorMap = new Color[textureSize * textureSize];
        for (int i = 0; i < colorMap.Length; i++)
        {
            int   rowIncrement    = (Mathf.FloorToInt(i / textureSize)) * textureSize * 4;
            int   columnIncrement = (i % textureSize) * 2;
            float red             = (combinedColorMap[columnIncrement + rowIncrement].r + combinedColorMap[columnIncrement + 1 + rowIncrement].r + combinedColorMap[columnIncrement + (textureSize * 2) + rowIncrement].r + combinedColorMap[columnIncrement + 1 + (textureSize * 2) + rowIncrement].r) / 4;
            float green           = (combinedColorMap[columnIncrement + rowIncrement].g + combinedColorMap[columnIncrement + 1 + rowIncrement].g + combinedColorMap[columnIncrement + (textureSize * 2) + rowIncrement].g + combinedColorMap[columnIncrement + 1 + (textureSize * 2) + rowIncrement].g) / 4;
            Color color           = new Color(red, green, 0f);
            colorMap[i] = color;
        }
    }
コード例 #2
0
    // This was a one use method for converting to 512x512
    private void ConvertTerrainTo512()
    {
        Debug.Log("convert start");

        // add every color to the color map
        Color[] colorMap = new Color[(int)maxSize * (int)maxSize];
        foreach (Quadrant quadrant in root.GetLeafQuadrants())
        {
            for (int i = 0; i < quadrant.colorMap.Length; i++)
            {
                colorMap[((quadrant.position.y + Mathf.FloorToInt(i / (int)minSize)) * (int)maxSize) + quadrant.position.x + (i % (int)minSize)] = quadrant.colorMap[i];
            }
        }

        Debug.Log("colormap done");

        // create new quadrants with new scale
        minSize = QuadrantSize.p256;
        root    = new Quadrant(maxSize, minSize, position);

        Debug.Log("quadrant creation done");

        // give quadrants appropriate colormaps
        foreach (Quadrant quadrant in root.GetLeafQuadrants())
        {
            quadrant.colorMap = new Color[(int)minSize * (int)minSize];
            for (int i = 0; i < quadrant.colorMap.Length; i++)
            {
                quadrant.colorMap[i] = colorMap[((quadrant.position.y + Mathf.FloorToInt(i / (int)minSize)) * (int)maxSize) + quadrant.position.x + (i % (int)minSize)];
            }
        }

        // give parent quadrants appropriate colormaps
        root.BuildColorMaps();

        Debug.Log("colormap assignment done");

        // generate textures for all quadrants
        DrawTerrain();

        // save all textures
    }