crafter-build V2
This commit is contained in:
parent
3aaffcd2e2
commit
b9b9ecb84c
3 changed files with 76 additions and 83 deletions
|
|
@ -2,21 +2,17 @@
|
||||||
Crafter®.Asset
|
Crafter®.Asset
|
||||||
Copyright (C) 2026 Catcrafts®
|
Copyright (C) 2026 Catcrafts®
|
||||||
catcrafts.net
|
catcrafts.net
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
This library is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU Lesser General Public
|
modify it under the terms of the GNU Lesser General Public
|
||||||
License version 3.0 as published by the Free Software Foundation;
|
License version 3.0 as published by the Free Software Foundation;
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
This library is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
Lesser General Public License for more details.
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
You should have received a copy of the GNU Lesser General Public
|
||||||
License along with this library; if not, write to the Free Software
|
License along with this library; if not, write to the Free Software
|
||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import Crafter.Asset;
|
import Crafter.Asset;
|
||||||
import Crafter.Math;
|
import Crafter.Math;
|
||||||
import std;
|
import std;
|
||||||
|
|
@ -24,19 +20,44 @@ using namespace Crafter;
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
if (argc != 3 && argc != 2) { // Allow the possibility of just one argument (input file)
|
// Parse arguments: crafter-asset <input_file> [output_file] [--format u8|f16]
|
||||||
std::cout << "Usage: crafter-asset <input_file> [output_file]\n";
|
fs::path inputPath;
|
||||||
|
fs::path outputPath;
|
||||||
|
std::string textureFormat = "f16"; // default
|
||||||
|
bool hasOutputPath = false;
|
||||||
|
|
||||||
|
std::vector<std::string> positional;
|
||||||
|
for (int i = 1; i < argc; ++i) {
|
||||||
|
std::string arg = argv[i];
|
||||||
|
if (arg == "--format" || arg == "-f") {
|
||||||
|
if (i + 1 >= argc) {
|
||||||
|
std::cerr << "Error: --format requires a value (u8 or f16)\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
textureFormat = argv[++i];
|
||||||
|
if (textureFormat != "u8" && textureFormat != "f16") {
|
||||||
|
std::cerr << "Error: Invalid format '" << textureFormat
|
||||||
|
<< "'. Must be 'u8' or 'f16'.\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
positional.push_back(arg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (positional.empty() || positional.size() > 2) {
|
||||||
|
std::cout << "Usage: crafter-asset <input_file> [output_file] [--format u8|f16]\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fs::path inputPath = argv[1];
|
inputPath = positional[0];
|
||||||
fs::path outputPath;
|
if (positional.size() == 2) {
|
||||||
|
outputPath = positional[1];
|
||||||
|
hasOutputPath = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Check if output path is provided; if not, use input path with a modified extension
|
// Check if output path is provided; if not, use input path with a modified extension
|
||||||
if (argc == 3) {
|
if (!hasOutputPath) {
|
||||||
outputPath = argv[2];
|
|
||||||
} else {
|
|
||||||
// Determine extension type for output
|
|
||||||
std::string extension = inputPath.extension().string();
|
std::string extension = inputPath.extension().string();
|
||||||
if (extension == ".obj") {
|
if (extension == ".obj") {
|
||||||
outputPath = inputPath;
|
outputPath = inputPath;
|
||||||
|
|
@ -56,18 +77,20 @@ int main(int argc, char** argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string extension = inputPath.extension().string();
|
std::string extension = inputPath.extension().string();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (extension == ".obj") {
|
if (extension == ".obj") {
|
||||||
// Load OBJ as MeshAsset with normal/tangent/uv data
|
|
||||||
auto mesh = MeshAsset<VertexNormalTangentUVPacked>::LoadOBJ(inputPath);
|
auto mesh = MeshAsset<VertexNormalTangentUVPacked>::LoadOBJ(inputPath);
|
||||||
mesh.Save(outputPath);
|
mesh.Save(outputPath);
|
||||||
}
|
}
|
||||||
else if (extension == ".png") {
|
else if (extension == ".png") {
|
||||||
// Load PNG as TextureAsset
|
if (textureFormat == "f16") {
|
||||||
auto texture = TextureAsset<Vector<_Float16, 4, 4>>::LoadPNG<_Float16>(inputPath);
|
auto texture = TextureAsset<Vector<_Float16, 4, 4>>::LoadPNG<_Float16>(inputPath);
|
||||||
texture.Save(outputPath);
|
texture.Save(outputPath);
|
||||||
}
|
} else { // u8
|
||||||
|
auto texture = TextureAsset<Vector<std::uint8_t, 4, 4>>::LoadPNG<std::uint8_t>(inputPath);
|
||||||
|
texture.Save(outputPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
std::cerr << "Unsupported file type: " << extension << "\n";
|
std::cerr << "Unsupported file type: " << extension << "\n";
|
||||||
return 1;
|
return 1;
|
||||||
|
|
@ -76,6 +99,5 @@ int main(int argc, char** argv) {
|
||||||
std::cerr << "Error: " << e.what() << "\n";
|
std::cerr << "Error: " << e.what() << "\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
34
project.cpp
Normal file
34
project.cpp
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
import std;
|
||||||
|
import Crafter.Build;
|
||||||
|
namespace fs = std::filesystem;
|
||||||
|
using namespace Crafter;
|
||||||
|
|
||||||
|
extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> args) {
|
||||||
|
GitProjectSpec mathSpec{
|
||||||
|
.source = { .url = "https://forgejo.catcrafts.net/Catcrafts/Crafter.Math.git" },
|
||||||
|
.args = std::vector<std::string>(args.begin(), args.end()),
|
||||||
|
};
|
||||||
|
Configuration* math = GitProject(mathSpec);
|
||||||
|
|
||||||
|
Configuration cfg;
|
||||||
|
cfg.path = "./";
|
||||||
|
cfg.name = "Crafter.Asset";
|
||||||
|
ApplyStandardArgs(cfg, args);
|
||||||
|
cfg.outputName = (cfg.type == ConfigurationType::Executable) ? "crafter-asset" : "Crafter.Asset";
|
||||||
|
cfg.dependencies = { math };
|
||||||
|
|
||||||
|
std::array<fs::path, 3> ifaces = {
|
||||||
|
"interfaces/Crafter.Asset",
|
||||||
|
"interfaces/Crafter.Asset-Texture",
|
||||||
|
"interfaces/Crafter.Asset-Mesh",
|
||||||
|
};
|
||||||
|
if (cfg.type == ConfigurationType::Executable) {
|
||||||
|
std::array<fs::path, 1> impls = { "implementations/main" };
|
||||||
|
cfg.GetInterfacesAndImplementations(ifaces, impls);
|
||||||
|
} else {
|
||||||
|
std::array<fs::path, 0> impls = {};
|
||||||
|
cfg.GetInterfacesAndImplementations(ifaces, impls);
|
||||||
|
}
|
||||||
|
|
||||||
|
return cfg;
|
||||||
|
}
|
||||||
63
project.json
63
project.json
|
|
@ -1,63 +0,0 @@
|
||||||
{
|
|
||||||
"name": "crafter-asset",
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "base",
|
|
||||||
"implementations": [],
|
|
||||||
"interfaces": ["interfaces/Crafter.Asset", "interfaces/Crafter.Asset-Texture", "interfaces/Crafter.Asset-Mesh"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "deps-debug",
|
|
||||||
"extends": ["base"],
|
|
||||||
"dependencies": [
|
|
||||||
{
|
|
||||||
"path":"https://forgejo.catcrafts.net/Catcrafts/Crafter.Math.git",
|
|
||||||
"configuration":"lib-debug"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "deps",
|
|
||||||
"extends": ["base"],
|
|
||||||
"type":"executable",
|
|
||||||
"dependencies": [
|
|
||||||
{
|
|
||||||
"path":"https://forgejo.catcrafts.net/Catcrafts/Crafter.Math.git",
|
|
||||||
"configuration":"lib"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "executable",
|
|
||||||
"extends": ["deps"],
|
|
||||||
"implementations": ["implementations/main"],
|
|
||||||
"type": "executable"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "executable-windows",
|
|
||||||
"extends": ["deps"],
|
|
||||||
"implementations": ["implementations/main"],
|
|
||||||
"type": "executable",
|
|
||||||
"target": ""
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "executable-debug",
|
|
||||||
"extends": ["deps-debug"],
|
|
||||||
"type": "executable",
|
|
||||||
"implementations": ["implementations/main"],
|
|
||||||
"debug": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "lib",
|
|
||||||
"extends": ["deps"],
|
|
||||||
"type": "library"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "lib-debug",
|
|
||||||
"extends": ["deps-debug"],
|
|
||||||
"type": "library",
|
|
||||||
"debug": true
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue