Giter Site home page Giter Site logo

sandrofigo / voxreader Goto Github PK

View Code? Open in Web Editor NEW
50.0 1.0 3.0 187 KB

A C# library to read .vox files created with MagicaVoxel

License: MIT License

C# 93.15% Batchfile 0.26% PowerShell 3.71% Shell 2.88%
vox voxel reader parser magicavoxel vox-files magica-voxel parser-library unity unity-3d

voxreader's People

Contributors

dependabot[bot] avatar sandrofigo 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

voxreader's Issues

KeyNotFoundException when parsing specific .vox files

KeyNotFoundException when parsing specific .vox files
I am experiencing a KeyNotFoundException when attempting to parse certain .vox files. The error message is:

System.Collections.Generic.KeyNotFoundException: 'The given key was not present in the dictionary.'

I have tried parsing several .vox files and have found that some of them work as expected, while others do not. I have not been able to identify any specific pattern or cause for the files that are causing this exception to be thrown.

I have attached a .zip of the vox file below, when parsing this file you will be presented with the error above:

Example.zip

Any help or guidance on this issue would be greatly appreciated. Thank you!

Support for exported .vox files

After a little investigation I could reproduce the behaviour by exporting the file with the ".vox" export function instead of saving the "project".
image

If the file is exported this way, some chunks are missing that would normally be used to parse the models. I will add the feature to read "exported" .vox files in the next release.

Originally posted by @sandrofigo in #16 (reply in thread)

Indexes in PalleteChunk.Colors don't match with actual color indexes in a pallete.

In MagicaVox palletes color indexes start from 1, but in PalleteChunk.Colors they start from 0. Indexes are shifted. Because of it, if I want to get a color with index i, I need to write palleteChunk.Color[i - 1]. This is counter intuitive and caused me a problem, because palleteChunk.Color[voxel.ColorIndex] doesn't give me a color of that voxel. Instead I have to write palleteChunk.Color[voxel.ColorIndex - 1]. That takes some time and nerves to understand. Please make color indexes start with 1 like in MagicaVox, so color indexes would match.

Access palette notes

Hello, I would like to access palette notes per voxel.
image

I managed to get the notes out of the note chunk with the following code:

        var noteChunk = vox.Chunks.Single(x => x.Type == ChunkType.Note);
        var noteList = new List<string>();

        var i = 4; // skip row count
        while (i < noteChunk.Content.Length)
        {
            var noteLength = BitConverter.ToInt32(noteChunk.Content, i);
            i += 4;

            var note = Encoding.ASCII.GetString(noteChunk.Content[i..(i + noteLength)]).Trim();
            i += noteLength;

            noteList.Add(note);
        }

This creates an array with 32 names that match with what's in the editor.
Unfortunately, I have not been able to match colors to the actual group names. The color indexes don't match up at all, in fact, they aren't even in the same order.

I've noticed the existence of ChunkType.IndexMap, maybe I need to use that somehow?
Also, it would be nice if you could access the color index from the public Voxel struct. As things are right now, I had to clone this repo and modify it to expose it.

Helper method for global voxel position

If the user wants to know the global voxel position in the scene the user must calculate this manually. There should exist a method to calculate the global position of a voxel in the scene.

Add support to get model positions

I'm working with .vox files, and I noticed there isn't a way to get the position of a group, the cars.vox file included with magicavoxel, has two groups which can be seen below, however when I parse the voxels using voxelReader and since there's no group positions, the voxels all occupy the same space.

image
,

About credit for your work

Hello!

I've used this tool in a game server plugin, where it is responsible for loading in custom terrain from magica voxel. In order to load this plugin, users need to drop my plugin in a folder as .dll, however they also need to put in voxreader.dll for it to work.

Right now, I've published both our dll's under one release like such: https://github.com/SwatDoge/SOTTBBVFMVTAEBP/releases/tag/1.0.0 and credited accordingly. I've mostly done this for convenience.

Do you feel this is sufficient crediting? Would you prefer me to delete the voxreader.dll, and refer users to this github?

I apologize for publishing your code, I am still figuring out the best way to do this.

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.