andyp123 / blender_io_mesh_bsp

Blender addon that imports Quake BSP files
108 stars 22 forks source link

Doesn't load BSP2 format files #1

Closed andyp123 closed 5 years ago

andyp123 commented 5 years ago

BSP2 is not currently supported, which means a lot of modern and very cool maps will not import correctly. Right now it seems as if the vertices of the first model are loaded, and then there is an error, preventing anything else from loaded. Looks like some format details are not correct, so data is either the wrong size or in the wrong place:

Traceback (most recent call last):
  File "---\io_mesh_bsp\__init__.py", line 105, in execute
    bsp_importer.import_bsp(context, self.filepath, options)
  File "---\io_mesh_bsp\bsp_importer.py", line 310, in import_bsp
    texinfo = BSPTexInfo._make(texinfo_struct.unpack_from(texinfo_data[texinfo_ofs:texinfo_ofs+texinfo_size]))
struct.error: unpack_from requires a buffer of at least 40 bytes
JDragan commented 5 years ago

ask for this on http://forums.insideqc.com

andyp123 commented 5 years ago

Thanks. Adding BSP2 support is super low priority for me right now, as I've other things I need to be working on. However, it's probably not that hard, as the format is not much different to regular BSP. I suspect the only changes are that some of the types used are largers (int instead of char or short etc.) to support increased limits. There is some info here: https://quakewiki.org/wiki/BSP2 and I'm sure it's an easy problem to solve by just looking at the source for Quakespasm or a compiler to see how it's handled there.

aguaviva commented 5 years ago

FYI: The code in the link below takes a boolean called bsp2 in the map loading code, with that will load bsp or bsp2 files

https://github.com/Novum/vkQuake/blob/e3d863d042345aa7a4c6551c29499c71ba4c1591/Quake/gl_model.c

Example:

if (bsp2)
        {
            out->firstedge = LittleLong(inl->firstedge);
            out->numedges = LittleLong(inl->numedges);
            planenum = LittleLong(inl->planenum);
            side = LittleLong(inl->side);
            texinfon = LittleLong (inl->texinfo);
            for (i=0 ; i<MAXLIGHTMAPS ; i++)
                out->styles[i] = inl->styles[i];
            lofs = LittleLong(inl->lightofs);
            inl++;
        }
        else
        {
            out->firstedge = LittleLong(ins->firstedge);
            out->numedges = LittleShort(ins->numedges);
            planenum = LittleShort(ins->planenum);
            side = LittleShort(ins->side);
            texinfon = LittleShort (ins->texinfo);
            for (i=0 ; i<MAXLIGHTMAPS ; i++)
                out->styles[i] = ins->styles[i];
            lofs = LittleLong(ins->lightofs);
            ins++;
        }

Most of the time it will use longs instead of shorts

andyp123 commented 5 years ago

Thanks. I'll take a look at this today and see how far I can get with it.

aguaviva commented 5 years ago

Awesome, this is pretty exciting!

(BTW I am looking into adding support for lightmaps)

andyp123 commented 5 years ago

OK, it was really easy to implement after all. It's in the repository now, and will be made official in the next release.