Search code examples
javascriptthree.jsfilesizeexporter

Exporting threeJS scene to STL file results to very big file size


I want to export my threeJS scene to STL file. I am using this exporter : https://gist.github.com/kjlubick/fb6ba9c51df63ba0951f

My problem is the file size that I get. For example, for 4 spheres (created via new THREE.SphereGeometry(1,32, 32) ) I got a file of 15MB, which I think is huge if you think that this ball here : http://archive3d.net/?a=download&id=469e26a6 is less than 0.5 MB.

Is there any way to reduce the file size? Why is it so big for just 4 spheres? One way is to create some low res (new THREE.SphereGeometry(1, 16, 16)) temp spheres at the time of exporting and delete them afterwards, but is there any other better way?

EDIT : I had done a mistake independently from the exporting process, and when I corrected it the size went down to 6 MB but it is still very big for just 2 spheres.

Thank you in advance, any opinion will be appreciated.


Solution

  • The exported you have linked uses the ASCII STL format, which by its nature is quite verbose and takes up a significant number of bytes to store a single triangle. Each of your spheres would be composed of several thousand triangles. Options are to:

    • Use the binary STL file format. This is a much more compact representation, using 50 bytes per facet. According to some back of the envelope calculations*, this would take ~0.1MB per sphere. The three.js repository has a binary STL exporter example.
    • Reduce the numeric precision you use to export your numbers. If you export numbers like 0.1 rather than 0.100001 it will take less characters to hold your result (but you will lose precision).
    • Use less triangles to make up your spheres as discussed in the question.
    • If you are really really desperate to use ASCII you could also try removing some of the unneccesary whitespace indentation the exporter generates, but this would yield only very minor improvements.

    * Assuming 32 * 32 * 2 triangles per sphere, 32 * 32 * 2 * 50 = ~100e3 = ~0.1MB