Last active
March 6, 2020 13:23
-
-
Save bitsydoge/bbd6eae40583f8491ccdb1eec3f1a866 to your computer and use it in GitHub Desktop.
A custom node to draw Rhombus/Diamond with color or texture/normalmap and project it or not. Tested on Godot 3.2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tool | |
extends Control | |
class_name RhombusControl | |
export (Color) var color = Color(1,1,1) setget set_color | |
export (Texture) var texture = null setget set_texture | |
export (Texture) var normal_texture = null setget set_normal_texture | |
export (bool) var antialiasing = true setget set_antialiasing | |
export (bool) var projection = true setget set_projection | |
var ___cached_pool_point : PoolVector2Array | |
var ___cached_pool_color : PoolColorArray | |
var ___cached_pool_uv : PoolVector2Array | |
const ___uv_projected := [Vector2(0,0), Vector2(1,0), Vector2(1,1), Vector2(0,1)] | |
const ___uv_not_projected := [Vector2(0.5,0.0), Vector2(1,0.5), Vector2(0.5,1), Vector2(0,0.5)] | |
func set_projection(new_value : bool): | |
if projection != new_value: | |
projection = new_value | |
___cached_pool_uv = ___uv_projected if projection else ___uv_not_projected | |
update() | |
func set_antialiasing(new_value : bool): | |
if antialiasing != new_value: | |
antialiasing = new_value | |
update() | |
func set_texture(new_texture : Texture): | |
if texture != new_texture: | |
texture = new_texture | |
update() | |
func set_normal_texture(new_texture : Texture): | |
if normal_texture != new_texture: | |
normal_texture = new_texture | |
update() | |
func set_color(new_color : Color): | |
if new_color != color: | |
color = new_color | |
___cached_pool_color = [new_color,new_color,new_color,new_color] | |
update() | |
func ___resized(): | |
___cached_pool_point = [Vector2(rect_size.x/2, 0), Vector2(rect_size.x,rect_size.y/2), Vector2(rect_size.x/2,rect_size.y), Vector2(0,rect_size.y/2)] | |
update() | |
func _ready(): | |
connect("resized", self, "___resized") | |
___resized() | |
___cached_pool_color = [color,color,color,color] | |
___cached_pool_uv = ___uv_projected if projection else ___uv_not_projected | |
func _draw(): | |
draw_polygon\ | |
( | |
___cached_pool_point, | |
___cached_pool_color, | |
___cached_pool_uv, | |
texture, normal_texture, antialiasing | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment