Skip to content

Instantly share code, notes, and snippets.

@arnholm
Last active May 25, 2019 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arnholm/af72c7d0790bb3d72e6bdf29c7aac1ed to your computer and use it in GitHub Desktop.
Save arnholm/af72c7d0790bb3d72e6bdf29c7aac1ed to your computer and use it in GitHub Desktop.

Step one, download "gregs-large.stl" from https://www.thingiverse.com/thing:6713/files and convert it into OBJ format and read it into AngelCAD, and "melt" it

AngelCAD language reference https://arnholm.github.io/angelcad-docs/docs/annotated.html

// AngelCAD code.

shape@ main_shape()
{
   auto@ p = polyhedron("gregs-large.obj");

   // traverse the vertices
   double factor = 0.025;
   for(uint i=0; i<p.nvert(); i++) {
   
      // get position of this vertex
      pos3d@ vtx = p.vertex(i);
      double t   = vtx.x();
      if(t > 0.0) {
      
         // transform vertex by rotation
         double angle = factor*t*PI/4;
         @vtx = rotate_y(rad:angle)*vtx;
         p.set_vertex(i,vtx);
      }
   }

   return p;
}

void main()
{
   shape@ obj = main_shape();
   obj.write_xcsg(GetInputFullPath(),secant_tolerance:-1.0);
}

This works in principle, but the result is ugly due to the coarse mesh:

Display the source blob
Display the rendered blob
Raw

Step two, we remesh the file to have 4mm sized triangles so that "melting" will work better

$ polyfix gregs-large.stl gregs-large_remesh.obj -remesh=4 -dtol=1E-6

Then perform the same operation on the remeshed file.

// AngelCAD code.

shape@ main_shape()
{
   auto@ p = polyhedron("gregs-large_remesh.obj");

   // traverse the vertices
   double factor = 0.025;
   for(uint i=0; i<p.nvert(); i++) {
   
      // get position of this vertex
      pos3d@ vtx = p.vertex(i);
      double t   = vtx.x();
      if(t > 0.0) {
      
         // transform vertex by rotation
         double angle = factor*t*PI/4;
         @vtx = rotate_y(rad:angle)*vtx;
         p.set_vertex(i,vtx);
      }
   }

   return p;
}

void main()
{
   shape@ obj = main_shape();
   obj.write_xcsg(GetInputFullPath(),secant_tolerance:-1.0);
}

This time, the result is as we want:

Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment