83 lines
3.3 KiB
C#
83 lines
3.3 KiB
C#
![]() |
using Godot;
|
||
|
using System;
|
||
|
using System.Diagnostics;
|
||
|
|
||
|
public class HexTile3DMaterialAssign : Spatial
|
||
|
{
|
||
|
// Declare member variables here. Examples:
|
||
|
// private int a = 2;
|
||
|
// private string b = "text";
|
||
|
|
||
|
private Button _blackWhitePatternButton;
|
||
|
private Button _colorPatternButton;
|
||
|
private Button _changeMaterialButton;
|
||
|
private SpinBox _textureSizeSpinBox;
|
||
|
private HexTile3D _hexTile;
|
||
|
private ShaderMaterial _customTileMaterial;
|
||
|
private ImageTexture _blackWhitePatternTexture;
|
||
|
private ImageTexture _colorPatternTexture;
|
||
|
|
||
|
// Called when the node enters the scene tree for the first time.
|
||
|
public override void _Ready()
|
||
|
{
|
||
|
_blackWhitePatternButton = (Button)FindNode("BlackWhitePatternButton");
|
||
|
Debug.Assert(_blackWhitePatternButton != null);
|
||
|
_blackWhitePatternButton.Connect("pressed", this, nameof(OnBlackWhitePatternButton));
|
||
|
|
||
|
_colorPatternButton = (Button)FindNode("ColorPatternButton");
|
||
|
Debug.Assert(_colorPatternButton != null);
|
||
|
_colorPatternButton.Connect("pressed", this, nameof(OnColorPatternButton));
|
||
|
|
||
|
_textureSizeSpinBox = (SpinBox)FindNode("TextureSizeSpinBox");
|
||
|
Debug.Assert(_textureSizeSpinBox != null);
|
||
|
_textureSizeSpinBox.Connect("value_changed", this, nameof(OnTextureSizeChanged));
|
||
|
|
||
|
_hexTile = (HexTile3D)FindNode("HexTile3D");
|
||
|
Debug.Assert(_hexTile != null);
|
||
|
|
||
|
_customTileMaterial = GD.Load<ShaderMaterial>("materials/HexTileTextureLookup.tres");
|
||
|
|
||
|
_blackWhitePatternTexture = new ImageTexture();
|
||
|
Image image = new Image();
|
||
|
image.Load("assets/4x4checker.png");
|
||
|
_blackWhitePatternTexture.CreateFromImage(image, (uint) (Texture.FlagsEnum.Mipmaps | Texture.FlagsEnum.Repeat));
|
||
|
|
||
|
_colorPatternTexture = new ImageTexture();
|
||
|
image.Load("assets/4x4checkerColor.png");
|
||
|
_colorPatternTexture.CreateFromImage(image, (uint) (Texture.FlagsEnum.Mipmaps | Texture.FlagsEnum.Repeat));
|
||
|
}
|
||
|
|
||
|
public void OnBlackWhitePatternButton()
|
||
|
{
|
||
|
GD.Print("Apply Black White Pattern!");
|
||
|
ShaderMaterial currentMaterial = (ShaderMaterial) _hexTile.Mesh.GetSurfaceMaterial(0);
|
||
|
Debug.Assert(currentMaterial != null);
|
||
|
currentMaterial.SetShaderParam("MapAlbedoTexture", _blackWhitePatternTexture);
|
||
|
|
||
|
// _customTileMaterial.SetShaderParam("MapAlbedoTexture", _imageTexture);
|
||
|
|
||
|
// _hexTile.Mesh.SetSurfaceMaterial(0, _customTileMaterial);
|
||
|
}
|
||
|
|
||
|
public void OnColorPatternButton()
|
||
|
{
|
||
|
GD.Print("Apply Collor Pattern!");
|
||
|
ShaderMaterial currentMaterial = (ShaderMaterial) _hexTile.Mesh.GetSurfaceMaterial(0);
|
||
|
Debug.Assert(currentMaterial != null);
|
||
|
currentMaterial.SetShaderParam("MapAlbedoTexture", _colorPatternTexture);
|
||
|
|
||
|
// _customTileMaterial.SetShaderParam("MapAlbedoTexture", _imageTexture);
|
||
|
|
||
|
// _hexTile.Mesh.SetSurfaceMaterial(0, _customTileMaterial);
|
||
|
}
|
||
|
|
||
|
public void OnTextureSizeChanged(float value)
|
||
|
{
|
||
|
GD.Print("Texture size: " + value);
|
||
|
ShaderMaterial currentMaterial = (ShaderMaterial) _hexTile.Mesh.GetSurfaceMaterial(0);
|
||
|
Debug.Assert(currentMaterial != null);
|
||
|
currentMaterial.SetShaderParam("TextureSize", (int) value);
|
||
|
GD.Print("Texture size: " + currentMaterial.GetShaderParam("TextureSize"));
|
||
|
}
|
||
|
}
|