Question about BSP file format (probably for devs...?)


(Flippy) #1

Hi,

I am trying to write a simple program that will extract all used textures from either the .map or the compiled .bsp file.

So far, the .bsp file looks to be the best candidate, since each texture is actually preceded by the string “textures/” which makes them easy to extract.

However, the files are really large and contain loads of NULL characters. When I try to load them into my application, it stops reading as soon as it hits a NULL character, and so most of the information is lost…

One possible solution to this is to replace each NULL character by a different character (like a space). Unfortunately, since the files are so large and contain so many null characters, this takes AGES to complete…

Now after looking at a few random BSP files in Wordpad, I found that the textures are only in the first few (10-20?) lines, and the rest of the BSP file (99.9999% or something :stuck_out_tongue: ) is garbage for me. If I would only use the first few relevant lines that would make my application so much faster…
But the problem ofcourse, is that I don’t know how many lines to look for!

I don’t think so, but is there maybe some kind of ‘rule’ that tells me how many lines contain the texture information? Is there any way I can get my program to only read the texture information, not the rest of the file?

Thanks!!


(Kic) #2

Hi Flippy, if you will search on google(sorry for this) , you will probably find some wiki or page with detailed description of this file format, some time back l found it, or go here to other modeling application folder, l have here some link http://3dnow.informe.com


(Flippy) #3

Thanks, interesting…

I’ve learned that the BSP files consist of chunks of data called “lumps”, and that one of these lumps contains the texture data. I also learned that the header of the BSP file should contain the location/length etc of each lump… I have not learned however how to extract that information so I can use it :frowning:


(nUllSkillZ) #4

Not sure but I think q3map2 is open source.
So you could take a look in the source.


(Flippy) #5

Using the help of someone else I managed to get it! Seems you have to skip the first 4 chars, and then skip some more, and some more (I really don’t understand this :stuck_out_tongue: ) and then you get the textures. After some filtering I was able to get a list of the textures and models used in the BSP file.

I now realize however that the textures are actually the shaders. So it also lists the common/caulk, common/clip etc, which are not actually textures…

My program works so far, but I have some more plans for it… I am planning to have the program read the shader that belongs to each texture, and:

  • extracts the actual texture image filename, and displays it when doubleclicked
  • compares it to a hardcoded list to determine if it is a standard shader, or if it is a custom one you need to supply in your PK3
    (- Maybe! Add the textures you require in your pk3 to a specified folder so all you have to do is copy that folder into your pk3)

Not sure if Im going to manage this but I might… ^^

Here’s a screenshot so far (from battery):


(Cambodunum) #6

jsut a lil suggestion for another feature … really dont know if this is possible:

would be nice if there is a feature where you can edit the texture-paths of each (custom-)texture in the bsp

… so if ive used
textures/wall/xxx.tga
textures/window/yyy.tga
textures/misc/zzz.tga

and i wanna get em into one folder like (… so its better organized):
textures/mapx/xxx.tga
textures/mapx/yyy.tga
textures/mapx/zzz.tga

click …
done …
xD

greetz Cambo


(-SSF-Sage) #7

Lazyness is supreme efficiency. :smiley: But seriously you need a program for couple things that would take only a few minutes, lol. :tongue:

Nice work again Flippy!

ps. Cambo I don’t think it is a realistic request, since you would need to do it everytime (and would not see the changes in radiant), seeing how it currently only accepts bsp. Only good choice would be probably figuring out how to read a map file without much lag.


(Cambodunum) #8

ps. Cambo I don’t think it is a realistic request, since you would need to do it everytime (and would not see the changes in radiant), seeing how it currently only accepts bsp. Only good choice would be probably figuring out how to read a map file without much lag.

oops ive forgot that shitty .map file xD

Lazyness is supreme efficiency.

hell yeah! xD


(Pande) #9

And what pray tell is this going to be used for?


(nUllSkillZ) #10

Nice work.


(Flippy) #11

Quick update:

After selecting a texture in the list you can click the ‘View Shader Info’ button to view the Shader Information window, which lists all the shaders that contain this texture. You can then open the selected shader in Notepad, or in a small extra window which automatically finds and selects the texture in the text.

You can also Filter the results with the Filter textbox.

And the ‘Select BSP file’ is now a dropdown box that lists each BSP file in your W:ET/maps directory (don’t worry, you can still type or browse to any other bsp file).


(rambo13) #12

u r gonna release this handy tool to public when u r done right?