示例#1
0
    def readCamerasFromScene(self, selected=False):
        """List all cameras in scene and check if they contains production attribute. If all attribute are set, put a new camera item in list.
        Continues without new camera item if already in ui.
        @param selected: only consider selected nodes
        @return: None
        """
        # list cameras
        if system.isMaya():
            cams = mc.ls(type="camera", sl=selected, l=True)
        else:
            raise (NotImplementedError)

        for cam in cams:
            # get attributes and continue if one was not found at the camera. assuming its not a shot camera
            context = self.getCameraAttributes(cam, {
                'cmp_show': None,
                'cmp_scene': None,
                'cmp_shot': None
            })
            if not context:
                continue

            # get db object
            cameraDB = db.query_asset_camera(context['cmp_show'],
                                             context['cmp_scene'],
                                             context['cmp_shot'])

            # check if camera already there
            if self.isCameraInList(cameraDB.get('id')):
                system.warning("Camera already in scene")
                continue

            # create list item
            camItem = CameraItem(
                cameraDB.get('id'),
                mc.listRelatives(cam, parent=True, f=False)[0])
            camItem.range = cameraDB.get('range')
            camItem.focalLength = cameraDB.get('focallength')
            if system.isMaya():
                camTransform = mc.listRelatives(cam, parent=True, f=True)[0]
                camItem.transform = mc.ls(camTransform, uuid=True)[0]
                camItem.shape = mc.ls(cam, uuid=True)[0]
            else:
                raise (NotImplementedError)

            # add to list
            self.cameras.append(camItem)

        self.populateCameras()
示例#2
0
 def __getMainWindow(self):
     """Receive main window from host application
     @return: None
     """
     if system.isMaya():
         return mayaMainWindow()
     else:
         raise (NotImplementedError)
示例#3
0
 def lookThrough(self, cam):
     """Look through given camera.
     @param cam: path to camera
     @return: None
     """
     if system.isMaya():
         dag = mc.ls(cam.transform, l=True)
         mc.lookThru(dag)
     else:
         raise (NotImplementedError)
示例#4
0
    def _createCamera(self, show, scene, shot):
        """Create a camera in the application based on shot info and put a new camera item in list. Don't create if already in ui.
        @param show: show name
        @param scene: scene name
        @param shot:  shot name
        @return: None
        """
        # get db object
        cameraDB = db.query_asset_camera(show, scene, shot)

        # check if camera already there and return
        if self.isCameraInList(cameraDB.get('id')):
            system.warning("Camera already in scene")
            return None

        # create
        if system.isMaya():
            cam = mc.camera(name=db.query_name(show, scene, shot))
        else:
            raise (NotImplementedError)

        # set attributes at shape node
        self.setCameraAttributes(cam[1], {
            'cmp_show': show,
            'cmp_scene': scene,
            'cmp_shot': shot
        })

        # list item
        camItem = CameraItem(cameraDB.get('id'), cam[0])
        camItem.range = db.query_camera_range(show, scene, shot)
        camItem.focalLength = db.query_camera_focallength(show, scene, shot)
        # path to nodes
        if system.isMaya():
            camItem.transform = mc.ls(cam[0], uuid=True)[0]
            camItem.shape = mc.ls(cam[1], uuid=True)[0]
        else:
            raise (NotImplementedError)

        # add to list
        self.cameras.append(camItem)
示例#5
0
 def getCameraAttributes(self, node, context):
     """Read camera information at the camera node within application
     @param node: path to the node shape or transform
     @param context: dictionary with production information to look for
     @return: dictionary context with attributes or None if one(!) is missing
     """
     assert isinstance(context, dict), "Argument not of type dictionary"
     context_read = {}
     for k in context.keys():
         if system.isMaya():
             if not mc.objExists("{0}.{1}".format(node, k)):
                 return None
             context_read[k] = mc.getAttr("{0}.{1}".format(node, k))
         else:
             raise (NotImplementedError)
     return context_read
示例#6
0
    def updateActiveCamera(self, frame):
        """Check if there is an current camera and if frame fits in it's range. Switch to next matching camera, if frame is outside current camera's range.
        @param frame: usually the frame value from timeline slider
        @return: None
        """
        if not self.currentCamera or not self.currentCamera.isInRange(frame):
            for c in self.cameras:
                if c.isInRange(frame):
                    self.currentCamera = c
                    self.lookThrough(self.currentCamera)
                    break

        # set app timeline
        if system.isMaya():
            mc.currentTime(frame - self.currentCamera.offset)
        else:
            raise (NotImplementedError)
示例#7
0
 def setCameraAttributes(self, node, context):
     """Write camera information at the camera node within application
     @param node: path to the node shape or transform
     @param context: dictionary with production information and id of the camera asset
     @return: None
     """
     assert isinstance(context, dict), "Argument not of type dictionary"
     for k, v in context.items():
         assert isinstance(v, basestring), "Value not of type string"
         if system.isMaya():
             if not mc.objExists("{0}.{1}".format(node, k)):
                 mc.addAttr(node,
                            shortName=k,
                            longName=k,
                            dt="string",
                            readable=True,
                            keyable=False,
                            writable=False,
                            hidden=False)
             mc.setAttr("{0}.{1}".format(node, k), v, type="string")
         else:
             raise (NotImplementedError)
示例#8
0
"""
import os

from blechmaya.libs import db
from blechmaya.libs import system
from blechmaya.libs import ui
from blechmaya.libs.decorators import *

import PySide2.QtGui as QtGui
import PySide2.QtCore as QtCore
import PySide2.QtWidgets as QtWidgets

from shiboken2 import wrapInstance

if system.isMaya():
    import maya.cmds as mc
    import maya.OpenMayaUI

ICON_HEIGHT = 16
ICON_VISIBLE = os.path.join(os.path.dirname(__file__), "icon_visible.png")
ICON_INVISIBLE = os.path.join(os.path.dirname(__file__), "icon_invisible.png")
ICON_TEXTURE_PREVIEW_DIM = 16
COLORFIELD_PADDING = 2
COLORFIELD_WIDTH = 40
FOCALFIELD_WIDTH = 60
RANGEFIELD_WIDTH = 80


def mayaMainWindow():
    """Returns the Maya window as a QMainWindow instance.