Shopping Cart (0)

mrEnvironment for Maya Python Script

mrEnvironment test render

mrEnvironment for Maya is a new python script that makes it easy to set up and use mental ray environment map nodes in Autodesk Maya. This is useful for rendering environment maps using spherical or cubic texture maps.

About the mrEnvironment Script

Version 1.1 – Feb 16, 2013

mrEnvironment is an automatic mental ray environment creation script that makes it easy to use the mib_lookup_spherical, mib_lookup_cube1 and mib_lookup_cube6 shaders in Autodesk Maya.

The script links in the required nodes and adds a place3Dtexture node for rotating the placement of the environment map in the background of your Maya scene. This removes the need to use 4×4 matrix transforms with the mib_texture_remap node.

This is a test scene that uses the mental ray mib_lookup_spherical node in Maya to create simulated reflections.

This is a test scene that uses the mental ray mib_lookup_spherical node in Maya to create simulated reflections.

There are three Maya test scenes that show the effect of the spherical, cube1, and cube6 shelf icons.

The script also includes a Maya “Environment” shelf that adds a set of pre-made icons.

This is the new Environment shelf.

This is the new Environment shelf.

 

Download the Script

You can download the mrEnvironment script here:
MrEnvironment.zip (14MB)

Environment Shader Usage

The cubic environment map node can be linked to a camera’s environment shader port or assigned to a specific material using the surface material’s shading group node.

If you link the env shader to a camera the environment map will show up in the reflected color on the glossy materials in the scene. If you link the env shader directly to a material’s shading group it will override any camera specific environment maps in your scene.

To assign the environment shader to a specific camera, open the Hypershade and use the middle mouse button to drag the environment shader onto the camera node. In the connection popup menu select default. The env shader should be automatically connected to the camera’s environment shader input.

To assign the environment shader to a specific material’s shading group, open the Hypershade and use the middle mouse button to drag the environment shader onto the materials shading group node. In the connection popup window select default. The env shader should be automatically connected to the shading group .miEnvironmentShader input.

The python script “MrEnvironment.py” has the following functions:
createMrCube1()
createMrCube6()
createMrSphere()

Installation

Mac OS X Install

1. Copy the icons to your user account’s Maya icons folder:

~/Library/Preferences/Autodesk/maya/2013-x64/prefs/icons/

2. Copy the python scripts “__init__.py” and “mrEnvironment.py” from the “scripts” folder to your user account’s Maya script folder:

~/Library/Preferences/Autodesk/maya/2013-x64/prefs/scripts

3. Copy the “shelf_Environments.mel” file from the “shelves” folder to your user account’s Maya shelves folder:

~/Library/Preferences/Autodesk/maya/2013-x64/prefs/shelves

4. (optional) Copy the sample environment map textures to your current Maya project’s sourceimages folder.

Windows Install

1. Copy the icons to your user account’s Maya icons folder:

My Documents\maya\2013\prefs\icons\

2. Copy the python scripts “__init__.py” and “mrEnvironment.py” from the “scripts” folder to your user account’s Maya script folder:

My Documents\maya\2013\prefs\scripts

3. Copy the “shelf_Environments.mel” file from the “shelves” folder to your user account’s Maya shelves folder:

My Documents\maya\2013\prefs\shelves

4. (optional) Copy the sample environment map textures to your current Maya project’s sourceimages folder.

Linux Install

1. Copy the icons to your user account’s Maya icons folder:

~/maya/2013-x64/prefs/shelves/icons

2. Copy the python scripts “__init__.py” and “mrEnvironment.py” from the “scripts” folder to your user account’s Maya script folder:

~/maya/2013-x64/prefs/scripts

3. Copy the “shelf_Environments.mel” file from the “shelves” folder to your user account’s Maya shelves folder:

~/maya/2013-x64/prefs/shelves

4. (optional) Copy the sample environment map textures to your current Maya project’s sourceimages folder.

How the mrEnvironment Script Works

The script starts by setting the mib_texture_vector node to select a ray direction output (select -4) using world space.

The mib_texture_vector node is set to output a world space ray direction value.

The mib_texture_vector node is set to output a world space ray direction value.

The mib_texture_remap node rotates the environment map in the scene.

The mib_texture_remap node allows us to rotate the visible part of the environment map.

The mib_texture_remap node allows us to rotate the visible part of the environment map.

The place3DTexture node provides the in-scene rotation manipulator and handles the 4×4 matrix math required by the mib_texture_remap transform attribute.

The place3DTexture node starts with a value of RotateX -90 to orient the environment cube map “upright”.

The place3Dtexture node provides an in-scene control for rotating the position of the environment map.

The place3Dtexture node provides an in-scene control for rotating the position of the environment map.

mib_lookup_cube1 Setup

The mib_lookup_cube1 node takes a single horizontal strip formatted texture map and simulates environmental reflections.

If you are interested in a Photoshop Action that converts cubic panoramas into the mib_lookup_cube1 format you should download the free Domemaster Photoshop Actions Pack.

The mib_lookup_cube1 node expects the single texture map to be oriented in a horizontal strip format with the cube map face order of:
1 Left
2 Right
3 Bottom
4 Top (flipped vertically)
5 Back
6 Front

This is an example mental ray compatible mib_lookup_cube1 texture map.

This is an example mental ray compatible mib_lookup_cube1 texture map.

If your Cubic map face textures are 1024x1024 pixels then the horizontal cubemap strip would have the dimensions of 6144x1024 pixels.

Node Connections
mib_texture_vector.outValue > mib_texture_remap.input
mib_texture_remap.outValue > mib_lookup_cube1.dir
place3dTexture.worldInverseMatrix[0] > mib_texture_remap.transform

Texture Map Connection Summary
mentalrayTexture.message > mib_lookup_cube1.tex

Camera Connections
mib_lookup_cube1.message > perspShape.miEnvironmentShader

This is a typical mib_lookup_cube1 shading network.

This is a typical mib_lookup_cube1 shading network. (Click to enlarge)

mib_lookup_cube6 Setup

The mib_lookup_cube6 node takes a six cubic face textures map and simulates environmental reflections.

It is possible to use the mib_lookp_cube6 node to render hemi-cubic environments by disconnecting the bottom texture map node called bottom_env_mentalrayTexture1 from the mib_lookup_cube6.tex_my input.

Node Connections
mib_texture_vector.outValue > mib_texture_remap.input
place3dTexture.worldInverseMatrix[0] > mib_texture_remap.transform
mib_texture_remap.outValue > mib_lookup_cube6.dir

Texture Map Connection Summary
left_env_mentalrayTexture1 > mib_lookup_cube6.tex_mx
right_env_mentalrayTexture1 > mib_lookup_cube6.tex_px
bottom_env_mentalrayTexture1 > mib_lookup_cube6.tex_my
top_env_mentalrayTexture1 > mib_lookup_cube6.tex_py
back_env_mentalrayTexture1 > mib_lookup_cube6.tex_mz
front_env_mentalrayTexture1 > mib_lookup_cube6.tex_pz

Camera Connections
mib_lookup_cube6.message > perspShape.miEnvironmentShader

This is a typical mib_lookup_cube6 shading network. (click to enlarge)

This is a typical mib_lookup_cube6 shading network. (click to enlarge)

mib_lookup_spherical Setup

The mib_lookup_spherical node uses a lat/long (equirectangular) image to simulate environmental reflections.

Node Connection Summary
mib_texture_vector.outValue > mib_texture_remap.input
mib_texture_remap.outValue > env_mib_lookup_spherical.dir
place3dTexture.worldInverseMatrix[0] > mib_texture_remap.transform

Texture Map Connection Summary
mentalrayTexture.message > env_mib_lookup_spherical.tex

Camera Connections
env_mib_lookup_spherical.message > perspShape.miEnvironmentShader

This is a typical mib_lookup_spherical shading network.

This is a typical mib_lookup_spherical shading network. (Click to enlarge)

Version History

Version 1.0 Beta – Released Jan 8, 2013
Created first version of the mrEnvironment script, icons, and shelf.

Version 1.1 – Released Feb 16, 2013
Updated python code to fix cube6 face order issue.

2 comments

Comments are closed.