mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-05-19 03:56:26 +02:00
Import a scene from an .mg file into the current graph
Add an "Import Scene" (Ctrl+Shift+I) option in the File menu that allows to select an existing .mg file and import it in the current graph. The imported scene will automatically be placed below the lowest existing node along the Y axis.
This commit is contained in:
parent
ede24713d0
commit
a33f79e4d7
4 changed files with 159 additions and 3 deletions
|
@ -7,7 +7,7 @@ from PySide2.QtCore import Property, Signal
|
|||
|
||||
from meshroom.core.attribute import ListAttribute, Attribute
|
||||
from meshroom.core.graph import GraphModification
|
||||
from meshroom.core.node import nodeFactory
|
||||
from meshroom.core.node import nodeFactory, Position
|
||||
|
||||
|
||||
class UndoCommand(QUndoCommand):
|
||||
|
@ -216,6 +216,37 @@ class PasteNodeCommand(GraphCommand):
|
|||
self.graph.removeNode(self.nodeName)
|
||||
|
||||
|
||||
class ImportSceneCommand(GraphCommand):
|
||||
"""
|
||||
Handle the import of a scene into a Graph.
|
||||
"""
|
||||
def __init__(self, graph, filepath=None, yOffset=0, parent=None):
|
||||
super(ImportSceneCommand, self).__init__(graph, parent)
|
||||
self.filepath = filepath
|
||||
self.importedNames = []
|
||||
self.yOffset = yOffset
|
||||
|
||||
def redoImpl(self):
|
||||
status = self.graph.load(self.filepath, setupProjectFile=False, importScene=True)
|
||||
importedNodes = self.graph.importedNodes
|
||||
self.setText("Import Scene ({} nodes)".format(importedNodes.count))
|
||||
|
||||
lowestY = 0
|
||||
for node in self.graph.nodes:
|
||||
if node not in importedNodes and node.y > lowestY:
|
||||
lowestY = node.y
|
||||
|
||||
for node in importedNodes:
|
||||
self.importedNames.append(node.name)
|
||||
self.graph.node(node.name).position = Position(node.x, node.y + lowestY + self.yOffset)
|
||||
|
||||
return status
|
||||
|
||||
def undoImpl(self):
|
||||
for nodeName in self.importedNames:
|
||||
self.graph.removeNode(nodeName)
|
||||
self.importedNames = []
|
||||
|
||||
class SetAttributeCommand(GraphCommand):
|
||||
def __init__(self, graph, attribute, value, parent=None):
|
||||
super(SetAttributeCommand, self).__init__(graph, parent)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue