Add project files.
This commit is contained in:
commit
a9ae435321
52 files changed
+65378
No files matched your search
@@ -0,0 +1,4 @@
|
||||
add_executable(hmap_info hmap_info.cpp)
|
||||
add_executable(hmap_sample hmap_sample.cpp)
|
||||
target_link_libraries(hmap_info PRIVATE hmap)
|
||||
target_link_libraries(hmap_sample PRIVATE hmap)
|
||||
@@ -0,0 +1,35 @@
|
||||
// hmap_info: prints a summary of a .hmap file using only the public libhmap API.
|
||||
// hmap_info level.hmap [--fbx out.fbx] [--obj out.obj]
|
||||
#include <hmap/hmap.h>
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <map>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc < 2) {
|
||||
std::puts("usage: hmap_info <file.hmap> [--fbx out.fbx] [--obj out.obj]");
|
||||
return 2;
|
||||
}
|
||||
hmap::CompiledMap cm;
|
||||
hmap::Status s = hmap::loadCompiled(argv[1], cm);
|
||||
if (!s) {
|
||||
std::fprintf(stderr, "error: %s\n", s.message.c_str());
|
||||
return 1;
|
||||
}
|
||||
std::printf("%s\n materials: %zu\n batches: %zu (%u triangles, %u vertices)%s\n", argv[1], cm.materials.size(), cm.batches.size(),
|
||||
cm.stats.triangles, cm.stats.vertices, cm.baked ? ", baked vertex lighting" : "");
|
||||
std::printf(" models: %zu (1 world + %zu brush entities)\n", cm.models.size(), cm.models.size() - 1);
|
||||
std::printf(" BSP: %zu nodes, %zu leaves, %zu brushes\n", cm.bsp.nodes.size(), cm.bsp.leaves.size(), cm.bsp.brushes.size());
|
||||
std::printf(" lights: %zu\n bounds: (%.0f %.0f %.0f) - (%.0f %.0f %.0f)\n", cm.lights.size(), cm.bounds.mn.x, cm.bounds.mn.y,
|
||||
cm.bounds.mn.z, cm.bounds.mx.x, cm.bounds.mx.y, cm.bounds.mx.z);
|
||||
std::map<std::string, int> classes;
|
||||
for (const hmap::Entity& e : cm.entities) classes[e.classname]++;
|
||||
std::printf(" entities: %zu\n", cm.entities.size());
|
||||
for (auto& kv : classes) std::printf(" %-22s x%d\n", kv.first.c_str(), kv.second);
|
||||
for (int i = 2; i + 1 < argc; ++i) {
|
||||
if (!std::strcmp(argv[i], "--fbx")) std::printf("FBX: %s\n", hmap::exportFBX(argv[i + 1], cm) ? "written" : "failed");
|
||||
if (!std::strcmp(argv[i], "--obj")) std::printf("OBJ: %s\n", hmap::exportOBJ(argv[i + 1], cm) ? "written" : "failed");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// hmap_sample: writes a demo map in every format Hammer++ supports.
|
||||
// hmap_sample [outdir] -> demo.hmap (editable source), demo_runtime.hmap (compiled + baked), demo.fbx, demo.obj
|
||||
#include <hmap/hmap.h>
|
||||
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
std::string dir = argc > 1 ? argv[1] : ".";
|
||||
hmap::Map map = hmap::makeDemoMap();
|
||||
|
||||
hmap::CompileOptions opt;
|
||||
opt.bakeLighting = true;
|
||||
opt.lightEdge = 64; // coarse light grid keeps the sample files small
|
||||
hmap::CompiledMap cm = hmap::compile(map, opt);
|
||||
std::printf("compiled in %.1f ms: %u brushes, %u meshes, %u tris, BSP %u nodes / %u leaves (depth %u), %u lights\n", cm.stats.ms,
|
||||
cm.stats.brushes, cm.stats.meshes, cm.stats.triangles, cm.stats.bspNodes, cm.stats.bspLeaves, cm.stats.bspDepth,
|
||||
cm.stats.lights);
|
||||
|
||||
auto report = [](const char* what, const hmap::Status& s) {
|
||||
std::printf("%-22s %s\n", what, s ? "ok" : s.message.c_str());
|
||||
return s.ok;
|
||||
};
|
||||
bool ok = true;
|
||||
ok &= report("demo.hmap", hmap::saveMap(dir + "/demo.hmap", map));
|
||||
ok &= report("demo_runtime.hmap", hmap::saveCompiled(dir + "/demo_runtime.hmap", cm));
|
||||
ok &= report("demo.fbx", hmap::exportFBX(dir + "/demo.fbx", cm));
|
||||
ok &= report("demo.obj", hmap::exportOBJ(dir + "/demo.obj", cm));
|
||||
return ok ? 0 : 1;
|
||||
}
|
||||
Reference in new issue
Block a user