wolph / numpy-stl

Simple library to make working with STL files (and 3D objects in general) fast and easy.
http://numpy-stl.readthedocs.org/
BSD 3-Clause "New" or "Revised" License
624 stars 105 forks source link

Building a large stl #97

Closed da4throux closed 5 years ago

da4throux commented 5 years ago

Hi, Great module, really thanks a lot for that. my script is building a large stl: doing an assembly of about 80k cubes for example. I tested two approaches:

I was wondering if there is a third approach with the best of both world ?

wolph commented 5 years ago

It's possible but I'm not sure if it will cause any problems. The binary stl format starts with a header that specifies the amount of vertices. After that it's plain binary writing of the data.

Still though, 80k cubes is not an insane amount and numpy stores it in memory really efficiently. I would not expect too many problems with memory usage.

wolph commented 5 years ago

Thinking about it slightly further, it shouldn't be too hard to write a binary stl merge script. That would allow you to write a bunch of binary stl files and merge them after.

I'll give it a shot once I have time (probably within a week)

wolph commented 5 years ago

I've created a simple method to merge both ascii and binary files. It does (at max) take twice the amount of memory it would normally take. That can be worked around but it's a tradeoff between reading the files multiple times and using a bit more memory temporarily. Please let me know if it's enough or not :)

My best guess for the size of a 80k cubes wouldn't be that bad though. A single triangle takes 50 bytes. A side of a cube would be 2 triangles, so 100 bytes. There are 6 sides to a cube so 100 6 80k would be about 45.8 MiB. Hardly a stellar amount :) Max memory usage would be around 100 MiB for this operation.