diff --git a/src/ObjCommon/PhysCollmap/PhysCollmapCommon.cpp b/src/ObjCommon/PhysCollmap/PhysCollmapCommon.cpp new file mode 100644 index 00000000..7414207e --- /dev/null +++ b/src/ObjCommon/PhysCollmap/PhysCollmapCommon.cpp @@ -0,0 +1,11 @@ +#include "PhysCollmapCommon.h" + +#include + +namespace phys_collmap +{ + std::string GetFileNameForAssetName(const std::string& assetName) + { + return std::format("phys_collmaps/{}.map", assetName); + } +} // namespace phys_collmap diff --git a/src/ObjCommon/PhysCollmap/PhysCollmapCommon.h b/src/ObjCommon/PhysCollmap/PhysCollmapCommon.h new file mode 100644 index 00000000..eaf0877e --- /dev/null +++ b/src/ObjCommon/PhysCollmap/PhysCollmapCommon.h @@ -0,0 +1,8 @@ +#pragma once + +#include + +namespace phys_collmap +{ + std::string GetFileNameForAssetName(const std::string& assetName); +} diff --git a/src/ObjWriting/Game/IW4/ObjWriterIW4.cpp b/src/ObjWriting/Game/IW4/ObjWriterIW4.cpp index 727ab8d8..a7874a66 100644 --- a/src/ObjWriting/Game/IW4/ObjWriterIW4.cpp +++ b/src/ObjWriting/Game/IW4/ObjWriterIW4.cpp @@ -12,7 +12,7 @@ #include "Menu/MenuDumperIW4.h" #include "Menu/MenuListDumperIW4.h" #include "ObjWriting.h" -#include "PhysCollmap/AssetDumperPhysCollmap.h" +#include "PhysCollmap/PhysCollmapDumperIW4.h" #include "PhysPreset/PhysPresetInfoStringDumperIW4.h" #include "RawFile/RawFileDumperIW4.h" #include "Shader/AssetDumperPixelShader.h" @@ -40,7 +40,7 @@ bool ObjWriter::DumpZone(AssetDumpingContext& context) const const auto* assetPools = dynamic_cast(context.m_zone.m_pools.get()); DUMP_ASSET_POOL(phys_preset::InfoStringDumper, m_phys_preset, ASSET_TYPE_PHYSPRESET) - DUMP_ASSET_POOL(AssetDumperPhysCollmap, m_phys_collmap, ASSET_TYPE_PHYSCOLLMAP) + DUMP_ASSET_POOL(phys_collmap::Dumper, m_phys_collmap, ASSET_TYPE_PHYSCOLLMAP) // DUMP_ASSET_POOL(AssetDumperXAnimParts, m_xanim_parts, ASSET_TYPE_XANIMPARTS) DUMP_ASSET_POOL(xmodel::Dumper, m_xmodel, ASSET_TYPE_XMODEL) DUMP_ASSET_POOL(material::JsonDumper, m_material, ASSET_TYPE_MATERIAL) diff --git a/src/ObjWriting/Game/IW4/PhysCollmap/AssetDumperPhysCollmap.cpp b/src/ObjWriting/Game/IW4/PhysCollmap/AssetDumperPhysCollmap.cpp deleted file mode 100644 index 7055e8aa..00000000 --- a/src/ObjWriting/Game/IW4/PhysCollmap/AssetDumperPhysCollmap.cpp +++ /dev/null @@ -1,87 +0,0 @@ -#include "AssetDumperPhysCollmap.h" - -#include "Dumping/MapFile/MapFileDumper.h" - -#include -#include - -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* asset) -{ - return true; -} - -void AssetDumperPhysCollmap::DumpAsset(AssetDumpingContext& context, XAssetInfo* 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(); -} diff --git a/src/ObjWriting/Game/IW4/PhysCollmap/PhysCollmapDumperIW4.cpp b/src/ObjWriting/Game/IW4/PhysCollmap/PhysCollmapDumperIW4.cpp new file mode 100644 index 00000000..046a9c5e --- /dev/null +++ b/src/ObjWriting/Game/IW4/PhysCollmap/PhysCollmapDumperIW4.cpp @@ -0,0 +1,83 @@ +#include "PhysCollmapDumperIW4.h" + +#include "Dumping/MapFile/MapFileDumper.h" +#include "PhysCollmap/PhysCollmapCommon.h" + +#include +#include + +using namespace IW4; +using namespace ::phys_collmap; + +namespace IW4::phys_collmap +{ + bool Dumper::ShouldDump(XAssetInfo* asset) + { + return true; + } + + void Dumper::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) + { + const auto* physCollmap = asset->Asset(); + const auto assetFile = context.OpenAssetFile(GetFileNameForAssetName(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(); + } +} // namespace IW4::phys_collmap diff --git a/src/ObjWriting/Game/IW4/PhysCollmap/AssetDumperPhysCollmap.h b/src/ObjWriting/Game/IW4/PhysCollmap/PhysCollmapDumperIW4.h similarity index 59% rename from src/ObjWriting/Game/IW4/PhysCollmap/AssetDumperPhysCollmap.h rename to src/ObjWriting/Game/IW4/PhysCollmap/PhysCollmapDumperIW4.h index 213f1ce1..2407233e 100644 --- a/src/ObjWriting/Game/IW4/PhysCollmap/AssetDumperPhysCollmap.h +++ b/src/ObjWriting/Game/IW4/PhysCollmap/PhysCollmapDumperIW4.h @@ -3,14 +3,12 @@ #include "Dumping/AbstractAssetDumper.h" #include "Game/IW4/IW4.h" -namespace IW4 +namespace IW4::phys_collmap { - class AssetDumperPhysCollmap final : public AbstractAssetDumper + class Dumper final : public AbstractAssetDumper { - static std::string GetAssetFilename(const std::string& assetName); - protected: bool ShouldDump(XAssetInfo* asset) override; void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; }; -} // namespace IW4 +} // namespace IW4::phys_collmap