#include <stdio.h>
#include <vector>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <assert.h>
#include <QtCore/QFile>
#if defined(JAMBUILD)
#else
#include "../../include/Mudbox/mudbox.h"
#endif
#include "utility.hpp"
{
MB_PLUGIN(
"STL Exporter",
"STL file export plugin",
"Autodesk",
"http://www.mudbox3d.com", 0 );
class STLExporter :
public BaseExporter,
public Singleton<STLExporter>
{
public:
STLExporter() {
}
virtual QString Extension()
const {
return "stl"; };
virtual QString Description()
const {
return "Stereolithography File"; };
{
ret.
push_back(FileExtension(
"stl",
"Stereolithography File"));
return ret;
}
{
if (GetNumMeshes() == 0)
MB_ERROR(
"There are no meshes to export");
if (GetNumMeshes() > 1)
MB_ERROR(
"Multiple meshes can not be exported to this format");
const Mesh* m = GetMesh(0);
if (IsMeshOpen(m))
MB_ERROR(
"Only continuous meshes can be exported");
const uint STL_HEADER_SIZE = 80;
char header[STL_HEADER_SIZE] = "";
std::fill(header, header + STL_HEADER_SIZE, 0);
ofile.
write(header, STL_HEADER_SIZE);
uint32 cnt = m->FaceCount();
cnt *= 2;
WriteUInt32(ofile, cnt);
{
for ( uint i = 0; i < m->FaceCount(); ++i ) {
const Vector& normal = m->FaceNormal(i);
WriteVectorFloat32(ofile, normal);
for (uint j = 0; j < 3; ++j) {
const Vector&
v = m->TriangleVertexPosition( i, j );
WriteVectorFloat32(ofile, v);
}
WriteUInt16(ofile, 0);
}
}
{
for ( uint i = 0; i < m->FaceCount(); ++i ) {
const Vector& normal = m->FaceNormal(i);
WriteVectorFloat32(ofile, normal);
for (uint j = 0; j < 4; ++j) {
if (j != 1) {
const Vector&
v = m->QuadVertexPosition( i, j );
WriteVectorFloat32(ofile, v);
}
}
WriteUInt16(ofile, 0);
WriteVectorFloat32(ofile, normal);
for (uint j = 0; j < 4; ++j) {
if (j != 3) {
const Vector&
v = m->QuadVertexPosition( i, j );
WriteVectorFloat32(ofile, v);
}
}
WriteUInt16(ofile, 0);
}
}
};
};
}