Skip to content

Commit

Permalink
lightstyles export option
Browse files Browse the repository at this point in the history
  • Loading branch information
lewa-j committed Mar 22, 2022
1 parent f311886 commit a9c2855
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ A tool to convert bsp maps (Half-Life and other GoldSrc games) into gltf scenes.

* `-lm <number>` - set a lightmap atlas size
* `-skip_sky` - exclude polygons with 'sky' texture from export
* `-lstyle <number>|all` - export lightmap with a specified lightstyle index or all lightyles in one

## Dependencies (already included)

Expand Down
17 changes: 16 additions & 1 deletion src/bsp-converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ int main(int argc, const char *argv[])
printf("bsp-converter by lewa_j v0.6 - 2022\n");
if (argc < 2 || !strcmp(argv[1], "-h"))
{
printf("Usage: bsp-converter map.bsp [-lm <lightmap atlas size>] [-skip_sky]\n");
printf("Usage: bsp-converter map.bsp [-lm <lightmap atlas size>] [-skip_sky] [-lstyles <light style index>|all]\n");
return -1;
}

Expand Down Expand Up @@ -41,6 +41,21 @@ int main(int argc, const char *argv[])
printf("Warning: '-lm' parameter requires a number - lightmap atlas resolution\n");
}
}
if (!strcmp(argv[i], "-lstyle"))
{
if (argc > i + 1)
{
i++;
if (!strcmp(argv[i], "all"))
config.lstylesAll = true;
else
config.lstyle = atoi(argv[i]);
}
else
{
printf("Warning: '-lstyle' parameter requires a number - light style index, or a word 'all'\n");
}
}
else if (!strcmp(argv[i], "-skip_sky"))
{
config.skipSky = true;
Expand Down
9 changes: 7 additions & 2 deletions src/hlbsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ bool Map::load(const char *path, const char *name, LoadConfig *config)
const dface_t &f = faces[i];
for (int j = 0; j < LM_STYLES; j++)
{
if (f.styles[j] != 0 && f.styles[j] != 255)
if (f.styles[j] != 0 && f.styles[j] != 255 && (config->lstylesAll || f.styles[j] == config->lstyle))
{
activeStyles++;
break;
Expand All @@ -218,6 +218,8 @@ bool Map::load(const char *path, const char *name, LoadConfig *config)
for (int s = 1; s < LM_STYLES && f.styles[s] != 255; s++)
{
lmOffset += fl.size[0] * fl.size[1] * 3;
if (!config->lstylesAll && f.styles[s] != config->lstyle)
continue;
for (int l = 0; l < flmap.size(); l++)
{
int val = flmap[l] + lightmapPixels[f.lightofs + lmOffset + l];
Expand All @@ -234,7 +236,10 @@ bool Map::load(const char *path, const char *name, LoadConfig *config)
data += fl.size[0] * 3;
}
}
lmap2.save((std::string(name) + "_styles_lightmap.png").c_str());
if (config->lstylesAll)
lmap2.save((std::string(name) + "_styles_lightmap.png").c_str());
else
lmap2.save((std::string(name) + "_style" + std::to_string(config->lstyle) + "_lightmap.png").c_str());
}

return true;
Expand Down
2 changes: 2 additions & 0 deletions src/hlbsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ struct LoadConfig
{
bool skipSky = false;
int lightmapSize = 1024;
int lstyle = -1;
bool lstylesAll = false;
};

class Map
Expand Down

0 comments on commit a9c2855

Please # to comment.