CAD Exchanger SDK
OBJ Converter

Overview

OBJ_Reader can read files and OBJ_Writer can write files in Wavefront OBJ file format.

The reader can read files with external .mtl (material library) files, files with both multiple and single parts. In the case of multiple parts they are created as roots of the resulting model (ModelData_Model).

Scope

  • polygonal representations
  • colors and materials

Mapping

Import Mapping

Below table shows how OBJ content are mapped into CAD Exchanger entities after import.

Product Structure

OBJ tag Description CAD Exchanger Entity Note
v vertex data ModelData_Part All accumulated data between "g" tags maps directly to ModelData_IndexedTriangleSet.
vn vertex normals data
vt texture coordinates data
f face data
o object name
g group name
matlib external .mtl file name
usemlt specifies the material name for the element following it

Export Mapping

Below table shows how CAD Exchanger entities are mapped into OBJ entities after export. Note that OBJ could not store the hierarchy therefore all polygonal data of every instance of part will be bake in the world coordinate system.

Product Structure

CAD Exchanger Entity OBJ tag Note
ModelData_Assembly v / vn / vt / f / g / o / matlib / usemlt
ModelData_Part Every body of part will map to OBJ-group (surrounded with "g" tag)
ModelData_Instance

Parameters

Importer Parameters

The OBJ import parameters are controlled by OBJ_ReaderParameters. The following table contains a list of parameters for OBJ import:

Parameter Default value Description
UnitCoef() 1.

Specifies the measurement unit to interpret coordinates in the input .obj file.

The value is a scale coefficient to millimeters. For instance to interpret file coordinates in meters, the value of 1000. must be used. By default, coordinates values are interpreted in millimeters.

Exporter Parameters

The OBJ export parameters are controlled by OBJ_WriterParameters. The following table contains a list of parameters for OBJ export:

Parameter Default value Description
ToGenerateMtlFile() true

Specifies whether a separate .mtl file (with material library) should be created.

If the value is true then an .mtl file is created. The .mtl file will have the same base file name as the resulting .obj file.

If the value is false then no colors will be stored and no .mtl file will be created.

WriteNormals() true

Specifies whether vertex normals should be saved in a resulting .obj file.

If the value is true then normals are stored in the file. In this case, third-party viewers may display 3D models in smooth shading. If the value is false then normals are not stored in the .obj file, and the third-party viewers may display 3D models in flat shading.

OverrideDuplicateNames() true

Specifies whether original names of parts should be supplemented with suffix(es).

If the value is true every part which encountered twice or more during export to .obj file will supplemented with suffix to avoid merging of geometries with same name during import by CAD Applications. If the value is false every part will be saved with original name during export to .obj file, it may cause that some geometries data with same name will be merged during import by CAD Applications into one geometry object.