Ejemplo n.º 1
0
        private List <Vector2> GetUVMapping(List <Vector3> planeVerticies)
        {
            TransformHelpers th = new TransformHelpers();

            float textureHeight = 1;
            float textureWidth  = 1;


            float xTiling = 1f;
            float yTiling = 1f;

            //The uv tiling also has to factor in the height and width of the textures we are using
            if (settings.MainMaterial != null && settings.MainMaterial.mainTexture != null)
            {
                textureHeight = settings.MainMaterial.mainTexture.height;
                textureWidth  = settings.MainMaterial.mainTexture.width;
            }

            if (settings.TopMaterial != null && settings.TopMaterial.mainTexture != null)
            {
                textureHeight = settings.TopMaterial.mainTexture.height;
                textureWidth  = settings.TopMaterial.mainTexture.width;
            }

            if (settings.DetailMaterial != null && settings.DetailMaterial.mainTexture != null)
            {
                textureHeight = settings.DetailMaterial.mainTexture.height;
                textureWidth  = settings.DetailMaterial.mainTexture.width;
            }

            //Set our tiling depending on the plane
            if (PlaneType == Plane.Front)
            {
                xTiling = settings.MainMaterialXTiling;
                yTiling = settings.MainMaterialYTiling;
            }

            if (PlaneType == Plane.Top)
            {
                xTiling = settings.TopMaterialXTiling;
                yTiling = settings.TopMaterialYTiling;
            }

            if (PlaneType == Plane.Detail)
            {
                xTiling = settings.DetailMaterialXTiling;
                yTiling = settings.DetailMaterialYTiling;
            }


            //Tile the texture as needed
            textureWidth  = textureWidth / xTiling;
            textureHeight = textureHeight / yTiling;

            //Track how far along we are on the top texture mapping
            float currentTopTextureX = 0;


            List <Vector2> uvs = new List <Vector2>();

            for (int i = 0; i < planeVerticies.Count; i++)
            {
                Vector3 vertex         = planeVerticies[i];
                Vector3 previousVertex = Vector3.zero;
                if (i > 0)
                {
                    previousVertex = planeVerticies[i - 1];
                }


                //Our standard uv mapping is just our point in space divided by the width and the height of our texture (assuming an x/y plane)
                float xMapping = vertex.x / textureWidth;
                float yMapping = vertex.y / textureHeight;


                if (PlaneType == Plane.Top)
                {
                    //We have to factor in the rise in y (from the lowest point in the list to our current point), as well as the x movement across
                    //in our uv mapping.  This is because this is not a flat plane

                    //The first time through, set our current x position based off the vertex
                    if (currentTopTextureX == 0)
                    {
                        currentTopTextureX = vertex.x;
                    }
                    xMapping = (currentTopTextureX) / textureWidth;

                    //After that, increment it by the length of the line between the two points (which includes the movement in the x and y plane) in the uv mapping
                    if (previousVertex != Vector3.zero)
                    {
                        float length = GetLengthOfLine(vertex, previousVertex);
                        currentTopTextureX += length;
                        xMapping            = (currentTopTextureX) / textureWidth;
                    }

                    //For the y mapping, since we are in the z plane divide the texture height by z instead of y.
                    yMapping = vertex.z / textureHeight;
                }


                //If we want the uv mapping to follow the curve of the plane instead, set it here
                if (PlaneType == Plane.Front && settings.MainPlaneFollowTerrainCurve)
                {
                    if (i % 2 == 0)
                    {
                        yMapping = -settings.MainPlaneHeight / textureHeight;
                    }
                    else
                    {
                        yMapping = 1;
                    }
                }

                if (PlaneType == Plane.Detail && settings.DetailPlaneFollowTerrainCurve)
                {
                    if (i % 2 == 0)
                    {
                        yMapping = -settings.DetailPlaneHeight / textureHeight;
                    }
                    else
                    {
                        yMapping = 1;
                    }
                }

                //Finally set the actual uv mapping
                Vector2 uv = new Vector2(xMapping, yMapping);


                //Now set the rotation of the uv mapping
                if (settings.MainMaterialRotation != 0 && PlaneType == Plane.Front)
                {
                    uv = th.RotateVertex(uv, settings.MainMaterialRotation);
                }

                if (settings.DetailMaterialRotation != 0 && PlaneType == Plane.Detail)
                {
                    uv = th.RotateVertex(uv, settings.DetailMaterialRotation);
                }


                if (settings.TopMaterialRotation != 0 && PlaneType == Plane.Top)
                {
                    uv = th.RotateVertex(uv, settings.TopMaterialRotation);
                }

                uvs.Add(uv);
            }

            return(uvs);
        }
Ejemplo n.º 2
0
        private List<Vector2> GetUVMapping(List<Vector3> planeVerticies)
        {

            TransformHelpers th = new TransformHelpers();
			
			float textureHeight = 1;
			float textureWidth = 1;


            float xTiling = 1f;
            float yTiling = 1f;

            //The uv tiling also has to factor in the height and width of the textures we are using
			if (settings.MainMaterial!= null && settings.MainMaterial.mainTexture != null){	        
	             textureHeight = settings.MainMaterial.mainTexture.height;
	             textureWidth = settings.MainMaterial.mainTexture.width;
			}
    
            if (settings.TopMaterial !=null && settings.TopMaterial.mainTexture != null)
            {
                textureHeight = settings.TopMaterial.mainTexture.height;
                textureWidth = settings.TopMaterial.mainTexture.width;
            }

            if (settings.DetailMaterial != null && settings.DetailMaterial.mainTexture != null)
            {
                textureHeight = settings.DetailMaterial.mainTexture.height;
                textureWidth = settings.DetailMaterial.mainTexture.width;
            }

            //Set our tiling depending on the plane
            if (PlaneType == Plane.Front)
            {
                xTiling = settings.MainMaterialXTiling;
                yTiling = settings.MainMaterialYTiling;
            }

            if (PlaneType == Plane.Top)
            {         
                xTiling = settings.TopMaterialXTiling;
                yTiling = settings.TopMaterialYTiling;
            }

            if (PlaneType == Plane.Detail)
            {
                xTiling = settings.DetailMaterialXTiling;
                yTiling = settings.DetailMaterialYTiling;
            }


            //Tile the texture as needed
            textureWidth = textureWidth / xTiling;
            textureHeight = textureHeight / yTiling;

            //Track how far along we are on the top texture mapping
            float currentTopTextureX = 0;


            List<Vector2> uvs = new List<Vector2>();
            for (int i = 0; i < planeVerticies.Count; i++)
            {
                Vector3 vertex = planeVerticies[i];
                Vector3 previousVertex = Vector3.zero;
                if (i > 0)
                {
                    previousVertex = planeVerticies[i - 1];
                }
               

                //Our standard uv mapping is just our point in space divided by the width and the height of our texture (assuming an x/y plane)
                float xMapping = vertex.x / textureWidth;
                float yMapping = vertex.y / textureHeight;

             
                if (PlaneType == Plane.Top)
                {
                    //We have to factor in the rise in y (from the lowest point in the list to our current point), as well as the x movement across
                    //in our uv mapping.  This is because this is not a flat plane

                    //The first time through, set our current x position based off the vertex
                    if (currentTopTextureX == 0) { currentTopTextureX = vertex.x; }              
                    xMapping = (currentTopTextureX) / textureWidth;

                    //After that, increment it by the length of the line between the two points (which includes the movement in the x and y plane) in the uv mapping
                    if (previousVertex != Vector3.zero)
                    {
                        float length = GetLengthOfLine(vertex, previousVertex);
                        currentTopTextureX += length;
                        xMapping = (currentTopTextureX) / textureWidth;
                    }

                    //For the y mapping, since we are in the z plane divide the texture height by z instead of y.
                    yMapping = vertex.z / textureHeight;
                }


                //If we want the uv mapping to follow the curve of the plane instead, set it here
                if (PlaneType == Plane.Front && settings.MainPlaneFollowTerrainCurve)
                {
                    if (i % 2 == 0)
                    {
                        yMapping = -settings.MainPlaneHeight / textureHeight;
                    }
                    else
                    {
                        yMapping = 1;
                    }
                }

                if (PlaneType == Plane.Detail && settings.DetailPlaneFollowTerrainCurve)
                {
                    if (i % 2 == 0)
                    {
                        yMapping = -settings.DetailPlaneHeight / textureHeight;
                    }
                    else
                    {
                        yMapping = 1;
                    }
                }

                //Finally set the actual uv mapping
                Vector2 uv = new Vector2(xMapping, yMapping);


                //Now set the rotation of the uv mapping
                if (settings.MainMaterialRotation != 0 && PlaneType == Plane.Front)
                {
                    uv = th.RotateVertex(uv, settings.MainMaterialRotation);
                }

                if (settings.DetailMaterialRotation != 0 && PlaneType == Plane.Detail)
                {
                    uv = th.RotateVertex(uv, settings.DetailMaterialRotation);
                }


                if (settings.TopMaterialRotation != 0 && PlaneType == Plane.Top)
                {
                    uv = th.RotateVertex(uv, settings.TopMaterialRotation);
                }

                uvs.Add(uv);
            }

            return uvs;

        }