Example #1
0
 def init(self):
     self.engine = sgtk.platform.start_engine("tk-vred", self.context.sgtk,
                                              self.context)
     file_to_open = os.environ.get("SGTK_FILE_TO_OPEN", None)
     if file_to_open:
         vrController.newScene()
         vrFileIO.load(file_to_open)
Example #2
0
def add_tool(name, code, script_ext=None, file=None):
    '''
    Adds a tool the current scene.
    Injects a Variantset with tool code, and extends the script editor
    with some setup code.
    Only injects if a Variantsame with the tool name does not already 
    exist, otherwise it's assumed the tool is loaded
    '''

    # Bail if stuff is already loaded
    if "VRTools_{}".format(name) in vrVariantSets.getVariantSets():
        return

    inject_script_variant("VRTools_{}".format(name), code)

    if file:
        vrFileIO.load(os.path.join(plugin_path(), file))

    # Hacky way to extend the editor script
    if script_ext:
        tempdir = tempfile.mkdtemp()
        filepath = os.path.join(tempdir, "scripts.py")
        vrFileIO.save(filepath)
        with open(filepath, 'a') as scripts_file:
            scripts_file.write(script_ext)
        vrFileIO.load(filepath)
        shutil.rmtree(tempdir)
Example #3
0
    def connect(self):
        if not self.paused:
            print "Already connected"
            return

        if not self.initialized:
            print "Init Leap"
            self.init_leap()

        print "Starting Leap"

        # Check if there are actually hands in the scene, and add hands if not
        # Only checks for hand root, not each bone
        if vrScenegraph.findNode("Hands").isValid():
            print "Hands found"
        else:
            print "Import hands structure"
            if vr_cam_name:
                cam_node = vrScenegraph.findNode(vr_cam_name)
            else:
                cam_node = vrCamera.getActiveCameraNode()
            vrFileIO.load(filenames=[os.path.join(plugin_path(), "Hands.osb")],
                          parent=cam_node,
                          newFile=False,
                          showImportOptions=False)

        self.build_hand_structure()
        self.paused = False
        self.leap_controller.set_paused(self.paused)
Example #4
0
    def load_file(self, file_path):
        """Load a new file into VRED. This will reset the workspace."""
        can_load = self._engine.execute_hook_method("file_usage_hook",
                                                    "file_attempt_open",
                                                    path=file_path)

        if not can_load:
            return

        self.logger.debug("Loading file: {}".format(file_path))
        vrFileIO.load(file_path)
        self.set_render_path(file_path)
Example #5
0
    def init(self):
        engine = sgtk.platform.start_engine("tk-vred", self.context.sgtk,
                                            self.context)

        # Set the version text in the plugin dialog once the engine is initialized
        self.version_label.setText("tk-vred {}".format(engine.version))

        file_to_open = os.environ.get("SGTK_FILE_TO_OPEN", None)
        if file_to_open:
            vrFileIO.load(
                [file_to_open],
                vrScenegraph.getRootNode(),
                newFile=True,
                showImportOptions=False,
            )
    def importCamera(self):
        check = vrScenegraph.findNode("ADSK_Turntable_Offset")
        checkname = check.getName()
        print checkname
        node = vrScenegraph.getSelectedNode()
        center = vrNodeUtils.getBoundingBoxCenter(node, 1)

        if checkname == "ADSK_Turntable_Offset":
            print("Camera already exists in your Scene")
        else:
            print("Camera is loaded into your Sceen")
            vrFileIO.load("C:/temp/SG_ADSK_Turntable_Offset.osb")

        vrScenegraph.findNode("ADSK_Turntable_Offset").setTranslation(
            center.x(), center.y(), center.z())
        print "Camera was moved to", center
        vrCamera.jumpViewPoint("ICV")
Example #7
0
    def _load_for_review(self, sg_data, confirm_action=False):
        """
        Find an associated published file from the entity defined by the `sg_data`,
        and load it into VRED.

        :param sg_data: The ShotGrid data for the entity to load for review.
        :type sg_data: dict
        :param confirm_action: True will ask the user to confirm executing this action,
                               or False to execute the action immediately.
        :type confirm_action: bool
        :return: True for success, else False
        :rtype: bool
        """

        # The current entity. This entity dictionary will be the return value to
        # trigger a context change in SG Panel to this entity.
        entity = {"type": sg_data["type"], "id": sg_data["id"]}

        # Load for review action only supports Version entity type
        if sg_data["type"] != "Version":
            return True

        # Ask the user if they want to proceed with loading the Version for review.
        if confirm_action:
            answer = QtGui.QMessageBox.question(
                None,
                "Load for Review?",
                "Do you want to load this {} for review?".format(
                    sg_data["type"]),
                QtGui.QMessageBox.Yes | QtGui.QMessageBox.No
                | QtGui.QMessageBox.Cancel,
            )

            if answer == QtGui.QMessageBox.Cancel:
                # Abort this action altogether.
                return False

            if answer == QtGui.QMessageBox.No:
                # Continue this action but do not load for review.
                return True

        # Check for unsaved changes and do not load new scene until changes are resolved.
        engine = self.parent.engine
        resolved = engine.save_or_discard_changes()
        if not resolved:
            return False

        # OK to proceed with loading the Version for review
        published_file_entity_type = sgtk.util.get_published_file_entity_type(
            self.sgtk)
        accepted_published_file_types = engine.get_setting(
            "accepted_published_file_types", [])
        published_files = self.parent.engine.shotgun.find(
            published_file_entity_type,
            [
                ["version", "is", entity],
                [
                    "published_file_type.PublishedFileType.code",
                    "in",
                    accepted_published_file_types,
                ],
            ],
            fields=["id", "path"],
            order=[{
                "field_name": "version_number",
                "direction": "desc"
            }],
        )

        if not published_files:
            raise sgtk.TankError(
                "Version has no published files to load for review.")

        if len(published_files) != 1:
            raise sgtk.TankError(
                "Failed to load Version for review with VRED because there is more than one PublishedFile entity with the same PublishedFileType associated for this Version"
            )

        # Load the Version's "latest" PublishedFile, the one with the highest version.
        published_file = published_files[0]
        if published_file:
            path = _get_published_file_path(published_file)
            if not path:
                raise sgtk.TankError(
                    "Unable to determine the path on disk for published file with id '{}'."
                    .format(published_file["id"]))

            QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)
            vrFileIO.load(
                [path],
                vrScenegraph.getRootNode(),
                newFile=True,
                showImportOptions=False,
            )
            QtGui.QApplication.restoreOverrideCursor()

        return True
    def execute(self,
                operation,
                file_path=None,
                context=None,
                parent_action=None,
                file_version=None,
                read_only=None,
                **kwargs):
        """
        Main hook entry point

        :param operation:       String
                                Scene operation to perform

        :param file_path:       String
                                File path to use if the operation requires it (e.g. open)

        :param context:         Context
                                The context the file operation is being performed in.

        :param parent_action:   This is the action that this scene operation is being executed for.

        :param file_version:    The version/revision of the file to be opened.

        :param read_only:       Specifies if the file should be opened read-only or not

        :returns:               Depends on operation:
                                'current_path' - Return the current scene file path as a String
                                all others     - True for success, else False
        """

        self.logger.debug(
            "{self} executing operation '{op}' on file '{path}'".format(
                self=self, op=operation, path=file_path))

        success = True

        if operation == "current_path":
            current_path = vrFileIO.getFileIOFilePath()
            return "" if current_path is None else current_path

        if operation == "open":
            vrFileIO.load(
                [file_path],
                vrScenegraph.getRootNode(),
                newFile=True,
                showImportOptions=False,
            )
            self.parent.engine.set_render_path(file_path)

        elif operation == "save":
            if file_path is None:
                file_path = vrFileIO.getFileIOFilePath()

            self.parent.engine.save_current_file(file_path)

        elif operation == "save_as":
            self.parent.engine.save_current_file(file_path)

        elif operation == "reset":
            success = self.parent.engine.save_or_discard_changes(
                override_cursor=QtCore.Qt.ArrowCursor)
            if success:
                vrController.newScene()

        return success