Exporting 3d Models
STL Files
Stereolithography CAD files or STL is a 3d file format common in rapid prototyping, 3d printing, and computer aided design. STL files come in in two forms, an ASCII version as well as a Binary version. Loading and saving of STL files for both binary and ASCII version is supported via the Qkmaxware.Geometry.IO.StlSerializer
class.
ASCII STL
To save an ASCII encoded STL, use the Serialize
method of an StlSerializer
object to create an ASCII string representing the geometry that can then be saved to a file.
using System.IO;
using Qkmaxware.Geometry;
using Qkmaxware.Geometry.IO;
public class Program {
public static void Export(Mesh mesh) {
var serializer = new StlSerializer();
using (var writer = new StreamWriter("myfile.stl")) {
writer.Write(serializer.Serialize(mesh));
}
}
}
Binary STL
To save an binary encoded STL, use the SerializeBinary
method of an StlSerializer
object to write mesh data to a given BinaryWriter.
using System.IO;
using Qkmaxware.Geometry;
using Qkmaxware.Geometry.IO;
public class Program {
public static void Export(Mesh mesh) {
var serializer = new StlSerializer();
using (var writer = new BinaryWriter(File.Open("myfile.stl", FileMode.Create))) {
exporter.SerializeBinary(mesh, writer);
}
}
}
Wavefront Obj Files
Wavefront Obj files are another common file format. Unlike STL and other formats, OBJ files are only available as an ASCII encoded format. Loading and saving of OBJ files is supported via the Qkmaxware.Geometry.IO.ObjSerializer
class.
ASCII Obj
To save an ASCII encoded OBJ, use the Serialize
method of an ObjSerializer
object to create an ASCII string representing the geometry that can then be saved to a file.
using System.IO;
using Qkmaxware.Geometry;
using Qkmaxware.Geometry.IO;
public class Program {
public static void Export(Mesh mesh) {
var serializer = new ObjSerializer();
using (var writer = new StreamWriter("myfile.obj")) {
writer.Write(serializer.Serialize(mesh));
}
}
}
Extensible 3D Graphics X3d Files
Extensible 3D Graphics files or X3D files is a royalty free xml based format for representing 3D computer graphics. Given that X3D files are an based on the XML format, there only is an ASCII version available for this format. Saving of X3D files is supported via the Qkmaxware.Geometry.IO.X3dSerializer
class.
ASCII X3d
To save an ASCII encoded X3D, use the Serialize
method of an X3dSerializer
object to create an ASCII string representing the geometry that can then be saved to a file.
using System.IO;
using Qkmaxware.Geometry;
using Qkmaxware.Geometry.IO;
public class Program {
public static void Export(Mesh mesh) {
var serializer = new X3dSerializer();
using (var writer = new StreamWriter("myfile.x3d")) {
writer.Write(serializer.Serialize(mesh));
}
}
}