Created a new tile generator addon. Also experiments with the textures from the 3d project.

This commit is contained in:
Relintai 2021-12-13 23:25:39 +01:00
parent 8211849b72
commit c22deed1e3
18 changed files with 334 additions and 44 deletions

View File

@ -4,4 +4,7 @@
!Godoxel !Godoxel
!Godoxel/** !Godoxel/**
!mat_maker_gd !mat_maker_gd
!mat_maker_gd/** !mat_maker_gd/**
!tile_generator
!tile_generator/**

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/dirt.png-4619a7b524d3617207cc200232d61a8d.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://addons/tile_generator/dirt.png"
dest_files=[ "res://.import/dirt.png-4619a7b524d3617207cc200232d61a8d.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=1
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=false
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

View File

@ -0,0 +1,14 @@
[gd_resource type="Resource" load_steps=3 format=2]
[ext_resource path="res://modules/planets/textures/dirt_albedo.png" type="Texture" id=1]
[ext_resource path="res://addons/tile_generator/smple_tile.gd" type="Script" id=2]
[resource]
script = ExtResource( 2 )
input = ExtResource( 1 )
output_image_name = "dirt"
image_count = 1
image_size_x = 64
image_size_y = 32
alpha_crop = true
generate = false

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/grass.png-403246ac380304d7e211486fe1219a6a.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://addons/tile_generator/grass.png"
dest_files=[ "res://.import/grass.png-403246ac380304d7e211486fe1219a6a.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=1
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=false
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

View File

@ -0,0 +1,14 @@
[gd_resource type="Resource" load_steps=3 format=2]
[ext_resource path="res://modules/planets/textures/grass_albedo.png" type="Texture" id=1]
[ext_resource path="res://addons/tile_generator/smple_tile.gd" type="Script" id=2]
[resource]
script = ExtResource( 2 )
input = ExtResource( 1 )
output_image_name = "grass"
image_count = 1
image_size_x = 64
image_size_y = 32
alpha_crop = true
generate = false

View File

@ -0,0 +1,39 @@
[gd_resource type="RTileSet" load_steps=4 format=2]
[ext_resource path="res://addons/tile_generator/dirt.png" type="Texture" id=1]
[ext_resource path="res://addons/tile_generator/grass.png" type="Texture" id=2]
[sub_resource type="FastnoiseNoiseParams" id=1]
frequency = 0.02
cellular_jitter = 0.6
[resource]
noise = SubResource( 1 )
0/name = "dirt.png 0"
0/texture = ExtResource( 1 )
0/tex_offset = Vector2( 0, 0 )
0/modulate = Color( 1, 1, 1, 1 )
0/region = Rect2( 0, 0, 64, 32 )
0/tile_mode = 0
0/occluder_offset = Vector2( 0, 0 )
0/navigation_offset = Vector2( 0, 0 )
0/shape_offset = Vector2( 0, 0 )
0/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
0/shape_one_way = false
0/shape_one_way_margin = 0.0
0/shapes = [ ]
0/z_index = 0
1/name = "grass.png 1"
1/texture = ExtResource( 2 )
1/tex_offset = Vector2( 0, 0 )
1/modulate = Color( 1, 1, 1, 1 )
1/region = Rect2( 0, 0, 64, 32 )
1/tile_mode = 0
1/occluder_offset = Vector2( 0, 0 )
1/navigation_offset = Vector2( 0, 0 )
1/shape_offset = Vector2( 0, 0 )
1/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
1/shape_one_way = false
1/shape_one_way_margin = 0.0
1/shapes = [ ]
1/z_index = 0

View File

@ -0,0 +1,7 @@
[plugin]
name="tile_generator"
description=""
author="Relintai"
version=""
script="plugin.gd"

View File

@ -0,0 +1,10 @@
tool
extends EditorPlugin
var SimpleTile = preload("res://addons/tile_generator/smple_tile.gd")
func _enter_tree():
add_custom_type("SimpleTile", "Resource", SimpleTile, null)
func _exit_tree():
remove_custom_type("SimpleTile")

View File

@ -0,0 +1,128 @@
tool
extends Resource
export(Texture) var input : Texture
export(String) var output_image_name : String = "output"
export(int) var image_count : int = 1
export(int) var image_size_x : int = 64
export(int) var image_size_y : int = 32
export(bool) var alpha_crop : bool = true
export(bool) var generate : bool = false setget set_generate, get_generate
#from mat_maker_gd
static func rotate(uv : Vector2, center : Vector2, rotate : float) -> Vector2:
var rv : Vector2 = Vector2()
uv -= center
rv.x = cos(rotate)*uv.x + sin(rotate)*uv.y
rv.y = -sin(rotate)*uv.x + cos(rotate)*uv.y
rv += center
return rv
#from mat_maker_gd
static func scale(uv : Vector2, center : Vector2, scale : Vector2) -> Vector2:
uv -= center
uv /= scale
uv += center
return uv
func generate():
if !input:
return
var inimg : Image = input.get_data()
var img : Image = null
if image_count > 1:
pass
else:
img = Image.new()
img.create(inimg.get_width() * 3, inimg.get_height() * 3, false, Image.FORMAT_RGBA8)
var ofsx : int = inimg.get_width()
var ofsy : int = inimg.get_height()
img.lock()
inimg.lock()
for x in range(inimg.get_width()):
for y in range(inimg.get_height()):
var np : Vector2 = rotate(Vector2(x, y), Vector2(x / 2, y / 2), deg2rad(90))
np += Vector2(ofsx, ofsy)
var c : Color = inimg.get_pixel(x, y)
img.set_pixel(np.x, np.y, c)
img.unlock()
inimg.unlock()
img = crop_image(img)
img.resize(image_size_x, image_size_y, Image.INTERPOLATE_CUBIC)
if alpha_crop:
alpha_crop(img)
img.save_png(resource_path.get_base_dir() + "/" + output_image_name + ".png")
func alpha_crop(img : Image) -> void:
img.lock()
for x in range(img.get_width()):
for y in range(img.get_height()):
var c : Color = img.get_pixel(x, y)
if c.a < 0.5:
img.set_pixel(x, y, Color(0, 0, 0, 0))
elif c.a < 1:
c.a = 1
img.set_pixel(x, y, c)
img.unlock()
func crop_image(img : Image) -> Image:
img.lock()
var xmin : int = img.get_width() + 1
var xmax : int = 0
var ymin : int = img.get_height() + 1
var ymax : int = 0
for x in range(img.get_width()):
for y in range(img.get_height()):
var c : Color = img.get_pixel(x, y)
if c.a < 0.02:
continue
if xmin > x:
xmin = x
if xmax < x:
xmax = x
if ymin > y:
ymin = y
if ymax < y:
ymax = y
img.unlock()
var w : int = xmax - xmin
var h : int = ymax - ymin
var rimg : Image = Image.new()
rimg.create(w, h, false, Image.FORMAT_RGBA8)
rimg.blit_rect(img, Rect2(xmin, ymin, w, h), Vector2())
return rimg
func set_generate(val):
if val:
generate()
func get_generate():
return false

View File

@ -387,21 +387,6 @@ points = PoolRealArray( 0, 0, 0, 0, 0, 0.59322, 0, 0, 0, 0, 0.635593, 0.0823529,
image = SubResource( 23 ) image = SubResource( 23 )
input = SubResource( 43 ) input = SubResource( 43 )
[sub_resource type="Resource" id=53]
script = ExtResource( 2 )
default_type = 5
default_int = 0
default_float = 0.0
default_vector2 = Vector2( 0, 0 )
default_vector3 = Vector3( 0, 0, 0 )
default_color = Color( 0, 0, 0, 1 )
[sub_resource type="Resource" id=38]
script = ExtResource( 7 )
graph_position = Vector2( 980, 540 )
image = SubResource( 53 )
postfix = "_albedo"
[sub_resource type="Resource" id=45] [sub_resource type="Resource" id=45]
script = ExtResource( 2 ) script = ExtResource( 2 )
default_type = 5 default_type = 5
@ -411,6 +396,22 @@ default_vector2 = Vector2( 0, 0 )
default_vector3 = Vector3( 0, 0, 0 ) default_vector3 = Vector3( 0, 0, 0 )
default_color = Color( 0, 0, 0, 1 ) default_color = Color( 0, 0, 0, 1 )
[sub_resource type="Resource" id=53]
script = ExtResource( 2 )
default_type = 5
default_int = 0
default_float = 0.0
default_vector2 = Vector2( 0, 0 )
default_vector3 = Vector3( 0, 0, 0 )
default_color = Color( 0, 0, 0, 1 )
input_property = SubResource( 45 )
[sub_resource type="Resource" id=38]
script = ExtResource( 7 )
graph_position = Vector2( 980, 540 )
image = SubResource( 53 )
postfix = "_albedo"
[sub_resource type="Resource" id=49] [sub_resource type="Resource" id=49]
script = ExtResource( 2 ) script = ExtResource( 2 )
default_type = 5 default_type = 5
@ -466,5 +467,5 @@ channel = 3
[resource] [resource]
script = ExtResource( 1 ) script = ExtResource( 1 )
image_size = Vector2( 256, 256 ) image_size = Vector2( 64, 64 )
nodes = [ SubResource( 2 ), SubResource( 4 ), SubResource( 7 ), SubResource( 9 ), SubResource( 11 ), SubResource( 13 ), SubResource( 18 ), SubResource( 26 ), SubResource( 28 ), SubResource( 33 ), SubResource( 34 ), SubResource( 35 ), SubResource( 36 ), SubResource( 38 ), SubResource( 47 ), SubResource( 52 ) ] nodes = [ SubResource( 2 ), SubResource( 4 ), SubResource( 7 ), SubResource( 9 ), SubResource( 11 ), SubResource( 13 ), SubResource( 18 ), SubResource( 26 ), SubResource( 28 ), SubResource( 33 ), SubResource( 34 ), SubResource( 35 ), SubResource( 36 ), SubResource( 38 ), SubResource( 47 ), SubResource( 52 ) ]

Binary file not shown.

Before

Width:  |  Height:  |  Size: 112 KiB

After

Width:  |  Height:  |  Size: 6.1 KiB

View File

@ -241,6 +241,21 @@ input2 = SubResource( 23 )
blend_type = 4 blend_type = 4
opacity = SubResource( 24 ) opacity = SubResource( 24 )
[sub_resource type="Resource" id=31]
script = ExtResource( 3 )
default_type = 5
default_int = 0
default_float = 0.0
default_vector2 = Vector2( 0, 0 )
default_vector3 = Vector3( 0, 0, 0 )
default_color = Color( 0, 0, 0, 1 )
[sub_resource type="Resource" id=27]
script = ExtResource( 8 )
graph_position = Vector2( 900, 340 )
image = SubResource( 31 )
postfix = "_albedo"
[sub_resource type="Resource" id=28] [sub_resource type="Resource" id=28]
script = ExtResource( 3 ) script = ExtResource( 3 )
default_type = 5 default_type = 5
@ -250,22 +265,6 @@ default_vector2 = Vector2( 0, 0 )
default_vector3 = Vector3( 0, 0, 0 ) default_vector3 = Vector3( 0, 0, 0 )
default_color = Color( 0, 0, 0, 1 ) default_color = Color( 0, 0, 0, 1 )
[sub_resource type="Resource" id=26]
script = ExtResource( 3 )
default_type = 5
default_int = 0
default_float = 0.0
default_vector2 = Vector2( 0, 0 )
default_vector3 = Vector3( 0, 0, 0 )
default_color = Color( 0, 0, 0, 1 )
input_property = SubResource( 28 )
[sub_resource type="Resource" id=27]
script = ExtResource( 8 )
graph_position = Vector2( 900, 340 )
image = SubResource( 26 )
postfix = "_albedo"
[sub_resource type="Resource" id=29] [sub_resource type="Resource" id=29]
script = ExtResource( 3 ) script = ExtResource( 3 )
default_type = 4 default_type = 4
@ -285,5 +284,5 @@ width = 0.1
[resource] [resource]
script = ExtResource( 1 ) script = ExtResource( 1 )
image_size = Vector2( 256, 256 ) image_size = Vector2( 64, 64 )
nodes = [ SubResource( 5 ), SubResource( 7 ), SubResource( 10 ), SubResource( 13 ), SubResource( 18 ), SubResource( 20 ), SubResource( 25 ), SubResource( 27 ), SubResource( 30 ) ] nodes = [ SubResource( 5 ), SubResource( 7 ), SubResource( 10 ), SubResource( 13 ), SubResource( 18 ), SubResource( 20 ), SubResource( 25 ), SubResource( 27 ), SubResource( 30 ) ]

Binary file not shown.

Before

Width:  |  Height:  |  Size: 84 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

View File

@ -503,7 +503,7 @@ window/size/ui_scale_touch=1.0
[editor_plugins] [editor_plugins]
enabled=PoolStringArray( "res://addons/Godoxel/plugin.cfg", "res://addons/mat_maker_gd/plugin.cfg" ) enabled=PoolStringArray( "res://addons/Godoxel/plugin.cfg", "res://addons/mat_maker_gd/plugin.cfg", "res://addons/tile_generator/plugin.cfg" )
[ess] [ess]

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long