What is the preferred method for loading STL files in Three.js

user1460044 picture user1460044 · Jun 16, 2012 · Viewed 21.7k times · Source

I'm writing an application that is designed to be used as part of a mechanical design and simulation workflow, and we'd like to be able to use Three.js to load and visualize parts designed in Solidworks, which can be exported as STL (text or binary).

** I fully recognize that one can use something like Meshlab to convert to OBJ or some other format, but this seems like an unnecessary additional step that encumbers the workflow. **

It seems Three.js has good loading solutions for Collada, OBJ, UTF-8, VTK, and JSON, but there is no clean STL support example. I saw some things floating around that have been used in the past, such as https://github.com/tbuser/thingiview.js/blob/master/javascripts/thingiloader.js which I'd like to avoid because of the license, and https://github.com/tbuser/three.js/blob/master/utils/stl_geometry.js which seems not fully integrated.

Am I missing something?

Answer

Luis E. Fraguada picture Luis E. Fraguada · Aug 10, 2018

There is an STLLoader and an example of how to use it. These were added to Three.js in August of 2012, a mere month or so after this question was originally posted. Since then, there have been several commits involving the STLLoader.