Sunday, October 23, 2011

Maya - Simple script for viewport performance increase

Here I will share a simple solution I made to a relatively simple problem; disable Maya's "Two-sided lighting" by default when you open Maya and open any scenes during the same session. Disabling this feature increases the default viewport performance by more than 100% (without hardware texturing enabled), and it also allows you to view reversed normals (due to single-sided lighting), easily seen on geometry that has been scaled negatively and had its transformation matrix frozen, as a nice bonus. This script uses a simple scriptJob to accomplish the task. For more details on scriptJobs and the available flags/arguments, view the MEL command reference.

An accompanying video demonstrating the result is located here:
http://www.youtube.com/watch?v=OvVB...ayer_detailpage
It's not necessary to watch however, as all information on how to get this to work is below:


This file you will be editing, initHUDScripts.mel, is stored in the path below, in Windows:
C:\Program Files\Autodesk\<MayaVersion>\scripts\startup\

It's highly preferable for you to copy the file and paste it into your user scripts directory under the (for example, in Windows and Maya 2011 x64) "/UserName/Documents/maya/2011-x64/scripts" settings folder. This way, if you make a mistake, you will be able to revert back to Maya's default script by just deleting your copy of the script. This script will work with previous versions of Maya, and should benefit all Maya users. I highly recommend you try it, especially if you deal with polygon heavy scenes.

I should make note that to get the most out of this script, you should know it operates on the default 4 camera panels. Under the menu Window - Settings/Preferences - Preferences, in the UI Elements tab, you'll see a "Panel Configurations" rollout. Uncheck the options "Save panel layouts with file", and also uncheck "Restore saved layouts from file". This allows the script to disable "Two-sided Lighting" on the default 4 viewports when you open any scene or create new ones; persp, top, front, and side.

Note that some objects in Maya, such as the muscle objects of the muscle system, are polygonal, so you might see mirrored muscles appear flat black, which is slightly inconvenient if you need to edit them; simply enable "Two-sided Lighting" manually for those certain but overall very few circumstances.


Append the lines below to your copy of the "initHUDScripts.mel" script:

// CUSTOM SETTINGS BELOW

// Set Two-sided lighting to off in default 4 views.
modelEditor -e -twoSidedLighting false modelPanel1;
modelEditor -e -twoSidedLighting false modelPanel2;
modelEditor -e -twoSidedLighting false modelPanel3;
modelEditor -e -twoSidedLighting false modelPanel4;

// Run a script job when a scene is opened/created.
string $setupCommands001 = "modelEditor -e -twoSidedLighting false modelPanel1; modelEditor -e -twoSidedLighting false modelPanel2; modelEditor -e -twoSidedLighting false modelPanel3; modelEditor -e -twoSidedLighting false modelPanel4;";

scriptJob -e "NewSceneOpened" $setupCommands001;

// END CUSTOM SETTINGS

1 comment: