From BlenderWiki

Jump to: navigation, search
This is how your render will look if you use my example settings.
How to import your SolidWorks model in Blender and render it using Yafray.

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, sometimes 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 tutorial, I will describe how to do this using Blender with YafRay.

Both programs are open-source software, which means you can download them for free:

If you use different versions (especially YafRay), you might have difficulties trying to follow this how-to.

You need a basic understanding of the Blender interface to be able to follow this how-to. If you have never worked with blender before, I advise you to read the 3D: Noob to Pro/Blender Interface|Blender Interface chapter of the 3D: Noob to Pro wikibook first.

Another great option is to watch some video tutorials first. This one about the interface is really helpful. There are very good other video tutorials as well at http://www.ibiblio.org/bvidtute/

Exporting from SolidWorks

I will be working with a model of a lighter that I downloaded from Paul Salvador's Site (Z-XYS) somewhere at the bottom.

Before you can import your model into Blender, you need to export it to the VRML 1.0 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.

the export options window
  • Open your assembly.
  • If you don't want to export all the objects, suppress the objects you don't want to export first.
  • The export quality (strangely enough) depends on the screen settings. To improve this, go to Tools > Options > Document Properties tab > Image Quality. If your model looks faceted in your viewport, just set the "Shaded and draft quality HLR/HLV resolution" to a higher value. Especially for complex shapes with a lot of curvature, you'll probably want a higher value. Take into account, however, that a higher value means a bigger file and slower operations within Blender.
  • Go to File > Save As...
  • Select VRML as your file-type and click on the "Options..." button.
  • Make sure "VRML 1.0" is selected. Usually you need to set the unit to something bigger than millimeters; normally centimeters will do, but for the bigger models I advice you to set the unit to meters. You'll be able to scale the model again once you're in Blender.
  • uncheck "save all components of the assembly into a single file"

Because SolidWorks appears to be making a mess out of large assemblies (randomly combining several parts into one mesh), we'll export the assembly as separate files into one directory. To be able to load these files easily, you need to create a new directory for this export first. Later on, we'll import all the files in this directory at once (time saver), so make sure there's no other files in this directory!

  • Close the "Export Options" window (click OK).
  • Create a new directory for the export (or use an empty one), and hit "Save".

Importing in Blender

It is recommended that you now close SolidWorks for better performance. We'll import the exported VRML data into Blender.

  • First you need a script to import all the .wrl files in your export directory at once. Because there wasn't one, I wrote one. You can download it from my site: http://www.extrapuur.nl/blender/vrmlbatch.py (right-click "Save As...").
  • Place the script inside your blender scripts folder (probably something like C:\Program Files\Blender Foundation\Blender\.blender\scripts). After you have done this, the script will always be easily accessible from the import menu!
  • Start Blender (if you had already started it before installing the script, you need to restart Blender)
  • Delete the default cube. Delete the light aswell, we'll be using a different way of lighting, so you won't need that either.
  • Go to "File > Import > VRML batch loader". Select a file in your export dir (any file), and press "Open files in this dir".
  • You may get some "Error: No Data" messages in Blender, but you can ignore these (just keep your mouse moving in figures on your screen...).

Note: if for some reason you can't download the script from my site, you need to create a plain text file called vrmlbatch.py and copy & paste this into it.

Prepare your scene & model

the viewport of the lighter seen from the camera
  • If your model is extremely big (in comparison with the grid), or you can't even see parts, scale it down first. You can do this by selecting all the meshes ("Select > Select All byT type > Mesh"), pressing '.' and SKEY ('s' key), 0.1 (where the number is the scale factor).
  • For my example (the lighter), rotate it first, so that it lies flat - RKEY, X, 89. Press ',' to activate the Bounding Box Center pivot again.
  • Go to the top view (numpad 7), press spacebar and go to Add > Mesh > Plane. Press TAB to go to object mode.
  • Scale the plane to something bigger - SKEY ('s' key), 8.
  • Move your view to a nice perspective and press CTRL + ALT + NUM0 to set the camera to this view. The outer dotted line marks the render border.
  • Now select the meshes that look faceted and set the following properties (you can only do this for one mesh at a time): "Auto Smooth" and then "Set Smooth". You won't see a change in the viewport, but in the render it will look much better.

Save

Time to save!

  • Go to File > Save As... (F2)
  • Enter an appropriate name for your file (ending with .blend) and hit "Save As".

Creating an HDRI environment

the Uffizi probe
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 to light your scene. This will result in very realistic and convincing shadows, higlights 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.

To apply the HDRI environment to your scene:

  • Go to the shading settings (press F5) and click the World button.
  • In the "Texture and Input" tab, click "Add New" and "Angmap".
  • Then go to the "Map To" tab and deactivate "Blend" and activate "Hori".
  • Now go to the Texture settings (press F6) and change the "Texture Type" to "Image".
  • Click the "Load Image" button and locate your HDR image.
  • To be able to render using this environment, you need to enable YafRay. Press F10 and change the "Blender Internal" to "YafRay".
  • Go to the YafRay tab and deactivate the XML button and set Exp (the exposure control) to 1.5.
  • Set the Raydepth to 6.
  • In the YafRay GI tab, select "Full" as your method, and "Low" quality (that's good enough for a preview). Also enable the "Cache" button.
  • Set both Depth and CDepth to 10.
  • For caustic effects you can activate the "Photons" button, but in my case (a lighter lying on a table), it won't make much difference.

Assigning materials

Tutorials-lighter-black-material.png

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 transparent it is etc. because these are your parameters within Blender's material editor. To create the plastic material:

  • Select the two middle parts, the push button and the gas regulator (use SHIFT + click to select more than one mesh at once).
  • Go to the shading settings (F5) and add a new material (Click "Add New").
  • Press CTRL + L (in the viewport) and select Materials from the popup to use this material on all the objects you selected.
  • Change the color to almost completely black (RGB: 0.07/0.07/0.07).
  • In the Shader tab, set the specular shader to "Blinn".
  • Set the "Spec" value to 1.4 and "Hard" to 320.
  • Press "Ray Mirror" in the Mirror Transp tab, and set the "rayMir" value to 0.3.
Tutorials-lighter-green-transp-material.png

Transparent plastic

For the fuel part, we'll assign a nice green transparent material.

  • Select the fuel part, and add a new material to it (again, F5, "Add New").
  • Set the color to a bright green (HSV: 0.220/1.000/1.000) and the alpha value (A) to 0.300.
  • Set the Amb value to 1.000.
  • Go to the Mirror Transp tab and enable both "Ray Mirror" and "Ray Transp".
  • Set rayMir to 0.20 and IOR to 1.45 (which is an approximate index of refraction).
  • Set Filt to 0.250.
Tutorials-lighter-chrome-material.png

Chrome

The metal part needs to be nice & shiny, so we'll make a chrome-like material for that.

  • Set the Ref value to 1.000.
  • Set the specular shader to "Blinn", and use the following values: Spec 2.000, Hard 50 (default), Refr 6.500.
  • In the Mirror Transp tab, enable "Ray Mirror" and set the rayMir value to 0.9. Leave the rest unchanged.
Tutorials-lighter-ground-wood-texture.png

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".

  • Because this texture is 1600x1200, we'll scale the ground-plane to the same aspect-ratio - S, 1.6 (TAB), 1.2.
  • Set the Ref value of the diffuse shader (Lambert) to 0.600.
  • Set the Spec value to 0.175, Hard to 30.
  • In the Texture tab, press "Add New". Press F6 to switch to the texture properties.
  • Change the Texture Type to "Image" and load your texture (in my case the wood texture from Mayang) in the Image tab ("Load Image").

Rendered with materials applied

To render, you can hit F12 directly, or you can go to the render settings first (F10). To speed up rendering a bit, it's a good idea to remove some of the objects that are not visible, like all the small rings inside etc! This can be a mayor timesaver sometimes! Because of the render settings we use (GI and an HDRI environment), my render took about 3 minutes on a AMD64 3200+ with 1GB of RAM. If you just want a preview, you can either make a smaller render (set it to 25% in the Render tab), or use worse quality GI settings. For a final render, I advice you to use at least High for the GI quality - it will take more time but the result will be better looking!

Below you can see the result I got with all the settings from this how-to. Remember that this is just a general guide, and I encourage you to change the settings (Exposure for example), to see the effect. You have to get a little bit of 'feeling' with the material settings to be able to create a satisfying material quickly. I hope this how-to helps to get started with a SW to Blender workflow.

note: if your result is very different from the picture below, please report this on the discussion page (the tab at the top of this page). That way we can keep improving the tutorial. You can upload the render aswell, but make sure it has a specific name (lighter-yourname.jpg for example).

Tutorials-yafray-render-lighter.png

Usefull links

Tutorials