Drawings SDK Developer Guide > Working with .dwg Files > Working with Other File Formats > Exporting to Other Formats > Exporting to Three.js Format
Exporting to Three.js Format

The Three.js export TX module exports graphical data from .dwg drawing file format to Three.js (JSON) format.

TD_ThreejsJSONExport_xx.yy_zz.tx

where:

  • xx — Major Drawings SDK version number.
  • yy — Minor Drawings SDK version number.
  • zz — Visual C++® compiler version number. For example, for Microsoft® Visual Studio® 2015 version, the number is 14.

The module exposes a single interface ThreejsJSONModule with a single method exportThreejsJSON().

The Three.js export TX module is a single support module for the Drawings SDK, and it's available in dynamic and static forms for Windows, Linux, and macOS (x86 and x64 versions). All source is available in the release packages.

For dynamic (.dll) configurations, the Three.js export TX module can be loaded dynamically; it does not need to be linked to. For static configurations, the Three.js export module should be linked to.

Export process

There is only an abstract class that can be inherited by classes that implement their own algorithm of Three.js export: ThreejsJSONModule.

The import process commonly consists of three steps:

  1. Create a Three.js export module.
  2. Call the exportThreejsJSON() method of the Three.js export module.
  3. Analyze the results of the export process.

Before following the previous steps, some preliminary actions must be performed, including creating a custom services object and initializing it:

// Create a custom Services object.
OdStaticRxObject svcs;
// Initialize Teigha.
odInitialize(&svcs);

To create the Three.js export module, call the method loadModule() of the odrxDynamicLinker object. The loadModule() method returns a smart pointer to the export module (the export module object is an instance of the class inherited from the ThreejsJSONModule class).

// Load the Three.js export TX module
ThreejsJSONModulePtr pModule = ::odrxDynamicLinker()->loadApp(OdThreejsJSONExportModuleName, false);

To export a .dwg database to Three.js format, use the exportThreejsJSON() method of the export module.

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

Parameters:

  • pDb — Pointer to the OdDbBaseDatabase object with the .dwg database to be exported.
  • pOutStream — The output stream (files stream, memory stream).
  • background — The color of the scene background.
  • bFacesEnabled — Defines whether faces are exported (if "true") or only lines and points (if "false").

It is implied that the .dwg database already exists. For example, it can be created by loading it from a .dwg file:

OdDbDatabasePtr pDb = svcs.readFile(dwgPath);  //dwgPath contains full path to the input .dwg file

Also there must be a stream for the output to be sent to, for example, a file:

// Create the output file
OdStreamBufPtr file = svcs.createFile("output.json", Oda::kFileWrite, Oda::kShareDenyNo, Oda::kCreateAlways);

Now the export can be done by calling the exportThreejsJSON() method.

ODCOLORREF background = 0;
// Export a DWG database to Three.js format
OdResult exportResult = pModule->exportThreejsJSON(pDb, file, background, true);

Additionally, the function exportThreejsJSON() defined in the TD_THREEJSJSON_EXPORT namespace can be used for the export. When using this function, there is no need to create a Three.js export module.

#include "ThreejsJSONExport.h"
using namespace TD_THREEJSJSON_EXPORT;
// Export a DWG database to Three.js format
OdResult exportResult = exportThreejsJSON(pDb, file, background, true);

The exportResult variable is of the OdResult type. The "eOk" export result indicates a successful export process.

See Also

Copyright © 2002 – 2020. Open Design Alliance. All rights reserved.