Category: Maya

First PySide Application

GOAL

To understand Qt and PySide(PySide2) and create PySide application that

Emvironment

WIndows10
Python2.7.8

*I use python2 because python3 can’t be used in Maya, but I think python3 is better for general application development. And PySide2 which is used in Maya2017~ is easy to use in python3.

What is Qt?

Qt is a cross-platform application framework with many modules providing services like network abstraction and XML handling, along with a very rich GUI package.

Though Qt is developed in C++, it can be used in Python, Java, Perl and so on with API. The application developed with Qt can be executed in any platform such as Windows, Linux, macOS, desktop and mobile.

Qt has been upgraded constantly, and the latest version in 2020 is Qt5.

What is PySide?

PySide is the python module as a Python binding of Qt. Functions, variables and modules of Qt can be used in Python via PySide. GUI application can be developed on multi platform, windows, Linux and macOS using Python with PySide.

PySide and Pyside2

PySide2 is upgraded PySide. PySide2 provides access to the Qt 5 framework while PySide provide access to Qt4 or below. Qt4 and PySide can be used in Maya2016 and before, Qt5 and PySide2 is used in Maya2017 and after.

If you are using python2, it’s easy to install PySide by using pip install, but you should build PySide2 by yourself. So If you want to use PySide2, please use python3 and its pip install.

The difference between PySide and PyQt

PyQt is also one of the python modules as a Python binding of Qt. The document “Differences Between PySide and PyQt” is clear and detailed. And “PyQt vs Pyside” is easy to understand their advantages and disadvantages.

Method

The following is the method to create your first PySide application. This is for PySide so please replace words for PySide2 if you need.

Install PySide

Open Command prompt and input pip command. In my case, ‘pip2’ is used because python3 is installed and the command just ‘pip’ is equal to pip3.

> pip2 install pyside

Check if PySide is successfully installed.

>py -2
Python 2.7.8....
>>> import PySide
>>> PySide.__version__
'1.2.4'
>>>

Hello World

This is an application program to display HelloWorld.

import sys
from PySide.QtCore import *
from PySide.QtGui import *

#Create QApplication
firstApp = QApplication(sys.argv)
# Create a Label
label = QLabel("Hello World")
label.show()
# Enter Qt application main loop
firstApp.exec_()
sys.exit()

Execute and small window will appear.

QtGui

QtGui module contains classes that control widgets of PySide. Widget is a UI component that is used in GUI application such as button, label, Matrix, Layout and so on. You can see all class in PySide.QtGui.

Create Widget

You can create original widget as a Class. Add single widgets into QVBoxLayout.

import sys
from PySide.QtCore import *
from PySide.QtGui import *

class MyWidget(QWidget):
    def __init__(self):
        super(MyWidget, self).__init__()
        self.text = QLabel("Say Hello")
        self.text.setAlignment(Qt.AlignCenter)
        self.edit = QLineEdit("who?")
        self.button = QPushButton("Click here")
        self.output = QLabel("")
        self.layout = QVBoxLayout()
        self.layout.addWidget(self.text)
        self.layout.addWidget(self.edit)
        self.layout.addWidget(self.button)
        self.layout.addWidget(self.output)
        self.setLayout(self.layout)
        self.button.clicked.connect(self.sayHello)

    def sayHello(self):
        self.output.clear()
        self.output.setText("Hello " + self.edit.text()+"!")
        
if __name__ == '__main__':
    app = QApplication(sys.argv)

    widget = MyWidget()
    widget.resize(300, 100)
    widget.show()
    widget.setWindowTitle("My Widget Test")
    sys.exit(app.exec_())

This is the window. Input name into line edit and click the button.

Then name you enter in the field is displayed.

How to create C++ Plugin for Maya

GOAL

To set up the environment for C++ Maya plugin. To build sample plug-in and execute it.

Environment

Maya 2018
Maya 2018 Update 6 win64 DevKit
Windows10 with environment for C++ compile
Microsoft Visual C++ 2017 ver15.8.4

Method

Get Maya DevKit

Access Maya Developer Center. And scroll down to click “Maya <version> Update 6 win64 DevKit”. Then unzip the file.

Setting up the build environment

Refer to Autodesk Maya Document “Setting up your build environment“.

Add the 3 directories, \devkit , \mkspecs in devkitBase into Maya installation directory (e.g. C:\Program Files\Autodesk\Maya2018).

* To compile custom plug-ins, you can also find the C++ API header files(\include\maya ) and libraries(\lib).

Build enclosed plug-ins in Visual Studio

Open devkit/plug-ins folder( either maya installation folder or newly created folder where plug-in folder is copied and put would be fine). I create a folder named “maya_cpp_plugin” and copy plug-in files to the new folder.

Find “Hello World Cmd” and open it.

Add folder “include” into the list of include directories for Visual Studio. Right Click the name of project name and open Properties.

Then, add ” C:\Program Files \ Autodesk\Maya2018\include” into the Additional Include Directories.

Add ” C:\Program Files\Autodesk\Maya2018\lib” into Additional Library Directories.

Open solution file *.sln, then Visual Studio will start up. Click Build > Build Solution.

The output files are in the directory maya_cpp_plugin\helloWorldCmd\x64\Release(or Debug). “helloWorldCmd.mll” is the main plugin file.

Plug-in installation

Refer to Autodesk Maya Document “Installing a Maya plug-in“.

Add plugin helloWorldCmd.mll to the plug-in directory defined as MAYA_PLUG_IN_PATH in <username>\Documents\maya\<version>\Maya.env file. If Maya.env doesn’t exist, create it according to “Setting environment variables using Maya.env“.

Start Maya and open Plug-in Manager.

Click a check mark next to helloWorldCmd.mll

Execute the Plug-in with command

Open Script Editor and execute the Command “helloWorld”.

The message “helloWorld” is displayed on the console, upper side of the Script Editor.

What is color manager

GOAL

To understand color space and color manager.

What is color manager?

Color manager (also called “color management system” or “management solution”) is an application to change the color space of image and video.

In VFX production, many color spaces are used according to the tools such as digital cinema camera, rendered CG, photos and matte paint. it is necessary to unify or convert the color space. Color space conversion is an important process in VFX production.

What is color space?

Color space is a specific organization of colors in which colors are represented as coordinates.

Color model

Color model is an abstract mathematical model describing colors with some channels ( e.g. RGB, CMYK). Although color model is not the same thing as color space, some color system such as Adobe RGB and sRGB are based on color model.

Representative color space

Color spaces in Adobe Photoshop Color Picker
Comparison of some RGB and CMYK colour gamut on a CIE 1931 xy chromaticity diagram, based on http://commons.wikimedia.org/wiki/File:CIE1931xy_blank.svg and data from Blatner and Fraser’s “Real World Photoshop CS”, p179: http://canopuscomputing.com.au/gallery2/d/8631-1/Gamuts_comparison-B_F.jpg . ( CC BY-SA 3.0 )

sRGB

sRGB (standard Red Green Blue) is an RGB color space to use mainly on monitors, printers, and the Internet. The color gamut that can be represented in this method is the color triangle defined by three primary colors, Red, Green and Blue.

CIE 1931 xy chromaticity diagram showing the gamut of the sRGB color space and location of the primaries.( CC BY-SA 3.0)
* This image is colored in sRGB space, so the colors outside of the triangle are interpolated.

Adobe RGB

Adobe RGB is a color space definition proposed by Adobe Systems. It has a wider RGB color reproduction range than sRGB (especially green), designed to cover most of the colors achievable with CMYK color printers. It encompasses about 50% of the visible colors specified in the CIELAB color space.

The CIE 1931 xy chromaticity diagram showing the primaries of the Adobe RGB (1998) color space. The CIE Standard Illuminant D65 white point is shown in the center.( CC BY-SA 3.0)

NTSC (BT.601)

NTSC Color Space is designed for television. It features a color gamut that is much wider than sRGB.While NTSC is not used in modern displays, it is commonly used to compare and specify color gamut.
This is also one of the major television formats in the world including PAL, SECAM.

Rec.2020

ITU-R Recommendation BT.2020 aka Rec.2020 or BT.2020 defines various aspects of ultra-high-definition television (UHDTV) with standard dynamic range (SDR) and wide color gamut (WCG).
It defines picture resolutions, frame rates with progressive scan, bit depths, color primaries, RGB and luma-chroma color representations, chroma subsamplings, and an opto-electronic transfer function. full HD and HDR are not supported.

Rec.2100

Rec.2100 is upward compatible with Rec.2020. ITU-R Recommendation BT.2100 aka Rec.2100 or BT.2100 is an international standard for specifications that must be met by devices that handle full HD(2K), 4K and 8K resolutions. It was established by the International Telecommunication Union Wireless Communication Sector (ITU-R).

CMYK(or just CMY)

CMYK uses subtractive color mixing used in the printing process.
CMYK corresponds to Ink colors, Cyan, Magenta, Yellow and Black.

HSV 

HSV(HueSaturationValue) is used for painting or color sample on computers. Painting artists use it because it is more natural and intuitive to consider colors in terms of hue, color and saturation than additive mixing or subtractive mixing. HSV is a transformation of an RGB color space. HSV is also called HSB (hue, saturation, brightness).

HSL

HSL (hue, saturation, lightness / luminance) is quite similar to HSV, with “lightness” replacing “brightness”. The difference is a value calculation method. HSV uses a hexagonal pyramid model in which the brightness of pure color is equal to the brightness of white, while HLS uses a bi-hexagonal pyramid model in which the brightness of pure color is 50% of the brightness of white.(Please refer this image). It is also called HSI (hue, saturation, intensity).

LMS

LMS color place is based on three kinds of cone cells that human eye with normal vision has. These cone cells sense light and have peaks of spectral sensitivity in Short wavelength, Middle wavelength and Long wavelength.
The three parameters corresponding to levels of stimulus of the three kinds of cone cells(L, M, S) describe any human color sensation. So LMS color space can contain all visible colors.
However LMS is not objective representation of colors because parameters L, M and S is different between people and emvironment.

CIE 1931 color spaces

CIE (Commission internationale de l’éclairage, the International Commission on Illumination) is the organization that creates international standards related to light and color.
CIE 1931 color spaces is the first defined quantitative relations between distributions of wavelengths in the electromagnetic visible spectrum, and physiologically perceived colors.

The CIE XYZ is remap of the color space in which the tristimulus values ​​are conceptualized as amounts of three primary colors.These primary colors are unvisible for human. The CIE XYZ color space is designed so that Y component corresponds to luminance.
CIE XYZ can contain all visible colors.While RGB can’t represent some of visible colors without using negative value, CIE XYZ can contain all visible colors in positive quadrant.

Why is color management needed?

©2020 Nako

When you transfer exported video to another media, color gamut remapping, gamma correction, setting of white chromaticity (white point) are required and so on.

What is ACES?

ACES(Academy Color Encoding System) is a color image encoding system created under the auspices of the Academy of Motion Picture Arts and Sciences. The system defines its own primary color that encompass the visible spectral locus as defined by the CIE xyY specification.

When you use ACES in Video editing software such as Adobe AfterEffects , Maya and Nuke, color manager is needed. Color manager is usually provided as a plugin or built-in function.

Representative Color manager

OpenColorIO

OpenColorIO (OCIO) is a complete color management solution geared towards motion picture production with an emphasis on visual effects and computer animation.

OpenColorIO official web site( https://opencolorio.org/ )

OCIO is compatible with ACES and is LUT-format agnostic, supporting many popular formats.

SynColor

SynColor is the Autodesk Color Management component.

Adobe Color Management Module(CMM)

CMM is color manager for Adobe software such as Photoshop.