7.3. 3D model and geometry modules

7.3.1. OBJ file import

In order to maximize the potential application of the software, an import module allowing the import of standard CAD files was implemented. There are various common file formats used to store and deploy threedimensional CAD models. Because of its simplicity and widespread use as an exchange format, the OBJ format (The Library of Congress (USA), no date; Bourke, 2022) has been chosen for implementation.
The format is clear-text-based, so it can be viewed with any text file editor. The following sample shows the data of a simple triangulated cube with a dimension of one located at the origin (see Figure 95).

Firstly a list of vertices (“v”) and normal vectors (“vn”) is contained. In the bottom section, the indices of these elements are referenced (“f”) to define 12 triangular surfaces. While the format allows additional features, see e.g. (Bourke, 2022), the data contained in this simple example covers all types that are required for importing geometry to the RadiCal method. Beyond the features contained in the above example, only the functionality to import texture coordinates is additionally implemented. The texture feature can potentially be used to define the directional system for non-isotropic surface roughness. However, this feature is currently not fully implemented in the raytracer.

7.3.1.1. Implementation

The OBJ import is contained in class TimportOBJ of the module rc_OBJimport.

The class contains solely the function ReadOBJ which performs the import. All required additional routines are contained within this function. The function returns the imported geometry (geo), extracted material list (mlib) and a list with errors or warnings (errList) that can potentially occur during the import.
Apart from the filename (fn) the function has two input parameters that are used to control the function of the smooth shading feature (see 7.6). Additionally, an optional array can be passed to the function triggering an automatic subdivision of the geometry during the import. This array provides the relevant material identifiers (as strings) and the subdivision limit that should be applied during the import for the specified material layer.

7.3.2. Internal geometry definitions

Internally, the imported geometry is stored in a hierarchical structure: The master node (TRCGeometry) contains a list of objects (TRCGeoObject), and each object contains a list of faces (TRCface). Along with the objects, the boundary boxes (relevant to collision detection) are included at each level.

As shown in the class definitions above, the 3D data contained in the OBJ file is stored in a hierarchical structure that additionally contains pre-computed data to increase the performance of the raytracing algorithm.

The three vertices provided by the OBJ face definition are converted into a face origin (v0) and two vectors (edge1, edge2). Based on the edge vectors, a local reference system is precomputed for every face (lxv, lyv, snv). The x-axis of the reference system is aligned to the edge1 vector, whereas the z-axis is aligned to the surface normal vector of the face. If the imported model contains normal vectors defined on the vertices (s0, s1, s2) the smooth shading function can be used to derive surface smooth normal vectors throughout the face

(see 7.6). If no vertex normals are contained in the file, a single constant surface normal vector (snv) is generated by applying the cross-product of edge1 and edge2. The direction of the surface normal vector is used to distinguish the front and backside of the surface. The definition follows the convention of computer graphics: a counter-clockwise sequence of the vertices defines the front side of the surface, while the clockwise order defines its back side. Based on the ordinal variables frontID and backID, each side can be assigned a different surface material.