Sl-Alex home lab

3D models for KiCAD. Part 3 - Import

Views: 5881Comments: 3
Articles

Translation: RU
3D models for KiCAD. Part 3 - Import

In this article I'll show how to use 3D models in KiCAD from either FreeCAD or OpenSCAD. It is possible even if you use a model from another source. As you remember, in the first article we used OpenSCAD to create 3D model, in the second article we used FreeCAD. Using FreeCAD seems to be much easier (almost like point'n'click), but don't forget about the flexibility of OpenSCAD: in some cases its parametrization functionality can be very useful. Maybe you are the laziest and you prefer using 3D model from the internet. It does not matter, anyway in most cases you have to convert this model to the KiCAD-understandable format. In this article I'll try to describe all important steps of these convertions and add more light to the darkest parts of this process.

As you probably know, KiCAD uses VRML format (*.wrl extension). But I'm pretty sure that KiCAD will fail to render your 3D model, converted to VRML. The bad thing is that KiCAD uses VRML, which can be generated only by Wings3D. Things are changing quickly, so KiCAD definitely will support more formats, but nobody knows when it will happen. For beginners (and not only for them) it's very hard to draw something in Wings3D. And you will have a lot of problems if you decide to change such a simple thing as pin spacing, for example. Even if you will become an expert in Wings3D, you will not be able to modify models faster than in FreeCAD. In my case creation of the 3D model (SO-16 case) in FreeCAD took only 6 minutes. In Wings3D it would be about half an hour. As for me the choice is obvious: I use Wings3D only as an intermediate software, at the final step.

In order to open your model in Wings3D and convert it to KiCAD-understandable format you have to prepare input data for Wings3D. Usually I use STL format, which holds 3D model as a set of triangles. Now we will look at the export from both FreeCAD and OpenSCAD to STL file.

Export STL from FreeCAD

In fact, it is very easy to get a correct STL file from FreeCAD. Just select two pin arrays and make an export (menu item "File/Export"). Do not select all, otherwise you'll export everything, including invisible objects. When you are done your model is ready to be opened in Wings3D.

Export STL from OpenSCAD

In OpenSCAD you can also find menu item "File/Export/Export as STL". But the bad thing is that in best case Wings3D will refuse to open your fail, while in the worst it will fail out with an error. The reason is in the file format. Wings3D can open only binary STL files, while OpenSCAD generates plain text. For converting text STL to binary format I suggest to use MeshLab. Open our STL model via "File/Import Mesh" and save it in the same file via "File/Export Mesh". You have to check "binary encoding" checkbox.

Adding colors

OK, both our models can be successfully opened in Wings3D (menu item "File/Import/StereoLithography (.stl)") and both models looks nearly the same. Let's add more colors to this boring grey world! To do so, we open window with color palette (menu "Window/Palette") and list of materials (menu "Window/Outliner"). After that we switch to the face selection mode (button "f" on the keyboard), select all necessary faces and apply all colors we need. When this is done, we switch to body selection mode (button "b"), select our model and in drop-down menu select "Vertex Attributes/Colors to Materials". After that we will see that our list of materials contain several materials with selected colors. For each material we will set values of "Ambient", "Specular" and "Emission" to zero. Now we will export model to VRML format. At this step our model is ready for KiCAD.

How to use it in KiCAD

Let's create a footprint for our component. For our model it will look like the following:

SO-16 footprint Figure 1: SO-16 footprint

Now open component properties and add our model in the list of the available 3D models. If you use inches, you are done with scaling. If you use millimeters, add a coefficient 1/2.54 (~0.3937) to the each axis. If you need to adjust offset in millimeters use a coefficient 1/25.4 (~0.03937) to convert millimeters to inches. In my case I had to add -0.2mm X offset (half of the pin width), so offset in inches was 0.2/25.4 (0.07874)

Footprint properties Figure 2: Footprint properties

Let's look at the result:

Final 3D model in KiCAD Figure 3: Final 3D model in KiCAD

It seems that at this point article can be finished, but I want to add several small tips:

  • Before model creation think about how to make it more universal. Probably a bit later you will have to create similar models, but with the different sizes, number of pins and so on. The best choice will be OpenSCAD. In case if your model will be relatively unique, or is too hard to keep all details in mind - use FreeCAD. These are just a suggestions, which come from my own experience.
  • Do not create models with high detalization. Use rounding only when you have to, do not increase number of the polygons on the cylinders and other fragments. Always remember that your model will be used together with a lot of other models in one board. If you have a lot of details then probably you will spend a lot of time waiting until the final render of your board is done.
  • Don't afraid of OpenSCAD. It is great for the creation of the parametric models.

OK, that's all about how to create 3D models for KiCAD. Finally, here is a video, which shows all mentioned above.