Render a SolidWorks Model in Maya

How to import and render your SolidWorks model in Maya using the built in mental ray.

Introduction
SolidWorks is one of the main product design solid modellers. It has a built in render engine called PhotoWorks. With the release of PhotoWorks 2, rendering within SolidWorks has become more realistic and easier. In a lot of cases PhotoWorks will be the most convenient way to render your model, because you don't have to leave SolidWorks. However, in some cases you will find the need to make renders that are more realistic (or even photo-realistic), and PhotoWorks is not sufficient anymore. This is when you might consider using an external program for rendering. In this how-to, I will describe how to do this using Alias Maya with mental ray. I will be doing this with SolidWorks 2005 and Maya 6.5, but it will probably work in most other (recent) versions aswell.

Exporting from SolidWorks
I will be working with a model (Created by Marko.M.Markovic [mailto:mmmarko@neobee.net mmmarko@neobee.net]) of a lighter that I downloaded from the SolidWorks Users Group Network (SWUGN) at the bottom of the "FREE SolidWorks models" section.

Before you can import your model into Maya, you need to export it to the IGES format first. In this how-to I will describe how to do this with an assembly, but it is essentially the same for a separate part.
 * Open your assembly.
 * If you don't want to export all the objects, select the objects that you DO want to export first. If you want to export the complete assembly, don't select anything.
 * Go to File > Save As...
 * Select IGES as your file-type and click on the "Options..." button.
 * Use the settings in the image below and click OK.
 * If you had selected any objects in your assembly, SolidWorks will ask you if you want to export only the selected objects.
 * You may also get the question if you want to resolve hidden, suppressed or lightweight objects first. Usually your answer will be "Yes", unless you do not want to export certain parts.

Importing in Maya
It is recommended that you now close SolidWorks for better performance. We'll now import the exported IGES data into Maya. It will probably look like a mess, but don't worry, we'll get to that. Note: If Opening an IGES file is not available, you need to enable the plug in as follows.
 * Start Maya.
 * Go to File > Open Scene..., locate your IGES file and hit Open. Note: large assemblies can take Maya a while to convert, so be patient!

Select Window > Settings/Preferences > Plug-in Manager to display the list of all known plug-ins. Click the loaded or auto load check box to load one of the ge2Export.mll, or ge2Export.so, or ge2Export.lib and igesadd.mll  plug-ins.

Cleaning up the scene
As you might or might not see, Maya will have quite a lot of duplicate parts and some settings need to be changed as well. Because this can be quite a lot of work, we'll do this by using the following MEL-script:

string $select[] = `ls "transform*"`; delete $select; string $currentSelection [] = `ls -geometry`; string $loopSelection; for ($loopSelection in $currentSelection) { setAttr ($loopSelection + "." + "visibleInReflections") 1;
 * Open the Script Editor by clicking on the icon in the right bottom of the screen.
 * Paste the above script into the Script Editor, select it again by pressing CTRL+A.
 * Open the "Custom" tab on the top shelve. (If you don't have one, create a new one, Go to Window > Settings/Preferences > Shelves...)
 * Now go back to the Script Editor and drag the selected script into the "Custom" tab area - a new button appears.
 * You can (but it is not necessary) make a nice icon for this button, so you can recognize it better later, or just because it looks nice.
 * Go to Window > Settings/Preferences > Shelves...
 * You will see something like this: [[Image:Maya-shelves-editor.png|none|]]
 * First download this icon: http://www.extrapuur.nl/SWCLEANUP.bmp [[Image:SWCLEANUP.png]] (make sure you download the bmp, not the png hosted here on wikibooks!)
 * Click the "Change Image..." button and locate the icon you just downloaded.
 * Hit close and VOILA! There you have your very own SW-cleanup button!


 * Now you can finally cleanup your scene: simply press the button you just created. This button will still be there the next time you start Maya, so it'll be much faster next time. important note: If you imported a part model and not an assembly, you won't have duplicate geometry, and you don't have to cleanup the scene either!

If everything has gone well, you will now have a clean version of your SolidWorks model in Maya. Time to save!
 * Go to File > Save Scene As...
 * Enter an appropriate name for your file and hit "Save".

Creating an HDRI environment
Because the aim of this how-to is to get you started on photorealistic rendering, we will be using an HDRI environment. HDRI stands for High Dynamic Range Imaging, and is basically a technique to use a picture of the environment for lighting your scene. This will result in very realistic and convincing shadows, highlights and reflections. This is very important for realistic emulation of chrome for example.

First of all, you'll need an HDR image. There is a whole range at http://debevec.org/Probes/ that you can download for free. I will use the Uffizi Gallery probe, but any other HDR image will do just fine.

Since maya 6.0 there's a special IBL node that you can create within mental ray. We will use this node to create the Image Based Lighting (IBL) within the scene. to create this node:
 * Go to Window > Rendering Editors > Render Globals... ('Render Settings...' in Maya 7.0)
 * Select "mental ray" in the "Render Using" drop down menu.
 * If there is no mental ray in that menu, you need to turn it on. To do this, go to Window > Settings/Preferences > Plug-in Manager.
 * Scroll down to Mayatomr.mll, and tick both boxes behind it. Now Maya will load mental ray by default when you start Maya.
 * Now go to the mental ray tab.
 * Scroll down until you see "Image Based Lighting", open it and hit the "Create" button.
 * A new settings window will appear in the right of the main screen (this area is called the Attribute Editor).

What we'll do next will appear to be double work (selecting the same image twice), but this way you can see your environment within your scene and still be able to adjust it.
 * Set the "Mapping" option to "Angular"
 * Click on the folder icon next to the "Image Name" field and locate the HDR image you just downloaded.
 * Now change the "Type" option to "Texture" and click on the checkered icon next to the "Texture" option.
 * A new window will pop up called "Create Render Node". In the "2D Textures"-section, select "File".
 * Again, click the folder icon next to the "Image Name" field and locate the (same) HDR image.

We're now going to make a network to be able to adjust the gamma of the image. We need to do this because most HDR images are set at 1 (or at least read that way in Maya), and it should be around 2.


 * With the texture file tab still open, go to Window > Rendering Editors > Hypershade...
 * A new window will appear. Click twice on the [[Image:Maya-hypershade-inputoutput.png]] button.
 * You will now see how the texture is connected to the mental ray IBL node in the bottom of this window: [[Image:Maya-hypershade-probe-connections.png|none|500px]]
 * Now go to Create > Color Utilities > Gamma Correct
 * Drag the gamma node to a convenient location, so that you can still see the "file1" node, and the "mentalrayIblShape1" node; preferably between these two. You can zoom / pan in the views with the standard camera controls.
 * Select the "out"-arrow at the right bottom of the "file1"-node, keep pressing it and go to outColor > outColor.
 * Click on the "in"-arrow on the left bottom of the gamma node and select value. You have connected the "file1" and the "gammaCorrect1" nodes with a green line.
 * Connect the outValue of the "gammaCorrect1" node (outValue > outValue) with the color of the "mentalrayIbleShape1" node in the same way. If you have done everything as described, you should see something that is connected like this: [[Image:Maya-nodes-connectedexample.png|none|500px]]

Now you can adjust the gamma of the HDR image. If you don't do this, your renders will be extremely bright in most cases.
 * Click on the gamma node to select it. The properties open in the Attribute Editor (in the main Maya screen).
 * Set all three gamma values to 2.2

Normally a gamma of 2.2 will do fine, but if you still think it is too bright (or even too dark) after you render the scene (we'll get to that later) you can always go back to this node and adjust the values: a higher value means "darker", and a lower value means "lighter".

As a final step in this part, you need to turn off the default light. This is because Maya places a light in the scene if there isn't already one. Apparently Maya doesn't recognize our IBL-node as a light, so you have to turn it off manually - otherwise your scene will be overexposed.
 * Go to the Render Globals window
 * Select the "Common" tab.
 * Turn off "Enable Default Light" at the bottom of this window (you may need to scroll down).

Assigning materials
We've now imported the SolidWorks model into Maya and set up an environment for it, so we're ready to assign materials to our model. It will not go into deep detail of how exactly you should tune your shaders - that's beyond the scope of this how-to - but it will provide you with a good basis to start from.

Right now, your model doesn't have any materials assigned to it, so when you render it, it won't be visible. Because it's more convenient if you can see the complete model when you test-render, we'll assign a temporary, bright and shiny material to the complete model. We'll also create a plane for the model to lay on.


 * Make sure you're in "shaded" mode, by pressing 6 in the viewport.
 * Go to Create > NURBS primitives > Plane, or click the plane button in the Surfaces tab.
 * Scale this plane (by pressing r on your keyboard or clicking the scale button) to a size that fits your model.
 * Open the Hypershade (Window > Rendering Editors > Hypershade...)
 * Press the "Blinn" button in the left of this window. (Make sure you are in Create Maya nodes, not mental ray nodes) You've just created a new material.
 * Click on this node to open it's properties, and drag the color slider to the right to make it brighter (not completely white).
 * Now select all the geometry from your model by opening the Outliner (Window > Outliner...), selecting the first group of geometry and SHIFT selecting the last group:[[Image:Maya-selected-all-geometry-outliner.png|none|150px]]
 * Go back to the Hypershade and right click your Blinn material. Hold your mouse-button down and go to "Assign Material To Selection".

We're now going to make a first test render, to see if everything has gone well.
 * First create a resolution gate for your viewport, so you can see what area is going to be rendered. Go to View > Camera Settings > Resolution Gate in the viewport menu.
 * Zoom in to a nice view on your model.
 * Go to the Render Globals window (Window > Rendering Editors > Render Globals...)
 * In the mental ray tab, turn on "Final Gather" (only the first checkbox). We'll leave these settings for what they are now.
 * Now you can render! Hit the render-button, or go to Render > Render Current Frame...
 * This is how my render looks: [[Image:Maya-lighter-first-render.jpg|none]]

Plastic
The first material we'll create will be plain plastic. We'll apply this material to the middle part, the gas regulator and the push button. Whenever you're going to create a new material, think of it in terms of how much it should reflect, how much it diffuses light, how transparant it is etc. because these are your parameters within Maya. To create the plastic material: If you're not sure about the settings, you can look at the picture beside this text on the right. You have now created a material that is a bit reflective, but with sharp, bright highlights. I strongly encourage you to play with these settings, and those of other materials; it will learn you what parameters you need to quickly set the material/look you are after. To apply this material to the middle part, the gas regulator and the push button, select these first. Normally these would be easy to recognise in the outliner (Window > Outliner...), because they get the same name you gave them in Solidworks. In this example (the lighter), the creator of that assembly didn't give names to the parts, so you'll have to browse through the Outliner. Watch out! If you select the parts in the viewport, there's a big chance you'll miss some faces, so in most cases you should use the Outliner for selecting. In this case it's Part020, Part017, Part013 & Part015. Use CTRL click to select all of these together. Now go back to the Hypershade, right click on your new black material and drag your mouse to "Assign Material To Selection".
 * Open the Hypershade window.
 * Create a Blinn material just like you did before. Blinn differs from Lambert for example (which is the standard material in Maya) that it has a reflectivity parameter.
 * Set the Color to black (not completely! set the slider at about 5%).
 * Set the Eccentricity to 0.175
 * Set the Specular Roll Off to 1.000
 * Set the Specular Color to 100% white
 * Set the Reflectivity to 0.400

Transparent plastic
For the fuel part, we'll assign a nice orange transparant material. Assign the material to Part016 in the Outliner. As you can see in the viewport, the color of that part has changed.
 * Open the Hypershade window.
 * Create a Phong material.
 * Double click on the gray Color field in the Attribute Editor.
 * A new color window opens. Select a color you like; I chose the brightest orange, but if you're more into green, just choose that!
 * Set the Transparency to about 60-70%
 * Set the Diffuse to 1.000
 * Set the Reflectivity to 0.400

Chrome
The metal part needs to be nice & shiny, so we'll make a chrome-like material for that. Assign this material to the metal part - Part014 in the Outliner. Chrome is quite a difficult material to make, because you're all dependent from you're environment - it's nearly "all" reflections. Because we have the HDR environment, that problem is not so big anymore, but to make it more convincing, it would need more reflections from things that are closer to the lighter. It could be the table it's lying on or the person that is watching it. Right now it's lying in an empty street on a completely homogenic plane. Anyway, you can check the results, I think this looks quite realistic already. You really need to experiment with the settings for each material to make it work, and if you really want realistic images, you would probably want to apply a texture to the plane it's lying on.
 * Again, go to the Hypershade
 * Create a Phong material.
 * Set the Cosine Power to 5.000
 * Set the Specular Color to 100% white
 * Set the reflectivity to 1.000

Wood Texture
As stated before, to make it make the lighter more realistic, it needs a realistic environment. We already made part of this environment with the HDR-image, but to make it even more convincing, we're going to turn the ground-plane into a realistic looking table. We need an image of wood to apply to the plane. I'll use one from Mayang's Free Texture Library, called "parallel wooden planks".
 * In the Hypershade, select the "Lambert1" material
 * Go to the Attribute editor and click on the checkered icon next to the "Color" option.
 * Choose "File" and load your texture into the "Image Name" field (click on the folder icon)
 * You can now see a preview of the texture in your viewport (if not, press 6 while in the viewport)
 * In my case, the lighter was not really fortunate positioned, so I selected everything in the outliner and dragged the lighter a bit back

If you render now, you will see it has become quite realistic! Tune your materials a bit more and tweak your mental ray settings, and no-one will be able to tell it from real.

Setting up mental ray
In general, setting mental ray's render quality to a lower quality level is appropriate while you are tweaking your materials, changing camera angles, and any other process that may require repeatedly rendering your scene. But when you are relatively satisfied with how it looks you can then switch your mental ray settings to a level appropriate for production rendering:
 * Either click the render settings button (black clapperboard icon with the two radio buttons) or go to: Render > Render Current Frame > []
 * On the "Quality" tab, change the quality preset dropdown to "Production"
 * On the "Indirect Lighting" tab, under the "Final Gathering" heading, check the box to enable Final Gathering
 * The default accuracy of 100 is usually insufficient. Raising this to 256 is usually a good place to start
 * If, at 256, you are getting spotty artifacts in your render, try raising the point interpolation to 30
 * If you have multiple layers of transparent geometry, it may be necessary to raise the reflection, refractions, and trace depth under "Final Gathering Tracing"