Crafter.Build/interfaces/Crafter.Build-Asset.cppm
Jorijn van der Graaf f442caa888
Some checks failed
CI / build-test-release (push) Failing after 15m11s
asset changes
2026-05-19 00:50:06 +02:00

61 lines
2.5 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
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;
#include "Crafter.Build-Api.h"
export module Crafter.Build:Asset;
import std;
namespace fs = std::filesystem;
namespace Crafter {
// Compress a build-time asset (.png/.obj) into its on-disk
// SaveCompressed counterpart (.ctex/.cmesh) using Crafter.Asset's
// library API in-process. Returns "" on success, an error message
// otherwise (matches Shader::Compile's contract).
//
// Real implementation lives in the impl unit and only compiles when
// CRAFTER_BUILD_HAS_ASSET is defined (i.e. when the build links
// Crafter.Asset). The bootstrap build.sh produces a stub variant
// that errors out at runtime if cfg.assets is non-empty — full
// support requires a self-host rebuild via crafter-build itself,
// which resolves the Crafter.Asset dep through project.cpp.
export CRAFTER_API std::string CompressAsset(const fs::path& input, const fs::path& output);
// Split a single .obj + .mtl file by material group into per-material
// .cmesh files, per-unique-albedo .ctex files, and a scene.txt manifest
// under outDir. All albedo textures are resized to albedoSize × albedoSize
// before compression (required for a texture_2d_array where all layers
// must have identical dimensions).
//
// scene.txt format (read by the Sponza example at runtime):
// <albedoCount>
// <meshCount>
// <albedoIdx_for_mesh_0> (-1 = no albedo)
// ...
//
// Idempotent: returns "" immediately if outDir/scene.txt already exists,
// so repeated builds skip the expensive split+resize step.
// Returns "" on success, an error string on failure.
export CRAFTER_API std::string BuildOBJBundle(
const fs::path& objPath,
const fs::path& mtlPath,
const fs::path& outDir,
std::uint16_t albedoSize = 1024
);
}