2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2026-01-11 19:21:50 +00:00

refactor: move iw3,iw4,iw5,t5 dumpers into seperate folders

This commit is contained in:
Jan Laupetin
2025-07-25 21:23:49 +01:00
parent 64bd89dc46
commit 39fe9965d1
143 changed files with 70 additions and 69 deletions

View File

@@ -0,0 +1,87 @@
#include "AssetDumperPhysCollmap.h"
#include "Dumping/MapFile/MapFileDumper.h"
#include <cassert>
#include <sstream>
using namespace IW4;
std::string AssetDumperPhysCollmap::GetAssetFilename(const std::string& assetName)
{
std::ostringstream ss;
ss << "phys_collmaps/" << assetName << ".map";
return ss.str();
}
bool AssetDumperPhysCollmap::ShouldDump(XAssetInfo<PhysCollmap>* asset)
{
return true;
}
void AssetDumperPhysCollmap::DumpAsset(AssetDumpingContext& context, XAssetInfo<PhysCollmap>* asset)
{
const auto* physCollmap = asset->Asset();
const auto assetFile = context.OpenAssetFile(GetAssetFilename(asset->m_name));
if (!assetFile)
return;
MapFileDumper mapFileDumper(*assetFile);
mapFileDumper.Init();
if (physCollmap->count <= 0 || physCollmap->geoms == nullptr)
return;
mapFileDumper.BeginEntity();
mapFileDumper.WriteKeyValue("classname", "worldspawn");
for (auto i = 0u; i < physCollmap->count; i++)
{
const auto& geom = physCollmap->geoms[i];
mapFileDumper.BeginBrush();
switch (geom.type)
{
case PHYS_GEOM_NONE:
// TODO: Dump BrushWrapper (probably GJK related)
mapFileDumper.WriteComment("TODO: Brush data");
break;
case PHYS_GEOM_BOX:
mapFileDumper.WritePhysicsBox({
{geom.bounds.midPoint.v[0], geom.bounds.midPoint.v[1], geom.bounds.midPoint.v[2]},
{geom.bounds.halfSize.v[0], geom.bounds.halfSize.v[1], geom.bounds.halfSize.v[2]},
{geom.orientation[0][0], geom.orientation[0][1], geom.orientation[0][2] },
{geom.orientation[1][0], geom.orientation[1][1], geom.orientation[1][2] },
{geom.orientation[2][0], geom.orientation[2][1], geom.orientation[2][2] }
});
break;
case PHYS_GEOM_CYLINDER:
mapFileDumper.WritePhysicsCylinder({
{geom.bounds.midPoint.v[0], geom.bounds.midPoint.v[1], geom.bounds.midPoint.v[2]},
geom.bounds.halfSize.v[0],
geom.bounds.halfSize.v[2] * 2,
{geom.orientation[0][0], geom.orientation[0][1], geom.orientation[0][2] }
});
break;
case PHYS_GEOM_BRUSHMODEL:
case PHYS_GEOM_BRUSH:
case PHYS_GEOM_COLLMAP:
case PHYS_GEOM_CAPSULE:
case PHYS_GEOM_GLASS:
default:
// These do not seem to appear inside any collmap assets
assert(false);
break;
}
mapFileDumper.EndBrush();
}
mapFileDumper.EndEntity();
}

View File

@@ -0,0 +1,16 @@
#pragma once
#include "Dumping/AbstractAssetDumper.h"
#include "Game/IW4/IW4.h"
namespace IW4
{
class AssetDumperPhysCollmap final : public AbstractAssetDumper<PhysCollmap>
{
static std::string GetAssetFilename(const std::string& assetName);
protected:
bool ShouldDump(XAssetInfo<PhysCollmap>* asset) override;
void DumpAsset(AssetDumpingContext& context, XAssetInfo<PhysCollmap>* asset) override;
};
} // namespace IW4