public override void _Ready() { if (Terrain == null || Terrain.GetWidth() != TileSize || Terrain.GetHeight() != TileSize) { Terrain = new ImageTexture(); Terrain.Create(TileSize, TileSize, Image.Format.Rgbaf); terrainImg = new Image(); terrainImg.Create(TileSize, TileSize, false, Image.Format.Rgbaf); } if (Mesh == null) { var mesh = new PlaneMesh(); mesh.Size = new Vector2(TileSize, TileSize); mesh.SubdivideWidth = TileSize; mesh.SubdivideDepth = TileSize; Mesh = mesh; var mat = new ShaderMaterial(); mat.SetShader(TerrainShader); SetSurfaceMaterial(0, mat); } if (WorldPos != Vector3.Zero) { _LoadTerrainData(); } hydraulics = new HydraulicSimulation(Terrain); terrainImg = Terrain.GetData(); }
public ImageTexture CreateTexture(string resourcePath, bool fill, Color fillColor, Vector2 imgSize) { ImageTexture res = new ImageTexture(); if ((imgSize != null) && (imgSize.x >= 16) && (imgSize.y >= 16)) { res.Create((int)imgSize.x, (int)imgSize.y, Image.Format.Rgba8); } Image myImage = new Image(); if (fill) { myImage.Create((int)imgSize.x, (int)imgSize.y, false, Image.Format.Rgba8); myImage.Fill(fillColor); } myImage.Load(resourcePath); GD.Print($"CreateTexture resourcePath={resourcePath}, width={myImage.GetWidth()}"); //FillSolidRectangle(myImage, new Vector2(120, 100), new Vector2(250, 240), selectedFill); res.CreateFromImage(myImage); return(res); }
public HydraulicSimulation(ImageTexture terrain) { this.Terrain = terrain; Flow = new ImageTexture(); Flow.Create(Terrain.GetWidth(), Terrain.GetHeight(), Image.Format.Rgbaf); }