Exemplo n.º 1
0
        public void LoadFromTexture2D(Texture2D texture, GaiaConstants.ImageChannel channel)
        {
            //Check if it is readable - if not then make it readable
            Gaia.GaiaUtils.MakeTextureReadable(texture);

            //Make sure its not compressed
            Gaia.GaiaUtils.MakeTextureUncompressed(texture);

            //And load
            m_widthX     = texture.width;
            m_depthZ     = texture.height;
            m_widthInvX  = 1f / (float)(m_widthX);
            m_depthInvZ  = 1f / (float)(m_depthZ);
            m_heights    = new float[m_widthX, m_depthZ];
            m_isPowerOf2 = Gaia.GaiaUtils.Math_IsPowerOf2(m_widthX) && Gaia.GaiaUtils.Math_IsPowerOf2(m_depthZ);

            if (channel == GaiaConstants.ImageChannel.R)
            {
                for (int x = 0; x < m_widthX; x++)
                {
                    for (int z = 0; z < m_depthZ; z++)
                    {
                        m_heights[x, z] = texture.GetPixel(x, z).r;
                    }
                }
            }
            else if (channel == GaiaConstants.ImageChannel.G)
            {
                for (int x = 0; x < m_widthX; x++)
                {
                    for (int z = 0; z < m_depthZ; z++)
                    {
                        m_heights[x, z] = texture.GetPixel(x, z).g;
                    }
                }
            }
            else if (channel == GaiaConstants.ImageChannel.B)
            {
                for (int x = 0; x < m_widthX; x++)
                {
                    for (int z = 0; z < m_depthZ; z++)
                    {
                        m_heights[x, z] = texture.GetPixel(x, z).b;
                    }
                }
            }
            else
            {
                for (int x = 0; x < m_widthX; x++)
                {
                    for (int z = 0; z < m_depthZ; z++)
                    {
                        m_heights[x, z] = texture.GetPixel(x, z).a;
                    }
                }
            }

            m_isDirty = false;
        }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Gaia.UnityHeightMap"/> class from a texture.
 /// </summary>
 /// <param name="texture">Texture.</param>
 public UnityHeightMap(Texture2D texture, GaiaConstants.ImageChannel channel = GaiaConstants.ImageChannel.R) : base()
 {
     LoadFromTexture2D(texture, channel);
     m_isDirty = false;
 }