Howto:Methods to replace the dial gauge bit mapped texture with vectorial objects: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
Line 21: Line 21:
On the right you can see the appearance of a medium-sized gauge (about 2 inches). As you can see the gauge is made with four bitmapped layers that define the colors and the levels on the surfaces (bottom for the bicolour graduated circle, medium for the description, hight for the arc applied on the glass). Each of these layers also has a different reflectance and light emission properties.
On the right you can see the appearance of a medium-sized gauge (about 2 inches). As you can see the gauge is made with four bitmapped layers that define the colors and the levels on the surfaces (bottom for the bicolour graduated circle, medium for the description, hight for the arc applied on the glass). Each of these layers also has a different reflectance and light emission properties.


<gallery mode=packed widths=230px heights=230px>
<gallery perrow=5 widths=230px heights=230px perrow="3">
Screenshot 20181225 204112.png|1th step: The image is import to keep the file's DPI
Screenshot 20181225 204112.png|1th step: The image is import to keep the file's DPI
Screenshot 20181225 204149.png|2th step: The image when it is important that it is the same size as the original. This way it will be easily inserted into objects with Blender
Screenshot 20181225 204149.png|2th step: The image when it is important that it is the same size as the original. This way it will be easily inserted into objects with Blender

Revision as of 20:21, 25 December 2018

In the FIAT G91-R1B project it was necessary to realize high resolution analog gauges (tolerance <1/10 mm) to allow a better visualization of the instruments and therefore a more comfortable simulated flight experience. The creation of high resolution analog gauges required the creation of the instruments with a CAD program called Freecad (very suitable for mechanical and micromechanical parts). FreeCAD is an open source project based on OpenSCAD libraries initially developed for the US Army. Unfortunately Freecad does not contain a .ac converter, but you must first go to Blender via the .obj format and then convert to .ac format. If you want to obtain a resolution of the dial lower than 1/10 of mm it is necessary to use 1024 textures because the gauge has an average dimension between 50-100 mm. Flightgear's airplanes rarely have gauge dials so detailed and so this work has served to show that the Flightgear system is still capable of working effectively with dozens of high-resolution gauges. But sometimes, especially for smaller PCs, it may happen to witness an evident slowdown and in some cases the abort of the program for an evident end of the available resources. To overcome this drawback, a detailed analysis of the causes was made and it was found that the problem was due to the high amount of 1024 textures present in the cockpit instruments. The reason is substantially related to the internal mode of operation of modern GPUs that convert a bitmapped image into vertices that with tens of images with a size of 1024 can lead to the saturation of memory available. Therefore, the solution can be given by using a different paradigm in which the bitmapped image is substituted with an equivalent vectorized image.

Efficiency in converting a bitmapped image into vector

A dial image is essentially an image consisting of 90-95% of empty pixels. Therefore, in this case, it is possible to apply the method of converting bitmapped image in vector. This method is not always advantageous, if the bitmapped image is complex, such as a geographic map, the conversion into vector format, described in this how-to, may not have the desired benefits. Even the characteristics of the bitmapped image can greatly change the quality of the conversion work and therefore it is necessary to make some tests to understand if this is a useful way to solve the problem.

Converting a raster image to vector

In the open-source spirit of Flightgear everything that is explained here must be freely available and without particular constraints on the propiety of the work done. I want to remind you that many converters on the Internet change the terms of intellectual property of the processed content and are therefore not compatible with Flightgear.

For the enhancement of bitmaps in this how-to is proposed Inkscape that is very used by the developers of Flghtgear and often many textures were made with Inkscape (SVG format) and then converted to PNG or via canvas used directly on the surfaces.

So the main work is to take a PNG or 2D raster image with SVG format and convert it into a vectorized two-dimensional image. Sometimes it may be convenient to transform the vectorized two-dimensional image into a 3D image and this step will be explained as a technique to simulate the characters carved by punching on the knobs.

On the right you can see the appearance of a medium-sized gauge (about 2 inches). As you can see the gauge is made with four bitmapped layers that define the colors and the levels on the surfaces (bottom for the bicolour graduated circle, medium for the description, hight for the arc applied on the glass). Each of these layers also has a different reflectance and light emission properties.

The bitmap (The image must be in shades of gray) is load (Steps 1-2-3) and be converted using the "trace bitmap" option of "Path" (Steps 4-5-6). At this point we have a SVG format vectorized object that can be used by Blender. Then take care to eliminate the bitamapped image that has remained under the vectorized image. It is better to take a second step before saving the SVG file, converting the page format to the size of the generated image, in this way it will be easier to manage it in Blender. For this you need to select the vectorized image go to the "edit" menu and then "resize page to selection". At this point the image is ready to be exported in SVG vector format. Normally the vectorization parameters are good, sometimes it is better to change "brightness reduction" according to the thickness to be obtained.

This first phase can be different if, instead of starting from a raster image, we start from an image generated with Inkscape. In this second case, conversion is always convenient to avoid problems with fonts. Inkscape's resolution, at this stage, is enough to ensure a good job. Sometimes I got a more realistic result by doing a first rasterization step of the SVG file at a resolution of 1024x1024 and then I converted the PNG file into vector format.

NOTE: Attention to scale problems
It is possible with blender to scale the objects generated in SVG format, but it is not a good practice because if you wanted to resume the gauge to make other changes and additions with Freecad you would need to redo the scalings. It is better always with Inkscape to correctly dimension the drawing. The PNG file has within it the metric and the vectorization and subsequent conversion in SVG preserving this metric. Therefore always proceed in 1: 1 scale if you do not follow this rule the work becomes much longer and more complicated.

Finally we now have an image that can be imported into Blender (but unfortunately, at least for now, not in Freecad!) And applied to parts of the 3D model. This work must be performed for all 4 layers of the example.