Skip to content

Commit 9328d2b

Browse files
committed
[UPD] : update doc
1 parent 77a9910 commit 9328d2b

3 files changed

Lines changed: 130 additions & 8 deletions

File tree

README.md

Lines changed: 130 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,138 @@ With this simple code (thanks to [@unphased](https://github.com/unphased))
1616
#include "VoxWriter.h"
1717
int main()
1818
{
19-
vox::VoxWriter vox;
20-
for (int i = 0; i < 1000; ++i) {
21-
for (int j = 0; j < 1000; ++j) {
22-
vox.AddVoxel(i, j, (int)std::floor(sinf((float)(i * i + j * j) / 50000) * 150) + 150, (i + j) % 255 + 1);
23-
}
24-
}
25-
vox.SaveToFile("output_voxwriter.vox");
19+
const int32_t SIZE = 189;
20+
const int32_t OFFSET = SIZE;
21+
const float Z_SCALE = 1.0f;
22+
const int32_t FRAMES = 30;
23+
const float len_ratio = 1.0f / (SIZE * SIZE);
24+
25+
vox::VoxWriter vox;
26+
27+
vox.StartTimeLogging();
28+
float time = 0.0f;
29+
for (int32_t k = 0; k < FRAMES; ++k) {
30+
vox.SetKeyFrame(k);
31+
for (int32_t i = -SIZE; i < SIZE; ++i) {
32+
for (int32_t j = -SIZE; j < SIZE; ++j) {
33+
float len = (i * i + j * j) * len_ratio;
34+
int32_t pz = (int32_t)((std::sin(len * 10.0 + time) * 0.5 + 0.5) * (std::abs(50.0f - 25.0f * len)) * Z_SCALE);
35+
int32_t cube_color = (int32_t)(len * 100.0) % 255 + 1;
36+
vox.AddVoxel(i + OFFSET, j + OFFSET, pz, cube_color); // magicavoxel use the z as up axis
37+
}
38+
}
39+
time += 0.5f;
40+
}
41+
vox.StopTimeLogging();
42+
vox.SaveToFile("output_voxwriter.vox");
43+
vox.PrintStats();
2644
}
2745
```
2846

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

31-
![main](main.jpg)
49+
![main](main.gif)
50+
51+
possible console print ( vox.PrintStats() ) :
52+
53+
```cpp
54+
---- Stats ------------------------------
55+
Volume : 377 x 377 x 49
56+
count cubes : 9
57+
count key frames : 30
58+
-----------------------------------------
59+
o--\-> key frame : 0
60+
\-> voxels count : 142884
61+
\-> elapsed time : 0.045 secs
62+
o--\-> key frame : 1
63+
\-> voxels count : 142884
64+
\-> elapsed time : 0.046 secs
65+
o--\-> key frame : 2
66+
\-> voxels count : 142884
67+
\-> elapsed time : 0.046 secs
68+
o--\-> key frame : 3
69+
\-> voxels count : 142884
70+
\-> elapsed time : 0.047 secs
71+
o--\-> key frame : 4
72+
\-> voxels count : 142884
73+
\-> elapsed time : 0.047 secs
74+
o--\-> key frame : 5
75+
\-> voxels count : 142884
76+
\-> elapsed time : 0.048 secs
77+
o--\-> key frame : 6
78+
\-> voxels count : 142884
79+
\-> elapsed time : 0.048 secs
80+
o--\-> key frame : 7
81+
\-> voxels count : 142884
82+
\-> elapsed time : 0.047 secs
83+
o--\-> key frame : 8
84+
\-> voxels count : 142884
85+
\-> elapsed time : 0.048 secs
86+
o--\-> key frame : 9
87+
\-> voxels count : 142884
88+
\-> elapsed time : 0.048 secs
89+
o--\-> key frame : 10
90+
\-> voxels count : 142884
91+
\-> elapsed time : 0.048 secs
92+
o--\-> key frame : 11
93+
\-> voxels count : 142884
94+
\-> elapsed time : 0.047 secs
95+
o--\-> key frame : 12
96+
\-> voxels count : 142884
97+
\-> elapsed time : 0.047 secs
98+
o--\-> key frame : 13
99+
\-> voxels count : 142884
100+
\-> elapsed time : 0.049 secs
101+
o--\-> key frame : 14
102+
\-> voxels count : 142884
103+
\-> elapsed time : 0.049 secs
104+
o--\-> key frame : 15
105+
\-> voxels count : 142884
106+
\-> elapsed time : 0.049 secs
107+
o--\-> key frame : 16
108+
\-> voxels count : 142884
109+
\-> elapsed time : 0.05 secs
110+
o--\-> key frame : 17
111+
\-> voxels count : 142884
112+
\-> elapsed time : 0.048 secs
113+
o--\-> key frame : 18
114+
\-> voxels count : 142884
115+
\-> elapsed time : 0.049 secs
116+
o--\-> key frame : 19
117+
\-> voxels count : 142884
118+
\-> elapsed time : 0.049 secs
119+
o--\-> key frame : 20
120+
\-> voxels count : 142884
121+
\-> elapsed time : 0.049 secs
122+
o--\-> key frame : 21
123+
\-> voxels count : 142884
124+
\-> elapsed time : 0.05 secs
125+
o--\-> key frame : 22
126+
\-> voxels count : 142884
127+
\-> elapsed time : 0.049 secs
128+
o--\-> key frame : 23
129+
\-> voxels count : 142884
130+
\-> elapsed time : 0.05 secs
131+
o--\-> key frame : 24
132+
\-> voxels count : 142884
133+
\-> elapsed time : 0.049 secs
134+
o--\-> key frame : 25
135+
\-> voxels count : 142884
136+
\-> elapsed time : 0.05 secs
137+
o--\-> key frame : 26
138+
\-> voxels count : 142884
139+
\-> elapsed time : 0.05 secs
140+
o--\-> key frame : 27
141+
\-> voxels count : 142884
142+
\-> elapsed time : 0.051 secs
143+
o--\-> key frame : 28
144+
\-> voxels count : 142884
145+
\-> elapsed time : 0.051 secs
146+
o--\-> key frame : 29
147+
\-> voxels count : 142884
148+
\-> elapsed time : 0.051 secs
149+
-----------------------------------------
150+
voxels total : 4286520
151+
total elapsed time : 1.472 secs
152+
-----------------------------------------
153+
```

main.gif

4.88 MB
Loading

main.jpg

-722 KB
Binary file not shown.

0 commit comments

Comments
 (0)