Skip to content

Commit

Permalink
[UPD] : update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
aiekick committed Aug 11, 2023
1 parent 77a9910 commit 9328d2b
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 8 deletions.
138 changes: 130 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,138 @@ With this simple code (thanks to [@unphased](https://github.com/unphased))
#include "VoxWriter.h"
int main()
{
vox::VoxWriter vox;
for (int i = 0; i < 1000; ++i) {
for (int j = 0; j < 1000; ++j) {
vox.AddVoxel(i, j, (int)std::floor(sinf((float)(i * i + j * j) / 50000) * 150) + 150, (i + j) % 255 + 1);
}
}
vox.SaveToFile("output_voxwriter.vox");
const int32_t SIZE = 189;
const int32_t OFFSET = SIZE;
const float Z_SCALE = 1.0f;
const int32_t FRAMES = 30;
const float len_ratio = 1.0f / (SIZE * SIZE);

vox::VoxWriter vox;

vox.StartTimeLogging();
float time = 0.0f;
for (int32_t k = 0; k < FRAMES; ++k) {
vox.SetKeyFrame(k);
for (int32_t i = -SIZE; i < SIZE; ++i) {
for (int32_t j = -SIZE; j < SIZE; ++j) {
float len = (i * i + j * j) * len_ratio;
int32_t pz = (int32_t)((std::sin(len * 10.0 + time) * 0.5 + 0.5) * (std::abs(50.0f - 25.0f * len)) * Z_SCALE);
int32_t cube_color = (int32_t)(len * 100.0) % 255 + 1;
vox.AddVoxel(i + OFFSET, j + OFFSET, pz, cube_color); // magicavoxel use the z as up axis
}
}
time += 0.5f;
}
vox.StopTimeLogging();
vox.SaveToFile("output_voxwriter.vox");
vox.PrintStats();
}
```

you can generate that (previewed in [Magicavoxel](https://ephtracy.github.io/)

![main](main.jpg)
![main](main.gif)

possible console print ( vox.PrintStats() ) :

```cpp
---- Stats ------------------------------
Volume : 377 x 377 x 49
count cubes : 9
count key frames : 30
-----------------------------------------
o--\-> key frame : 0
\-> voxels count : 142884
\-> elapsed time : 0.045 secs
o--\-> key frame : 1
\-> voxels count : 142884
\-> elapsed time : 0.046 secs
o--\-> key frame : 2
\-> voxels count : 142884
\-> elapsed time : 0.046 secs
o--\-> key frame : 3
\-> voxels count : 142884
\-> elapsed time : 0.047 secs
o--\-> key frame : 4
\-> voxels count : 142884
\-> elapsed time : 0.047 secs
o--\-> key frame : 5
\-> voxels count : 142884
\-> elapsed time : 0.048 secs
o--\-> key frame : 6
\-> voxels count : 142884
\-> elapsed time : 0.048 secs
o--\-> key frame : 7
\-> voxels count : 142884
\-> elapsed time : 0.047 secs
o--\-> key frame : 8
\-> voxels count : 142884
\-> elapsed time : 0.048 secs
o--\-> key frame : 9
\-> voxels count : 142884
\-> elapsed time : 0.048 secs
o--\-> key frame : 10
\-> voxels count : 142884
\-> elapsed time : 0.048 secs
o--\-> key frame : 11
\-> voxels count : 142884
\-> elapsed time : 0.047 secs
o--\-> key frame : 12
\-> voxels count : 142884
\-> elapsed time : 0.047 secs
o--\-> key frame : 13
\-> voxels count : 142884
\-> elapsed time : 0.049 secs
o--\-> key frame : 14
\-> voxels count : 142884
\-> elapsed time : 0.049 secs
o--\-> key frame : 15
\-> voxels count : 142884
\-> elapsed time : 0.049 secs
o--\-> key frame : 16
\-> voxels count : 142884
\-> elapsed time : 0.05 secs
o--\-> key frame : 17
\-> voxels count : 142884
\-> elapsed time : 0.048 secs
o--\-> key frame : 18
\-> voxels count : 142884
\-> elapsed time : 0.049 secs
o--\-> key frame : 19
\-> voxels count : 142884
\-> elapsed time : 0.049 secs
o--\-> key frame : 20
\-> voxels count : 142884
\-> elapsed time : 0.049 secs
o--\-> key frame : 21
\-> voxels count : 142884
\-> elapsed time : 0.05 secs
o--\-> key frame : 22
\-> voxels count : 142884
\-> elapsed time : 0.049 secs
o--\-> key frame : 23
\-> voxels count : 142884
\-> elapsed time : 0.05 secs
o--\-> key frame : 24
\-> voxels count : 142884
\-> elapsed time : 0.049 secs
o--\-> key frame : 25
\-> voxels count : 142884
\-> elapsed time : 0.05 secs
o--\-> key frame : 26
\-> voxels count : 142884
\-> elapsed time : 0.05 secs
o--\-> key frame : 27
\-> voxels count : 142884
\-> elapsed time : 0.051 secs
o--\-> key frame : 28
\-> voxels count : 142884
\-> elapsed time : 0.051 secs
o--\-> key frame : 29
\-> voxels count : 142884
\-> elapsed time : 0.051 secs
-----------------------------------------
voxels total : 4286520
total elapsed time : 1.472 secs
-----------------------------------------
```
Binary file added main.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed main.jpg
Binary file not shown.

0 comments on commit 9328d2b

Please sign in to comment.