asset compression
Some checks failed
CI / build-test-release (push) Failing after 15m11s

This commit is contained in:
Jorijn van der Graaf 2026-05-12 01:16:40 +02:00
commit 03717b5f33
9 changed files with 230 additions and 14 deletions

View file

@ -0,0 +1,55 @@
/*
Crafter® Build
Copyright (C) 2026 Catcrafts®
Catcrafts.net
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License version 3.0 as published by the Free Software Foundation;
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
module Crafter.Build:Asset_impl;
import :Asset;
import std;
#ifdef CRAFTER_BUILD_HAS_ASSET
import Crafter.Asset;
import Crafter.Math;
#endif
namespace fs = std::filesystem;
namespace Crafter {
std::string CompressAsset(const fs::path& input, const fs::path& output) {
std::string ext = input.extension().string();
#ifdef CRAFTER_BUILD_HAS_ASSET
try {
if (ext == ".png") {
auto tex = TextureAsset<Vector<std::uint8_t, 4, 4>>::LoadPNG<std::uint8_t>(input);
tex.SaveCompressed(output);
} else if (ext == ".obj") {
auto mesh = MeshAsset<VertexNormalTangentUVPacked>::LoadOBJ(input);
mesh.SaveCompressed(output);
} else {
return std::format("{}: unsupported asset extension '{}'", input.string(), ext);
}
} catch (const std::exception& e) {
return std::format("{}: {}", input.string(), e.what());
}
return {};
#else
return std::format(
"{}: crafter-build was bootstrapped without Crafter.Asset linkage; "
"rebuild via `./bin/crafter-build` so the self-host pass picks up the "
"Crafter.Asset dep declared in project.cpp",
input.string());
#endif
}
}