STL import script with some helpers

Next
 From:  r2d3
8860.1 
Hi all,
i worked on a STL import script for MoI, and that is the result (for now...)
First i have to thank Karsten, Marco, Pilou and Michael for guiding the way!
Second to say: Its a stupid thing to import STL files into MoI because MoI is NURBS and STL is only Polygones!
But if you only have a STL file you can try to rebuild it to NURBS.
The script can help a little...

WARNING: IF YOU IMPORT BIG (>5mb) STL FILES IT CAN TAKE HOURS TO PROCESS AND IT CAN CRASH MOI!



This is what the script does:
1. reading the STL file, creating triangles and joining them to a solid (if possible..)
2. cleaning flat surfaces (removing all needless faces with a double boolean difference)
If your STL object only has flat surfaces -> YOU ARE DONE you will have a NURB object!
3. Redrawing curves and circles
Mostly your STL file will have curved or round surfaces. These will be converted to polylines in your STL file and the script helps you to redraw the polys to NURBS. In the end you will have nice outlines of the original STL object and you can rebuild it with the normal tools of MoI (Joining, Loft and Boolean operations).

SOME screenshots:

The imported Triangles as a solid:


Result after "Clean flat surfaces"


Select all polyline curves (no straight lines)


Choose if it should be a curve:


or a circle:

(Line is for a straight polyline which has more than two points. It will be converted to a 2 point line. Dont select this together with a curved polyline)

Result:


After some face deleting, joining, lofting:


and the final boolean difference you end up with a clean NURBS !


Use the script also for "Only Cleaning":


For every state of the import you find a object in the Objects folder:


HAVE FUN!

EDIT 23.03: added a binary STL Fault detection and putting the script files into a zip

EDITED: 23 Mar 2018 by R2D3


  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Frenchy Pilou (PILOU)
8860.2 
That is a task! Bravo!

But what about load an STL file inside a "Polygon modeler" then export as OBJ, then import "OBJ file" inside MOi ?
---
Pilou
Is beautiful that please without concept!
My Moi French Site My Gallery
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  mkdm
8860.3 In reply to 8860.1 
Hello "r2d3"!

Many thanks for this very interesting "coding"! My congratulations!

Maybe not really useful for "real life" use-cases but anyway, very interesting piece of code.

Thank you very much :)

Ciao!

- Marco (mkdm)
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  r2d3
8860.4 In reply to 8860.2 
>>But what about load an STL file inside a "Polygon modeler" then export as OBJ, then import "OBJ file" inside MOi ?

My old way to import STL was to use FreeCad to prepare the file for MoI.. But you still have no clean NURBS file...
Or do you have a SECRET PILOU trick??


Ralf:)
looking for moments of inspiration...
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  r2d3
8860.5 In reply to 8860.3 
>>> Maybe not really useful for "real life"...

For 3Dprint-MoIers the STL is a very common format.
But sometimes a only as STL available print file needs a little tweak to fit and then you need a clean file ...

>> but anyway, very interesting piece of code.

THX :-)


Ralf:)
looking for moments of inspiration...
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  mkdm
8860.6 In reply to 8860.5 
Hello r23d!

Just a little clarification to my previous words :)

When I've written "Maybe not really useful for "real life"..." I only meant that unfortunately the execution of the scripts with objects containing many faces is rather slow.
Clearly because Moi is not very well suited to manage that kind polygonal information, and this is normal.

@You : "...For 3Dprint-MoIers the STL is a very common format..."

Yes, for sure!

Anyway as I've said, it's a really useful bunch of JS code, a kind of "proving ground" :)

Thanks.

Marco (mkdm)
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Frenchy Pilou (PILOU)
8860.7 
<< a SECRET trick??
_import OBJ by Max Smirnov ?
But not sure that result will be different than your before some cleaning...
---
Pilou
Is beautiful that please without concept!
My Moi French Site My Gallery
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  r2d3
8860.8 In reply to 8860.6 
Absolut no clarification necessary :)

>> Anyway as I've said, it's a really useful bunch of JS code, a kind of "proving ground" :)
Exactly, just playing around and learning whats possible to realise with MoI.


Ralf:)
looking for moments of inspiration...
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Hamish Mead (HAIRYKIWI)
8860.9 
Very nice work Ralf!

There can never be enough conversion tools - even if extra time is still needed to clean and tweak such imported files.

Many thanks :)

- Hamish
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Chris (UGMENTALCASE)
8860.10 
Hi,

Is there a way to edit this script so it just imports the stl without trying to make it solid and so on? I have literally no idea when it comes to scripts so forgive me :-)
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
8860.11 In reply to 8860.10 
Hi Chris, you might want to try converting the STL file to .obj format and then use the OBJ to 3DM wireframe converter from here:
https://moi3d.com/wiki/Resources#Obj23dmWireframe_converter

That makes wireframe lines or closed polylines for each polygon instead of trying to construct a solid out of it which is much more heavyweight.

If you did want to edit this script to not try to join it into a solid, the joining part is done by a function named JoinTriangles(). The function is called on line number 17 in the file _STLimport.js . It's a long line of code, look for the piece of it that has this:

var solid=JoinTriangles(triangles);var sol=solid.numSolids;if(sol<1){var message="SORRY!\nI WAS NOT ABLE TO MAKE A SOLID!\nDont't try to \"Clean flat surfaces\"";}else{var message=sol+" SOLID CREATED!";};

Delete all of that or "comment it out" by putting /*    */ around it and then it shouldn't do the joining part.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
 From:  Chris (UGMENTALCASE)
8860.12 In reply to 8860.11 
Cheers I'll take a look. I have used the other script a little bit, but sometimes there is just too many lines!
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged
 

Reply to All Reply to All