feat: add model / texture cooking
This commit is contained in:
@@ -13,6 +13,14 @@
|
||||
|
||||
#include "ShaderCompiler.h"
|
||||
|
||||
#ifdef THECHEF_MODEL_COOKING
|
||||
#include "ModelCooker.h"
|
||||
#endif
|
||||
|
||||
#ifdef THECHEF_TEXTURE_COOKING
|
||||
#include "TextureCooker.h"
|
||||
#endif
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
using json = nlohmann::json;
|
||||
|
||||
@@ -60,6 +68,7 @@ static Args parse_args(int argc, char** argv) {
|
||||
static std::string classify_type(const fs::path& src) {
|
||||
const std::string ext = to_lower(src.extension().string());
|
||||
if (ext == ".png" || ext == ".jpg" || ext == ".jpeg" || ext == ".tga") return "texture";
|
||||
if (ext == ".exr") return "hdr_texture";
|
||||
// Treat these as "shader family" (entry: .vert/.frag/.comp, include-only: .glsl)
|
||||
if (ext == ".vert" || ext == ".frag" || ext == ".comp" || ext == ".glsl") return "shader";
|
||||
if (ext == ".wav" || ext == ".ogg" || ext == ".mp3") return "audio";
|
||||
@@ -79,15 +88,9 @@ static bool copy_if_needed(const fs::path& src, const fs::path& dst) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Choose your SPV output naming scheme.
|
||||
// Option A: shader.vert -> shader.vert.spv (keeps original extension)
|
||||
// Option B: shader.vert -> shader.spv (replace with .spv)
|
||||
static fs::path make_spv_output_path(const fs::path& dstLikeSrc) {
|
||||
fs::path out = dstLikeSrc;
|
||||
// Option A:
|
||||
out.replace_extension(dstLikeSrc.extension().string() + ".spv");
|
||||
// Option B (uncomment to use):
|
||||
// out.replace_extension(".spv");
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -119,32 +122,29 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
fs::create_directories(args.output);
|
||||
|
||||
// ----------------------------
|
||||
// Shader compiler setup
|
||||
// ----------------------------
|
||||
SpirvShaderCompiler::Options scOpt;
|
||||
scOpt.debugInfo = false; // set true if you want debug info in SPIR-V
|
||||
scOpt.defines = { "DEBUG=1" };
|
||||
|
||||
|
||||
// Common conventions (adjust to your folder layout):
|
||||
// - shaders live under <input>/shaders
|
||||
// - includes live under <input>/shaders/include
|
||||
//
|
||||
// If you don't have these folders, either remove these or point them elsewhere.
|
||||
scOpt.includeDirs = {
|
||||
args.input / "shaders",
|
||||
args.input / "shaders" / "include"
|
||||
};
|
||||
|
||||
// Optional defines:
|
||||
// scOpt.defines = { "MY_DEFINE=1", "USE_FOG" };
|
||||
|
||||
SpirvShaderCompiler shaderCompiler(scOpt);
|
||||
|
||||
// ----------------------------
|
||||
// Manifest init
|
||||
// ----------------------------
|
||||
#ifdef THECHEF_MODEL_COOKING
|
||||
ModelCooker::Options mcOpt;
|
||||
mcOpt.inputRoot = args.input;
|
||||
|
||||
ModelCooker modelCooker(mcOpt);
|
||||
#endif
|
||||
|
||||
#ifdef THECHEF_TEXTURE_COOKING
|
||||
TextureCooker textureCooker;
|
||||
#endif
|
||||
|
||||
json manifest;
|
||||
manifest["version"] = 1;
|
||||
manifest["assets"] = json::array();
|
||||
@@ -191,6 +191,40 @@ int main(int argc, char** argv) {
|
||||
finalOut = dst;
|
||||
finalType = "shader_raw";
|
||||
}
|
||||
} else if (type == "mesh") {
|
||||
// The source model is still copied for code that imports it directly.
|
||||
changed = copy_if_needed(src, dst);
|
||||
finalOut = dst;
|
||||
|
||||
#ifdef THECHEF_MODEL_COOKING
|
||||
// Models that can't be imported on their own (e.g. animation-only files) keep using the source.
|
||||
const fs::path modelOut = ModelCooker::MakeOutputPath(dst);
|
||||
try {
|
||||
changed = modelCooker.CookFileIfNeeded(src, modelOut) || changed;
|
||||
|
||||
finalOut = modelOut;
|
||||
finalType = "model";
|
||||
} catch (const std::exception& e) {
|
||||
spdlog::warn("Not cooking {}, using the source model instead: {}", rel.generic_string(), e.what());
|
||||
}
|
||||
#endif
|
||||
} else if (type == "hdr_texture") {
|
||||
#ifdef THECHEF_TEXTURE_COOKING
|
||||
const fs::path textureOut = TextureCooker::MakeOutputPath(dst);
|
||||
try {
|
||||
changed = textureCooker.CookFileIfNeeded(src, textureOut);
|
||||
|
||||
finalOut = textureOut;
|
||||
finalType = "texture_cooked";
|
||||
} catch (const std::exception& e) {
|
||||
spdlog::warn("Not cooking {}, copying the source image instead: {}", rel.generic_string(), e.what());
|
||||
changed = copy_if_needed(src, dst);
|
||||
finalOut = dst;
|
||||
}
|
||||
#else
|
||||
changed = copy_if_needed(src, dst);
|
||||
finalOut = dst;
|
||||
#endif
|
||||
} else {
|
||||
// Normal assets: copy if needed.
|
||||
changed = copy_if_needed(src, dst);
|
||||
|
||||
Reference in New Issue
Block a user