scale() 공개 정적인 메소드

Scales the texture data of the given texture.
public static scale ( Texture2D tex, int width, int height, FilterMode mode = FilterMode.Trilinear ) : void
tex UnityEngine.Texture2D Texure to scale
width int New width
height int New height
mode FilterMode Filtering mode
리턴 void
예제 #1
0
    public static void AddTexture(string CacheId, Texture2D CacheContents, string WalletAddress = "", string WalletName = "")
    {
        if (!String.IsNullOrEmpty(WalletAddress))
        {
            CacheId = CacheId + "." + WalletAddress;
        }

        string filePath = GetFilePath(CacheId, FileType.PNG);

        var imageSizeLimit = 256;

        if (CacheContents.width > imageSizeLimit)
        {
            TextureScaler.scale(CacheContents, imageSizeLimit, (int)((double)imageSizeLimit / CacheContents.width * CacheContents.height));
        }
        else if (CacheContents.height > imageSizeLimit)
        {
            TextureScaler.scale(CacheContents, (int)((double)imageSizeLimit / CacheContents.height * CacheContents.width), imageSizeLimit);
        }

        byte[] bytes = CacheContents.EncodeToPNG();
        File.WriteAllBytes(filePath, bytes);

        UpdateRegistry(CacheId, DateTime.Now, bytes.Length, WalletName);
    }
예제 #2
0
//    public float highOffset;
//    public float lowOffset;

    public static List <Texture2D> Open()
    {
        //string path = EditorUtility.OpenFilePanel("Open a image", "", "png;*jpg;*jpeg;*");
        List <Texture2D> textures = new List <Texture2D>();

        ExtensionFilter[] extensions = new [] {
            new ExtensionFilter("Image Files", "png", "jpg", "jpeg"),
        };

        string[] paths = StandaloneFileBrowser.OpenFilePanel("Open a image", "", extensions, true);

        foreach (string path in paths)
        {
            Texture2D texture;

            var fileContent = File.ReadAllBytes(path);

            texture = new Texture2D(0, 0);
            texture.LoadImage(fileContent);

            texture = Clean(texture);
            TextureScaler.scale(texture, 100, 100, 0);
            texture.Apply();

            textures.Add(texture);
        }

        return(textures);
    }
 static int QPYX_scale_YXQP(IntPtr L_YXQP)
 {
     try
     {
         int QPYX_count_YXQP = LuaDLL.lua_gettop(L_YXQP);
         if (QPYX_count_YXQP == 3)
         {
             UnityEngine.Texture2D QPYX_arg0_YXQP = (UnityEngine.Texture2D)ToLua.CheckObject(L_YXQP, 1, typeof(UnityEngine.Texture2D));
             int QPYX_arg1_YXQP = (int)LuaDLL.luaL_checknumber(L_YXQP, 2);
             int QPYX_arg2_YXQP = (int)LuaDLL.luaL_checknumber(L_YXQP, 3);
             TextureScaler.scale(QPYX_arg0_YXQP, QPYX_arg1_YXQP, QPYX_arg2_YXQP);
             return(0);
         }
         else if (QPYX_count_YXQP == 4)
         {
             UnityEngine.Texture2D QPYX_arg0_YXQP = (UnityEngine.Texture2D)ToLua.CheckObject(L_YXQP, 1, typeof(UnityEngine.Texture2D));
             int QPYX_arg1_YXQP = (int)LuaDLL.luaL_checknumber(L_YXQP, 2);
             int QPYX_arg2_YXQP = (int)LuaDLL.luaL_checknumber(L_YXQP, 3);
             int QPYX_arg3_YXQP = (int)LuaDLL.luaL_checknumber(L_YXQP, 4);
             TextureScaler.scale(QPYX_arg0_YXQP, QPYX_arg1_YXQP, QPYX_arg2_YXQP, QPYX_arg3_YXQP);
             return(0);
         }
         else
         {
             return(LuaDLL.luaL_throw(L_YXQP, "invalid arguments to method: TextureScaler.scale"));
         }
     }
     catch (Exception e_YXQP)                {
         return(LuaDLL.toluaL_exception(L_YXQP, e_YXQP));
     }
 }
예제 #4
0
    static int scale(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 3)
            {
                UnityEngine.Texture2D arg0 = (UnityEngine.Texture2D)ToLua.CheckObject(L, 1, typeof(UnityEngine.Texture2D));
                int arg1 = (int)LuaDLL.luaL_checknumber(L, 2);
                int arg2 = (int)LuaDLL.luaL_checknumber(L, 3);
                TextureScaler.scale(arg0, arg1, arg2);
                return(0);
            }
            else if (count == 4)
            {
                UnityEngine.Texture2D arg0 = (UnityEngine.Texture2D)ToLua.CheckObject(L, 1, typeof(UnityEngine.Texture2D));
                int arg1 = (int)LuaDLL.luaL_checknumber(L, 2);
                int arg2 = (int)LuaDLL.luaL_checknumber(L, 3);
                int arg3 = (int)LuaDLL.luaL_checknumber(L, 4);
                TextureScaler.scale(arg0, arg1, arg2, arg3);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: TextureScaler.scale"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
예제 #5
0
    //Captures the screen and sends it as a texture through ASL
    private void SendScreenCapture()
    {
        Texture2D texture2D = ScreenCapture.CaptureScreenshotAsTexture();

        TextureScaler.scale(texture2D, ImageWidth, ImageHeight);

        aslObject.SendAndSetTexture2D(texture2D, OnFrameDelivered, false);

        Destroy(texture2D);
    }
예제 #6
0
    void setBrush()
    {
        if (selectBrushIndex >= brushTexture.Length)
        {
            selectBrushIndex = selectBrushIndex % brushTexture.Length;
        }
        if (selectBrushIndex < 0)
        {
            selectBrushIndex = 0;
        }

        selectedBrush.SetPixels(((Texture2D)brushTexture[selectBrushIndex]).GetPixels());
        selectedBrush = new Texture2D(brushTexture[0].width, brushTexture[0].height);
        int w = (int)(brushTexture[selectBrushIndex].width * selectBrushSize);
        int h = (int)(brushTexture[selectBrushIndex].height * selectBrushSize);

        selectedBrush = TextureScaler.scaled((Texture2D)brushTexture[selectBrushIndex], w, h);
        TextureScaler.scale(selectedBrush, w, h);
    }
예제 #7
0
        private static IEnumerator <Texture2D> RenderHighwayShield(DynamicSpriteFont defaultFont, HighwayShieldDescriptor descriptor, AdrHighwayParameters parameters)
        {
            if (defaultFont is null)
            {
                defaultFont = FontServer.instance[WTSEtcData.Instance.FontSettings.GetTargetFont(FontClass.HighwayShields)];
            }

            UITextureAtlas.SpriteInfo spriteInfo = descriptor.BackgroundImageParameter.GetCurrentSpriteInfo(null);
            if (spriteInfo is null)
            {
                LogUtils.DoWarnLog("HW: Background info is invalid for hw shield descriptor " + descriptor.SaveName);
                yield break;
            }
            else
            {
                int shieldHeight  = WTSAtlasLoadingUtils.MAX_SIZE_IMAGE_IMPORT;
                int shieldWidth   = WTSAtlasLoadingUtils.MAX_SIZE_IMAGE_IMPORT;
                var shieldTexture = new Texture2D(spriteInfo.texture.width, spriteInfo.texture.height);
                var targetColor   = descriptor.BackgroundColorIsFromHighway && parameters.hwColor != default ? parameters.hwColor : descriptor.BackgroundColor;
                shieldTexture.SetPixels(spriteInfo.texture.GetPixels().Select(x => x.MultiplyChannelsButAlpha(targetColor)).ToArray());
                TextureScaler.scale(shieldTexture, shieldWidth, shieldHeight);
                Color[] formTexturePixels = shieldTexture.GetPixels();

                foreach (var textDescriptor in descriptor.TextDescriptors)
                {
                    if (!textDescriptor.GetTargetText(parameters, out string text))
                    {
                        continue;
                    }

                    Texture2D overlayTexture;
                    if (text is null && textDescriptor.m_textType == TextType.GameSprite)
                    {
                        var spriteTexture = textDescriptor.m_spriteParam?.GetCurrentSpriteInfo(null)?.texture;
                        if (spriteTexture is null)
                        {
                            continue;
                        }
                        overlayTexture = new Texture2D(spriteTexture.width, spriteTexture.height);
                        overlayTexture.SetPixels(spriteTexture.GetPixels());
                        overlayTexture.Apply();
                    }
예제 #8
0
    IEnumerator loadBySlices()
    {
        bool pngMode = true;

        // First, calculate image size from first texture
        Texture2D texture0   = new Texture2D(4, 4);
        int       ii         = 0;
        string    loadImage0 = pathToImages + imagePrefix + ii.ToString(numberingFormat);

        if (loadImage0.Substring(0, 4) == "http")
        {
            loadImage0 += ".png";
            WWW ww0 = new WWW(loadImage0);
            yield return(ww0);

            if (!string.IsNullOrEmpty(ww0.error))
            {
                pngMode    = false;
                loadImage0 = pathToImages + imagePrefix + ii.ToString(numberingFormat) + ".jpg";
                ww0        = new WWW(loadImage0);
                yield return(ww0);
            }

            ww0.LoadImageIntoTexture(texture0);
        }
        else
        {
            offlineMode = true;
            texture0    = Resources.Load(loadImage0) as Texture2D;
        }

        int texWidth  = texture0.width;
        int texHeight = texture0.height;

        // Make sure we're within size limits
        imageWidth  = texWidth > sizeLimit ? sizeLimit : texWidth;
        imageHeight = texHeight > sizeLimit ? sizeLimit : texHeight;

        // Calcualte atlas size
        float paddedImageWidth  = (float)ceil2((uint)imageWidth);
        float paddedImageHeight = (float)ceil2((uint)imageHeight);
        float slicesPerAtlas    = Mathf.Ceil(imageDepth / numAtlases);

        int atlasWidth  = (int)ceil2((uint)paddedImageWidth);
        int atlasHeight = (int)ceil2((uint)(paddedImageHeight * slicesPerAtlas));

        while ((atlasHeight > 2 * atlasWidth) && (atlasHeight > paddedImageHeight))
        {
            atlasHeight /= 2;
            atlasWidth  *= 2;
        }

        // Create array of atlas textures
        Color32 black = new Color32(0, 0, 0, 255);

        Texture2D[] atlasArray = new Texture2D[(int)numAtlases];
        for (int i = 0; i < (int)numAtlases; i++)
        {
            atlasArray[i] = new Texture2D(atlasWidth, atlasHeight, TextureFormat.ARGB32, false);
        }

        // Set all pixels in the atlases to be clear
        Color32[] bigClearArray = atlasArray[0].GetPixels32();
        for (int i = 0; i < bigClearArray.Length; i++)
        {
            bigClearArray [i] = black;
        }

        for (int i = 0; i < (int)numAtlases; i++)
        {
            atlasArray[i].SetPixels32(bigClearArray);
        }


        // Set up some variables for atlas filling
        int xOffset = Mathf.FloorToInt(((float)paddedImageWidth - (float)texWidth) / 2.0f);
        int yOffset = Mathf.FloorToInt(((float)paddedImageHeight - (float)texHeight) / 2.0f);

        float slicesPerRow = Mathf.Floor((float)atlasWidth / (float)paddedImageWidth);

        // This loop does the actual downloading and filling of the atlases
        for (int i = 0; i < imageDepth; i++)
        {
            int   atlasNumber   = (int)(((float)i) % numAtlases);
            float locationIndex = Mathf.Floor(((float)i) / numAtlases);

            Texture2D downloadedImage = new Texture2D(imageWidth, imageHeight);
            if (vr)
            {
                infoTextObject.GetComponent <TextMesh>().text = "Loading slice " + (i + 1).ToString() + " of " + imageDepth + ".";
            }
            else
            {
                infoTextObject.GetComponent <Text>().text = "Loading slice " + (i + 1).ToString() + " of " + imageDepth + ".";
            }

            string imageToLoad = pathToImages + imagePrefix + i.ToString(numberingFormat);
            if (!offlineMode)
            {
                if (pngMode)
                {
                    imageToLoad += ".png";
                }
                else
                {
                    imageToLoad += ".jpg";
                }
                WWW www = new WWW(imageToLoad);
                yield return(www);

                www.LoadImageIntoTexture(downloadedImage);
                //yield return new WaitForSeconds (0.025f);
            }
            else
            {
                //byte[] fileData = File.ReadAllBytes (imageToLoad);
                //downloadedImage.LoadImage (fileData);
                downloadedImage = Resources.Load(imageToLoad) as Texture2D;
                yield return(null);
            }

            if (texWidth > sizeLimit || texHeight > sizeLimit)
            {
                TextureScaler.scale(downloadedImage, imageWidth, imageHeight);
            }

            float xCoord = (locationIndex % slicesPerRow) * paddedImageWidth;
            xCoord += xOffset;
            float yCoord = Mathf.Floor(locationIndex / slicesPerRow) * paddedImageHeight;
            yCoord += yOffset;

            atlasArray[atlasNumber].SetPixels((int)xCoord, (int)yCoord, texWidth, texHeight, downloadedImage.GetPixels(0, 0, texWidth, texHeight));
        }

        // Apply pixels and send to GPU
        if (vr)
        {
            infoTextObject.GetComponent <TextMesh>().text = "Preparing volumetric renderer...";
        }
        else
        {
            infoTextObject.GetComponent <Text>().text = "Preparing volumetric renderer...";
        }
        for (int i = 0; i < (int)numAtlases; i++)
        {
            atlasArray [i].Apply();
            rayMarchMaterial.SetTexture("_Atlas" + i, atlasArray [i]);
        }

        // Now set the material and rendering properties
        rayMarchMaterial.SetFloat("_atlasWidth", atlasWidth);
        rayMarchMaterial.SetFloat("_atlasHeight", atlasHeight);
        rayMarchMaterial.SetFloat("_imageDepth", imageDepth);
        rayMarchMaterial.SetFloat("_imageWidth", paddedImageWidth);
        rayMarchMaterial.SetFloat("_imageHeight", paddedImageHeight);
        rayMarchMaterial.SetFloat("_slicesPerAtlas", slicesPerAtlas);
        rayMarchMaterial.SetFloat("_slicesPerRow", slicesPerRow);

        Vector3 cubeSize = new Vector3(imageWidth * voxelSize.x, imageHeight * voxelSize.y, imageDepth * voxelSize.z).normalized;

        cubeSize *= 3.5f * Mathf.Min(1.0f / cubeSize.x, Mathf.Min(1.0f / cubeSize.y, 1.0f / cubeSize.z));
        cube.transform.localScale = cubeSize;

        // Load the scene
        if (vr)
        {
            infoTextObject.GetComponent <TextMesh>().text = "Click to start";
        }
        else
        {
            infoTextObject.GetComponent <Text>().text = "Click to start";
        }
        variables.freezeAll = false;
        cube.SetActive(true);
        qualityButton.SetActive(true);
        variables.triggerRender    = true;
        variables.volumeReadyState = 1;
    }
예제 #9
0
        public void Bake()
        {
            var tSize = TextureSize;

            _bakedTexture = new Bitmap(tSize.Width, tSize.Height);

            // Clear baked texture with transparent color.
            for (int y = 0; y < _bakedTexture.Height; y++)
            {
                for (int x = 0; x < _bakedTexture.Width; x++)
                {
                    _bakedTexture.SetPixel(x, y, Color.Transparent);
                }
            }

            int xOffset = 0;

            for (int i = 0; i < Text.Length; i++)
            {
                if (_font.textureList.ContainsKey(Text[i]) == false)
                {
                    continue;
                }
                var textC = _font.textureList[Text[i]];
                if (textC == null)
                {
                    continue;
                }

                float _scale     = _charSettings[i].Scale;
                Color _foreColor = _charSettings[i].ForeColor;

                float cX = xOffset + textC.OffsetX * _scale;
                float cY = GetCursor() - textC.OffsetY * _scale;
                float cW = textC.Texture.Width * _scale;
                float cH = textC.Texture.Height * _scale;
                float cA = textC.Advance * _scale;

                if (cW <= 0 || cH <= 0)
                {
                    // Skip
                }
                else
                {
                    var origPixels = textC.Texture.uTexture.GetPixels32();
                    var newTexture = new UnityEngine.Texture2D(textC.Texture.Width, textC.Texture.Height);
                    newTexture.name = "backedGlyphTexture";
                    newTexture.SetPixels32(origPixels);
                    newTexture.Apply();
                    // Scale texture if needed.
                    if ((int)cW != newTexture.width || (int)cH != newTexture.height)
                    {
                        TextureScaler.scale(newTexture, (int)cW, (int)cH);
                        //TextureScale.Bilinear(newTexture, (int)cW, (int)cH);
                        newTexture.Apply();
                    }

                    var newImagePixels = newTexture.GetPixels32();
                    for (int p = 0; p < newImagePixels.Length; p++)
                    {
                        // BlendMode: Multiply
                        var origColor   = Color.FromUColor(newImagePixels[p]);
                        var blendColorA = (float)(origColor.A * _foreColor.A) / 255;
                        var blendColorR = (float)(origColor.R * _foreColor.R) / 255;
                        var blendColorG = (float)(origColor.G * _foreColor.G) / 255;
                        var blendColorB = (float)(origColor.B * _foreColor.B) / 255;
                        var blendColor  = Color.FromArgb((int)blendColorA, (int)blendColorR, (int)blendColorG, (int)blendColorB);
                        newImagePixels[p] = blendColor.ToUColor();
                    }

                    _bakedTexture.uTexture.SetPixels32((int)cX, (int)cY, newTexture.width, newTexture.height, newImagePixels);
                }

                xOffset += (int)cA;
            }

            _bakedTexture.Apply();

            if (AutoSize)
            {
                Size = tSize;
            }
        }
        public void GenerateLodImages(string filepath)
        {
            Texture2D texture1;

            string[] textureFileExtensions = { "_d.png", "_a.png", "_p.png", "_r.png" };

            try
            {
                DebugOutputPanel.AddMessage(PluginManager.MessageType.Message, "filename: " + filepath);
                if (filepath == "")
                {
                    if (NetDumpPanel.instance.GetCustomFilePrefix() != "")
                    {
                        string importFolder = Path.Combine(DataLocation.addonsPath, "Import");
                        filepath = Path.Combine(importFolder, NetDumpPanel.instance.GetCustomFilePrefix());
                    }
                    else
                    {
                        throw new System.Exception("No File Path Found! \nDump a network first or put a custom filename in the custom file prefix field\n");
                    }
                }
                for (int i = 0; i < textureFileExtensions.Length; i++)
                {
                    if (File.Exists(filepath + textureFileExtensions[i]))
                    {
                        texture1 = new Texture2D(1, 1);
                        texture1.LoadImage(File.ReadAllBytes(filepath + textureFileExtensions[i]));
                        texture1.anisoLevel = 16;
                        texture1.MakeReadable();
                        TextureScaler.scale(texture1, 64, 64);
                        //turn off if elevated?
                        if (NetDumpPanel.instance.GetNetEleIndex == 0)
                        {
                            texture1 = FlipTexture(texture1, false);
                            DebugOutputPanel.AddMessage(PluginManager.MessageType.Message, "flipped texture1!");
                        }
                        string fileExt     = "_lod" + textureFileExtensions[i];
                        string lodFilepath = filepath + fileExt;

                        DumpTexture2D(texture1, lodFilepath);
                        filePathsLog += lodFilepath + "\n";
                        NetDumpPanel.instance.dumpedFiles += lodFilepath + "\n";
                    }
                    else
                    { //make this try/catch?
                        Debug.Log(textureFileExtensions[i] + " failed");
                    }
                }

                if (NetDumpPanel.instance.GetNetEleIndex != 0)
                {
                    //bit of hack since for some reason uv maps are often completely different on lod meshes than main mesh on some vanilla elevations - ok since elevated sections are not used that much on a map anyway for custom roads. - do properly later maybe?
                    File.Copy(filepath + ".obj", filepath + "_lod.obj", true);
                }

                ExceptionPanel panel = UIView.library.ShowModal <ExceptionPanel>("ExceptionPanel");
                panel.SetMessage("LOD File Generation Successful", "Files Exported:\n" + filePathsLog, false);
            }
            catch (Exception e)
            {
                ExceptionPanel panel = UIView.library.ShowModal <ExceptionPanel>("ExceptionPanel");
                panel.SetMessage("LOD File Generation Failed", "" + e, false);
                panel.GetComponentInChildren <UISprite>().spriteName = "IconError";
            }
        }