Add export of the mesh as an STL file. That's trivial.
[git-p4: depot-paths = "//depot/solvespace/": change = 1822]
This commit is contained in:
parent
cad77c9c47
commit
b4a9ac993c
|
@ -16,7 +16,8 @@ const GraphicsWindow::MenuEntry GraphicsWindow::menu[] = {
|
|||
{ 1, "&Save\tCtrl+S", MNU_SAVE, 'S'|C, mFile },
|
||||
{ 1, "Save &As...", MNU_SAVE_AS, 0, mFile },
|
||||
{ 1, NULL, 0, 0, NULL },
|
||||
{ 1, "&Export Image...", MNU_EXPORT_PNG, 0, mFile },
|
||||
{ 1, "Export &Image...", MNU_EXPORT_PNG, 0, mFile },
|
||||
{ 1, "Export &Mesh...", MNU_EXPORT_MESH, 0, mFile },
|
||||
{ 1, NULL, 0, 0, NULL },
|
||||
{ 1, "E&xit", MNU_EXIT, 0, mFile },
|
||||
|
||||
|
|
|
@ -473,6 +473,57 @@ void SolveSpace::SolveGroup(hGroup hg) {
|
|||
FreeAllTemporary();
|
||||
}
|
||||
|
||||
void SolveSpace::ExportMeshTo(char *filename) {
|
||||
SMesh *m = &(SS.GetGroup(SS.GW.activeGroup)->runningMesh);
|
||||
if(m->l.n == 0) {
|
||||
Error("Active group mesh is empty; nothing to export.");
|
||||
return;
|
||||
}
|
||||
SKdNode *root = SKdNode::From(m);
|
||||
root->SnapToMesh(m);
|
||||
SMesh vvm;
|
||||
ZERO(&vvm);
|
||||
root->MakeMeshInto(&vvm);
|
||||
|
||||
FILE *f = fopen(filename, "wb");
|
||||
if(!f) {
|
||||
Error("Couldn't write to '%s'", filename);
|
||||
vvm.Clear();
|
||||
return;
|
||||
}
|
||||
char str[80];
|
||||
memset(str, 0, sizeof(str));
|
||||
strcpy(str, "STL exported mesh");
|
||||
fwrite(str, 1, 80, f);
|
||||
|
||||
DWORD n = vvm.l.n;
|
||||
fwrite(&n, 4, 1, f);
|
||||
|
||||
int i;
|
||||
for(i = 0; i < vvm.l.n; i++) {
|
||||
STriangle *tr = &(vvm.l.elem[i]);
|
||||
Vector n = tr->Normal().WithMagnitude(1);
|
||||
float w;
|
||||
w = (float)n.x; fwrite(&w, 4, 1, f);
|
||||
w = (float)n.y; fwrite(&w, 4, 1, f);
|
||||
w = (float)n.z; fwrite(&w, 4, 1, f);
|
||||
w = (float)tr->a.x; fwrite(&w, 4, 1, f);
|
||||
w = (float)tr->a.y; fwrite(&w, 4, 1, f);
|
||||
w = (float)tr->a.z; fwrite(&w, 4, 1, f);
|
||||
w = (float)tr->b.x; fwrite(&w, 4, 1, f);
|
||||
w = (float)tr->b.y; fwrite(&w, 4, 1, f);
|
||||
w = (float)tr->b.z; fwrite(&w, 4, 1, f);
|
||||
w = (float)tr->c.x; fwrite(&w, 4, 1, f);
|
||||
w = (float)tr->c.y; fwrite(&w, 4, 1, f);
|
||||
w = (float)tr->c.z; fwrite(&w, 4, 1, f);
|
||||
fputc(0, f);
|
||||
fputc(0, f);
|
||||
}
|
||||
|
||||
vvm.Clear();
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
void SolveSpace::ExportAsPngTo(char *filename) {
|
||||
int w = (int)SS.GW.width, h = (int)SS.GW.height;
|
||||
// No guarantee that the back buffer contains anything valid right now,
|
||||
|
@ -641,6 +692,13 @@ void SolveSpace::MenuFile(int id) {
|
|||
break;
|
||||
}
|
||||
|
||||
case GraphicsWindow::MNU_EXPORT_MESH: {
|
||||
char exportFile[MAX_PATH] = "";
|
||||
if(!GetSaveFile(exportFile, STL_EXT, STL_PATTERN)) break;
|
||||
SS.ExportMeshTo(exportFile);
|
||||
break;
|
||||
}
|
||||
|
||||
case GraphicsWindow::MNU_EXIT:
|
||||
if(!SS.OkayToStartNewFile()) break;
|
||||
SS.Exit();
|
||||
|
|
|
@ -58,6 +58,8 @@ int SaveFileYesNoCancel(void);
|
|||
#define SLVS_EXT "slvs"
|
||||
#define PNG_PATTERN "PNG (*.png)\0*.png\0All Files (*)\0*\0\0"
|
||||
#define PNG_EXT "png"
|
||||
#define STL_PATTERN "STL Mesh (*.stl)\0*.stl\0All Files (*)\0*\0\0"
|
||||
#define STL_EXT "stl"
|
||||
BOOL GetSaveFile(char *file, char *defExtension, char *selPattern);
|
||||
BOOL GetOpenFile(char *file, char *defExtension, char *selPattern);
|
||||
void GetAbsoluteFilename(char *file);
|
||||
|
@ -396,8 +398,9 @@ public:
|
|||
bool LoadFromFile(char *filename);
|
||||
bool LoadEntitiesFromFile(char *filename, EntityList *le, SMesh *m);
|
||||
void ReloadAllImported(void);
|
||||
// And the PNG export too
|
||||
// And the various export options
|
||||
void ExportAsPngTo(char *file);
|
||||
void ExportMeshTo(char *file);
|
||||
|
||||
void MarkGroupDirty(hGroup hg);
|
||||
void MarkGroupDirtyByEntity(hEntity he);
|
||||
|
|
Loading…
Reference in New Issue
Block a user