mirror of
https://github.com/Relintai/broken_seals_2d.git
synced 2024-11-11 20:35:10 +01:00
Added a new spritesheet generator. This one generates sprites in 2 steps. The first step is just taking a picture of a sprite like the old one, however in the second step it takes the picture from the previous step puts it into a 3d scene and takes a pic of that. This fixes issues with the perspective of my character. Also I managed to set it up in a way by accident that it works with the tileset that I'm experimenting with from open game art (will add it later if everything works out).
This commit is contained in:
parent
e4153c60d5
commit
a43461cc6f
137
game/spritesheet_generator/SSGenv2.tscn
Normal file
137
game/spritesheet_generator/SSGenv2.tscn
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
[gd_scene load_steps=12 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://characters/CharacterFrontModel.tscn" type="PackedScene" id=1]
|
||||||
|
[ext_resource path="res://characters/CharacterSideModel.tscn" type="PackedScene" id=2]
|
||||||
|
[ext_resource path="res://spritesheet_generator/SheetGenv2.gd" type="Script" id=3]
|
||||||
|
[ext_resource path="res://testsave.png" type="Texture" id=4]
|
||||||
|
[ext_resource path="res://spritesheet_generator/SpriteMover.gd" type="Script" id=5]
|
||||||
|
[ext_resource path="res://characters/naturalist_characteratlas.tres" type="CharacterAtlas" id=6]
|
||||||
|
[ext_resource path="res://modules/entity_classes/naturalist/spell_effects/nature2d/NatureCast.tscn" type="PackedScene" id=7]
|
||||||
|
|
||||||
|
[sub_resource type="Environment" id=1]
|
||||||
|
ssao_enabled = true
|
||||||
|
|
||||||
|
[sub_resource type="World" id=2]
|
||||||
|
environment = SubResource( 1 )
|
||||||
|
|
||||||
|
[sub_resource type="Environment" id=3]
|
||||||
|
|
||||||
|
[sub_resource type="World" id=4]
|
||||||
|
environment = SubResource( 3 )
|
||||||
|
|
||||||
|
[node name="TextureAtlasGenerator" type="Node2D"]
|
||||||
|
script = ExtResource( 3 )
|
||||||
|
_sprite_size = 40
|
||||||
|
_sprite_num = 16
|
||||||
|
_show_atlas = true
|
||||||
|
save_texture = true
|
||||||
|
animations = [ "run", "idle", "casting", "rest" ]
|
||||||
|
z_index_paths = [ NodePath("Viewport/Node2D/CharacterFrontModel/Hip/Torso/remote_arm_r/remote_hand_r"), NodePath("Viewport/Node2D/CharacterFrontModel/Hip/Torso/arm_l/hand_l") ]
|
||||||
|
wp2_sprite3d_path = NodePath("Viewport2/Sprite3D")
|
||||||
|
instant_preview_path = NodePath("InstantPreview")
|
||||||
|
sprite_preview_path = NodePath("SpritePreview")
|
||||||
|
viewport_path = NodePath("Viewport")
|
||||||
|
viewport2_path = NodePath("Viewport2")
|
||||||
|
atlas_preview_path = NodePath("AtlasPreview")
|
||||||
|
model_front_path = NodePath("Viewport/Node2D/CharacterFrontModel")
|
||||||
|
model_front_animation_player_path = NodePath("Viewport/Node2D/CharacterFrontModel/AnimationPlayer")
|
||||||
|
model_front_animation_tree_player_path = NodePath("Viewport/Node2D/CharacterFrontModel/AnimationTree")
|
||||||
|
model_side_path = NodePath("Viewport/Node2D/CharacterSideModel")
|
||||||
|
model_side_animation_player_path = NodePath("Viewport/Node2D/CharacterSideModel/AnimationPlayer")
|
||||||
|
model_side_animation_tree_player_path = NodePath("Viewport/Node2D/CharacterSideModel/AnimationTree")
|
||||||
|
cast_animation_index = 2
|
||||||
|
cast_animation_scene = ExtResource( 7 )
|
||||||
|
cast_animation_paths = [ NodePath("Viewport/Node2D/CharacterFrontModel/Hip/Torso/remote_arm_r/remote_hand_r/Position2D"), NodePath("Viewport/Node2D/CharacterFrontModel/Hip/Torso/arm_l/hand_l/end"), NodePath("Viewport/Node2D/CharacterSideModel/Hip/Torso/remote_arm_r/remote_hand_r/Position2D"), NodePath("Viewport/Node2D/CharacterSideModel/Hip/Torso/arm_l/hand_l/end") ]
|
||||||
|
|
||||||
|
[node name="Viewport" type="Viewport" parent="."]
|
||||||
|
size = Vector2( 64, 64 )
|
||||||
|
own_world = true
|
||||||
|
world = SubResource( 2 )
|
||||||
|
transparent_bg = true
|
||||||
|
handle_input_locally = false
|
||||||
|
hdr = false
|
||||||
|
usage = 0
|
||||||
|
render_target_v_flip = true
|
||||||
|
render_target_update_mode = 3
|
||||||
|
|
||||||
|
[node name="Camera" type="Camera2D" parent="Viewport"]
|
||||||
|
position = Vector2( 0, -15.726 )
|
||||||
|
z_index = 2
|
||||||
|
current = true
|
||||||
|
|
||||||
|
[node name="Node2D" type="Node2D" parent="Viewport"]
|
||||||
|
|
||||||
|
[node name="CharacterFrontModel" parent="Viewport/Node2D" instance=ExtResource( 1 )]
|
||||||
|
_atlas = ExtResource( 6 )
|
||||||
|
|
||||||
|
[node name="Torso" parent="Viewport/Node2D/CharacterFrontModel/Hip" index="1"]
|
||||||
|
position = Vector2( 0, -2.289 )
|
||||||
|
|
||||||
|
[node name="hand_l" parent="Viewport/Node2D/CharacterFrontModel/Hip/Torso/arm_l" index="0"]
|
||||||
|
z_index = 1
|
||||||
|
|
||||||
|
[node name="AnimationTree" parent="Viewport/Node2D/CharacterFrontModel" index="2"]
|
||||||
|
active = false
|
||||||
|
|
||||||
|
[node name="CharacterSideModel" parent="Viewport/Node2D" instance=ExtResource( 2 )]
|
||||||
|
visible = false
|
||||||
|
rotation = 3.14147
|
||||||
|
scale = Vector2( 1, -1 )
|
||||||
|
_atlas = ExtResource( 6 )
|
||||||
|
|
||||||
|
[node name="arm_r" parent="Viewport/Node2D/CharacterSideModel" index="0"]
|
||||||
|
position = Vector2( -3.50004, -24.6155 )
|
||||||
|
|
||||||
|
[node name="hand_r" parent="Viewport/Node2D/CharacterSideModel" index="1"]
|
||||||
|
position = Vector2( -3.50004, -19.1155 )
|
||||||
|
z_index = 1
|
||||||
|
|
||||||
|
[node name="Torso" parent="Viewport/Node2D/CharacterSideModel/Hip" index="3"]
|
||||||
|
position = Vector2( 0, -2 )
|
||||||
|
|
||||||
|
[node name="AnimationTree" parent="Viewport/Node2D/CharacterSideModel" index="4"]
|
||||||
|
active = false
|
||||||
|
|
||||||
|
[node name="Viewport2" type="Viewport" parent="."]
|
||||||
|
size = Vector2( 64, 64 )
|
||||||
|
own_world = true
|
||||||
|
world = SubResource( 4 )
|
||||||
|
transparent_bg = true
|
||||||
|
handle_input_locally = false
|
||||||
|
keep_3d_linear = true
|
||||||
|
render_target_v_flip = true
|
||||||
|
render_target_update_mode = 3
|
||||||
|
|
||||||
|
[node name="Camera" type="Camera" parent="Viewport2"]
|
||||||
|
transform = Transform( 1, 0, 0, 0, 0.889783, 0.456384, 0, -0.456384, 0.889783, 0, 0.154229, 0.172536 )
|
||||||
|
projection = 1
|
||||||
|
current = true
|
||||||
|
|
||||||
|
[node name="Sprite3D" type="Sprite3D" parent="Viewport2"]
|
||||||
|
|
||||||
|
[node name="InstantPreview" type="Sprite" parent="."]
|
||||||
|
|
||||||
|
[node name="SpritePreview" type="Sprite" parent="."]
|
||||||
|
|
||||||
|
[node name="AtlasPreview" type="Sprite" parent="."]
|
||||||
|
position = Vector2( 603.531, 254.594 )
|
||||||
|
|
||||||
|
[node name="Sprite" type="Sprite" parent="."]
|
||||||
|
position = Vector2( 101.579, 162.161 )
|
||||||
|
texture = ExtResource( 4 )
|
||||||
|
hframes = 16
|
||||||
|
vframes = 16
|
||||||
|
frame = 9
|
||||||
|
script = ExtResource( 5 )
|
||||||
|
|
||||||
|
[node name="Test" type="Sprite" parent="."]
|
||||||
|
position = Vector2( -91.0568, 21.4517 )
|
||||||
|
texture = ExtResource( 4 )
|
||||||
|
hframes = 16
|
||||||
|
vframes = 16
|
||||||
|
|
||||||
|
[node name="Camera2D" type="Camera2D" parent="."]
|
||||||
|
current = true
|
||||||
|
|
||||||
|
[editable path="Viewport/Node2D/CharacterFrontModel"]
|
||||||
|
[editable path="Viewport/Node2D/CharacterSideModel"]
|
292
game/spritesheet_generator/SheetGenv2.gd
Normal file
292
game/spritesheet_generator/SheetGenv2.gd
Normal file
@ -0,0 +1,292 @@
|
|||||||
|
extends Node
|
||||||
|
|
||||||
|
export (int) var _sprite_size
|
||||||
|
export (int) var _sprite_num
|
||||||
|
var _directions : int = 4
|
||||||
|
|
||||||
|
export (bool) var _show_atlas = false
|
||||||
|
|
||||||
|
export (bool) var save_texture = false
|
||||||
|
|
||||||
|
export (bool) var generate : bool = false setget set_generate, get_generate
|
||||||
|
|
||||||
|
export (String) var output_file_name : String = "res://testsave.png"
|
||||||
|
|
||||||
|
export (Array, String) var animations : Array
|
||||||
|
export (Array, NodePath) var z_index_paths : Array
|
||||||
|
|
||||||
|
export (NodePath) var wp2_sprite3d_path
|
||||||
|
|
||||||
|
export (NodePath) var instant_preview_path
|
||||||
|
export (NodePath) var sprite_preview_path
|
||||||
|
export (NodePath) var viewport_path
|
||||||
|
export (NodePath) var viewport2_path
|
||||||
|
export (NodePath) var atlas_preview_path
|
||||||
|
|
||||||
|
export (NodePath) var model_front_path
|
||||||
|
export (NodePath) var model_front_animation_player_path
|
||||||
|
export (NodePath) var model_front_animation_tree_player_path
|
||||||
|
export (NodePath) var model_side_path
|
||||||
|
export (NodePath) var model_side_animation_player_path
|
||||||
|
export (NodePath) var model_side_animation_tree_player_path
|
||||||
|
|
||||||
|
export(int) var cast_animation_index : int = 0
|
||||||
|
export(PackedScene) var cast_animation_scene : PackedScene = null
|
||||||
|
export (Array, NodePath) var cast_animation_paths : Array
|
||||||
|
var cast_animations : Array
|
||||||
|
|
||||||
|
var _wp2_sprite3d
|
||||||
|
|
||||||
|
var _viewport
|
||||||
|
var _viewport_texture
|
||||||
|
var _viewport2
|
||||||
|
var _viewport2_texture
|
||||||
|
var _atlas
|
||||||
|
var _image_texture
|
||||||
|
var _atlas_texture
|
||||||
|
|
||||||
|
var _instant_preview
|
||||||
|
var _sprite_preview
|
||||||
|
var _atlas_preview
|
||||||
|
|
||||||
|
var _time = 0
|
||||||
|
var _frame = 0
|
||||||
|
var _index = 0
|
||||||
|
var _direction = 0
|
||||||
|
var _current_animation_index = 0
|
||||||
|
var _current_animation_player = null
|
||||||
|
|
||||||
|
var _running = false
|
||||||
|
|
||||||
|
var _model_front
|
||||||
|
var _model_front_animation_player
|
||||||
|
var _model_front_animation_tree_player
|
||||||
|
var _model_side
|
||||||
|
var _model_side_animation_player
|
||||||
|
var _model_side_animation_tree_player
|
||||||
|
|
||||||
|
var _texture
|
||||||
|
var _texture2
|
||||||
|
|
||||||
|
var _first = true
|
||||||
|
var _first_frame = true
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
_viewport = get_node(viewport_path)
|
||||||
|
_viewport2 = get_node(viewport2_path)
|
||||||
|
_wp2_sprite3d = get_node(wp2_sprite3d_path)
|
||||||
|
|
||||||
|
_instant_preview = get_node(instant_preview_path)
|
||||||
|
_sprite_preview = get_node(sprite_preview_path)
|
||||||
|
_atlas_preview = get_node(atlas_preview_path)
|
||||||
|
|
||||||
|
var img = ImageTexture.new()
|
||||||
|
img.flags = 0
|
||||||
|
img.create(_sprite_size, _sprite_size, 5, 0)
|
||||||
|
_sprite_preview.texture = img
|
||||||
|
|
||||||
|
var img2 = ImageTexture.new()
|
||||||
|
img2.flags = 0
|
||||||
|
img2.create(64, 64, 5, 0)
|
||||||
|
_wp2_sprite3d.texture = img2
|
||||||
|
|
||||||
|
_model_front = get_node(model_front_path)
|
||||||
|
_model_front_animation_player = get_node(model_front_animation_player_path)
|
||||||
|
_model_front_animation_tree_player = get_node(model_front_animation_tree_player_path)
|
||||||
|
|
||||||
|
if _model_side_animation_tree_player:
|
||||||
|
_model_front_animation_tree_player.active = false
|
||||||
|
|
||||||
|
_model_side = get_node(model_side_path)
|
||||||
|
_model_side_animation_player = get_node(model_side_animation_player_path)
|
||||||
|
_model_side_animation_tree_player = get_node(model_side_animation_tree_player_path)
|
||||||
|
|
||||||
|
if _model_side_animation_tree_player:
|
||||||
|
_model_side_animation_tree_player.active = false
|
||||||
|
|
||||||
|
_model_front.hide()
|
||||||
|
_model_side.show()
|
||||||
|
|
||||||
|
_viewport_texture = _viewport.get_texture()
|
||||||
|
|
||||||
|
_texture = Image.new()
|
||||||
|
var frame = _viewport.get_texture().get_data()
|
||||||
|
_texture.create(512, 512, false, frame.get_format())
|
||||||
|
|
||||||
|
_texture2 = Image.new()
|
||||||
|
var frame2 = _viewport2.get_texture().get_data()
|
||||||
|
_texture2.create(_sprite_size * _sprite_num, _sprite_size * _directions * animations.size(), false, frame2.get_format())
|
||||||
|
|
||||||
|
|
||||||
|
_running = true
|
||||||
|
set_process(true)
|
||||||
|
|
||||||
|
func _process(delta):
|
||||||
|
if not _running:
|
||||||
|
return
|
||||||
|
|
||||||
|
#todo remove, only to make development easier
|
||||||
|
if !_viewport || !_viewport2:
|
||||||
|
_ready()
|
||||||
|
|
||||||
|
if _first:
|
||||||
|
_first = false
|
||||||
|
|
||||||
|
setup_direction()
|
||||||
|
|
||||||
|
setup_animation()
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
var frame = _viewport.get_texture().get_data()
|
||||||
|
|
||||||
|
_wp2_sprite3d.get_texture().set_data(frame)
|
||||||
|
|
||||||
|
if _first_frame:
|
||||||
|
_first_frame = false
|
||||||
|
#we need to let the second step render the first image from the prev step
|
||||||
|
return
|
||||||
|
|
||||||
|
var frame2 = _viewport2.get_texture().get_data()
|
||||||
|
|
||||||
|
var ur = frame2.get_used_rect()
|
||||||
|
var xx : float = 0
|
||||||
|
xx = (_sprite_size - ur.size.x) / 2
|
||||||
|
_texture2.blend_rect(frame2, ur, Vector2((_frame * _sprite_size) + xx, (_index * _sprite_size)))
|
||||||
|
_current_animation_player.seek(_frame * (_current_animation_player.current_animation_length / (_sprite_num)), true)
|
||||||
|
|
||||||
|
|
||||||
|
if (_index >= _directions * animations.size()):
|
||||||
|
_running = false
|
||||||
|
create_atlas()
|
||||||
|
return
|
||||||
|
|
||||||
|
_sprite_preview.get_texture().set_data(frame2)
|
||||||
|
|
||||||
|
if _frame >= _sprite_num:
|
||||||
|
_frame = 0
|
||||||
|
_index += 1
|
||||||
|
_direction += 1
|
||||||
|
|
||||||
|
if _direction >= _directions:
|
||||||
|
_direction = 0
|
||||||
|
|
||||||
|
_current_animation_index += 1
|
||||||
|
|
||||||
|
setup_direction()
|
||||||
|
|
||||||
|
if (_index >= _directions * animations.size()):
|
||||||
|
# _running = false
|
||||||
|
# create_atlas()
|
||||||
|
return
|
||||||
|
|
||||||
|
setup_animation()
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
_frame += 1
|
||||||
|
|
||||||
|
func setup_animation():
|
||||||
|
_current_animation_player.play(animations[_current_animation_index])
|
||||||
|
_current_animation_player.seek(0, true)
|
||||||
|
|
||||||
|
if !cast_animation_scene:
|
||||||
|
return
|
||||||
|
|
||||||
|
if _current_animation_index == cast_animation_index:
|
||||||
|
for cap in cast_animation_paths:
|
||||||
|
var n = get_node(cap)
|
||||||
|
|
||||||
|
if !n:
|
||||||
|
continue
|
||||||
|
|
||||||
|
var pa = cast_animation_scene.instance()
|
||||||
|
|
||||||
|
cast_animations.push_back(pa)
|
||||||
|
|
||||||
|
n.add_child(pa)
|
||||||
|
else:
|
||||||
|
for n in cast_animations:
|
||||||
|
n.queue_free()
|
||||||
|
|
||||||
|
cast_animations.clear()
|
||||||
|
|
||||||
|
#enum CharacterFacing
|
||||||
|
# FACING_FRONT = 0,
|
||||||
|
# FACING_BACK = 1,
|
||||||
|
# FACING_RIGHT = 2,
|
||||||
|
# FACING_LEFT = 3,
|
||||||
|
|
||||||
|
func setup_direction():
|
||||||
|
for a in cast_animations:
|
||||||
|
if a.has_method("get_z_index"):
|
||||||
|
a.z_index = 0
|
||||||
|
|
||||||
|
if _direction == 0:
|
||||||
|
_current_animation_player = _model_side_animation_player
|
||||||
|
_model_side.set_facing(2)
|
||||||
|
_model_side.transform.x.x = -1
|
||||||
|
|
||||||
|
_model_side.show()
|
||||||
|
_model_front.hide()
|
||||||
|
|
||||||
|
for np in z_index_paths:
|
||||||
|
get_node(np).z_index = 0
|
||||||
|
if _direction == 1:
|
||||||
|
_current_animation_player = _model_side_animation_player
|
||||||
|
_model_side.set_facing(3)
|
||||||
|
_model_side.transform.x.x = 1
|
||||||
|
|
||||||
|
_model_side.show()
|
||||||
|
_model_front.hide()
|
||||||
|
|
||||||
|
for np in z_index_paths:
|
||||||
|
get_node(np).z_index = 0
|
||||||
|
if _direction == 2:
|
||||||
|
_current_animation_player = _model_front_animation_player
|
||||||
|
_model_front.set_facing(0)
|
||||||
|
|
||||||
|
_model_side.hide()
|
||||||
|
_model_front.show()
|
||||||
|
|
||||||
|
for np in z_index_paths:
|
||||||
|
get_node(np).z_index = 0
|
||||||
|
if _direction == 3:
|
||||||
|
_current_animation_player = _model_front_animation_player
|
||||||
|
_model_front.set_facing(1)
|
||||||
|
|
||||||
|
_model_side.hide()
|
||||||
|
_model_front.show()
|
||||||
|
|
||||||
|
for np in z_index_paths:
|
||||||
|
get_node(np).z_index = -1
|
||||||
|
|
||||||
|
for a in cast_animations:
|
||||||
|
if a.has_method("get_z_index"):
|
||||||
|
a.z_index = -1
|
||||||
|
|
||||||
|
|
||||||
|
func create_atlas():
|
||||||
|
_image_texture = ImageTexture.new()
|
||||||
|
_image_texture.create_from_image(_texture2, 0)
|
||||||
|
|
||||||
|
_image_texture.get_data().save_png(output_file_name)
|
||||||
|
|
||||||
|
if save_texture:
|
||||||
|
_sprite_preview.set_texture(_image_texture)
|
||||||
|
|
||||||
|
if _show_atlas:
|
||||||
|
_atlas_preview.set_texture(_image_texture)
|
||||||
|
|
||||||
|
|
||||||
|
func set_generate(v : bool) -> void:
|
||||||
|
if !v:
|
||||||
|
return
|
||||||
|
|
||||||
|
#for easier development
|
||||||
|
_ready()
|
||||||
|
_running = true
|
||||||
|
#set_process(true)
|
||||||
|
|
||||||
|
func get_generate() -> bool:
|
||||||
|
return false
|
Loading…
Reference in New Issue
Block a user