Dynamic Object Properties and Stylesheets: PyQt PySide

Dynamic Object Properties and Stylesheets: PyQt PySide

Qt, and by extension, PyQt and PySide, offers the ability to style widgets based on properties of that widget.
For example, you could style buttons differently based on whether it is clicked, whether it’s good or bad, or any other arbitrary property that you set.

Dynamic Properties

Qt  supports custom properties on objects by using the setProperty method.


QObject.setProperty('PropertyName', value)

Usually you’d want to restrict this to just be booleans, but it supports anything that can be cast into a QVariant like a string or int etc.
This is really handy if you want to store attributes on the widget but it is incredibly useful when you want to use it to toggle stylesheet styles on an object as the rest of my post will hopefully demonstrate.

QStylesheets

Stylesheets are the Qt equivalent to CSS on the web.
Qt uses a similar box model, which has the advantage of both being very familiar to anyone who’s done web, but also means you can lift a lot of CSS examples and use them easily.

An example of this to make a button with a red font color and black background:


QPushButton{
 color: #F00;
 background-color: #000;
}

You can read more about them here: http://doc.qt.io/qt-5/stylesheet-examples.html

But the really cool thing is that stylesheets can be coupled with dynamic properties to do state based styles.
So for example I want to only have the above when a Test property is True


QPushButton[Test=true] {...}

You might be wondering why true is lowercase. This is because Qt is a C++ app and true is lowercase there.

How about if I only want it to affect a button with an object name StyledButton and only when the state is True?


QPushButton#StyledButton[Test=true] {...}

So it can be really useful for defining all your styles in one place and then simply updating the property later and calling an update function.

Updating On Property Changes

Unfortunately Qt doesn’t automatically hook up property changes to style changes, so you need to call a simple update function after.
This is very easy and there are two ways you can do this:


# Option 1
myWidget.setStyle(myWidget.style())

#OR

# Option 2
myWidget.style().unpolish(myWidget)
myWidget.style().polish(myWidget)
myWidget.update()

Personally I prefer the first one since it’s a one liner, but just presenting both options here for you in case you want more control over the process.

Putting It All Together

You can run this code.
It will generate a QDialog with two buttons.
The stylesheet in this example affects both buttons when Test=true, but additionally affects the button with the name StyledButton differently than the other one.
Because of style inheritance, the StyledButton inherits the style of the generic button with Test=True but also it’s own overrides

This example uses PyQt4, but the same applies for PyQt5, PySide, PySide2 etc…
If you’re using the Qt5 bindings (PyQt5 or PySide2) you need to use QtWidgets instead of QtGui


class Test(QtGui.QDialog):
    """A sample widget to show dyanmic properties with stylesheets"""
    def __init__(self):
        # Do the usual
        super(Test, self).__init__()
        self.setWindowTitle('Style Sheet Test')
        layout = QtGui.QVBoxLayout(self)

        # Set the stylesheet
        self.setStyleSheet("""
            QPushButton[Test=true] {
                border: 2px solid #8f8f91;
                border-radius: 6px;
                background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                      stop: 0 #f6f7fa, stop: 1 #dadbde);
                min-width: 80px;
            }

            QPushButton#StyledButton[Test=true] {
                color: #F00;
                background-color: #000;
            }
                           """)

        # Create the button
        btn = QtGui.QPushButton('Click Me')
        btn.setProperty('Test', True)
        btn.setObjectName('StyledButton')
        btn.clicked.connect(lambda: self.toggle(btn))
        layout.addWidget(btn)

        btn2 = QtGui.QPushButton('Click Me')
        btn2.setProperty('Test', True)
        btn2.clicked.connect(lambda: self.toggle(btn2))
        layout.addWidget(btn2)

    def toggle(self, widget):
        # Query the attribute
        isTest = widget.property('Test').toBool()
        widget.setProperty('Test', not isTest)

        # Update the style
        widget.setStyle(widget.style())

if __name__ == '__main__':
    app = QtGui.QApplication([])
    dlg = Test()
    dlg.show()
    app.exec_()

Anyway that’s it for this little introduction. Hope you find that useful!

MEL For Maya

MEL For Maya

MEL For Maya

After the unexpected popularity of my Python For Maya programming course, I had a lot of requests to do a course for MEL.

So here it is, FREE for anyone to access. There’s over an hour of content that goes over the basics of everything you need to know in MEL. It’s not as in depth as the 8 hour Python course, but it should get you up and running with MEL pretty quickly.

Introduction To MEL

In this first video, we are introduced to MEL and compare it Maya’s other programming languages. We also learn how to use the script editor and write our very first, simple script.

 

Learn Python



If you're interested in learning more about Python, why not sign up for my course here?

This course takes you from learning the fundamentals of Python, to creating tools with advanced user interfaces, all while creating projects you can use immediately.
It will teach you many of the skills necessary to create tools like the ones in this article.

With over 700 students in its' first week, including artists from major studios, it is sure to provide valuable knowledge to everyone.


Python For Maya: Artist Friendly Programming - $70 $90
 

If you sign up from this link, it will save you $20 off the retail price using the coupon code: DGOVILCOM

Learning By Doing

Maya uses MEL for pretty much everything we interact with. It also tells us every MEL command it runs.

We can use that to learn how to script by using Maya like we normally would, and in this video I teach you to take those commands, how to understand them and finally how to modify them to do what you want.

Variables

In this video we learn about using variables. Variables allow us to give names to our data to refer to it easily. In this video we learn about the different types of variables in Maya and how we can use them.

Comments

Comments are really useful while coding, because they let us leave notes to ourselves for the future. That way if we come back to code tomorrow, or in a few weeks or even many years, it’s easy to pickup where we left of.

If Statements

In this video, we’ll be going over how to make our code smarter by being able to deal with different situations. I’ll be going over the If/Else statement, the ternary operator and switch cases.

Loops

In this video we’ll learn how to use Loops in MEL to iterate over ranges of values or arrays. I’ll be going over the For loop, For Each, While and Do While loops.

Putting It All Together

Now that we’ve learned a lot of the basic skills we need to write a MEL script, let’s put everything we’ve learned together to make a script. Our script will rig any selected objects as a prop for animation.

Functions

Probably the biggest tentpole of programming, functions let us group our code together into reusable chunks.

Saving Scripts and Scopes

Now that we’ve written some code that we want to reuse, we’ll probably want to save it for use later. In this video we’ll go over how to save your scripts and then how to source them.

This naturally brings us to another issue called scopes and we’ll go over the access scopes of functions and variables, and how to best use the global keyword.

User Interfaces

Making command line scripts is one thing, but everyone loves to use pretty interfaces! In this video, I’ll be going over how to make a simple window with a few buttons.

External Editors

We’ll quickly be outgrowing the Maya script editor. It’s limited and if Maya crashes, we lose all our work. Instead lets go over how to setup an external code editor that will make for a much nicer coding experience.

Visual Studio Code is a free, multi-platform editor from Microsoft and we’ll learn how to set it up to edit MEL.

Mixing Python and MEL

Sometimes you need to mix languages, because what you’re trying to do is either easier in the other language, or just straight up not possible in your current language. I’ll be going over how to run Python code from MEL, and how to execute MEL code from within Python.

Thanks!

If you’ve made it this far, I’d like to thank you for watching! Even if you just watched one video, thank you for giving it the time.

If you feel like you want to learn more about programming, check out my Python for Maya course. I have thousands of students in the first two months of it being up, with artists from major film and games studios enrolled as well.

Chasing Efficiency In Programming

Chasing Efficiency In Programming

There’s something I’ve been trying to achieve this year. Really, it’s something we all try and achieve, but it’s something I’ve been giving more thought to lately. Efficiency.

That’s dumb though, who tries to not be efficient? Why would you act against your own interests of time? Well, the answer I find is, a lot of us are less efficient than we can be. Specifically today I would talk as a software developer and efficiency in programming.

So let’s set up a scenario. We’ve just hired two new developers who are completely equal in skill. Let’s call them Linda and Tina. We give them similar tasks. Linda gets her task done in a single day, whereas Tina takes two days to finish her task. Who was more efficient? It’s not such a simple answer.

In the pursuit of speed, Linda may have inadvertently been the less efficient of the two. Let’s go over why.

“There Was No Time For Clean Code”

This is an obvious one. Just because you’re faster doesn’t mean you write clean code.

Often a lot of the code reviews I give at work end up being caused by the developer trying to get the task done as quickly as possible. Sometimes this is valid, sometimes you do really need to just get it out as soon as possible, but at what cost?

Common issues are blocks of code that have been copied all over the place, or hard-coding values in place when it’s better to have done it programmatically. Sometimes it’s just variable names that make no sense or dumping your code inside existing code without stopping to do minor refactors.

Again, this can be valid sometimes. Sometimes you do not have the time to write good code, but instead ship whatever is working. It does make a lot of people happy too even if there aren’t strict deadlines. You have happy managers for meeting targets ahead of schedule and it makes the developer look good.

That is, till it comes time to make changes later on. An edge case has come up, that could have been caught if your code wasn’t using hardcoded values everywhere. You go into your old code and you can’t understand what your variables mean. You change one block of code and forget you have to change it in 5 other places that you copied it around to.

This is where I think code review really helps.

It forces the developer to slow down to be vetted and to have their code on display, and it forces them to reason about their design choices. This means they’re more likely to keep their code tidy for fear of being called out for it and having to explain it. It means they get an outsiders perspective on their design, and it forces them to take a step back and see the forest for the trees. All too often we get lost in the code itself and forget how it all relates together.

This is not to say that you should leave your developers in fear of code reviews, but it’s indeed a scary process for new developers (and some veteran devs). It’s putting your hard work on display and asking to be torn apart.

I think a successful code review process can be constructive, critical, and more importantly teach  the developers to be better. It changes from dreading the process to looking forward to it because you take pride in your work, and want it to be as good as possible.

It also is the place I see my favorite excuse…

“It’s Just Throw Away Code”

This is my pet peeve. Seriously. Don’t put code into production and then claim it was throwaway code when I ask you about it.
This is something people who want to be fast always hide behind. “I’ll just change it later when I get time”

Firstly, You won’t get time. Write it well the first time or we’ll be paying the price later on.

Secondly, why would you double your own work? Why would you write code that you now have to maintain if you’re just going to rewrite it again. You should never be aiming to rewrite your code while you’re writing it to begin with. That’s just daft.

Yes, you should have reasonable layers of abstraction so that you can rewrite it if you need to, but that’s different. That’s good API design, whereas hiding behind ‘throwaway code’ is just being lazy.

Speaking of API design, it is something that I think more developers should be taught because I often hear this…

Sometimes it’s good to just take a step back from the code and look at it in context.

“This Will Only Be Used By My GUI (or my library)”

A lot of the code review comments I give on user interfaces is that they need to decouple their logic from their interface. The most common response is that it won’t ever be used outside their user interface.

The problem is, if someone finds your tool or application useful, they will want to leverage it and often that means your pretty interface won’t be part of it. So now you have to spend all this time refactoring your code to decouple it from the user interface.

Properly decoupling a GUI and the underlying logic does require some time and thought to do cleanly. It’s not as trivial as it sounds and it requires the developer to put on their software architect hat and architect their design rather than focus on pushing out a feature.

Again though, this is something that a little extra time before hand could have saved you in the long run. Making sure your code can be used without any interface, or indeed, making sure your code can be called as a library for other projects is the hallmark of efficient development.

The alternative is making a new library or re-implementing your logic for every project. At the very least it requires at least one rewrite of something you could have done from the get go.

Designing your code like an API isn’t easy though and you really do have to think about other people. It requires a lot of care and it goes hand in hand with my next point…

“I Don’t Have Time To Write Documentation”

This is a huge fallacy. You always have time to write documentation, but I think it comes down to people thinking of documentation as needing to be this giant, in depth bible of the code. Of course, the more in depth you can go the better, but all you really need at a minimum is to add a docstring to your functions and write a ReadMe.

How does this make you efficient though? Well the amount of time you have to spend explaining your code to people and helping them with issues, could easily be spent writing documentation instead.

Seriously, if all you did was write a README.MD file with some usage examples, you would be miles ahead of so many repos online. That’s enough for a lot of libraries to be picked up by people and used. They can figure out quite a bit from just a few example snippets and it cuts down on how many questions you get asked.

Don’t stop there though. Document your functions. Add docstrings, explain your parameters and put comments in your code. That will dramatically cut the amount of time you have to spend explaining your code to someone else.

More importantly it will cut the time you need to spend re-familiarizing yourself with your own code when you eventually need to get back into it. All that time spent going, “I wonder how this worked…”, could be cut completely because you read your thought process from when you wrote it.

It doesn’t even take that much effort. IDE’s like PyCharm will quickly fill out your docstrings for you. Plus you get advantages like basically having a lot of your documentation done by just doing that. Tools like Sphinx can simply extract your docstrings and make documentation out of it.

Time spent now is lots of time saved later. Not just for you, but everyone using your code. Those people may even be inclined to help you maintain your code, but I often see this one..

 

Documentation doesn’t need to be a massive bible. It can be as simple as a Readme, docstrings and comments.

“Writing Tests is Hard”

Well you know what is hard too? Having your code do the wrong thing in production, wasting lots of man hours and having to answer to your manager how this happened. Write Tests.

Ideally you’d have as much coverage as possible in your tests, but even a few tests can dramatically cut the error rate of new commits to your code. This in turn can make it easier for people to contribute to your code because you’re not spending as much time vetting their code, and they’re not as afraid of breaking something important.

Lastly though…

“It’s Critical and Needs To Be Done Now”

This is completely valid. Sometimes you don’t have time to be meticulous. Sometimes you just need to get it now and have a task list piling up that needs to be addressed right away. That’s the reality of the world of a developer and sometimes you can’t escape it.

I definitely am not writing perfectly clean code that can be reused. I too often forget to document my code and I’ve only recently started embracing tests in my code. That said, I think it’s important to try and aim to be efficient, because that task list that’s piling up will only keep piling up otherwise. If 10 minutes spent here can save me 30 minutes tomorrow, then that’s definitely worth being a little slower. If a whole day can save me a week of time over the course of a year, that’s time well spent.

So write cleaner code, write documentation, write tests and make everyone’s lives easier. If you’re a manager, encourage your developers to spend time to do it right and give them that liberty.

Always try and be as efficient as you can be, even if that means you’re not the fastest. You’ll be the turtle in this race and come out ahead.

As always, here’s a relevant XKCD (https://xkcd.com/1205/)

2016: A Year In Review

2016: A Year In Review

2016 has been such an eventful year! It may go down in the history books quite infamously but for me, it’s been incredibly exciting.

I’d like to start 2017 off with a look back at how great 2016 has been for me personally, and I hope regardless of all the news in the world, that you too had a great 2016.

Engaged

In 2015 I happened to meet the most unlikely of people at a work party. Neither of us were sure we’d go to the party, but there we were.
I saw her spying at me across the table, and we got to talking. It was instant chemistry.

On paper we were such an unlikely fit, but it’s worked out so well. So well in fact that in August of 2016, I asked her to marry me.

We went on a trip to England and India, her first time outside of North America, and when we arrived at my parents place in the English countryside, we went for a boat ride. When we got back, I got down on one knee and asked her if she’d spend the rest of her life with me.

We’re getting married in 2017 and I couldn’t be happier to have met her.

New Home

At the very end of 2015, I bought my first home. It’s a little town house in downtown Vancouver, attached to a nice apartment complex. It’s been an incredibly big move, and it’s definitely put quite a few grey hairs on my head, but it is great to be able to own a place of my own.

I am so thankful to my parents who both encouraged me to make the decision but also helped immensely with it. They truly are the best parents I could have asked for. I’m also greatly thankful to my fiancée who puts up with all my homeowner anxiety.

It’s been a huge learning experience, and despite all the doom and gloom about Vancouver’s housing market, we’ve made a really happy home for ourselves. It’s comfortable, on a quiet street, close to multiple parks and within a few blocks of work.

 

Career Goals

This year we delivered a film that I was quite excited to work on. Despite horrible reviews, Suicide Squad was a really great experience.
The exciting part though was the continued progression of my career at Sony Pictures Imageworks.

After only 3 years of employment here, and just under 4 years in the visual effects industry, I was given the great opportunity of becoming one of our department leads for Pipeline.

It’s been a great jump in responsibility and involvement with the companies future and I’m looking forward to all the future challenges it brings. It’s meant that I’ve been responsible for some really exciting small projects that we’ve done here, but also that I may get to helm a show myself someday.

That almost came to be, for a really cool show in fact, but sadly a last minute client change caused it to fall through the cracks. Hopefully the opportunity comes along in the future again, but for now I’ll be working on Spider-Man: Homecoming , along side my supervisor from Suicide Squad and an incredibly skilled team.

Teaching

Another exciting milestone this year was that I launched my first course online. After much encouragement and pestering by friends and coworkers, I figured it was time to do it.

Python For Maya: Artist Friendly Programming released the week of Black Friday, and as of today I have close to 900 students from over 60 countries. It’s been incredibly well received, with lots of great feedback and some notable names signed up.

I intend to do some more courses in 2017 but for now it’s great to know that I both have something of value to teach, but that I’m also capable of doing so. It was a huge fear that I’d put something up and then have it fail spectacularly, but it’s uplifting to see that I could do it.

 

Other Cool Things

There’s just been a lot of things this year that I’m excited about. Here are just a few more:

My Dad Is Recording Music

After years of encouraging him to write his own music, it’s been great to see my dad both record his music and get such good reactions to it. He’s played the guitar for longer than I’ve been alive, and one of the reasons for my love of music.

Check out his music on Soundcloud and iTunes. He has over 54 tracks with 3000 listeners in over 60 countries.

Time for me to stop being lazy and record some music too.

 

 

My Mother is Making Art

My parents recently expanded their home and part of that includes a really fantastic art shed for my Mom. I need to get her to put her art up online, but it’s lovely seeing her putting out so many lovely pieces. Just like my Dad gave me a love for music, my Mom’s one of the reasons I like art so much and it’s so nice seeing them both do what they love.

 

 

My Brother is Studying Music

I’m really proud of my little brother who is working towards further education in music. He’s a drummer and bassist and a really great player.

In fact I’m very jealous of the places he’s going. He recently did a summer program at Berklee which is a college I’ve always dreamed of going to if I were to pursue music.

I can’t wait to see what he does next.

 

 

My Cousin is Studying At Oxford

My cousin recently started studying at Oxford and is doing so well there. She’s involved in so many projects there, and winning competitions all over the place. It’s really very cool.

 

 

My Family is Doing So Many Things

That’s not all, my entire family is doing so many things that I can’t keep up.

From one of my Grandmothers who was recently given a very prestigious award, to my other Grandmother who recently made her first trip outside India this year, just in time to be present for my engagement proposal in person.

My other cousins are doing so well too. Some are getting married this year, my youngest cousin is an amazing baker (or so I’m told) while my oldest cousin is now a father of two and my cousins in India are both following very ambitious career goals in art and politics.

It’s been a very exciting year for my family in general and I’m very proud.

 

 

 

 

Virtual Reality

So not a very personal thing, but this year I bought a Virtual Reality headest( the HTC Vive).

It’s early days, but what a mindblowing experience. This, in my opinion, is the future of media. It will get smaller with higher fidelity and fewer limitations, but even what it is now, it is simply breath taking. There’s already some ground breaking content and I can’t wait to see where it goes in 2017.

Check out the HTC Vive ,the Oculus Rift or the Playstation VR if you can in stores, because they are really just that cool.

In my opinion the HTC Vive is the model to beat, with the ability to walk around your room and have complete precision. The Oculus Rift is great too in the middle, while the PlaystationVR is more limited in that you can only sit, but still a great budget entry.

 

Epilogue

So I hope you had a great 2016 too. The world may be going through a lot of turmoil, but I think it’s possible to find the light even in the dark. It’s really schlocky, but it’s really how I feel as this year draws to an end.

Here’s to a wonderful 2016, and hoping that 2017 has many happy surprises in store.

Happy New Years everyone!

 

Python For Feature Film

Python For Feature Film

Python is a programming language that has become integral to the movie making process over the last few years. There’s rarely an animated feature or visual effects film, if any, that hasn’t had Python play a large part in getting it to the screen

When people think about movies, even programmers often think about the artistry involved in bringing those images to life. However, the technical side of the film industry is something that often goes unnoticed outside a small group of people.

To that end, I’ve written a few blog posts about how I’ve used Python on several major films that I’ve been lucky enough to work on. Hopefully this shows how much it contributes to the entire life of a movie.

I’ve also recently released a course on Udemy to teach artists how to learn Python For Maya since it’s becoming an increasingly valuable skill in the industry. These blog posts serve as companion material to the course as well.

With that intro out of the way let’s continue…

What is Python?

Some of you may not be familiar with Python.

Python is a programming language designed to be very easy to read and write. It’s incredibly popular in the feature film industry as well as other groups, like mathematics, science and machine learning.

You can learn more about Python on the official website.

Additionally, it’s important to note that the film industry uses Python 2.7 and not Python 3. There has been significant code developed with Python 2 and it’s not easy to switch forward yet, despite Python 2 no longer being actively developed and Python 3 having many useful features.

The Feature Film Pipeline

The biggest use of Python is in our feature film pipeline.

This is an image that describes the pipeline at most major studios.
The Pipeline is the arrows that link each department together. It’s responsible for making sure that data flows between each department and that everyone can play well together. It’s also responsible for the toolsets in each department so that the artists themselves can work efficiently, but for now lets focus on the inter-department flow.

A more visual demonstration of this graph is in this video of the making of Ratatouille by Pixar

Here you can see the various stages of a visual effects film or animated feature. Studios may differ slightly from this, but it’s the general workflow.

The storyboards/footage/previs represent the data we get, and Compositing/Lighting are the last stages of the film for us.
Visual Effects Films differ slightly from animated films because you have to deal with the extra added element of film footage in the form of plates.

The Pipeline is responsible for getting the data between departments. Here’s the gist of how it works (though it is more organic a process than the one described):

  • We get data from the client or story artists in form of plates, previsualization (previs) or storyboards that tell us what is happening in the scene.
  • Modeling look at all of this and generate 3D models of all the assets that will be required.
  • Rigging take the modelled assets for characters and apply a virtual skeleton to make it animatable.
  • Matchmove are in charge of creating virtual cameras that match the ones used to shoot the film as well as any standin characters or geometry
  • Layout take the rigs, and either create their own cameras or take matchmoves cameras and set up the scene. They’re the equivalent of a virtual director of photography.
  • The scene is then handed off to Animation, who are the equivalent of the actors. They are in charge of the movement of the characters, and bring the inanimate skeletons to life.
  • CharacterFX are in charge of all the technical parts of animation. Muscle simulations, making cloth move realistically, the hair, grass etc… all comes from CharacterFX.
  • FX then handle the non animation related effects. Weather it be destruction, fire, voxelization, etc… there’s a lot that FX is in charge of.
  • While this is happening, Texturing are in charge of giving color to the 3D Assets so they aren’t just grey objects.
  • Shading then takes these textures and gives the assets a material that tells it how light should interact with it.
  • Matte Painting are the department we use when it is not logical or feasible to build an environment. We realistically can only build so much, and past that point it’s more efficient to have someone make a very high quality painting instead.
  • This all gets funnelled into Lighting who are in charge of adding lights to the shot and rendering the image out. They also do a little bit of compositing to sweeten the image. On an animated feature this may be the end of the show.
  • On a visual effects show, we have to prepare the plates by either removing unwanted elements, removing noise or removing the lens warp. This is handled by Plate Prep,also known as RotoPaint.
  • Finally everything goes to Compositing who take all the images and integrate our CG renders into the actual film plate. On a visual effects show, this will be the last stage.

We use Python to tie all these bits together.
In the next section I’ll go over publishing before moving onto describing how Python is used for the individual departments.

Case Studies of Feature Films

Here are a few posts I’ve done about movies that I’ve worked on, and the role Python played for those films.

Article Continued Below These

Publishing and Asset Management

This is pretty much the core of traditional pipeline, to make sure assets can be shared between departments and be tracked.

The first part of this is Asset Publishing. 

When a department deems it’s work ready, it decides to publish it so the next department in the chain can consume it. For example modeling exports models, but does animation export animation? Well that depends on who is consuming it. This is dependent on whether it needs to be interactive past this point or not.

For geometry  we often just publish as a geometry cache using Alembic  which is a industry standard developed by Imageworks and ILM so that we can have a consistent cache format.
For point cloud data, we either use Alembic or OpenVDB, for images we tend to use tiff’s or OpenEXR.
Soon the industry will probably also standardize on a universal scene format from Pixar called OpenUSD.

Anyway  the idea is to generally keep the data in the most efficient format possible, while allowing for easy interchange. Cache data is often best because you really only take an IO hit, which is cheap, versus a deformation hit, which can be very expensive.

This all gets really complex though. Artists don’t need to know where their data is coming from or going to, or even how it gets there. They just need to be able to load it in and publish it out.

This is the pipeline. We develop the UI’s and the tools to do this in a very user friendly manner.

To publish data, the user just has to open a publish UI that will validate their assets against some tests, and then send it off to the machine farms where the conversion to one of the open formats happens.

To ingest the published data, we similarly just have an asset browser that lets the artist pick which asset they want. Often they just see a thumbnail and description. The details are irrelevant to most artists.

Because these publishing and asset management systems need to be common to multiple apps, we develop them in Python and Qt (PyQt or PySide) , which allows us to reuse our code without recompiling for each application and makes it easy to rapidly add functionality where needed.

This is common to pretty much every department, so I figure it warrants its own section here rather than repeating for each.

This is Pyblishan open source Publishing system similar to the ones many studios have developed internally.

In this wireframe version of Big Buck Bunny from the Blender short, you can see how models are made up of polygons (each of the squares is a single polygon)

Modeling

Modeling is the department in charge of creating the 3D source geometry used by every other department.
Often there are quite a few repetitive tasks involved in regards to placing or editing geometry, or even just managing the scene.

This is where Python comes in handy. Most 3D packages have a Python API that lets you do program everything that you would do manually.

So instead of spending 10minutes creating a simple asset, you can script it up and then just click a button when you need it next time. That 10 minutes saved really adds up, and over the course of a project you may be saving hundreds of hours that could be better focused on building more complex assets that require artistic input.

For example, in  my course  (Python For Maya) I go over creating a simple gear using Python as well as creating a simple UI so that you can specify how many teeth the gear has and how long they will be.

This can get more complex though with using Python to create custom deformers or interactive tools, like this demo from Hans Godard demonstrates.

Rigging

Rigging’s job is to create a skeleton for the character geometry so that it can deform, just like a real human would.

Of course that’s an over simplification.
Rigging is also essentially creating the interface that animators use to bring these creatures to life, but they also have to make sure that any movement happens convincingly.
If an animator moves the arm, the rigger must make sure that the shoulders deform properly.

Python plays an integral role in Rigging. Here are just some of the uses:

  • Creating automated builds of rigs. Rather than doing everything manually, rigs can be composed using code which makes them easy to reuse.
  • Developing custom deformers or nodes to perform operations not native to the application.
  • Develop supporting scripts for animators to switch between modes or controls etc..

In  my course  (Python For Maya) I go over creating a controller library.
Controllers are, as the name suggests, the objects animators use to control the rig. Instead of using the geometry directly, they use controls, that move the skeleton, that in turn deforms the geometry.

I go over developing a user interface with Qt to save out and import the controllers for easy reuse.

If you’re interested in learning Rigging, I also recommend checking out Animator Friendly Rigging which is a resource that many riggers in the industry have learned from.

Kraken is a rigging framework, built on top of Fabric, but uses Python for its frontend UI

Another good resource for rigging is Stop Staring, a book about facial rigging and modelling.

A video demonstrating how animators interact with a rig, as well as the kind of tools animators use.

Animation

Animation is the department most people would be familiar with. They take the static rigs and give them motion, and make them emote. They’re essentially the virtual actors.

But as you can imagine, there’s a lot of repetitive actions that animators have to do that can also be scripted away using Python, or just made easier.

Examples include:

  • Picking controllers. A complex rig may have hundreds of controls that clutter the view. A picker interface lets animators have a friendly UI to select the controls while hiding them in their actual view.
  • Creating keys, specifically inbetweens. In the age of 2D, animators would define in between keys (the keys that give motion between poses) as a weighting towards a pose. In 3D we can have tools that help the animator say they want to weight the new key 30% of the way to the old key.
  • Setting up constraints. Characters will pick up objects, and at that point animators must constrain the object and their character together so they move as one. This can be made easier with tools that handle the management of this common task.

We develop most of our tools to do this kind of thing using Python and most of our user interfaces using Qt, via either PyQt or Pyside.

In  my course  (Python For Maya) I go over creating a an animation tweener Ui, where an animator can drag a slider to choose the weighting of their keys between two poses.

Character FX

Now that Animation is done animating the character, we still have to figure out the muscles, hair and cloth that are more technical considerations but add a lot of depth to the scene.

From flowing dresses in Tangled to crazy hair in Hotel Transylvania 2 or muscle simulations in Suicide Squad, these are all handled by the Character FX department.

Like the other departments they too have a lot of use for Python.

For example:

  • Setting up their simulations
  • Combining multiple takes of simulations together
  • Creating brand new procedural workflows.

Often overlooked, Character FX is that very important step in getting really lifelike images on screen.

A behind the scenes look at how the clothing on Hotel Transylvania 2 was simulated

This video  was created using Houdini to generate procedural FX with an input motion capture data

FX

A completely different department to Character FX, this FX department is in charge of more procedural effects.

Destroying buildings, explosions, magical particles or even entire oceans. This is driven by the Effects department.

They too use Python for many things including setting up their procedural effects graphs and scripting parameters that would otherwise be time consuming to do by hand.

Python can even be used to create entire procedural nodes that generate interesting effects. It’s very powerful.

Lighting

Now that all this 3D geometry has been created, we need to convert it to images that can be displayed on screen, but if we were to just do this, it would be black.

Lighting are in charge of adding the lights to the scene and making it look interesting as cinema. They are  the ones who can set the mood of the shot, make it dark and menacing or happy and vibrant even if nothing is happening.

Even here, Python can be incredibly useful because a scene may have many, many lights and many, many 3D assets. Here, we can make UI’s that help make these scenes manageable.

What can often be a scene with billions, or even trillions, of objects, can be distilled down to simple user interfaces.

In my course (Python For Maya) I go over the creation of a lighting manager using PyMel and Qt to generate a UI that lets us control all the lights in the scene. It also goes over importing and exporting them as JSON files, so that they can be shared among shots and artists.

Once the lighting is done, it is time to convert the scenes to images. This is done using a render like Arnold, Renderman or Vray, among many others.

Renderman is the render engine that Pixar developed (in fact it predates them as a movie company) and is used by many studios.

You can also download it for Non-Commercial use

An example of how the results all come together

Compositing

Finally, there is Compositing.

Here we take the final footage and any rendered elements, if any, and combine them together. It’s more than just combining, because you need to make sure everything integrates well and feels like it’s all one cohesive image.

People often think of visual effects as over the top explosions and creatures, but it can be even subtle things like background replacements, or adding crowds.

I bet most people didn’t realize how much work went into even something as seemingly simple as Forest Gump

Here too, Python is incredibly useful.

It can be used to automate setting up the compositing node graph in an appliication like Nuke, but it can also be used to do entire image processing operations itself using libraries like OpenColorIO or Pillow.

We can even use Python for Computer Vision to help track objects inside the scene.
The possibilities are really quite exciting.

Final Words

I hope this blog post has been a good look into how programming can be such a vital part of bringing moving to life nowadays, and more specifically, how Python itself is so useful.

It makes sure that we can quickly make very complex relationships between all these moving pieces simpler, and also makes it so each department can work more efficiently.

It’s often overlooked since it’s not an artistic part of the process and you rarely see the direct results of it on screen, but nevertheless, it’s a skiill that is increasingly valuable in getting these increasingly complex movies to the big screen.

Learn Python



If you're interested in learning more about Python, why not sign up for my course here?

This course takes you from learning the fundamentals of Python, to creating tools with advanced user interfaces, all while creating projects you can use immediately.
It will teach you many of the skills necessary to create tools like the ones in this article.

With over 700 students in its' first week, including artists from major studios, it is sure to provide valuable knowledge to everyone.


Python For Maya: Artist Friendly Programming - $70 $90
 

If you sign up from this link, it will save you $20 off the retail price using the coupon code: DGOVILCOM

Working on Suicide Squad

Working on Suicide Squad

In Part 5 of this blog series, I’ll be going over the work we did for Suicide Squad. One of 2016’s most hyped films, it landed with a critically derided meh.
I won’t go into the behind the scenes of why the movie went from A+ to D- in a heartbeat, there are plenty of articles out there that talk about what happened, but instead I’ll talk about the challenges we went through to bring some amazing visuals to the screen.

For the record, I honestly don’t think it was as bad as it was made out to be. It was definitely not great, but it was fun enough and I’ve seen worse films get better reviews. I’ve totally seen worse superhero films, and it doesn’t excuse it, but I feel the hate was a direct response to the immense hype, and not totally objective. But then again, maybe I’m not objective myself having worked on it.

Also my favorite review that I’ve read states: “If 2016 could be summed up in a movie, it would be Suicide Squad”. Ouch!

Challenges and Craziness

So for this movie, we were responsible for two primary characters.

Incubus (The big orange dude) and Enchantress (the lady in the green dress with the eyebrows).

 

We used the tentacle technology developed on Edge of Tomorrow to handle Incubus’s tentacles of destruction

Incubus

Incubus was of course fully CG. You can see him in the trailer as the guy who destroys the subway train.

This was lost in translation in the final movie, but he actually absorbs everything he destroys. There’s like a mini universe inside him.
If you were to pause on a frame of him and strip away his armor, there’s floating heads, eyeballs, guns, and even an entire tank inside of him.

Unfortunately with all the other effects, and the armor, it totally gets lost.

He also fires these tentacles outwards when destroying things. We made good use of the tentacle technology that was developed for Edge of Tomorrow, to make the tentacles that he fires.

Enchantress

Played by Cara Delevigne, Enchantress is a semi CG character. When she’s in her Jade outfit, basically the only part of her that is real is her face, and even then, we replace her face in a few shots.

The rest of her body is all computer generated, a mixture of some great tracking, animation, simulation and shading.
It may not look as realistic in the final film, with all her glowing tattoos and other effects, but if you were to see the CG model without all of that, there are several shots where all we could do to distinguish them was to look for her eyebrows (our model didn’t have eyebrows for a while).

We made use of some new skin shading technology, a new muscle simulation technology and a lot of talented artist time to recreate Ms.Delevigne in CGI.

Echantress in all her CG glory.
Forgive the low rez image, I had to find it via Google Images and there’s not much available yet.

Python For Suicide Squad

We made a lot of use of Python for the movie to make our lives easier and create new pipelines.

Our Muscle Simulation Pipeline used new technology invented by Ziva Dynamics

Muscle Simulation Pipeline

To get Enchantress to look as realistic as possible, we had to simulate the muscles under her skin.

About the same time we were doing this, Ziva Dynamics were doing closed betas of their new mucle simulation technology.
These are the same guys who did the amazing muscle work at Weta and now have their systems for sale for both feature film but also for interactive video games. (Seriously, their realtime VR demo is mindblowing).

Our character artist who was doing the sims needed to work in stages.

  1. Take the animation and prepare it
  2. Simulate the Bones (some bones are flexible) and write out their geometry cache.
  3. Simulate the muscles on top of the bones, and cache them out.
  4. Simulate a fascia on top of the muscles
  5. Simulate the fat and the skin sliding on top of this fascia.
  6. Simulate the tight clothing sliding on the skin.

While we used Ziva for the actual simulation, we still needed a new pipeline to procedurally handle all these stages.

So I built a framework where the artist could provide  a list of stages and their dependencies, as well as a construction class that would set up the sims.
Then my tool would figure out the dependency graph, generate all the data needed at each stage to feed the next and finally send it on through to the lighting department.

The framework was completely built using Python and in fact does not rely on Ziva at all, but does support it where needed.

This became especially useful when having to run through multiple shots as once, but it meant that setups could be reused for characters with little work.

Ingesting Motion Capture Data

For this show, we had a lot of motion capture data that needed to be ingested.
But we had some big problems that made it slow to do so manually.

  • Our motion capture vendor had their own naming conventions for scene files.
  • The motion capture rigs weren’t directly compatible with our production rigs and required some manual work.
  • We needed to then playblast these and add them to our animation library.

Doing this manually would have taken roughly 20 Minutes per captured clip, if I had no issues.. We had a couple hundred clips. That would be a full weeks work to do just one iteration over all of them.

This is where Python was super useful. I figured out the steps and scripted it all up. It could be done in a couple hours instead.

Given a list of files, it would:

  • Convert it to our naming conventions
  • Create a tracking camera to playblast it
  • Transfer the animation to our production rigs
  • Add these to our animation library
  • Send out an email

That meant I could start the process, go to my meetings, come back and it would be done.

That’s a lot of time saved.

Motion Capture lets us realistically capture animation from real world actors. This is often then used as a base to animate on top of, or even just as a reference.

Learn Python



If you're interested in learning more about Python, why not sign up for my course here?

This course takes you from learning the fundamentals of Python, to creating tools with advanced user interfaces, all while creating projects you can use immediately.
It will teach you many of the skills necessary to create tools like the ones in this article.

With over 700 students in its' first week, including artists from major studios, it is sure to provide valuable knowledge to everyone.


Python For Maya: Artist Friendly Programming - $70 $90
 

If you sign up from this link, it will save you $20 off the retail price using the coupon code: DGOVILCOM

Buy The Movie

Okay, I know I basically just talked about how bad the movie was, and I won’t lie it’s not great,but maybe you’ll like it in the same campy way people like the original Evil Dead? It’s actually pretty fun as a movie and you might have a good time.


 

Buy the BluRay

 

Affiliate Link

Pin It on Pinterest