Class ExportToThreeJs
- Namespace
- CADability
- Assembly
- CADability.dll
Converts a Model into a JSON description for a three.js based viewer: solids, shells and faces become triangle meshes, curves become polylines (approximated with the given precision), text objects keep their font, position and string, and the contents of blocks are merged into one entity. Colours come from the IColorDef of the objects, and the primitive entries of UserData are included. Create an instance with the model, set ExportEdges and ExportUserData as needed and call ToJSON(bool).
public class ExportToThreeJs
- Inheritance
-
ExportToThreeJs
- Inherited Members
Constructors
ExportToThreeJs(Model, double)
Creates the exporter for the model m. Nothing is converted until ToJSON(bool) is called.
public ExportToThreeJs(Model m, double precision)
Parameters
mModelthe model to export
precisiondoublethe maximum distance, in model units, between the exact geometry and the triangles or polylines that approximate it
Fields
ExportEdges
When true, the edges of solids, shells and faces are exported as lines in addition to the triangles. False by default.
public bool ExportEdges
Field Value
ExportTextAsTriangles
Intended to export text as triangles instead of as text entities. Currently not evaluated: text is always exported as a text entity with location, directions, font and string. False by default.
public bool ExportTextAsTriangles
Field Value
ExportUserData
When true (the default), the entries of the objects' UserData whose values are primitive types,
strings or Guids are written into the userData of the entity; other entries are skipped.
public bool ExportUserData
Field Value
Methods
ToJSON(bool)
Converts all objects of the model and returns the JSON text: an object with an entities array, where each entity
has faces (vertices, triangle indices and colour), lines, text and userData. Each call
appends the objects of the model again, so call it once per instance.
public string ToJSON(bool escapeQuote = true)
Parameters
escapeQuotebooltrue to remove backslashes and escape the double quotes, so that the result can be embedded as a string literal in a script or html page; false for the plain JSON
Returns
- string
the JSON text
Exceptions
- ExportToThreeJsException
when an object of the model cannot be converted