Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<manifold.h>
- #include<string.h>
- using manifold::Manifold;
- using manifold::Mesh;
- void export_stl(Manifold &man,const char *filename)
- {
- Mesh m = man.GetMesh();
- FILE *out;
- char temp[80];
- int i,j,triangles;
- float f[12];
- int ind1,ind2,ind3;
- out=fopen(filename,"wb");
- if(out == NULL)
- {
- printf("Cannot open file %s\n",filename);
- return;
- }
- printf("Writing Binary STL\n");
- memset(temp,'\0',80);
- strcpy(temp,"Tool");
- fwrite(temp,80,sizeof(char),out); // write dummy header
- triangles=m.triVerts.size();
- fwrite(&triangles,1,sizeof(int),out);
- temp[0]=0;
- temp[1]=0;
- for(j=0;j<m.triVerts.size();j++)
- {
- ind1=m.triVerts[j][0];
- ind2=m.triVerts[j][1];
- ind3=m.triVerts[j][2];
- f[0]=0.0; f[1]=0.0; f[2]=0.0;
- f[3]=m.vertPos[ind1][0];
- f[4]=m.vertPos[ind1][1];
- f[5]=m.vertPos[ind1][2];
- f[6]=m.vertPos[ind2][0];
- f[7]=m.vertPos[ind2][1];
- f[8]=m.vertPos[ind2][2];
- f[9]=m.vertPos[ind3][0];
- f[10]=m.vertPos[ind3][1];
- f[11]=m.vertPos[ind3][2];
- fwrite(&f,12,sizeof(float),out);
- fwrite(temp,2,sizeof(char),out);
- }
- fclose(out);
- }
- int main(void) {
- Manifold c = Manifold::Cube(glm::vec3(1,2,3));
- Manifold s = Manifold::Sphere(1);
- Manifold r = c+s;
- export_stl(r,"result.stl");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement