Esempio n. 1
0
        public static ImageTexture LoadTexture(string path, bool isPixelTexture)
        {
            _Image.Load(path);

            if (isPixelTexture)
            {
                _ImageTexture.CreateFromImage(_Image, 0);
            }
            else
            {
                _ImageTexture.CreateFromImage(_Image);
            }

            return(_ImageTexture);
        }
        public void ParseData(MemoryStream stream)
        {
            var img = new Image();

            if (System.IO.Path.GetExtension(uri.AbsolutePath).Equals(".png", StringComparison.OrdinalIgnoreCase))
            {
                img.LoadPngFromBuffer(stream.ToArray());
            }
            else if (System.IO.Path.GetExtension(uri.AbsolutePath).Equals(".jpg", StringComparison.OrdinalIgnoreCase))
            {
                img.LoadJpgFromBuffer(stream.ToArray());
            }
            else if (System.IO.Path.GetExtension(uri.AbsolutePath).Equals(".bmp", StringComparison.OrdinalIgnoreCase))
            {
                img.LoadBmpFromBuffer(stream.ToArray());
            }
            else if (System.IO.Path.GetExtension(uri.AbsolutePath).Equals(".tga", StringComparison.OrdinalIgnoreCase))
            {
                img.LoadTgaFromBuffer(stream.ToArray());
            }
            else if (System.IO.Path.GetExtension(uri.AbsolutePath).Equals(".webp", StringComparison.OrdinalIgnoreCase))
            {
                img.LoadWebpFromBuffer(stream.ToArray());
            }
            img.FlipY();

            var imageTexture = new ImageTexture();

            imageTexture.CreateFromImage(img);
            Texture = imageTexture;
        }
Esempio n. 3
0
    public void SetImageOnSprite(Image image)
    {
        ImageTexture texture = new ImageTexture();

        texture.CreateFromImage(image, 0);
        TokenSprite.Texture = texture;
    }
Esempio n. 4
0
    public static unsafe void RebuildFontAtlas()
    {
        var io = ImGui.GetIO();

        io.Fonts.GetTexDataAsRGBA32(out byte *pixelData, out int width, out int height, out int bytesPerPixel);

        byte[] pixels = new byte[width * height * bytesPerPixel];
        Marshal.Copy(new IntPtr(pixelData), pixels, 0, pixels.Length);

        Image img = new Image();

        img.CreateFromData(width, height, false, Image.Format.Rgba8, pixels);

        var imgtex = new ImageTexture();

        imgtex.CreateFromImage(img, 0);

        if (_fontTextureId.HasValue)
        {
            UnbindTexture(_fontTextureId.Value);
        }
        _fontTextureId = BindTexture(imgtex);

        io.Fonts.SetTexID(_fontTextureId.Value);
        io.Fonts.ClearTexData();
    }
Esempio n. 5
0
    private void SetShaderTiles()
    {
        int startX = (int)Position.x / 16;
        int startY = (int)Position.y / 16;

        float[] regionTileInfo = new float[(int)(sizeInTiles.y - startY) + (int)(sizeInTiles.x - startX)];

        for (int y = startY; y < startY + sizeInTiles.y; y++)
        {
            for (int x = startX; x < startX + sizeInTiles.x; x++)
            {
                if (WithinBounds(x, y))
                {
                    regionTileInfo[y + x] = lightValues[x, y] * 255;
                }
                else
                {
                    regionTileInfo[y + x] = 255;
                }
            }
        }

        Image img = new Image();

        byte[] byteRegionTileInfo = new byte[regionTileInfo.Length * 4];
        Buffer.BlockCopy(regionTileInfo, 0, byteRegionTileInfo, 0, byteRegionTileInfo.Length);
        img.CreateFromData((int)sizeInTiles.x, (int)sizeInTiles.y, false, Image.Format.L8, byteRegionTileInfo);

        ImageTexture tex = new ImageTexture();

        tex.CreateFromImage(img);
        (this.Material as ShaderMaterial).SetShaderParam("lightValues", tex);
    }
Esempio n. 6
0
    public static Texture GenerateNoiseTexture(float[,] noiseMap)
    {
        int width  = noiseMap.GetLength(0);
        int height = noiseMap.GetLength(1);

        Image mapImage = new Image();

        mapImage.Create(width, height, true, Image.Format.Rgb8);
        mapImage.Lock();
        for (int y = 0; y < height; ++y)
        {
            for (int x = 0; x < width; ++x)
            {
                mapImage.SetPixel(x, y, Colors.Black.LinearInterpolate(Colors.White, noiseMap[x, y]));
            }
        }
        mapImage.Unlock();

        ImageTexture mapTexture = new ImageTexture();

        mapTexture.CreateFromImage(mapImage);
        mapTexture.Flags = (uint)ImageTexture.FlagsEnum.Mipmaps;

        return(mapTexture);
    }
Esempio n. 7
0
    /// <summary>
    /// Stack the sprites, but with a custom spacing between each layer.
    /// </summary>
    public void MakeStackFromPath(string path, int offsetSize)
    {
        int offset = 0;

        foreach (var image in GetSpritesFromPath(path))
        {
            // Loading Image
            var image_ = new Image();
            image_.Load(image);

            // Making ImageTexture from image.
            var texture = new ImageTexture();
            texture.CreateFromImage(image_);
            texture.SetData(image_);

            // Adding the layer
            var sprite = new Sprite();
            sprite.SetTexture(texture);
            sprite.Position -= new Vector2(0, offset * offsetSize);
            sprite.Name      = offset.ToString();

            Layers[Layers.Length] = sprite;
            AddChild(sprite);

            // Increasing the offset for next layer.
            offset += 1;
        }
    }
Esempio n. 8
0
    public void GenerateFromPerlinNoise(float period, int octaves, float lacunarity, float persistence)
    {
        terrainImg = new Image();
        terrainImg.Create(TileSize, TileSize, false, Image.Format.Rgbaf);
        var noise = new OpenSimplexNoise();

        noise.Seed        = rng.Next();
        noise.Octaves     = octaves;
        noise.Period      = period;
        noise.Lacunarity  = lacunarity;
        noise.Persistence = persistence;
        var   center    = new Vector2(TileSize / 2f, TileSize / 2f);
        float maxDist   = 0.75f * (TileSize / 2f);
        float maxHeight = 40f;

        terrainImg.Lock();
        for (int x = 0; x < TileSize; x++)
        {
            for (int y = 0; y < TileSize; y++)
            {
                float distance             = new Vector2(x, y).DistanceTo(center);
                float inverseDistanceRatio = 1 - (distance / maxDist);
                float noiseHeight          = noise.GetNoise2d(x, y) + 0.5f;
                float height = 0f;
                if (distance <= maxDist)
                {
                    height = Mathf.Max(0, maxHeight * inverseDistanceRatio * noiseHeight);
                }
                terrainImg.SetPixel(x, y, new Color(height, 0, 0, 0));
            }
        }
        terrainImg.Unlock();
        Terrain = new ImageTexture();
        Terrain.CreateFromImage(terrainImg);
    }
Esempio n. 9
0
    public void finalToConvertSprite()
    {
        GD.Print("final the convertion");
        GD.Print("first draw");
        var img = captureViewport.GetTexture().GetData();

        img.FlipY();
        var imgTex = new ImageTexture();

        imgTex.CreateFromImage(img);
        var convertedSprite = new Sprite();

        convertedSprite.Texture  = imgTex;
        convertedSprite.Centered = false;
        convertedSprite.Position = new Vector2(xMin, yMin);
        if (drawMode == drawObjectMode.brush)
        {
            var material = new ShaderMaterial();
            material.Shader          = (Shader)ResourceLoader.Load("res://shaders/blackFix.shader");
            convertedSprite.Material = material;
        }
        else if (drawMode == drawObjectMode.erase)
        {
            convertedSprite.Material = Material;
        }
        GetParent().AddChild(convertedSprite);
        this.Visible = false;
        EmitSignal("converted_sprite", this, convertedSprite);
        captureViewport.QueueFree();
        cloneDrawObject.QueueFree();

        expectedSpriteConvertion = false;
        this.QueueFree();
    }
Esempio n. 10
0
    public override void _Process(float delta)
    {
        if (!loadingData)
        {
            return;
        }

        if (!saveInfoLoadTask.IsCompleted)
        {
            return;
        }

        var save = saveInfoLoadTask.Result;

        saveInfoLoadTask.Dispose();
        saveInfoLoadTask = null;

        // Screenshot
        var texture = new ImageTexture();

        texture.CreateFromImage(save.Screenshot);

        screenshot.Texture = texture;

        // General info
        version.Text           = save.Info.ThriveVersion;
        type.Text              = save.Info.Type.ToString();
        createdAt.Text         = save.Info.CreatedAt.ToString("G", CultureInfo.CurrentCulture);
        createdBy.Text         = save.Info.Creator;
        createdOnPlatform.Text = save.Info.Platform.ToString();
        description.Text       = save.Info.Description;

        loadingData = false;
    }
Esempio n. 11
0
    public void loadLastDrawings()
    {
        var img = new Image();
        var err = img.Load("user://lastDraw.png");

        if (err == Error.Ok)
        {
            var imgTex = new ImageTexture();
            imgTex.CreateFromImage(img);
            var spr = new Sprite();
            spr.Centered = false;
            var shader   = (Shader)ResourceLoader.Load("res://shaders/blackFix.shader");
            var material = new ShaderMaterial();
            material.Shader = shader;
            spr.Material    = material;

            spr.Material = material;
            spr.Texture  = imgTex;
            drawContainerNode.AddChild(spr);
        }
        else
        {
            GD.PrintErr(err);
        }
    }
Esempio n. 12
0
    private static Texture image2Texture(Image image)
    {
        var texture = new ImageTexture();

        texture.CreateFromImage(image, (int)Texture.FlagsEnum.Repeat);
        return(texture);
    }
Esempio n. 13
0
        public static ImageTexture RadialGradient(int width, int height, Gradient gradient)
        {
            Image image = new Image();

            image.Create(width, height, true, Image.Format.Rgb8);
            image.Lock();

            Color[,] colors = Gradients.RadialGradient(width, height, gradient);

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    image.SetPixel(x, y, colors[x, y]);
                }
            }

            image.Unlock();

            ImageTexture tex = new ImageTexture();

            tex.CreateFromImage(image);

            return(tex);
        }
    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        ImageTexture imageTexture = new ImageTexture();

        imageTexture.CreateFromImage(GD.Load <Texture>("res://background-border.png").GetData());
        NinePatchRect patchRect = new NinePatchRect
        {
            AnchorBottom          = 1,
            AnchorLeft            = 0,
            AnchorTop             = 0,
            AnchorRight           = 1,
            PatchMarginBottom     = 9,
            PatchMarginTop        = 9,
            PatchMarginLeft       = 9,
            PatchMarginRight      = 9,
            MarginBottom          = -20,
            MarginTop             = 20,
            MarginLeft            = 20,
            MarginRight           = -20,
            AxisStretchHorizontal = NinePatchRect.AxisStretchMode.TileFit,
            AxisStretchVertical   = NinePatchRect.AxisStretchMode.TileFit,
            Texture      = imageTexture,
            SelfModulate = Colors.Red
        };

        this.AddChild(patchRect);
    }
Esempio n. 15
0
    /// <summary>
    /// Stack the sprites
    /// </summary>
    public void MakeStackFromPath(string path)
    {
        // Set the name of the stack to the name of the loaded folder.
        string[] path_ = path.Split("\\");
        this.Name = path_[path_.Length - 1];

        int offset = 0;

        foreach (var image in GetSpritesFromPath(path))
        {
            // Loading Image
            var image_ = new Image();
            GD.Print(image);
            image_.Load(image);

            // Making ImageTexture from image.
            var texture = new ImageTexture();
            texture.CreateFromImage(image_);
            texture.SetData(image_);

            // Adding the layer
            var sprite = new Sprite();
            sprite.SetTexture(texture);
            sprite.Position -= new Vector2(0, offset);
            sprite.Name      = offset.ToString();

            Layers[Layers.Length - 1] = sprite;
            this.AddChild(sprite);

            // Increasing the offset for next layer.
            offset += 1;
        }
    }
Esempio n. 16
0
    public static Texture GenerateColorTexture(float[,] noiseMap, float[] regionThresholds, Color[] regionColors)
    {
        int width  = noiseMap.GetLength(0);
        int height = noiseMap.GetLength(1);

        Image mapImage = new Image();

        mapImage.Create(width, height, true, Image.Format.Rgb8);
        mapImage.Lock();
        for (int y = 0; y < height; ++y)
        {
            for (int x = 0; x < width; ++x)
            {
                for (int i = 0; i < regionThresholds.Length; ++i)
                {
                    if (noiseMap[x, y] <= regionThresholds[i])
                    {
                        mapImage.SetPixel(x, y, regionColors[i]);
                        break;
                    }
                }
            }
        }
        mapImage.Unlock();

        ImageTexture mapTexture = new ImageTexture();

        mapTexture.CreateFromImage(mapImage);
        mapTexture.Flags = (uint)ImageTexture.FlagsEnum.Mipmaps;

        return(mapTexture);
    }
Esempio n. 17
0
        private void update_waves()
        {
            generator.Seed = seed_value;
            waves_in_tex   = new ImageTexture();

            var img = new Image();


            img.Create(5, NUMBER_OF_WAVES, false, Image.Format.Rf);
            img.Lock();


            for (int i = 0; i < NUMBER_OF_WAVES; i++)
            {
                var w = waves[i];

                var _wind_direction = (new Vector2(1.0f, 1.0f)).Rotated(Mathf.Deg2Rad(wave_directions[i]));

                img.SetPixel(0, i, new Color(w[0] / 100.0f, 0, 0, 0));
                img.SetPixel(1, i, new Color(w[1] / 100.0f, 0, 0, 0));
                img.SetPixel(2, i, new Color(_wind_direction.x, 0, 0, 0));
                img.SetPixel(3, i, new Color(_wind_direction.y, 0, 0, 0));
                img.SetPixel(4, i, new Color((Mathf.Tau) / w[2], 0, 0, 0));
            }

            img.Unlock();

            waves_in_tex.CreateFromImage(img, 0);
            (MaterialOverride as ShaderMaterial).SetShaderParam("waves", waves_in_tex);
        }
Esempio n. 18
0
        public static Material GetSprite(int idx)
        {
            Material ret = _vswapSprite.ContainsKey(idx) ?
                           _vswapSprite[idx] : null;

            if (ret == null)
            {
                byte[] data = new byte[VSWAP.SpriteSize.Width * VSWAP.SpriteSize.Height * 4];

                SpatialMaterial mat = new SpatialMaterial();

                ImageTexture tex = new ImageTexture();
                Image        img = new Image();

                System.Drawing.Bitmap bmp = VSWAP.GetSpriteBitmap(Palette, (uint)idx);

                int stride = VSWAP.SpriteSize.Width * 4;

                for (int y = 0; y < VSWAP.SpriteSize.Height; y++)
                {
                    for (int x = 0; x < VSWAP.SpriteSize.Width; x++)
                    {
                        System.Drawing.Color pixel = bmp.GetPixel(x, y);

                        data[(stride * y) + (x * 4) + 0] = pixel.R;
                        data[(stride * y) + (x * 4) + 1] = pixel.G;
                        data[(stride * y) + (x * 4) + 2] = pixel.B;

                        if (pixel.R == Transparent.r8 &&
                            pixel.G == Transparent.g8 &&
                            pixel.B == Transparent.b8)
                        {
                            data[(stride * y) + (x * 4) + 3] = 0;
                        }
                        else
                        {
                            data[(stride * y) + (x * 4) + 3] = 255;
                        }
                    }
                }

                img.CreateFromData(
                    VSWAP.SpriteSize.Width,
                    VSWAP.SpriteSize.Height,
                    false, Image.Format.Rgba8, data);

                tex.CreateFromImage(img, (uint)0);

                mat.AlbedoTexture       = tex;
                mat.ParamsCullMode      = SpatialMaterial.CullMode.Disabled;
                mat.ParamsBillboardMode = SpatialMaterial.BillboardMode.FixedY;

                ret = mat;

                _vswapSprite.Add(idx, ret);
            }

            return(ret);
        }
        public void ExportTo(ImageTexture texture)
        {
            var image = texture.GetData() ?? new Image();

            ExportTo(image);

            texture.CreateFromImage(image, 0);
        }
Esempio n. 20
0
        public override void _Process(float delta)
        {
            if (!isshow)
            {
                return;
            }
            animeTime += delta;
            // next frame
            if (animeTime >= Data.Frames[animeIndex].Delay / 1000.0)
            {
                animeTime = 0;
                animeIndex++;
                newFrame = true;
            }
            // reach end
            if (animeIndex >= Data.Frames.Length)
            {
                if (Data.Loop)
                {
                    animeTime  = 0;
                    animeIndex = 0;
                    newFrame   = true;
                }
                else
                {
                    isshow   = false;
                    newFrame = false;
                }
            }

            if (newFrame)
            {
                newFrame = false;
                if (!ResourceManager.Instance.allNpkData.ContainsKey(Data.Frames[animeIndex].Image))
                {
                    Debug.LogError($"npk file now found : {Data.Frames[animeIndex].Image}");
                    return;
                }
                var npk = ResourceManager.Instance.allNpkData[Data.Frames[animeIndex].Image];
                var idx = Data.Frames[animeIndex].ImageIdx;
                if (idx >= npk.album.List.Count)
                {
                    Debug.Log($"npk image now found : {npk.album.Path} {idx} {npk.filePath}");
                    return;
                }

                Debug.Log($"select : {npk.album.Path} {idx} {npk.filePath}");
                if (npk.album.List[idx].Picture is GodotTexture godotText)
                {
                    tex.CreateFromImage(godotText.Image);
                }

                Debug.Log($"GraphicEffect : {Data.Frames[animeIndex].GraphicEffect}");
                ((ShaderMaterial)Material).SetShaderParam("graphicEffect", Data.Frames[animeIndex].GraphicEffect);

                Texture = tex;
            }
        }
Esempio n. 21
0
        public static ImageTexture ImageTexture(string Path)
        {
            ImageTexture Result      = new ImageTexture();
            Image        ResultImage = new Image();

            ResultImage.Load(Path);
            Result.CreateFromImage(ResultImage);
            return(Result);
        }
Esempio n. 22
0
    void Compute()
    {
        Vector2 pos  = Pos;
        Vector2 size = Size;

        if (size == Vector2.Zero)
        {
            return;
        }

        int posx = (int)render_rect.Position.x;
        int posy = (int)render_rect.Position.y;
        int endx = (int)render_rect.End.x;
        int endy = (int)render_rect.End.y;

        int sizex = (int)render_rect.Size.x;
        int sizey = (int)render_rect.Size.y;

        light_values = new Vector3[sizex, sizey];
        light_absorb = new Vector3[sizex, sizey];

        PopulateArrays(posx, posy, endx, endy, new Vector3(ambient.r, ambient.g, ambient.b) * ambient_strength);

        // for (int x = 0; x < sizex; x++)
        Parallel.For(0, sizex, (x, state) =>
        {
            for (int y = 0; y < sizey; y++)
            {
                if (light_values[x, y] > Vector3.Zero)
                {
                    ComputeLighting(x, y, sizex, sizey);
                }
            }
        });

        img = new Image();
        img.Create(sizex, sizey, false, Colored? Image.Format.Rgb8 : Image.Format.L8);

        img.Lock();

        for (int x = 0; x < sizex; x++)
        {
            for (int y = 0; y < sizey; y++)
            {
                Vector3 val = light_values[x, y];
                img.SetPixel(x, y, new Color(val.x, val.y, val.z, 1));
            }
        }

        img.Unlock();
        tex = new ImageTexture();
        tex.CreateFromImage(img, (uint)((int)(Smooth ? 4 : 8)));
        (Material as ShaderMaterial).SetShaderParam("light_values", tex);

        Position = pos;
        Scale    = size;
    }
Esempio n. 23
0
    private void OnFileSelected(String path)
    {
        RemoveChild(imageSprite);
        imageSprite = new Sprite();
        AddChild(imageSprite);

        string imgType = null;

        switch (System.IO.Path.GetExtension(path).ToLower())
        {
        case (".png"): imgType = ".png"; break;

        case (".jpeg"):
        case (".jpg"): imgType = ".jpg"; break;

        case (".webp"): imgType = ".webp"; break;
        }

        if (imgType == null)
        {
            errorDiag.PopupCenteredRatio();
            errorDiag.RectSize     = new Vector2(errorDiag.RectSize.x, errorLabel.RectSize.y);
            errorDiag.RectPosition = new Vector2(errorDiag.RectPosition.x, GetViewportRect().Size.y / 2f);
            return;
        }

        Task.Run(() => {
            try {
                var imageFile = new File();
                imageFile.Open(path, File.ModeFlags.Read);
                var buffer = imageFile.GetBuffer((int)imageFile.GetLen());
                var image  = new Image();
                if (imgType.Equals(".png"))
                {
                    image.LoadPngFromBuffer(buffer);
                }
                else if (imgType.Equals(".jpeg") || imgType.Equals(".jpg"))
                {
                    image.LoadJpgFromBuffer(buffer);
                }
                else if (imgType.Equals(".webp"))
                {
                    image.LoadWebpFromBuffer(buffer);
                }
                var im = new ImageTexture();
                im.CreateFromImage(image);
                imageSprite.Texture = im;
                var xScale          = GetViewportRect().Size.x / im.GetSize().x;
                imageSprite.Scale   = new Vector2(xScale * 0.95f, xScale * 0.95f);
                imageSprite.Translate(new Vector2(GetViewportRect().Size.x / 2f, GetViewportRect().Size.y / 2f));
            } catch {
                errorDiag.PopupCenteredRatio();
                errorDiag.RectSize     = new Vector2(errorDiag.RectSize.x, errorLabel.RectSize.y);
                errorDiag.RectPosition = new Vector2(errorDiag.RectPosition.x, GetViewportRect().Size.y / 2f);
            }
        });
    }
Esempio n. 24
0
        /**
         * load image files without properly importing them
         *
         * properly imported textures should be loaded with:
         * (Texture)GD.Load("res://static/foo.png")
         */
        public static Texture imageToTexture(string path)
        {
            var img = new Image();
            var ret = new ImageTexture();

            img.Load(path);
            ret.CreateFromImage(img);
            return(ret);
        }
Esempio n. 25
0
    public void RecieveMapImageData(int height, int width, Image.Format format, byte[] imageData)
    {
        Image image = new Image();

        image.CreateFromData(width, height, false, format, Decompress(imageData));
        ImageTexture imageTexture = new ImageTexture();

        imageTexture.CreateFromImage(image, 0);
        Texture = imageTexture;
    }
Esempio n. 26
0
            public static Texture LoadTexture(string path)
            {
                var image = new Image();

                image.Load(path);
                var imageTexture = new ImageTexture();

                imageTexture.CreateFromImage(image);
                return(imageTexture);
            }
Esempio n. 27
0
    private void CreateDensityTexture()
    {
        image = new Image();
        image.Create(Size, Size, false, Image.Format.Rgba8);
        texture = new ImageTexture();
        texture.CreateFromImage(image, (uint)Texture.FlagsEnum.Filter | (uint)Texture.FlagsEnum.Repeat);

        var material = (ShaderMaterial)Material;

        material.SetShaderParam("densities", texture);
    }
Esempio n. 28
0
 public void initBrushTextures()
 {
     for (int i = 0; i < brushTextureResources.Count; i++)
     {
         var img = brushTextureResources[i].GetData();
         img.Resize((int)(brushSize * img.GetSize().x), (int)(brushSize * img.GetSize().y));
         var nTex = new ImageTexture();
         nTex.CreateFromImage(img);
         brushTextures.Add(nTex);
     }
 }
Esempio n. 29
0
    private void _ImportSeed(String seedPath)
    {
        ImageTexture imageTexture = new ImageTexture();
        Image        img          = new Image();

        img.Load(seedPath);
        imageTexture.CreateFromImage(img);
        textRect.Texture   = imageTexture;
        imageTexture.Flags = 0;

        GD.Print(seedGen.GetSeedFromImage(img));
    }
Esempio n. 30
0
    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        Size       = Settings.Instance.CloudSimulationWidth;
        Resolution = Settings.Instance.CloudResolution;
        image      = new Image();
        image.Create(Size, Size, false, Image.Format.Rgba8);
        texture = new ImageTexture();
        texture.CreateFromImage(image, (uint)Texture.FlagsEnum.Filter);

        var material = (ShaderMaterial)this.Material;

        material.SetShaderParam("densities", texture);
    }