Use Drawings SDK’s ThreejsJSONModule class from the namespace TD_THREEJSJSON_EXPORT:
OdResult exportThreejsJSON(OdDbBaseDatabase *pDb, OdStreamBuf *pOutStream, const ODCOLORREF &background, bool bFacesEnabled = false);
- background – Color of scene background.
- bFacesEnabled – If true, pDb is exported to JSON with faces, otherwise only with lines and points.
- pOutStream – Output stream (files stream, memory stream).
- 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.
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: