mirror of
https://github.com/Relintai/broken_seals_2d.git
synced 2025-02-18 02:54:20 +01:00
Added a new shear tile resource.
This commit is contained in:
parent
1df673dc8d
commit
d24add3723
@ -2,9 +2,12 @@ tool
|
||||
extends EditorPlugin
|
||||
|
||||
var SimpleTile = preload("res://addons/tile_generator/smple_tile.gd")
|
||||
var ShearTile = preload("res://addons/tile_generator/shear_tile.gd")
|
||||
|
||||
func _enter_tree():
|
||||
add_custom_type("SimpleTile", "Resource", SimpleTile, null)
|
||||
add_custom_type("ShearTile", "Resource", ShearTile, null)
|
||||
|
||||
func _exit_tree():
|
||||
remove_custom_type("SimpleTile")
|
||||
remove_custom_type("ShearTile")
|
||||
|
138
game/addons/tile_generator/shear_tile.gd
Normal file
138
game/addons/tile_generator/shear_tile.gd
Normal file
@ -0,0 +1,138 @@
|
||||
tool
|
||||
extends Resource
|
||||
|
||||
export(Texture) var input : Texture
|
||||
export(String) var output_image_name : String = "output"
|
||||
export(float) var shear_amount : float = 0.3
|
||||
export(int) var image_count : int = 1
|
||||
export(int) var image_size_x : int = 32
|
||||
export(int) var image_size_y : int = 64
|
||||
export(bool) var alpha_crop : bool = true
|
||||
|
||||
export(bool) var generate : bool = false setget set_generate, get_generate
|
||||
|
||||
static func shear(uv : Vector2, center : Vector2, amount : float, direction : Vector2) -> Vector2:
|
||||
return uv + Vector2(amount, amount) * (Vector2(uv.y, uv.x) - center) * direction
|
||||
|
||||
static func shear_vertical(uv : Vector2, center : Vector2, amount : float) -> Vector2:
|
||||
return uv + Vector2(amount, amount) * (Vector2(uv.y, uv.x) - center) * Vector2(0, 1)
|
||||
|
||||
static func shear_horizontal(uv : Vector2, center : Vector2, amount : float) -> Vector2:
|
||||
return uv + Vector2(amount, amount) * (Vector2(uv.y, uv.x) - center) * Vector2(1, 0)
|
||||
|
||||
#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 = shear_vertical(Vector2(x, y), Vector2(x / 2, y / 2), shear_amount)
|
||||
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
|
@ -25,6 +25,7 @@ sprite_path = NodePath("CharacterSprite")
|
||||
[node name="CharacterSprite" type="Sprite" parent="."]
|
||||
modulate = Color( 0.737255, 0.737255, 0.784314, 1 )
|
||||
position = Vector2( 0, -11.906 )
|
||||
z_index = 1
|
||||
texture = ExtResource( 1 )
|
||||
hframes = 16
|
||||
vframes = 16
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,7 +1,22 @@
|
||||
[gd_resource type="RTileSet" load_steps=4 format=2]
|
||||
[gd_resource type="RTileSet" load_steps=9 format=2]
|
||||
|
||||
[ext_resource path="res://modules/planets/tiles/dirt.png" type="Texture" id=1]
|
||||
[ext_resource path="res://modules/planets/tiles/grass.png" type="Texture" id=2]
|
||||
[ext_resource path="res://modules/planets/sheared/dirt_shear.png" type="Texture" id=3]
|
||||
|
||||
[sub_resource type="NavigationPolygon" id=5]
|
||||
vertices = PoolVector2Array( 32.9336, 0, 64, 16.783, 33.4719, 32, 0, 16.6484 )
|
||||
polygons = [ PoolIntArray( 0, 1, 2, 3 ) ]
|
||||
|
||||
[sub_resource type="NavigationPolygon" id=4]
|
||||
vertices = PoolVector2Array( 33.0681, 0, 64, 16.783, 33.3373, 32, 0, 16.9176 )
|
||||
polygons = [ PoolIntArray( 0, 1, 2, 3 ) ]
|
||||
|
||||
[sub_resource type="OccluderPolygon2D" id=3]
|
||||
polygon = PoolVector2Array( 0, 0, 32, 16.2446, 32, 64, 0, 48.4112 )
|
||||
|
||||
[sub_resource type="ConvexPolygonShape2D" id=2]
|
||||
points = PoolVector2Array( 0, 0, 32, 16.1101, 32, 64, 0, 48.4112 )
|
||||
|
||||
[sub_resource type="FastnoiseNoiseParams" id=1]
|
||||
frequency = 0.02
|
||||
@ -17,6 +32,7 @@ noise = SubResource( 1 )
|
||||
0/tile_mode = 0
|
||||
0/occluder_offset = Vector2( 0, 0 )
|
||||
0/navigation_offset = Vector2( 0, 0 )
|
||||
0/navigation = SubResource( 5 )
|
||||
0/shape_offset = Vector2( 0, 0 )
|
||||
0/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
|
||||
0/shape_one_way = false
|
||||
@ -31,9 +47,32 @@ noise = SubResource( 1 )
|
||||
1/tile_mode = 0
|
||||
1/occluder_offset = Vector2( 0, 0 )
|
||||
1/navigation_offset = Vector2( 0, 0 )
|
||||
1/navigation = SubResource( 4 )
|
||||
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
|
||||
2/name = "dirt_shear.png 2"
|
||||
2/texture = ExtResource( 3 )
|
||||
2/tex_offset = Vector2( 0, 31 )
|
||||
2/modulate = Color( 1, 1, 1, 1 )
|
||||
2/region = Rect2( 0, 0, 32, 64 )
|
||||
2/tile_mode = 0
|
||||
2/occluder_offset = Vector2( 0, 31 )
|
||||
2/occluder = SubResource( 3 )
|
||||
2/navigation_offset = Vector2( 0, 31 )
|
||||
2/shape_offset = Vector2( 0, 31 )
|
||||
2/shape_transform = Transform2D( 1, 0, 0, 1, 0, 31 )
|
||||
2/shape = SubResource( 2 )
|
||||
2/shape_one_way = false
|
||||
2/shape_one_way_margin = 1.0
|
||||
2/shapes = [ {
|
||||
"autotile_coord": Vector2( 0, 0 ),
|
||||
"one_way": false,
|
||||
"one_way_margin": 1.0,
|
||||
"shape": SubResource( 2 ),
|
||||
"shape_transform": Transform2D( 1, 0, 0, 1, 0, 31 )
|
||||
} ]
|
||||
2/z_index = 1
|
||||
|
BIN
game/modules/planets/sheared/dirt_shear.png
Normal file
BIN
game/modules/planets/sheared/dirt_shear.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.6 KiB |
35
game/modules/planets/sheared/dirt_shear.png.import
Normal file
35
game/modules/planets/sheared/dirt_shear.png.import
Normal file
@ -0,0 +1,35 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path="res://.import/dirt_shear.png-fd9fb49597b5112c1269175ad6d266c8.stex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://modules/planets/sheared/dirt_shear.png"
|
||||
dest_files=[ "res://.import/dirt_shear.png-fd9fb49597b5112c1269175ad6d266c8.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
|
15
game/modules/planets/sheared/new_resource.tres
Normal file
15
game/modules/planets/sheared/new_resource.tres
Normal file
@ -0,0 +1,15 @@
|
||||
[gd_resource type="Resource" load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://addons/tile_generator/shear_tile.gd" type="Script" id=1]
|
||||
[ext_resource path="res://modules/planets/textures/stone_1_albedo.png" type="Texture" id=2]
|
||||
|
||||
[resource]
|
||||
script = ExtResource( 1 )
|
||||
input = ExtResource( 2 )
|
||||
output_image_name = "dirt_shear"
|
||||
shear_amount = 0.295
|
||||
image_count = 1
|
||||
image_size_x = 32
|
||||
image_size_y = 64
|
||||
alpha_crop = true
|
||||
generate = false
|
Loading…
Reference in New Issue
Block a user