aiekick / MagicaVoxel_File_Writer

MagicaVoxel File Writer dependency free cpp class
MIT License
34 stars 10 forks source link

Tools.hpp missing? #2

Closed Magnesus closed 4 years ago

Magnesus commented 5 years ago

Not sure what it is but it seems to be missing?

aiekick commented 5 years ago

its a template file for many of my tools like the cAABBCC used here?

its not specific, you can use other AABBCC on internet

unphased commented 4 years ago

Hi, I am looking for an easy way to export magicavoxel files from my scripts, and I was hoping I could get this working out of the box, it looks very complete.

Could you provide another clue for what the cAABBCC type is and where we can obtain it?

Also the header apparently defines a macro SAFE_DELETE and things like that.

Thanks.

aiekick commented 4 years ago

you are lucky :) I just relased some weeks ago my cTools where you can found cAABBCC and SAFE_DELETE btw all my tools a renamed but it will be easier to adapt to your needs :)

https://github.com/aiekick/cTools

unphased commented 4 years ago

Neat! Thanks!

unphased commented 4 years ago

@aiekick Could you comment on what format or what tool consumes the vox.hm file? It seems to be a human readable descriptor for the .vox binary format itself.

aiekick commented 4 years ago

vox.hm is the file format descriptor for HexaMonkey : original topic about it : https://github.com/ephtracy/voxel-model/issues/19 HexaMonkey tool : http://hexamonkey.com/

updated in readme

unphased commented 4 years ago

That’s awesome! Thanks!

I hacked on it and got it compiling, took me about 15 mins. Thanks for your help! I’ll fork, incorporate your other repo, and push my compiling changes soon.

I still have yet to really test the code heavily but so far this is by far the most complete .vox code I’ve found so far.

aiekick commented 4 years ago

thanks ahah. its pleasant to do things usefull for others :)

i have tested my version heavily. all the models you can found is this repo are geenrated with it : https://github.com/funparadigm/SdfMesher_Models

i successfully opened all my models. with it. by the way this file writer not create all types of chunks. but you can add from the file format via reverse ingeneering, using hexamonkey :)

like this monster kifs fractal : img

unphased commented 4 years ago

That's awesome. How is surpassing 126^3 achieved in that example? Looking at the VoxWriter.cpp,

497 // the limit of magicavoxel is 127 because the first is 1 not 0 
498 // so this is 0 to 126                                          
499 m_LimitX = min(vLimitX, 126);                                   
500 m_LimitY = min(vLimitY, 126);                                   
501 m_LimitZ = min(vLimitZ, 126);                                   

had me worried that trying to go beyond 126 would be pointless with VoxWriter. But I will test it out shortly and see what happens.

aiekick commented 4 years ago

the limit of MV is to have 127 cubes. but his first index is 1 you will see that when you will work with colors : btw magicavoxel is very bad to filter bad file format. you will see that you can write cube out of limit, and sse them in MV, ut its not good, because you will not have the abilites to edit them or may crash MV also :). im not sure if this file is the latest i have in local haha

aiekick commented 4 years ago

you dont have to take care of what is the limit of a cube. you just need to call the function

VoxWriter::AddVoxel(uint32_t vX, uint32_t vY, uint32_t vZ, uint8_t vColorIndex) so this is the xyz coord of voxel who define what is the cube to use.

you can also AddColor before and use an index you can use in AddVoxel func too

unphased commented 4 years ago

Cool, I'll play around with it. As promised, here is where I'll be putting my changes to get the tool working for me: https://github.com/unphased/MagicaVoxel_File_Writer Sorry in advance for butchering your code. Git wouldn't let me merge the two independent trees wholesale so I went and did it anyway using a chain of cherry-picks. Haha. I just wanted all the dependencies together in one repo so I can build it easily. I'll probably write a makefile for it and keep hacking if there's more stuff missing.

Also check out my topic here: https://github.com/ephtracy/ephtracy.github.io/issues/146

Thanks! Also I'm looking forward to eventually playing with the SDF thing you're making! Super cool.

aiekick commented 4 years ago

no problem do what you need with my code. its free :)

i plan to make it lib free, so maybe incorporate cAABBCC in code. but not time for it for the moment.

thanks too :)

unphased commented 4 years ago

You're right this works out of the box, you have really got the format figured out.

#include "VoxWriter.h"
int main() {
    vox::VoxWriter vox(1200,1200,300);  
    for (int i=0; i<1000; ++i) {
        for (int j=0; j<1000; ++j) {
            vox.AddVoxel(i,j, floor(sin((float)(i * i + j * j) / 50000) * 150) + 150,(i+j)%255 + 1);
        }
    }
    vox.SaveToFile("output_voxwriter.vox");
}
image

This is a staggering quantity of voxels. Looks like I pushed it past a threshold, if I go into render mode it only renders a region in the center. Anyway this will do quite nicely for me.

unphased commented 4 years ago

Interestingly when I had the ~1 million voxels spread across z from 0 to 100 (instead of 0 to 300) it was fine rendering everything. some internal limitation I suppose.

Also interesting, a full 126^3 model is twice as many voxels as that. I can't wait for 256^3! OK I'll try to stop geeking out over MV now.

unphased commented 4 years ago

@aiekick Hey dude I noticed an off-by-one positive-zero-negative-zero-rounding bug that I'm not sure which code (this code or MV) has, but I can see that the blocks adjacent to the X and Y axes are overlapping by a single voxel. you can see the seams. I was hoping to catch stuff like this by generating the sine based curve.

image
aiekick commented 4 years ago

indeed . i dont knpw where can be the bug. i think its in my format but where ? :)

aiekick commented 4 years ago

you are right there is some cube overlap

MagicaVoxel_sght6y3rST

aiekick commented 4 years ago

JkljYIMUXb

unphased commented 4 years ago

It reminds me of some kind of rounding behavior. Usually if you cast a float to an integer, 1.99f -> 1, -1.99 -> -1, and correspondingly, 0.99 -> 0, -0.99 -> -0. Notice how the entire range (-1,1) rounds to a form of floating point zero, which both become zero for an integer.

Conversion to integer from a float, especially if you want to ensure high performance, is tricky to get right.

I'll let you know what the fix is in a bit. Sorry for not opening a separate issue for this bug I found.

aiekick commented 4 years ago

yep, it hink i have resolved the issue. the problem was just about the cube placement. and the rounding problem like you pointed out was the issue i guess i have updated also the code, and make it lib free. i will commit with a cmake file. i have integrated your example with credits :)

no problem for the specific thread of issue :) you are the only one who speak to me about issue regarding this file in deep. like if it interest no one except you haha thanks for that

toDj09F2AZ

Commit done :)

unphased commented 4 years ago

Yeah I fixed it in my repo as well.

image

You had some extra float to int casting happening in here and fixing it with a floor does the trick.

aiekick commented 4 years ago

ha i not fiexd that like that maybe i have again an issue haha fixed

what is your ide ?

unphased commented 4 years ago

I use vim and tmux :)

you are the only one who speak to me about issue regarding this file in deep. like if it interest no one except you

Well voxels are definitely the future in gamedev and I think people are starting to figure it out... essentially, Minecraft wasn't a fluke. I got kinda inspired recently by this guy's blog: http://procworld.blogspot.com where he did a lot of awesome exploratory work back in 2011/2012 on voxel worlds.

And MV is such a cool piece of software.

I'm doing some stuff with voxels for work, I work for a robotics company. We do voxel based volumetric geometry stuff.

aiekick commented 4 years ago

haha vim is for pure coder :) nice i have some difficulties to work with vim. im not from this industry i worked as a cad designer in automotive industry. I learned the programming by myself since 20 years, so always empressed by pure coders who are uising this kind of tools. i know its powerfull but not simple to use like using toolchain directly in console haha

i choose simplicity, visual studio on win and clion for the others os :) but its not free

btw for this class i think we can improved it and add stuff like layers, and animation in a easy way

voxels can also be used for fluid computations :) it can be cool to create a MagicaFluid for fluid voxel simulation.. its in my todo list :)

unphased commented 4 years ago

I have really been impressed a lot by VS Code. The C++ plugin it provides is very very good. I would use it if it had better vim emulation, and I do use it for work when I am on a machine that is not mine. But for most of my work I stick with vim because I have a lot of plugins I use that fit in with its philosophy, and it is very fast and convenient to stay inside the terminal all the time. I heard great things about clion but these days VS Code will get the job done and has a great community making plugins to make your life better.

Do you know if/how MV supports animation? Yeah layers would be nice, but I personally have no need for features like that yet!

I love fluid simulation as well, I had a naiver stokes solver I made in college and it ran well on a CPU because I used conjugate gradient. that was before it became so easy nowadays to code algorithms on GPUs. You are absolutely right about the voxel -> fluids connection. Exciting times.

By the way I tried your latest commit because I saw that you made a lot of improvements that supersede my hacks. However it does not build for me because of some more missing dependencies and stuff, so unfortunately I am pushing forward on the XYZP to VOX converter command line tool in my branch for the time being.

02 20:19 ~/D/M/build ❯❯❯ cmake ..                                                                                                                                                                                                                                master 74b001b ◼
-- The C compiler identification is AppleClang 11.0.0.11000033
-- The CXX compiler identification is AppleClang 11.0.0.11000033
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
l-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/slu/Documents/MagicaVoxel_File_Writer/build
02 20:19 ~/D/M/build ❯❯❯ l                                                                                                                                                                                                                                       master 74b001b ◼
CMakeCache.txt      CMakeFiles          Makefile            cmake_install.cmake
02 20:19 ~/D/M/build ❯❯❯ make                                                                                                                                                                                                                                    master 74b001b ◼
Scanning dependencies of target VoxWriter
[ 33%] Building CXX object CMakeFiles/VoxWriter.dir/main.cpp.o
In file included from /Users/slu/Documents/MagicaVoxel_File_Writer/main.cpp:1:
/Users/slu/Documents/MagicaVoxel_File_Writer/VoxWriter.h:63:30: error: use of undeclared identifier 'StringToNumberVector'
                        ::std::vector<T> result = StringToNumberVector<T>(vec, c);
                                                  ^
/Users/slu/Documents/MagicaVoxel_File_Writer/VoxWriter.h:63:51: error: 'T' does not refer to a value
                        ::std::vector<T> result = StringToNumberVector<T>(vec, c);
                                                                       ^
/Users/slu/Documents/MagicaVoxel_File_Writer/VoxWriter.h:48:21: note: declared here
        template <typename T>
                           ^
/Users/slu/Documents/MagicaVoxel_File_Writer/VoxWriter.h:63:54: warning: expression result unused [-Wunused-value]
                        ::std::vector<T> result = StringToNumberVector<T>(vec, c);
                                                                          ^~~
/Users/slu/Documents/MagicaVoxel_File_Writer/VoxWriter.h:84:27: error: 'T' does not refer to a value
                T sumAbs() { return abs<T>(x) + abs<T>(y) + abs<T>(z); }
                                        ^
/Users/slu/Documents/MagicaVoxel_File_Writer/VoxWriter.h:48:21: note: declared here
        template <typename T>
                           ^
/Users/slu/Documents/MagicaVoxel_File_Writer/VoxWriter.h:84:39: error: 'T' does not refer to a value
                T sumAbs() { return abs<T>(x) + abs<T>(y) + abs<T>(z); }
                                                    ^
/Users/slu/Documents/MagicaVoxel_File_Writer/VoxWriter.h:48:21: note: declared here
        template <typename T>
                           ^
/Users/slu/Documents/MagicaVoxel_File_Writer/VoxWriter.h:84:51: error: 'T' does not refer to a value
                T sumAbs() { return abs<T>(x) + abs<T>(y) + abs<T>(z); }
                                                                ^
/Users/slu/Documents/MagicaVoxel_File_Writer/VoxWriter.h:48:21: note: declared here
        template <typename T>
                           ^
/Users/slu/Documents/MagicaVoxel_File_Writer/VoxWriter.h:495:64: error: a space is required between consecutive right angle brackets (use '> >')
                std::map<int32_t, std::map<int32_t, std::map<int32_t, int32_t>>> cubesId;
                                                                             ^~
                                                                             > >
/Users/slu/Documents/MagicaVoxel_File_Writer/VoxWriter.h:496:64: error: a space is required between consecutive right angle brackets (use '> >')
                std::map<int32_t, std::map<int32_t, std::map<int32_t, int32_t>>> voxelId;
                                                                             ^~
                                                                             > >
/Users/slu/Documents/MagicaVoxel_File_Writer/main.cpp:10:34: error: use of undeclared identifier 'sin'
                        vox.AddVoxel(i, j, (int)floor(sin((float)(i * i + j * j) / 50000) * 150) + 150, (i + j) % 255 + 1);
                                                      ^
1 warning and 8 errors generated.
make[2]: *** [CMakeFiles/VoxWriter.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/VoxWriter.dir/all] Error 2
make: *** [all] Error 2

it looks like also that c++11 isnt enabled for your cmake config.

aiekick commented 4 years ago

arf visual sutdio not produce errors, i saw it ignore unused code. as mingw32 block. sorry i will check that in clion

i would ike to converts my simu in 3d like this one : https://www.shadertoy.com/view/3dsyRl

aiekick commented 4 years ago

corrected :) there was an issue aboyut my last modif (no more generation) ahah. speed is the ennemy of good code :)

unphased commented 4 years ago

Awesome! Nice shader!!

aiekick commented 4 years ago

thanks. its my hobby :) i love all procedural stuff, or art via programming