I found an old project on github called thingiview. It can take (among other things) an STL file (exportable from SolidWorks and other CAD programs) and render it using canvas/WebGL (pretty much only works in Chrome). It is based off of the Three.js project. thingiview uses an outdated (R32) version of Three.js (currently R50) because the project seemed to have died off about 2 years ago.
Anyway, I wanted to render large, complex CAD models in the browser, mostly for experimentation. One example we have, exported from SolidWorks in coarse mode, has approximately 350,000 vertices. The way the code was written for thingiview, the STL to JSON rendering in PHP would bog down to an unsuable speed at even 50-100,000 vertices. As-is, I left the converter running for about 14 hours with our complex model, and it still didn’t finish.
I decided to rewrite portions of the code to make it more efficient for my use, so I forked it. My first commit was to make huge improvements on the efficiency of STL (binary) to JSON conversion. Now, the complex model takes a mere 30 seconds to render. Most of the previous inefficiencies were due to the calling of in_array and array_search (x3) for every vertex. As the number of vertices grew, the slower each call to in_array and array_search became. Using a hashmap (storing the contents into an array keyed by MD5 hashes of the contents), I’m able to avoid searching the array, massively improving execution time.
One day, I may take the time to update the project to the latest Three.js (a lot of the JS function calls are deprecated) and/or take a look at improving the other conversions. For now, this will satisfy my SolidWorks to interactive web model cravings.