|
| 1 | + |
| 2 | +# PyWavefront 2.0 |
| 3 | + |
| 4 | +## Introduction |
| 5 | + |
| 6 | +PyWavefront is used by projects and people from both data science and pure 3D |
| 7 | +rendering. Providing visualisation capabilities also seems to be important for |
| 8 | +a lot of users. There are ties to [pyglet](https://bitbucket.org/pyglet/pyglet/wiki/Home) |
| 9 | +we probably should not break. |
| 10 | + |
| 11 | +Currently the project mainly has 3D rendering in mind. We see that in the parser |
| 12 | +were interlaved vertex data is genereted on the fly. This is not always what |
| 13 | +users want and will need improvements. Collecting face data was also added |
| 14 | +fairly recently but is limited to trinagles to make it consistent with the |
| 15 | +rest of the library. |
| 16 | + |
| 17 | +The plan is to revamp the project structure and making the parse result a lot more flexible supporting triangles and quads + other optimization. The goal is to make the library easier to use for data science as well as 3d rendering. Parsing should only |
| 18 | +collect the actual data. We then provide methods for obtaining the data in |
| 19 | +various ways after the parse is done. |
| 20 | + |
| 21 | + |
| 22 | +## Improved Visualization |
| 23 | + |
| 24 | +To provide a modern cross-platform visualization system moving to |
| 25 | +[ModernGL](https://github.com/cprogrammer1994/ModernGL) is probably |
| 26 | +the way to go using PyQt5 as the default rendering window. |
| 27 | + |
| 28 | +**It's still important to also keep a pyglet option as a lot of |
| 29 | +users would expect this to be present.** |
| 30 | + |
| 31 | +We can simply brush up the old pyglet visualitzation module and |
| 32 | +migrate that to using shaders when Pyglet 2.x is out. |
| 33 | + |
| 34 | +## Introduce pywavefront Command |
| 35 | + |
| 36 | +Bring PyWavefront to the command line making common operations easily |
| 37 | +accessible. |
| 38 | + |
| 39 | +```bash |
| 40 | +# Renders the obj file |
| 41 | +pywavefront show test.obj |
| 42 | + |
| 43 | +# Cache management |
| 44 | +pywavefront gen_cache test.obj |
| 45 | +pywavefront del_cache test.obj |
| 46 | + |
| 47 | +# .. possibly other commands |
| 48 | +``` |
| 49 | + |
| 50 | +## Memory Management |
| 51 | + |
| 52 | +TLDR; Use `numpy` to store internal data using 6 times less memory. |
| 53 | + |
| 54 | +We are currently collecting and storing indices and postions using native |
| 55 | +python types. |
| 56 | + |
| 57 | +```py |
| 58 | +>> import sys |
| 59 | +>> data = [x for x in range(1000000)] |
| 60 | +>> f"Array size: {(len(data) * sys.getsizeof(int())) // 1024 // 1024} MB") |
| 61 | +Array size: 22.8876953125 MB |
| 62 | +>> f"sizeof int: {sys.getsizeof(int())} bytes" |
| 63 | +sizeof int: 24 bytes |
| 64 | +>> f"sizeof float: {sys.getsizeof(float())} bytes" |
| 65 | +sizeof float: 24 bytes |
| 66 | +``` |
| 67 | + |
| 68 | +As we can see an `int` and `float` actually takes 24 bytes in python. |
| 69 | +This is 6 times more than necessary |
| 70 | + |
| 71 | +With `numpy` we can solve this entirely |
| 72 | + |
| 73 | +```py |
| 74 | +import numpy as np |
| 75 | +data = np.arange(1_000_000) |
| 76 | +f"Item size: {data.itemsize}" |
| 77 | +Item size: 4 |
| 78 | +f"Array size: {len(data) * data.itemsize / 1024 / 1024} MB" |
| 79 | +Array size: 3.814697265625 MB |
| 80 | +``` |
| 81 | + |
| 82 | +An advantage is also that we can reshape the array without |
| 83 | +allocating new memory. |
0 commit comments