From 3bc341b8ba5d877db9e9cb8a3c9eb616d1f21636 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Tue, 5 Dec 2023 22:01:18 +0800 Subject: [PATCH 1/8] make sure the processEvents not rushing into indefinite loop --- openpype/hosts/substancepainter/api/lib.py | 1 + 1 file changed, 1 insertion(+) diff --git a/openpype/hosts/substancepainter/api/lib.py b/openpype/hosts/substancepainter/api/lib.py index 2cd08f862e..7055c1f8ba 100644 --- a/openpype/hosts/substancepainter/api/lib.py +++ b/openpype/hosts/substancepainter/api/lib.py @@ -588,6 +588,7 @@ def prompt_new_file_with_mesh(mesh_filepath): # the file while not file_dialog.selectedFiles(): app.processEvents(QtCore.QEventLoop.ExcludeUserInputEvents, 1000) + continue print(f"Selected: {file_dialog.selectedFiles()}") # Set it again now we know the path is refreshed - without this From 7c104e1336984071cbd341e4e4938421c094b54e Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Wed, 6 Dec 2023 22:28:35 +0800 Subject: [PATCH 2/8] make sure the select file dialog is closed after selecting the mesh file and make sure the new project dialog hit accepted after finishing the mesh selection and other settings --- openpype/hosts/substancepainter/api/lib.py | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/openpype/hosts/substancepainter/api/lib.py b/openpype/hosts/substancepainter/api/lib.py index 7055c1f8ba..71b7e3630a 100644 --- a/openpype/hosts/substancepainter/api/lib.py +++ b/openpype/hosts/substancepainter/api/lib.py @@ -583,21 +583,7 @@ def prompt_new_file_with_mesh(mesh_filepath): file_dialog.setDirectory(os.path.dirname(mesh_filepath)) url = QtCore.QUrl.fromLocalFile(os.path.basename(mesh_filepath)) file_dialog.selectUrl(url) - - # Give the explorer window time to refresh to the folder and select - # the file - while not file_dialog.selectedFiles(): - app.processEvents(QtCore.QEventLoop.ExcludeUserInputEvents, 1000) - continue - print(f"Selected: {file_dialog.selectedFiles()}") - - # Set it again now we know the path is refreshed - without this - # accepting the dialog will often not trigger the correct filepath - file_dialog.setDirectory(os.path.dirname(mesh_filepath)) - url = QtCore.QUrl.fromLocalFile(os.path.basename(mesh_filepath)) - file_dialog.selectUrl(url) - - file_dialog.done(file_dialog.Accepted) + file_dialog.close() app.processEvents(QtCore.QEventLoop.AllEvents) def _setup_prompt(): @@ -630,6 +616,8 @@ def prompt_new_file_with_mesh(mesh_filepath): if not mesh_filename_label.text(): dialog.close() raise RuntimeError(f"Failed to set mesh path: {mesh_filepath}") + else: + dialog.done(dialog.Accepted) new_action = _get_new_project_action() if not new_action: From e88b692d2acd44b686bec7e6759892ca1404b94a Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Thu, 7 Dec 2023 11:57:50 +0800 Subject: [PATCH 3/8] add the processEvents after the dialog has selected the file URL --- openpype/hosts/substancepainter/api/lib.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/openpype/hosts/substancepainter/api/lib.py b/openpype/hosts/substancepainter/api/lib.py index 71b7e3630a..bb4481bb1d 100644 --- a/openpype/hosts/substancepainter/api/lib.py +++ b/openpype/hosts/substancepainter/api/lib.py @@ -583,7 +583,9 @@ def prompt_new_file_with_mesh(mesh_filepath): file_dialog.setDirectory(os.path.dirname(mesh_filepath)) url = QtCore.QUrl.fromLocalFile(os.path.basename(mesh_filepath)) file_dialog.selectUrl(url) - file_dialog.close() + app.processEvents(QtCore.QEventLoop.ExcludeUserInputEvents, 3000) + + file_dialog.done(file_dialog.Accepted) app.processEvents(QtCore.QEventLoop.AllEvents) def _setup_prompt(): From 459000ec90fa3cdcd11608c4085a620844f5e0c9 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Thu, 7 Dec 2023 18:28:28 +0800 Subject: [PATCH 4/8] if the prompt dialog can't help to import mesh, use substance_painter.project.create instead to 'load' the mesh into the scene --- .../hosts/substancepainter/plugins/load/load_mesh.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/openpype/hosts/substancepainter/plugins/load/load_mesh.py b/openpype/hosts/substancepainter/plugins/load/load_mesh.py index 57db869a11..ca22163c5d 100644 --- a/openpype/hosts/substancepainter/plugins/load/load_mesh.py +++ b/openpype/hosts/substancepainter/plugins/load/load_mesh.py @@ -44,14 +44,20 @@ class SubstanceLoadProjectMesh(load.LoaderPlugin): # Get user inputs import_cameras = data.get("import_cameras", True) preserve_strokes = data.get("preserve_strokes", True) - + sp_settings = substance_painter.project.Settings( + import_cameras=import_cameras + ) if not substance_painter.project.is_open(): # Allow to 'initialize' a new project path = self.filepath_from_context(context) result = prompt_new_file_with_mesh(mesh_filepath=path) if not result: - self.log.info("User cancelled new project prompt.") - return + self.log.info("User cancelled new project prompt." + "Creating new project directly from" + " Substance Painter API Instead.") + settings = substance_painter.project.create( + mesh_file_path=path, settings=sp_settings + ) else: # Reload the mesh From aeaee28539a2903eb2fb061e14ab673204f2a11b Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Thu, 7 Dec 2023 18:51:07 +0800 Subject: [PATCH 5/8] edit the comment --- openpype/hosts/substancepainter/api/lib.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/openpype/hosts/substancepainter/api/lib.py b/openpype/hosts/substancepainter/api/lib.py index bb4481bb1d..35e5b63625 100644 --- a/openpype/hosts/substancepainter/api/lib.py +++ b/openpype/hosts/substancepainter/api/lib.py @@ -617,7 +617,9 @@ def prompt_new_file_with_mesh(mesh_filepath): mesh_filename_label = mesh_filename.findChild(QtWidgets.QLabel) if not mesh_filename_label.text(): dialog.close() - raise RuntimeError(f"Failed to set mesh path: {mesh_filepath}") + substance_painter.logging.warning( + f"Failed to set mesh path with the prompt dialog: {mesh_filepath}\n\n" + "Creating new project directly with the mesh path instead.") else: dialog.done(dialog.Accepted) From 34bb371b810ca0c12ff99729cfb9d045aaa1bdeb Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Thu, 7 Dec 2023 18:53:04 +0800 Subject: [PATCH 6/8] hound --- openpype/hosts/substancepainter/api/lib.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openpype/hosts/substancepainter/api/lib.py b/openpype/hosts/substancepainter/api/lib.py index 35e5b63625..4d3a1d19bd 100644 --- a/openpype/hosts/substancepainter/api/lib.py +++ b/openpype/hosts/substancepainter/api/lib.py @@ -618,7 +618,8 @@ def prompt_new_file_with_mesh(mesh_filepath): if not mesh_filename_label.text(): dialog.close() substance_painter.logging.warning( - f"Failed to set mesh path with the prompt dialog: {mesh_filepath}\n\n" + "Failed to set mesh path with the prompt dialog:" + f"{mesh_filepath}\n\n" "Creating new project directly with the mesh path instead.") else: dialog.done(dialog.Accepted) From f0692c87777f9bd31f73a48d3731c54f0f46c1d0 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Thu, 7 Dec 2023 20:53:53 +0800 Subject: [PATCH 7/8] add comment --- openpype/hosts/substancepainter/api/lib.py | 2 ++ openpype/hosts/substancepainter/plugins/load/load_mesh.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/openpype/hosts/substancepainter/api/lib.py b/openpype/hosts/substancepainter/api/lib.py index 4d3a1d19bd..1cb480b552 100644 --- a/openpype/hosts/substancepainter/api/lib.py +++ b/openpype/hosts/substancepainter/api/lib.py @@ -583,6 +583,8 @@ def prompt_new_file_with_mesh(mesh_filepath): file_dialog.setDirectory(os.path.dirname(mesh_filepath)) url = QtCore.QUrl.fromLocalFile(os.path.basename(mesh_filepath)) file_dialog.selectUrl(url) + # TODO: find a way to improve the process event to + # load more complicated mesh app.processEvents(QtCore.QEventLoop.ExcludeUserInputEvents, 3000) file_dialog.done(file_dialog.Accepted) diff --git a/openpype/hosts/substancepainter/plugins/load/load_mesh.py b/openpype/hosts/substancepainter/plugins/load/load_mesh.py index ca22163c5d..6b4b79753b 100644 --- a/openpype/hosts/substancepainter/plugins/load/load_mesh.py +++ b/openpype/hosts/substancepainter/plugins/load/load_mesh.py @@ -50,6 +50,8 @@ class SubstanceLoadProjectMesh(load.LoaderPlugin): if not substance_painter.project.is_open(): # Allow to 'initialize' a new project path = self.filepath_from_context(context) + #TODO: improve the prompt dialog function to not + # only works for simple polygon scene result = prompt_new_file_with_mesh(mesh_filepath=path) if not result: self.log.info("User cancelled new project prompt." From 16c7d5565d072d84d9a1f5e717c54b832431b7fc Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Thu, 7 Dec 2023 20:54:35 +0800 Subject: [PATCH 8/8] hound --- openpype/hosts/substancepainter/plugins/load/load_mesh.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openpype/hosts/substancepainter/plugins/load/load_mesh.py b/openpype/hosts/substancepainter/plugins/load/load_mesh.py index 6b4b79753b..08c1d5c391 100644 --- a/openpype/hosts/substancepainter/plugins/load/load_mesh.py +++ b/openpype/hosts/substancepainter/plugins/load/load_mesh.py @@ -50,7 +50,7 @@ class SubstanceLoadProjectMesh(load.LoaderPlugin): if not substance_painter.project.is_open(): # Allow to 'initialize' a new project path = self.filepath_from_context(context) - #TODO: improve the prompt dialog function to not + # TODO: improve the prompt dialog function to not # only works for simple polygon scene result = prompt_new_file_with_mesh(mesh_filepath=path) if not result: