diff --git a/bin/meshroom_batch b/bin/meshroom_batch index 7c948fb7..c1f3a539 100755 --- a/bin/meshroom_batch +++ b/bin/meshroom_batch @@ -91,15 +91,6 @@ if args.verbose: logging.getLogger().setLevel(logStringToPython[args.verbose]) -def getOnlyNodeOfType(g, nodeType): - """ Helper function to get a node of 'nodeType' in the graph 'g' and raise if no or multiple candidates. """ - nodes = g.nodesOfType(nodeType) - if len(nodes) != 1: - raise RuntimeError("meshroom_batch requires a pipeline graph with exactly one '{}' node, {} found." - .format(nodeType, len(nodes))) - return nodes[0] - - def getInitNode(g): """ Helper function to get the Init node in the graph 'g' and raise an exception if there is no or @@ -124,10 +115,10 @@ with multiview.GraphModification(graph): # initialize template pipeline loweredPipelineTemplates = dict((k.lower(), v) for k, v in meshroom.core.pipelineTemplates.items()) if args.pipeline.lower() in loweredPipelineTemplates: - graph.load(loweredPipelineTemplates[args.pipeline.lower()], setupProjectFile=False) + graph.load(loweredPipelineTemplates[args.pipeline.lower()], setupProjectFile=False, publishOutputs=True if args.output else False) else: # custom pipeline - graph.load(args.pipeline, setupProjectFile=False) + graph.load(args.pipeline, setupProjectFile=False, publishOutputs=True if args.output else False) # get init node and initialize it initNode = getInitNode(graph) @@ -140,8 +131,15 @@ with multiview.GraphModification(graph): graph.setVerbose(args.verbose) if args.output: - publish = getOnlyNodeOfType(graph, 'Publish') - publish.output.value = args.output + # if there is more than 1 Publish node, they will all be set to the same output; + # depending on what they are connected to, some input files might be overwritten in the output folder + # (e.g. if two Publish nodes are connected to two Texturing nodes) + publishNodes = graph.nodesOfType('Publish') + if len(publishNodes) > 0: + for node in publishNodes: + node.output.value = args.output + else: + raise RuntimeError("meshroom_batch requires a pipeline graph with at least one Publish node, none found.") if args.overrides: import json diff --git a/meshroom/core/graph.py b/meshroom/core/graph.py index 8acd9295..6469d1cf 100644 --- a/meshroom/core/graph.py +++ b/meshroom/core/graph.py @@ -241,7 +241,7 @@ class Graph(BaseObject): return Graph.IO.getFeaturesForVersion(self.header.get(Graph.IO.Keys.FileVersion, "0.0")) @Slot(str) - def load(self, filepath, setupProjectFile=True, importProject=False): + def load(self, filepath, setupProjectFile=True, importProject=False, publishOutputs=False): """ Load a meshroom graph ".mg" file. @@ -249,6 +249,9 @@ class Graph(BaseObject): filepath: project filepath to load setupProjectFile: Store the reference to the project file and setup the cache directory. If false, it only loads the graph of the project file as a template. + importProject: True if the project that is loaded will be imported in the current graph, instead + of opened. + publishOutputs: True if "Publish" nodes from templates should not be ignored. """ if not importProject: self.clear() @@ -284,6 +287,11 @@ class Graph(BaseObject): if "version" not in nodeData: nodeData["version"] = nodesVersions.get(nodeData["nodeType"], "0.0") + # if the node is a "Publish" node and comes from a template file, it should be ignored + # unless publishOutputs is True + if isTemplate and not publishOutputs and nodeData["nodeType"] == "Publish": + continue + n = nodeFactory(nodeData, nodeName, template=isTemplate) # Add node to the graph with raw attributes values diff --git a/meshroom/ui/graph.py b/meshroom/ui/graph.py index 3dfffd45..978bd554 100644 --- a/meshroom/ui/graph.py +++ b/meshroom/ui/graph.py @@ -350,9 +350,9 @@ class UIGraph(QObject): self._chunksMonitor.stop() @Slot(str, result=bool) - def loadGraph(self, filepath, setupProjectFile=True): + def loadGraph(self, filepath, setupProjectFile=True, publishOutputs=False): g = Graph('') - status = g.load(filepath, setupProjectFile) + status = g.load(filepath, setupProjectFile, importProject=False, publishOutputs=publishOutputs) if not os.path.exists(g.cacheDir): os.mkdir(g.cacheDir) self.setGraph(g) diff --git a/meshroom/ui/reconstruction.py b/meshroom/ui/reconstruction.py index 9706732f..9d04bc8e 100755 --- a/meshroom/ui/reconstruction.py +++ b/meshroom/ui/reconstruction.py @@ -488,9 +488,9 @@ class Reconstruction(UIGraph): self.load(p, setupProjectFile=False) @Slot(str, result=bool) - def load(self, filepath, setupProjectFile=True): + def load(self, filepath, setupProjectFile=True, publishOutputs=False): try: - status = super(Reconstruction, self).loadGraph(filepath, setupProjectFile) + status = super(Reconstruction, self).loadGraph(filepath, setupProjectFile, publishOutputs) # warn about pre-release projects being automatically upgraded if Version(self._graph.fileReleaseVersion).major == "0": self.warning.emit(Message(