Giter VIP home page Giter VIP logo

magicavoxel_file_writer's Introduction

MagicaVoxel File Writer

Rust Version available here : MagicaVoxel File Writer for Rust

vox.hm is the file format descriptor for HexaMonkey :

App

the main.cpp file show you how to generate a quick file :

With this simple code

#include "VoxWriter.h"
int main() 
{
    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

main

possible console print ( vox.PrintStats() ) :

---- 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
-----------------------------------------

magicavoxel_file_writer's People

Contributors

aiekick avatar eutro avatar flayan avatar forceflow avatar pjayb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

magicavoxel_file_writer's Issues

Support for converting pointclouds with decimal coordinates

Hi! I have been voxelizing some maps with your awesome software, but I'm facing some resolution issues due to my points coordinates are not integers and I'm working with decimal part too (0.25 meter resolution). I have tried to modify your lib but I don't know where to start as most functions are based on int32 arguments. It would be great to add support for float coordinates.

As my resolution is 0.25, I have tried multiplying all coordinates by four and it results in a rare tower (which has nothing to do with the real map) maybe it's because points go out of MagicaVoxel's range. Proof:

image
image

My point cloud file looks like this example:

7228
511.0 291.5 27.75
511.0 291.75 27.75
510.75 292.0 27.75
510.75 291.25 28.0
510.75 291.5 28.0
510.75 291.75 28.0
511.75 291.0 28.0
511.0 291.5 28.0
509.75 292.5 28.0
510.5 292.25 28.0
510.75 292.25 28.0
510.75 292.5 28.0
511.0 292.0 28.0
511.0 292.25 28.0
503.75 303.5 30.0
506.75 297.75 26.5
507.25 297.5 26.5
507.0 297.75 26.5
507.25 297.75 26.5
506.75 297.5 27.0
506.75 297.75 27.0
506.75 297.75 27.25
506.75 297.25 27.5
506.75 297.25 27.75
506.75 297.5 27.5
506.5 297.75 27.5
506.75 297.75 27.5
506.75 297.5 27.75
506.75 297.75 27.75
507.0 297.5 27.0
507.0 297.5 27.25
507.0 297.75 27.25
507.0 297.75 27.75

only 30 frames are output

I tested with main.cpp in the repo. No matter how I change the value of FRAMES, there are always 30 keyframes in the final file when I view with MigicaVoxel-0.99.7.1. If FRAMES < 30, there will be no change for frames > FRAMES. If FRAMES > 30, the rest frames don't show up in the final file. Any idea why? Thanks for the help

v0.99.5 and 256^3 multi model support

Hey there @aiekick,

I noticed that the latest MagicaVoxel windows release 0.99.5 supports 256^3 model sizes and also fails to load the format that this code produces. I made a trivial modification to the code that shows that it can export 256^3 blocks (and the first of which loads) but the multi block loading functionality appears to be changed and no longer works.

Since you were able to reverse engineer the format, I was wondering if you could take a stab at it again. ๐Ÿ˜„

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.