Topic outline

  • Kia ora Guest user

    Welcome to CGI506 Technical Development 1, S2-20. In this course you will be developing basic skills and knowledge of programming for animation and game development and to develop custom tools and functions for a successful production pipeline.

    On completion of this course you will be able to:

    1. Investigate and compare different programming languages used for animation, visual effects and real time applications. 
    2. Evaluate the effectiveness of different scripting/programming languages for selected applications. 
    3. Select and use a number of different scripting languages to achieve the desired effects and tools.  
    4. Create custom tools to facilitate a production scenario. 

    Alongside the class time and your project work, you will be provided with extra learning material, videos and tasks to help you improve your skills.  Work at your own pace spending roughly 4 hours a week on these. 

    All courses in this programme include an assessment of professionalism. Professionalism includes your active engagement in class activities, your ability to communicate with your peers and tutor, how you work in a team and more importantly how you manage your self.

    Usually we cover one session per week. Note this course content and schedule, may be adjusted as we understand more about our needs as a group of learners. 

  •  

    In this session we are going to be learning about Maya and Nuke APIs (Application Programming Interface) with a view towards equipping you to picking up any API you happen to look at. Maya and Nuke probably have the most commonly utilized interfaces in this industry.

    We are also going to be looking at more of Python’s built in functions that will help you along with your programs. 

    Getting started with Maya:

    Firstly, you have the ability to run single commands in Maya using the execution box: You can toggle between MEL and Python by pressing this button:

    Then you may run commands in the field immediately to the right of it, by typing in and pressing Enter.

    Secondly and more importantly, you have the script editor. Once open, click the “+” for a new tab, and press Python to open a Python tab if you don’t already have one open.

    This is where your MEL knowledge will come in handy, because almost any command you can run in MEL is also accessible by Python. Try it:

    from maya import cmds
    cube_parts = cmds.polyCube()

    Thirdly, you should familiarize with, and bookmark, any relevant reference material you need to lookup features you need. Autodesk documentation has pages on how to set up the environment for advanced users, but we’ll get back to that.

    (Instructors, be aware if these are the latest versions of the docs)

    PyMEL Documentation:

    http://help.autodesk.com/cloudhelp/2018/ENU/Maya-Tech-Docs/PyMel/why_pymel.html

    Our course here at NMIT is going to focus on PyMEL’s Custom API rather than Maya’s native cmds module. You should already have basic familiarity with the cmds module from your time spent with MEL.

    PyMEL gives a more pythonic, easier to understand, and easier to deploy approach to working with Python in Maya. It was developed by technical directors at Luma Pictures in California, and Autodesk was impressed enough by it to decide to include it with Maya by default.

    Maya Python & MEL commands Reference

    http://help.autodesk.com/cloudhelp/2018/ENU/Maya-Tech-Docs/Commands/

    Maya Scripting (Linked from the F1 help homepage)

    http://help.autodesk.com/view/MAYAUL/2018/ENU/?guid=GUID-703B18A2-89E5-48A8-988A-1ED815D5566F

    To do:

    Making tools in Maya:

    Don’t forget that to make tools in Maya, you can do this the same way as you would with MEL: by selecting text in the script editor, dragging and dropping into Shelf of Maya.

     At this point we would like you to use the following resources, please skip the Nuke material:

    Dragon-34167Here be (useful) dragons. Do the first in this series, use this as homework.

    "Building Maya Interfaces with Python: "

    https://vimeo.com/42848594

    See here for a link to a first go at including the LOADER.py

    https://drive.google.com/drive/folders/1-szGP2SDdY_6-s5D0cA5tW302dhZSokJ?usp=sharing

    The following set provides you with access to the full set.

    https://vimeo.com/showcase/2136748

    This SECTION IS UNDER REVIEW Getting started with Nuke:

    Nuke has a script editor much like Maya, which can be opened the same way as any panel.

    NUKE Python Developer’s Guide

    https://learn.foundry.com/nuke/developers/113/pythondevguide/

    And the Python Reference for commands:

    https://learn.foundry.com/nuke/developers/113/pythonreference/

    To do:

     

    Your first nuke tool:

    Let’s make a simple function which can be loaded into nuke at startup time and run by a shortcut key of our choosing.

    On Windows, navigate to -- ($USER should be replaced with your username)

    C:\Users\$USER\.nuke

    On linux or mac, the .nuke will be in your home folder.

    /home/$USER/.nuke

    Inside create an empty text file and name it “menu.py”. This will be a python script that is run on Nuke’s startup.

    Inside, write the following lines:

    import nuke
    import getpass


    user = getpass.getuser()
    user = user.capitalize()

    def make_cool_blur():
    b = nuke.nodes.Blur()
    b.setName('{}sAwesomeBlur'.format(user))

    nuke.menu('Nuke').addCommand('{}sMenu/make cool blur'.format(user), 'make_cool_blur()', 'ctrl+alt+m') 

    Now, run nuke and try pressing the “control+allt+M” key.

    Presto! You just wrote your first Nuke pipeline tool!

    There’s a few things going on here. getpass.getuser() can be used on any operating system to get the username of the current user. (This you can also do with the OS module, although that method can vary between operating systems)

    nuke.menu(), addCommand are both only found inside of Nuke's environment. menu() can be used to access any menu at the top of Nuke, the left-hand column of node menu icons, or even many of the right-click menus inside of Nuke.

    More information about menus and tools can be found in this documentation, it's worth reading.

    https://learn.foundry.com/nuke/developers/113/pythondevguide/custom_ui.html#creating-a-custom-menu-item

    This is the basic starting point of how studios or professional artists extend Nuke.

    A Graphic User Interface (GUI) teaser:

    Although we will not be exploring user interface libraries in detail during this course, I just want to give you a quick preview of how easy it will be to get started:

     from PySide import QtGui
    label = QtGui.QLabel("Hello World")
    label.show()

    If you run this in either Nuke or Maya’s script editor, you should see a small popup dialog with “Hello World” shown on it.

    Challenges:

    • Make a python function which does something in Nuke or Maya.

    • Brainstorm some ideas for tools that could automate tasks you do -- you’re going to want these ideas later. This could be duplicating something automatically, maybe porting something between applications,

     

    A local install:

    If you haven’t already, I would recommend installing python 2.7.15+ (3.x is OK too) locally on your machine to follow along with some of these examples which will be easier when you can access your local computer. (But not python 3.x unless your tutor recommends otherwise)

    https://www.python.org/downloads/release/python-2715/

    Let’s go on a walk :

    We’re going to look at os.walk which is used to list files and folders recursively.

    I am doing this in a local python interpreter which has access to my hard drive. You can do this exercise in any application script editor or standalone python interpreter.

    We’ll start with importing os and then running walk on a directory which has subfolders and files at different levels. I will approach it in an exploratory manner.

    >>> import os
    >>> os.walk(r'D:\1_DEV\Misc')
    <generator object walk at 0x04878698>

    Ah, now that’s interesting. Remember generators from our segment on iterables?

    It’s basically a deferred iterable -- instead of returning all of it’s items at once, it gives us a generator object which we can loop through, which will return as it goes. This is to defer and spread out processing time.

    So to see what this generator will return, I must either convert it into a list or iterate through it using a loop:

    >>> for t in os.walk(r'D:\1_DEV\Misc'):
    ...   print t
    ...
    ('D:\\1_DEV\\Misc', ['.idea'], ['PySide2_test.py'])
    ('D:\\1_DEV\\Misc\\.idea', ['inspectionProfiles'], ['Misc.iml', 'modules.xml', 'workspace.xml'])
    ('D:\\1_DEV\\Misc\\.idea\\inspectionProfiles', [], ['profiles_settings.xml'])

    Note that the parentheses indicate read-only tuples, and on each line we see three things: a string, followed by two lists.

    If you examine these closely, what do these correspond to?

    The first string gives you the path to a root directory, the following list gives a list of directories in the same root, and thirdly, a list of files in the same root directory.

    So what could we do with this? We could make a prank program that pretends to delete everything in a given path.

    The pseudo code for could look like this:

    Set path to root directory or user’s home folder
    Print scary message about self-destructing
    Run os.walk on path
    For each root string, list-of-files in os.walk,
    For each file in list-of-files,
    Add together path and filename to get full path
    Print scary deleting message with full path
    Print scary message that all is done and deleted

    You could even add a tally count of files “deleted”, and the total amount of bytes (divide by one million to get megabytes).

    The student who writes the scariest looking harmless program gets extra recognition:)

    Game Developers take note!

    If you are thinking about game development, I would recommend checking out Pygame or Pyxel. This is an excellent way to get your feet wet in basic game programming and algorithms, with the low level interfacing already taken care of for you. There are even tutorials to help you get started:

    https://www.pygame.org/

    https://www.pygame.org/wiki/tutorials

    Pyxel is simpler, and easier to learn.

    https://github.com/kitao/pyxel