Advertisement
Guest User

Manifold program

a guest
Mar 3rd, 2023
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<manifold.h>
  3. #include<string.h>
  4. using manifold::Manifold;
  5. using manifold::Mesh;
  6.  
  7. void export_stl(Manifold &man,const char *filename)
  8. {
  9. Mesh m = man.GetMesh();
  10. FILE *out;
  11. char temp[80];
  12. int i,j,triangles;
  13. float f[12];
  14. int ind1,ind2,ind3;
  15. out=fopen(filename,"wb");
  16. if(out == NULL)
  17. {
  18. printf("Cannot open file %s\n",filename);
  19. return;
  20. }
  21. printf("Writing Binary STL\n");
  22. memset(temp,'\0',80);
  23. strcpy(temp,"Tool");
  24. fwrite(temp,80,sizeof(char),out); // write dummy header
  25. triangles=m.triVerts.size();
  26. fwrite(&triangles,1,sizeof(int),out);
  27. temp[0]=0;
  28. temp[1]=0;
  29. for(j=0;j<m.triVerts.size();j++)
  30. {
  31. ind1=m.triVerts[j][0];
  32. ind2=m.triVerts[j][1];
  33. ind3=m.triVerts[j][2];
  34. f[0]=0.0; f[1]=0.0; f[2]=0.0;
  35. f[3]=m.vertPos[ind1][0];
  36. f[4]=m.vertPos[ind1][1];
  37. f[5]=m.vertPos[ind1][2];
  38. f[6]=m.vertPos[ind2][0];
  39. f[7]=m.vertPos[ind2][1];
  40. f[8]=m.vertPos[ind2][2];
  41. f[9]=m.vertPos[ind3][0];
  42. f[10]=m.vertPos[ind3][1];
  43. f[11]=m.vertPos[ind3][2];
  44.  
  45. fwrite(&f,12,sizeof(float),out);
  46. fwrite(temp,2,sizeof(char),out);
  47. }
  48. fclose(out);
  49. }
  50. int main(void) {
  51. Manifold c = Manifold::Cube(glm::vec3(1,2,3));
  52. Manifold s = Manifold::Sphere(1);
  53.  
  54. Manifold r = c+s;
  55. export_stl(r,"result.stl");
  56. return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement