Store shader directory as working directory and use this as the root for relative uniform image imports via !load directive, drop Windows compatibility - solves #7
This commit is contained in:
parent
b307635c09
commit
367dbe163c
6 changed files with 18 additions and 67 deletions
|
@ -220,20 +220,26 @@ func _on_save_shader_button_pressed():
|
|||
save_shader_dialog.current_path = last_save_filepath
|
||||
save_shader_dialog.show()
|
||||
|
||||
func _on_open_shader_dialog_file_selected(path):
|
||||
func _on_open_shader_dialog_file_selected(path: String):
|
||||
print("Load ", path)
|
||||
var file = FileAccess.open(path, FileAccess.READ)
|
||||
var shader_code = file.get_as_text()
|
||||
var shader = Shader.new()
|
||||
shader.code = shader_code
|
||||
Globals.shader = shader
|
||||
if "/" in path: # update current working directory
|
||||
Globals.cwd = path.substr(0, path.rfind("/"))
|
||||
Globals.target_viewport.update()
|
||||
update()
|
||||
last_save_filepath = path
|
||||
|
||||
func _on_save_shader_dialog_file_selected(path):
|
||||
print("Save ", path)
|
||||
var file = FileAccess.open(path, FileAccess.WRITE)
|
||||
var content = Globals.shader.code
|
||||
file.store_string(content)
|
||||
if "/" in path: # update current working directory
|
||||
Globals.cwd = path.substr(0, path.rfind("/"))
|
||||
last_save_filepath = path
|
||||
|
||||
func _on_apply_shader_button_pressed():
|
||||
|
|
|
@ -3,3 +3,4 @@ extends Node
|
|||
var camera_freeze = false
|
||||
@onready var shader: Shader = ShaderPresets.presets[ShaderPresets.default_preset]
|
||||
var target_viewport: SubViewport
|
||||
var cwd = "."
|
||||
|
|
|
@ -24,7 +24,13 @@ func update():
|
|||
# load images from //!load directives and apply them to
|
||||
# the material as shader parameters
|
||||
for m in load_uniform_regex.search_all(Globals.shader.code):
|
||||
var u_image = Image.load_from_file(m.strings[2])
|
||||
# this only works for Linux!
|
||||
var img_path = m.strings[2]
|
||||
if !img_path.begins_with("/"):
|
||||
img_path = Globals.cwd + "/" + img_path.lstrip("./")
|
||||
#
|
||||
print("Load ", img_path)
|
||||
var u_image = Image.load_from_file(img_path)
|
||||
mat.set_shader_parameter(
|
||||
m.strings[1], # uniform param name
|
||||
ImageTexture.create_from_image(u_image))
|
||||
|
|
|
@ -14,6 +14,7 @@ func _on_open_image_button_pressed():
|
|||
ui_control_fileopen.show()
|
||||
|
||||
func _on_open_image_dialog_file_selected(path):
|
||||
print("Load ", path)
|
||||
var img = Image.new()
|
||||
var err = img.load(path)
|
||||
if err == OK:
|
||||
|
@ -30,6 +31,7 @@ func _on_save_image_button_pressed():
|
|||
ui_control_filesave.show()
|
||||
|
||||
func _on_save_image_dialog_file_selected(path):
|
||||
print("Export ", path)
|
||||
var err = image_viewport.get_result().save_png(path)
|
||||
if err != OK:
|
||||
print("An error occured!")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue