Exporting to JSON format using ODA Drawings SDK

Vadim Asandiy

December 13, 2018

Need data in JSON format? ODA Drawing SDK can export data from a database’s view to JSON format. The format is applied using the JavaScript library named Three.js.

Use Drawings SDK’s ThreejsJSONModule class from the namespace TD_THREEJSJSON_EXPORT:

OdResult exportThreejsJSON(OdDbBaseDatabase *pDb, OdStreamBuf *pOutStream, const ODCOLORREF &background, bool bFacesEnabled = false);

Input parameters:

  • background – Color of scene background.
  • bFacesEnabled – If true, pDb is exported to JSON with faces, otherwise only with lines and points.

Output parameter:

  • pOutStream – Output stream (files stream, memory stream).

Return value:

  • eOk for ok or OdResult error code.

If the method result is eOk, pOutStream will contain text in JSON format with four objects:

  • JSON object of metadata.
  • JSON array of materials for points, lines and meshes.
  • JSON array of geometries with the data’s array. Geometry for points and lines contain vertex and empty face arrays; geometry for meshes contain vertex, normal, color and face arrays (count of array depends on the first index of face elements, which contain bitmasks).
  • JSON array of objects such as a scene-graph with a scene-object at the root node. The second level of this tree contains cameras and layers with default type Object3D. A camera object may contain a light object. Layers may contain point, line, mesh or metafile objects with default-type Object3D, which is the root node for primitive type objects.

The downside of converting to Threejs JSON format occurs if the original object has more than one camera object—it is impossible to change the coordinates of objects using matrices of a camera.

Don’t forget that in JSON format, the set of data is stored with a scene graph and arrays of geometry and materials. Displaying on layers and disabling types of objects (for example, displaying faces as meshes or as isolines) must be configured in JavaScript.

The next examples show 2D and 3D objects opened in ODA Viewer and converted to Threejs JSON format.

2D object in ODA Viewer:


2D object in Threejs JSON:


3D object in ODA Viewer:


3D object in Threejs JSON: