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:
- Investigate and compare different programming languages used for animation, visual effects and real time applications.
- Evaluate the effectiveness of different scripting/programming languages for selected applications.
- Select and use a number of different scripting languages to achieve the desired effects and tools.
- 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.
-
We are going to talk about directory structure and laying out your Python programs. We will also look at how to set up the environment for Python, how we can import and execute other files in the directory structure and common troubleshooting tips. going.
First, let’s choose a folder on your local hard-drive to set up a new project.
You can call this folder “skeleton” and use it as a basis for future python projects- by copying, pasting and renaming.
Inside, create four directories, “bin”, “docs”, “python”, and “tests”. Inside of “python” and “tests”, create an empty text file and rename it to “__init__.py”.
It should look like this.
└───skeleton
├───bin
├───docs
├───python
└───skeleton
└───__init__.py
└───tests
└───__init__.pyThe name "skeleton" is just a placeholder, as you write Python programs you can copy the whole folder and rename them.
"bin" stands for binary, and simply is a folder for placing directly executable files and programs. Python scripts can go here, but usually only as pointers. The actual modules should go in the Python directory.
"docs" is for documentation, readme files and HTML documents can go here.
"tests" is for testing -- we may not get to this this year but you will be learning about it the future.
Note: Make sure you named the file “skeleton/__init__.py” and not “skeleton/__init__.py.txt”, which can happen easily if you’re on Windows.
What are the __init__.py files?
For Python to import a Python file (module) On disk, there are two conditions that have to happen:
-
The path to the folder must be in the environment variable “PYTHONPATH”. This can be done before running your program or while running your program, so long as it is before the import. We’ll show you how to do this.
-
The folder must contain a “__init__.py” file. Python will look for this to indicate that this folder is a python module.
So let’s do test to show how this all works.
Take your skeleton folder, and rename both it and the “skeleton” folder inside to “SwedishChef” or something similarly amusing.
Inside of the formerly named “skeleton” folder (this is the second, inside folder, not the top-level one) that you renamed, next to the __init__.py file create a file called “jokes.py”.
Inside, we’re going to write a function (or class, if you prefer).
import random
jokes = [
"I don't always herdy dur mur flerpty floopin; but when I do, I yer der shmer dor her der foomty, der shoopin flerpty dur.",
"We're goofing dur flicky stuben der bork bork bork you betcha",
"I leeke-a pythun prugremmeeng, it's fuonner thuon shefing yeks",
]
def random_joke():
# Remember, indexes start from
return jokes[random.randint(0, 2)]Then fire up your interpreter, or favourite Script Editor in Nuke/Maya.
We are going to extend the PYTHONPATH while using python, before running the import. If you know how, you could also set the PYTHONPATH before running the application (interpreter, Nuke, Maya, etc).
import sys
# sys.path is built from the environment variable PYTHONPATH, same thing
sys.path.append(r'D:\1_DEV\NMIT_Project\SwedishChef\python')
from SwedishChef import jokes
dir(jokes)This should give you something like:
# Result: dir(jokes)
# Result: ['__builtins__', '__doc__', '__file__', '__name__', '__package__', 'jokes', 'random', 'random_joke']We imported our own module, and can see our functions inside.
Now we could run jokes.random_joke() directly or we could import that first.
from SwedishChef.jokes import random_joke
random_joke()
# Result: "I don't always herdy dur mur flerpty floopin; but when I do, I yer der shmer dor her der foomty, der shoopin flerpty dur."It’s working!
Here we are giving python the path to the folder with a python module inside. What makes a python module? Another folder with __init__.py found inside.
So for directories to be discovered by Python as modules, they must contain __init__.py. I hope I’ve made that clear! I’ve been caught out many times, wondering “why can’t Python import my module?” only to realize I forgot to put this file inside.
Requirements Gathering:
From Infogalactic (Wikipedia):
In requirements engineering, requirements gathering is the practice of collecting the requirements of a system from users, customers and other stakeholders.
I like to think of requirements gathering as figuring out what it is my program needs to do, and if I have the knowledge to implement it. At a company it may mean talking to the related staff who have an interest in your program. But on an individual level, it means researching if you can do what you plan to in python. Let’s say you wanted to write an auto-rig script for Maya. Planning would involve answering questions like “can I create and place joints in 3D space?” and “can I structure them in a hierarchy to do what I want?”.
Homework:
We are also going to be looking at more of Python’s built in functions that will help you along with your programs.
Built-ins: These keywords already defined in python, and some of them you’ve already seen. Don’t worry if same are beyond you, they’ll make sense later.
- range
- and
- del
- from
- not
- while
- as
- elif
- global
- or
- with
- assert
- else
- if
- pass
- yield
- break
- except
- import
- class
- exec
- in
- raise
- continue
- finally
- is
- return
- def
- for
- lambda
- try
Go through the list and research which ones you don’t know, and do an internet search to find out more about them. Take notes so you can refresh your memory down the road. It’s not important to know every one, but to have an overview, and to understand the idea behind it.
To search, you can just add “python” as a keyword, e.g. “python exec”.
Assessment Brief : Designing efficient production pipeline
Brainstorm, design, layout the folder structure, and pseudocode a tool of your design.
First brainstorm a list of ideas that you have for tools, and anything goes. The objective is to brainstorm as many ideas as possible, big or small, good or bad, without yet judging the ideas.
Secondly, narrow down your list of ideas, and do some research (documentation, internet) around how to implement what you want to do in python, if it so possible, which modules you’d need to use to accomplish this. This is a form of requirements gathering.
Lay out a directory structure for your tool which can be imported into Nuke or Maya or any python environment. Application integration is optional for this assessment.
Then finally pseudocode your application in detail to demonstrate you understand the work to be undertaken. This assessment is the design portion of your project, which you will next develop.
-