public static PaintContext BeginPaintTexture(Terrain terrain, Rect boundsInTerrainSpace, TerrainLayer inputLayer, int extraBorderPixels = 0)
        {
            if (inputLayer == null)
            {
                return(null);
            }

            int          resolution = terrain.terrainData.alphamapResolution;
            PaintContext ctx        = InitializePaintContext(terrain, resolution, resolution, RenderTextureFormat.R8, boundsInTerrainSpace, extraBorderPixels);

            ctx.GatherAlphamap(inputLayer, true);
            return(ctx);
        }
        public static PaintContext BeginPaintTexture(Terrain terrain, Rect boundsInTerrainSpace, TerrainLayer inputLayer, int extraBorderPixels = 0)
        {
            bool         flag = inputLayer == null;
            PaintContext result;

            if (flag)
            {
                result = null;
            }
            else
            {
                int          alphamapResolution = terrain.terrainData.alphamapResolution;
                PaintContext paintContext       = TerrainPaintUtility.InitializePaintContext(terrain, alphamapResolution, alphamapResolution, RenderTextureFormat.R8, boundsInTerrainSpace, extraBorderPixels, true);
                paintContext.GatherAlphamap(inputLayer, true);
                result = paintContext;
            }
            return(result);
        }
        public static PaintContext BeginPaintTexture(Terrain terrain, Rect boundsInTerrainSpace, TerrainLayer inputLayer, int extraBorderPixels = 0)
        {
            if (inputLayer == null)
            {
                return(null);
            }

            int terrainLayerIndex = FindTerrainLayerIndex(terrain, inputLayer);

            if (terrainLayerIndex == -1)
            {
                terrainLayerIndex = AddTerrainLayer(terrain, inputLayer);
            }

            Texture2D inputTexture = GetTerrainAlphaMapChecked(terrain, terrainLayerIndex >> 2);

            PaintContext ctx = InitializePaintContext(terrain, inputTexture, RenderTextureFormat.R8, boundsInTerrainSpace, extraBorderPixels);

            ctx.GatherAlphamap(inputLayer);
            return(ctx);
        }
        public static PaintContext BeginPaintTexture(Terrain terrain, Rect bounds, TerrainLayer inputLayer)
        {
            if (inputLayer == null)
            {
                return(null);
            }

            int terrainLayerIndex = FindTerrainLayerIndex(terrain, inputLayer);

            if (terrainLayerIndex == -1)
            {
                terrainLayerIndex = AddTerrainLayer(terrain, inputLayer);
            }

            Texture2D inputTexture = GetTerrainAlphaMapChecked(terrain, terrainLayerIndex >> 2);

            PaintContext ctx = InitializePaintContext(terrain, bounds, inputTexture.width, inputTexture.height, RenderTextureFormat.R8);

            ctx.GatherAlphamap(terrain, inputLayer);
            return(ctx);
        }
        public static void BuildTransformPaintContextUVToPaintContextUV(PaintContext src, PaintContext dst, out Vector4 scaleOffset)
        {
            // for example:
            //   src = alphaUV
            //   dst = normalUV
            // dst.uv = src.u * scales.xy + src.v * scales.zw + offset
            // terrainspace.xz = srcOrigin + src.uv * srcSize
            // terrainspace.xz = dstOrigin + dst.uv * dstSize
            // dstOrigin + dst.uv * dstSize = srcOrigin + src.uv * srcSize
            // dst.uv * dstSize = src.uv * srcSize + srcOrigin - dstOrigin
            // dst.uv = (src.uv * srcSize + srcOrigin - dstOrigin) / dstSize
            // dst.uv = (src.uv * srcSize) / dstSize + (srcOrigin - dstOrigin) / dstSize
            // scales.x = srcSize.x / dstSize.x
            // scales.yz = 0.0f;
            // scales.w = srcSize.y / dstSize.y
            // offset.xy = (srcOrigin.xy - dstOrigin.xy) / dstSize.xy

            // paint context origin in terrain space
            // (note this is the UV space origin and size, not the mesh origin & size)
            float srcOriginX = (src.pixelRect.xMin - 0.5f) * src.pixelSize.x;
            float srcOriginZ = (src.pixelRect.yMin - 0.5f) * src.pixelSize.y;
            float srcSizeX   = (src.pixelRect.width) * src.pixelSize.x;
            float srcSizeZ   = (src.pixelRect.height) * src.pixelSize.y;

            // paint context origin in terrain space
            // (note this is the UV space origin and size, not the mesh origin & size)
            float dstOriginX = (dst.pixelRect.xMin - 0.5f) * dst.pixelSize.x;
            float dstOriginZ = (dst.pixelRect.yMin - 0.5f) * dst.pixelSize.y;
            float dstSizeX   = (dst.pixelRect.width) * dst.pixelSize.x;
            float dstSizeZ   = (dst.pixelRect.height) * dst.pixelSize.y;

            scaleOffset = new Vector4(
                srcSizeX / dstSizeX,
                srcSizeZ / dstSizeZ,
                (srcOriginX - dstOriginX) / dstSizeX,
                (srcOriginZ - dstOriginZ) / dstSizeZ
                );
        }
 public static void EndPaintTexture(PaintContext ctx, string editorUndoName)
 {
     ctx.ScatterAlphamap(editorUndoName);
     ctx.Cleanup();
 }
 public static void EndPaintHeightmap(PaintContext ctx, string editorUndoName)
 {
     ctx.ScatterHeightmap(editorUndoName);
     ctx.Cleanup();
 }
 public static void ReleaseContextResources(PaintContext ctx)
 {
     ctx.Cleanup();
 }
Exemplo n.º 9
0
 public static void EndPaintSurfaceMask(PaintContext ctx, string editorUndoName)
 {
     ctx.ScatterSurfaceMask(editorUndoName);
     ctx.Cleanup();
 }
        public static void BuildTransformPaintContextUVToPaintContextUV(PaintContext src, PaintContext dst, out Vector4 scaleOffset)
        {
            float num  = ((float)src.pixelRect.xMin - 0.5f) * src.pixelSize.x;
            float num2 = ((float)src.pixelRect.yMin - 0.5f) * src.pixelSize.y;
            float num3 = (float)src.pixelRect.width * src.pixelSize.x;
            float num4 = (float)src.pixelRect.height * src.pixelSize.y;
            float num5 = ((float)dst.pixelRect.xMin - 0.5f) * dst.pixelSize.x;
            float num6 = ((float)dst.pixelRect.yMin - 0.5f) * dst.pixelSize.y;
            float num7 = (float)dst.pixelRect.width * dst.pixelSize.x;
            float num8 = (float)dst.pixelRect.height * dst.pixelSize.y;

            scaleOffset = new Vector4(num3 / num7, num4 / num8, (num - num5) / num7, (num2 - num6) / num8);
        }
 public static void EndPaintHoles(PaintContext ctx, string editorUndoName)
 {
     ctx.ScatterHoles(editorUndoName);
     ctx.Cleanup(true);
 }