mxgmn / WaveFunctionCollapse

Bitmap & tilemap generation from a single example with the help of ideas from quantum mechanics
Other
23.18k stars 1.24k forks source link

exception when running WFC-3D.exe #33

Closed NikkyAI closed 6 years ago

NikkyAI commented 6 years ago

i am trying to create 3d models, voxelsize: 8 could that be more than the program expects to handle ?

D:\dev\wfc-3d-basic>WFC-3D.exe                                                                                          < Station                                                                                                                                                                                                                                       Unhandled Exception: System.ArgumentException: The output char buffer is too small to contain the decoded characters, encoding 'Unicode (UTF-8)' fallback 'System.Text.DecoderReplacementFallback'.                                             Parameter name: chars                                                                                                      at System.Text.Encoding.ThrowCharsOverflow()                                                                            at System.Text.Encoding.ThrowCharsOverflow(DecoderNLS decoder, Boolean nothingDecoded)                                  at System.Text.UTF8Encoding.GetChars(Byte* bytes, Int32 byteCount, Char* chars, Int32 charCount, DecoderNLS baseDecoder)                                                                                                                        at System.Text.DecoderNLS.GetChars(Byte* bytes, Int32 byteCount, Char* chars, Int32 charCount, Boolean flush)           at System.IO.BinaryReader.InternalReadChars(Char[] buffer, Int32 index, Int32 count)                                    at System.IO.BinaryReader.ReadChars(Int32 count)                                                                        at Stuff.ReadVox(BinaryReader stream)                                                                                   at Stuff.ReadVox(String filename)                                                                                       at Model..ctor(String name, String subsetName, Int32 FMX, Int32 FMY, Int32 FMZ, Boolean periodic, String groundName)    at Program.Main()  
NikkyAI commented 6 years ago

or maybe i did not save the vox files correctly, i edited them with magicalvoxel on windows

edit: after some more testing it turns out that whatever i xsave with magicalvoxel breaks WFC-3D edit2: there seems to have been a change in the vox file format or encoding being used, the sample files seem to have a BaseStream length of 72 or 60, but the new files have garbage in the chunkIDs and apparently a lngth of ~ 1200 (also reflected in filesize)

NikkyAI commented 6 years ago

so i fixed it in the vox parsing i added:

else if (chunkName == "PACK")
{
    int numModels = stream.ReadInt32();
    Console.WriteLine($"numModels: {numModels}");
}
else if (chunkName == "RGBA")
{
    // stream.ReadBytes(chunkSize);
    int[] colors = new int[256];
    for (int i = 0; i <= 255; i++)
    {
        int color = stream.ReadInt32();
        colors[i] = color;
        // Console.WriteLine($"color: {i} {color}");
    }
}

in several other places i also fixed up the comment handling

if(xnode.NodeType == XmlNodeType.Comment) continue;
mxgmn commented 6 years ago

Thanks!

I'm preparing a proper 3d version of WFC, it'll work with the latest vox format.