Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remember Preview3D custom mesh across restarts #602

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions material_maker/panels/preview_3d/preview_3d.gd
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ func _ready() -> void:
await get_tree().process_frame
sun.shadow_enabled = mm_globals.get_config("ui_3d_preview_sun_shadow")

if mm_globals.config.has_section_key("path", "mesh"):
do_load_custom_mesh(mm_globals.config.get_value("path", "mesh"))

func update_menu():
mm_globals.menu_manager.create_menus(MENU, self, mm_globals.menu_manager.MenuBarGodot.new(ui))

Expand Down Expand Up @@ -100,19 +103,19 @@ func _on_Model_item_selected(id) -> void:
for f in MMMeshLoader.get_file_dialog_filters():
dialog.add_filter(f)
if mm_globals.config.has_section_key("path", "mesh"):
dialog.current_dir = mm_globals.config.get_value("path", "mesh")
dialog.current_dir = mm_globals.config.get_value("path", "mesh").get_base_dir()
var files = await dialog.select_files()
if files.size() == 1:
do_load_custom_mesh(files[0])
else:
select_object(id)

func do_load_custom_mesh(file_path) -> void:
mm_globals.config.set_value("path", "mesh", file_path.get_base_dir())
var id = objects.get_child_count()-1
var mesh : Mesh = null
mesh = MMMeshLoader.load_mesh(file_path)
if mesh != null:
mm_globals.config.set_value("path", "mesh", file_path)
var object : MeshInstance3D = objects.get_child(id)
object.mesh = mesh
mm_globals.main_window.set_current_mesh(mesh)
Expand Down