MODEL FILES


Edit, Convert, Save

What you need to have


A CAD model including one, or more parts (parts don’t have to be enclosed volumes, they also can be open shell structures). It doesn’t matter what CAD program you use, or what is its native file format.

Editing


If the model is large (see next chapter about what makes a model large), then you might want to reduce it using different techniques. Before doing anything it is important to understand how the conversion process works and what will be its outcome. When you save your model into STL, OBJ, or OFF formats, then the converter routine will mesh all surfaces with triangles. In computer graphics we like triangles, because using them we can process even the most complicated geometries. Using triangles has another great advantage: triangles are approximating the original geometry. In this way the shared geometry can’t be accurately reverse engineered by the recipient of the presentation, or any third party. The next picture shows a simple part in its original (CAD) form (left) and after meshing (right).

Since this part is bordered only by flat faces, the converter meshed them with a small amount of triangles. In this case the fewer the triangles, the better, because more triangles will not add more detail. However in the next picture there is an Allen-head screw, which has many curved faces (spherical, cylindrical and conical).

Even if the converter was set to make relative coarse mesh, this model includes much more triangles. And in this case the more the triangles the better, because it makes the curved surfaces smoother, therefore it adds more detail. Of course more triangles make the model look nicer (in case of the curved surfaces at least), but it also has its drawbacks: it makes screen operations slower, consumes more RAM (can be critial in handheld devices, such as smartphones, where the hardware has very limited capabilities) and has a bigger disk footprint. This is why you almost always have to find a trade off between quality and performance. After this introduction let’s see how we can reduce model size in the next chapter.

Model size reduction


In the previous chapter we learnt, that we have good reasons to reduce the size of our model. The followings are not a complete list. You may find additional possibilities. These modifications to be done in the CAD program (before converting the parts).

1. Look for parts, which are not needed in your presentation. Imagine you have a house model, which includes all details, and you just want to show how it looks like from inside and outside. You probably don’t have to keep small parts, like small screws, switches, sockets, base boards, clothes hanger, etc. Remove all of these unless they have to be really included (you may want to show the electric installation for example)
2. Look for complicated parts, which can be simplified. This process is the so called defeaturing and it involves many possible actions. Think about small geometrical entities, which would generate lot of triangles (beware of the curved surfaces!). Some surfaces are really small (compared to the full model, so omitting them will not make any difference). For example you have an engine block model and there are some threaded bores in it. Suppress them, if you can. Short edges generate additional triangles, so combine them into a larger one, if possible. Small surfaces, which will not be visible anyway are unnecessary.
3. Look for parts, which remain hidden. For example plumbing inside a wall. If it is not a plumbing presentation, delete it. A screw, which always remains in screwed-in position might not need its threaded shank. You can keep only the head. Or a washer under a bolt head. Can be deleted too.
4. Look for complicated parts, which can be substituted with simple ones. For example hex-head instead of Allen-head screw. Do you have a small diameter cylindrical part? Substitute it with 4 flat rectangular faces. Looking at from afar, nobody can tell the difference.

The model size reduction is not always necessary. If you are sure your presentation will always be viewed on desktop computers/workstations, then don’t waste your time with that. But if it will be possibly opened on smartphones, then try to open the completed presentation in your phone and see if it works at all. It also depends on the browser of choice. Firefox can open a bit bigger models than Chrome (at the time this article is written: end of 2020).

Part conversion


After a possible model size reduction comes the conversion, which produces the faceted geometry we can further use. Before getting into details, a few words about the most popular faceted file format, the STL (applies to both binary and ASCII). The STL file format is relative old and probably the worst from the trio of accepted formats. It doesn’t define nodes first before triangles, instead, it defines the triangles directly by its corner coordinates. If you have multiple bodies in the same CAD file and you save everything into a single STL file, then by reading the STL data, nobody can tell which triangle belongs to which body. If the bodies were well separated in space, then it would be theoretically possible, but since it cannot be guaranteed, we consider one body per one STL file. (Actually what matters here is the cornerpoint coincidence. If you have 2 bodies and they have coincident corner nodes, e.g.: due to overlapping surfaces, then you will have triangles which belong to different bodies while having the same corner coordinates.) This is why there is no possibility to break down the STL content in the project file, so we can assign only one name, one color and one displacement vector for each STL file. And since the STL has this limitation, our service won’t take advantage of using more advanced file formats (OBJ and OFF). Therefore they will also be considered as "dumb" as STL: one file, one part. This is why -in case of multiple bodies- you should convert each body into separate STL (or OBJ, or OFF) file. You can still use a single file to store all bodies, but in this case you have to accept some limitations. In this case you can’t define displacement vectors for exploded view. It will be impossible to define different colors for different bodies. You can’t handle the different bodies separately in any way. You can’t show/hide different bodies separately. Scripting will be also affected. Therefore the recommended way is to use a separate file for each body. This can be done in the different CAD programs in different ways and this article can’t cover all applications, not even only the major ones. This will be explained for one CAD application: FreeCAD. It is chosen, because it is free and multiplatform, so everyone can use it and repeat the same procedure what is explained here. In FreeCAD this kind of mass conversion is carried out using a script. Its script language is Python. The script we use for conversion is the following:

  • # -*- coding: utf-8 -*-
  • import FreeCAD
  • import Import
  • import MeshPart
  • doc = FreeCAD.newDocument()
  • FreeCAD.setActiveDocument(doc.Name)
  • Import.insert("Geom.stp", doc.Name)
objs = FreeCAD.ActiveDocument.Objects
b = 0
  • for obj in objs
  • a = obj.Name
  • __mesh__=doc.addObject
  • ("Mesh::Feature","Mesh")
  • __mesh__.Mesh=MeshPart
  • .meshFromShape(Shape=doc.getObject(a)
  • Shape, LinearDeflection=20000
  • AngularDeflection=0.4, Relative=True)
  • __mesh__.Label="Meshed"+str(b)
  • __mesh__.Mesh.write("body"+str(b)+".stl")
  • del __mesh__
  • mw=FreeCADGui.getMainWindow()
  • mw.deleteLater()

In the code section above the LinearDeflection and the AngularDeflection variables have been marked by bold. It means you might want to modify them according to your needs. Here is what they mean:

Before using the code above, it needs to be edited. Now we assume, that all different bodies are in the same CAD model and the assembly is exported into a neutral CAD format (STEP file in this example). Do the following steps:

This procedure results binary STL files. Its content is almost as same as the ASCII STL file, except, it supports facet coloring in 2 unofficial ways. Therefore this color support has not been implemented in our service 🡲 colors are defined in the project file.


Free photo 1610718 © - Dreamstime.com