2023-10-19 13:31:26 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								/**************************************************************************/ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/*  surface_upgrade_tool.cpp                                              */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/**************************************************************************/ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/*                         This file is part of:                          */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/*                             GODOT ENGINE                               */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/*                        https://godotengine.org                         */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/**************************************************************************/ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur.                  */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/*                                                                        */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/* Permission is hereby granted, free of charge, to any person obtaining  */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/* a copy of this software and associated documentation files (the        */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/* "Software"), to deal in the Software without restriction, including    */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/* without limitation the rights to use, copy, modify, merge, publish,    */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/* distribute, sublicense, and/or sell copies of the Software, and to     */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/* permit persons to whom the Software is furnished to do so, subject to  */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/* the following conditions:                                              */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/*                                                                        */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/* The above copyright notice and this permission notice shall be         */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/* included in all copies or substantial portions of the Software.        */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/*                                                                        */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,        */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF     */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY   */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,   */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE      */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/**************************************************************************/ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# include  "surface_upgrade_tool.h" 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# include  "editor/editor_file_system.h" 
 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-22 16:15:02 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  "editor/editor_log.h" 
 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-19 13:31:26 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								# include  "editor/editor_node.h" 
 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-20 14:44:38 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  "editor/editor_scale.h" 
 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-30 15:34:18 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  "editor/editor_settings.h" 
 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-22 16:15:02 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  "editor/gui/editor_toaster.h" 
 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-30 15:34:18 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  "scene/scene_string_names.h" 
 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-19 13:31:26 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								# include  "servers/rendering_server.h" 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-10-30 15:34:18 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								SurfaceUpgradeTool  * SurfaceUpgradeTool : : singleton  =  nullptr ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								void  SurfaceUpgradeTool : : _add_files ( EditorFileSystemDirectory  * p_dir ,  Vector < String >  & r_reimport_paths ,  Vector < String >  & r_resave_paths )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-19 13:31:26 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									for  ( int  i  =  0 ;  i  <  p_dir - > get_subdir_count ( ) ;  i + + )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-30 15:34:18 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										_add_files ( p_dir - > get_subdir ( i ) ,  r_reimport_paths ,  r_resave_paths ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-19 13:31:26 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									for  ( int  i  =  0 ;  i  <  p_dir - > get_file_count ( ) ;  i + + )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( p_dir - > get_file_type ( i )  = =  " Mesh "  | | 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												p_dir - > get_file_type ( i )  = =  " ArrayMesh "  | | 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												p_dir - > get_file_type ( i )  = =  " PackedScene " )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											if  ( FileAccess : : exists ( p_dir - > get_file_path ( i )  +  " .import " ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-30 15:34:18 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												r_reimport_paths . append ( p_dir - > get_file_path ( i )  +  " .import " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-19 13:31:26 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
											}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-30 15:34:18 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												r_resave_paths . append ( p_dir - > get_file_path ( i ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-19 13:31:26 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-10-30 15:34:18 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								void  SurfaceUpgradeTool : : _try_show_popup ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-22 16:15:02 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( singleton - > show_requested  | |  singleton - > updating )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-30 15:34:18 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-22 16:15:02 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-10-30 15:34:18 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									singleton - > show_requested  =  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-11-22 16:15:02 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ! EditorNode : : get_singleton ( ) - > is_editor_ready ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										// EditorNode may not be ready yet. It will call this tool when it is.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-30 15:34:18 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( EditorFileSystem : : get_singleton ( ) - > is_importing ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										EditorFileSystem : : get_singleton ( ) - > connect ( " resources_reimported " ,  callable_mp ( singleton ,  & SurfaceUpgradeTool : : _show_popup ) ,  CONNECT_ONE_SHOT ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-22 16:15:02 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-30 15:34:18 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										singleton - > _show_popup ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-22 15:35:50 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									RS : : get_singleton ( ) - > set_warn_on_surface_upgrade ( false ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-30 15:34:18 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								void  SurfaceUpgradeTool : : _show_popup ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									MutexLock  lock ( mutex ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-22 16:15:02 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ! show_requested )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return ;  // We only show the dialog if it was previously requested.
 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-30 15:34:18 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									show_requested  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-11-22 16:15:02 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// These messages are supposed to be translated as they are critical to users migrating their projects.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  String  confirmation_message  =  TTR ( " This project uses meshes with an outdated mesh format from previous Godot versions. The engine needs to update the format in order to use those meshes. Please use the 'Upgrade Mesh Surfaces' tool from the 'Project > Tools' menu. You can ignore this message and keep using outdated meshes, but keep in mind that this leads to increased load times every time you load the project. " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									EditorNode : : get_log ( ) - > add_message ( confirmation_message ,  EditorLog : : MSG_TYPE_WARNING ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  String  toast_message  =  TTR ( " This project uses meshes with an outdated mesh format. Check the output log. " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									EditorToaster : : get_singleton ( ) - > popup_str ( toast_message ,  EditorToaster : : SEVERITY_WARNING ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-30 15:34:18 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-19 13:31:26 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-11-20 14:44:38 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								void  SurfaceUpgradeTool : : prepare_upgrade ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									EditorSettings : : get_singleton ( ) - > set_project_metadata ( " surface_upgrade_tool " ,  " run_on_restart " ,  true ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									Vector < String >  reimport_paths ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									Vector < String >  resave_paths ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									_add_files ( EditorFileSystem : : get_singleton ( ) - > get_filesystem ( ) ,  reimport_paths ,  resave_paths ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									EditorSettings : : get_singleton ( ) - > set_project_metadata ( " surface_upgrade_tool " ,  " reimport_paths " ,  reimport_paths ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									EditorSettings : : get_singleton ( ) - > set_project_metadata ( " surface_upgrade_tool " ,  " resave_paths " ,  resave_paths ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// Delay to avoid deadlocks, since this dialog can be triggered by loading a scene.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									MessageQueue : : get_singleton ( ) - > push_callable ( callable_mp ( EditorNode : : get_singleton ( ) ,  & EditorNode : : restart_editor ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-10-30 15:34:18 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								// Ensure that the warnings and popups are skipped.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								void  SurfaceUpgradeTool : : begin_upgrade ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-22 16:15:02 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									updating  =  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-10-30 15:34:18 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									EditorSettings : : get_singleton ( ) - > set_project_metadata ( " surface_upgrade_tool " ,  " run_on_restart " ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									RS : : get_singleton ( ) - > set_surface_upgrade_callback ( nullptr ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									RS : : get_singleton ( ) - > set_warn_on_surface_upgrade ( false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-19 13:31:26 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-10-30 15:34:18 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								void  SurfaceUpgradeTool : : finish_upgrade ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									EditorNode : : get_singleton ( ) - > trigger_menu_option ( EditorNode : : FILE_CLOSE_ALL ,  true ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									// Update all meshes here.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									Vector < String >  resave_paths  =  EditorSettings : : get_singleton ( ) - > get_project_metadata ( " surface_upgrade_tool " ,  " resave_paths " ,  Vector < String > ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-22 15:35:50 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									Vector < String >  reimport_paths  =  EditorSettings : : get_singleton ( ) - > get_project_metadata ( " surface_upgrade_tool " ,  " reimport_paths " ,  Vector < String > ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									EditorProgress  ep ( " surface_upgrade_resave " ,  TTR ( " Upgrading All Meshes in Project " ) ,  resave_paths . size ( )  +  reimport_paths . size ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-19 13:31:26 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-11-22 15:35:50 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									int  step  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-30 15:34:18 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									for  ( const  String  & file_path  :  resave_paths )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										Ref < Resource >  res  =  ResourceLoader : : load ( file_path ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-22 15:35:50 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ep . step ( TTR ( " Attempting to re-save  " )  +  file_path ,  step + + ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-19 13:31:26 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
										if  ( res . is_valid ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											// Ignore things that fail to load.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											ResourceSaver : : save ( res ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-30 15:34:18 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									EditorSettings : : get_singleton ( ) - > set_project_metadata ( " surface_upgrade_tool " ,  " resave_paths " ,  Vector < String > ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-19 13:31:26 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-10-30 15:34:18 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// Remove the imported scenes/meshes from .import so they will be reimported automatically after this.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									for  ( const  String  & file_path  :  reimport_paths )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										Ref < ConfigFile >  config ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										config . instantiate ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										Error  err  =  config - > load ( file_path ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( err  ! =  OK )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											ERR_PRINT ( " Could not open  "  +  file_path  +  "  for upgrade. " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										String  remap_path  =  config - > get_value ( " remap " ,  " path " ,  " " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( remap_path . is_empty ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-11-22 15:35:50 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ep . step ( TTR ( " Attempting to remove  " )  +  remap_path ,  step + + ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-10-30 15:34:18 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										String  path  =  OS : : get_singleton ( ) - > get_resource_dir ( )  +  remap_path . replace_first ( " res:// " ,  " / " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										print_verbose ( " Moving to trash:  "  +  path ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										err  =  OS : : get_singleton ( ) - > move_to_trash ( path ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( err  ! =  OK )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											EditorNode : : get_singleton ( ) - > add_io_error ( TTR ( " Cannot remove: " )  +  " \n "  +  remap_path  +  " \n " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-19 13:31:26 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-30 15:34:18 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									EditorSettings : : get_singleton ( ) - > set_project_metadata ( " surface_upgrade_tool " ,  " reimport_paths " ,  Vector < String > ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									emit_signal ( SNAME ( " upgrade_finished " ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								void  SurfaceUpgradeTool : : _bind_methods ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									ADD_SIGNAL ( MethodInfo ( " upgrade_finished " ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-19 13:31:26 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								SurfaceUpgradeTool : : SurfaceUpgradeTool ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-30 15:34:18 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									singleton  =  this ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									RS : : get_singleton ( ) - > set_surface_upgrade_callback ( _try_show_popup ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-10-19 13:31:26 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-11-22 16:15:02 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								SurfaceUpgradeTool : : ~ SurfaceUpgradeTool ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									singleton  =  nullptr ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								void  SurfaceUpgradeDialog : : popup_on_demand ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  String  confirmation_message  =  TTR ( " The mesh format has changed in Godot 4.2, which affects both imported meshes and meshes authored inside of Godot. The engine needs to update the format in order to use those meshes. \n \n If your project predates Godot 4.2 and contains meshes, we recommend you run this one time conversion tool. This update will restart the editor and may take several minutes. Upgrading will make the meshes incompatible with previous versions of Godot. \n \n You can still use your existing meshes as is. The engine will update each mesh in memory, but the update will not be saved. Choosing this option will lead to slower load times every time this project is loaded. " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									set_text ( confirmation_message ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									get_ok_button ( ) - > set_text ( TTR ( " Restart & Upgrade " ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									popup_centered ( Size2 ( 750  *  EDSCALE ,  0 ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-20 14:44:38 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								void  SurfaceUpgradeDialog : : _notification ( int  p_what )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									switch  ( p_what )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										case  NOTIFICATION_READY : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											// Can't do it in the constructor because it doesn't know that the signal exists.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											connect ( " confirmed " ,  callable_mp ( SurfaceUpgradeTool : : get_singleton ( ) ,  & SurfaceUpgradeTool : : prepare_upgrade ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								SurfaceUpgradeDialog : : SurfaceUpgradeDialog ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									set_autowrap ( true ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									get_label ( ) - > set_custom_minimum_size ( Size2 ( 750  *  EDSCALE ,  0 ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								}