mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-09-01 06:27:26 +00:00
refactor: streamline physcollmap dumping
This commit is contained in:
11
src/ObjCommon/PhysCollmap/PhysCollmapCommon.cpp
Normal file
11
src/ObjCommon/PhysCollmap/PhysCollmapCommon.cpp
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#include "PhysCollmapCommon.h"
|
||||||
|
|
||||||
|
#include <format>
|
||||||
|
|
||||||
|
namespace phys_collmap
|
||||||
|
{
|
||||||
|
std::string GetFileNameForAssetName(const std::string& assetName)
|
||||||
|
{
|
||||||
|
return std::format("phys_collmaps/{}.map", assetName);
|
||||||
|
}
|
||||||
|
} // namespace phys_collmap
|
8
src/ObjCommon/PhysCollmap/PhysCollmapCommon.h
Normal file
8
src/ObjCommon/PhysCollmap/PhysCollmapCommon.h
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace phys_collmap
|
||||||
|
{
|
||||||
|
std::string GetFileNameForAssetName(const std::string& assetName);
|
||||||
|
}
|
@@ -12,7 +12,7 @@
|
|||||||
#include "Menu/MenuDumperIW4.h"
|
#include "Menu/MenuDumperIW4.h"
|
||||||
#include "Menu/MenuListDumperIW4.h"
|
#include "Menu/MenuListDumperIW4.h"
|
||||||
#include "ObjWriting.h"
|
#include "ObjWriting.h"
|
||||||
#include "PhysCollmap/AssetDumperPhysCollmap.h"
|
#include "PhysCollmap/PhysCollmapDumperIW4.h"
|
||||||
#include "PhysPreset/PhysPresetInfoStringDumperIW4.h"
|
#include "PhysPreset/PhysPresetInfoStringDumperIW4.h"
|
||||||
#include "RawFile/RawFileDumperIW4.h"
|
#include "RawFile/RawFileDumperIW4.h"
|
||||||
#include "Shader/AssetDumperPixelShader.h"
|
#include "Shader/AssetDumperPixelShader.h"
|
||||||
@@ -40,7 +40,7 @@ bool ObjWriter::DumpZone(AssetDumpingContext& context) const
|
|||||||
const auto* assetPools = dynamic_cast<GameAssetPoolIW4*>(context.m_zone.m_pools.get());
|
const auto* assetPools = dynamic_cast<GameAssetPoolIW4*>(context.m_zone.m_pools.get());
|
||||||
|
|
||||||
DUMP_ASSET_POOL(phys_preset::InfoStringDumper, m_phys_preset, ASSET_TYPE_PHYSPRESET)
|
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(AssetDumperXAnimParts, m_xanim_parts, ASSET_TYPE_XANIMPARTS)
|
||||||
DUMP_ASSET_POOL(xmodel::Dumper, m_xmodel, ASSET_TYPE_XMODEL)
|
DUMP_ASSET_POOL(xmodel::Dumper, m_xmodel, ASSET_TYPE_XMODEL)
|
||||||
DUMP_ASSET_POOL(material::JsonDumper, m_material, ASSET_TYPE_MATERIAL)
|
DUMP_ASSET_POOL(material::JsonDumper, m_material, ASSET_TYPE_MATERIAL)
|
||||||
|
@@ -1,87 +0,0 @@
|
|||||||
#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();
|
|
||||||
}
|
|
83
src/ObjWriting/Game/IW4/PhysCollmap/PhysCollmapDumperIW4.cpp
Normal file
83
src/ObjWriting/Game/IW4/PhysCollmap/PhysCollmapDumperIW4.cpp
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
#include "PhysCollmapDumperIW4.h"
|
||||||
|
|
||||||
|
#include "Dumping/MapFile/MapFileDumper.h"
|
||||||
|
#include "PhysCollmap/PhysCollmapCommon.h"
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
using namespace IW4;
|
||||||
|
using namespace ::phys_collmap;
|
||||||
|
|
||||||
|
namespace IW4::phys_collmap
|
||||||
|
{
|
||||||
|
bool Dumper::ShouldDump(XAssetInfo<PhysCollmap>* asset)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Dumper::DumpAsset(AssetDumpingContext& context, XAssetInfo<PhysCollmap>* 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
|
@@ -3,14 +3,12 @@
|
|||||||
#include "Dumping/AbstractAssetDumper.h"
|
#include "Dumping/AbstractAssetDumper.h"
|
||||||
#include "Game/IW4/IW4.h"
|
#include "Game/IW4/IW4.h"
|
||||||
|
|
||||||
namespace IW4
|
namespace IW4::phys_collmap
|
||||||
{
|
{
|
||||||
class AssetDumperPhysCollmap final : public AbstractAssetDumper<PhysCollmap>
|
class Dumper final : public AbstractAssetDumper<PhysCollmap>
|
||||||
{
|
{
|
||||||
static std::string GetAssetFilename(const std::string& assetName);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool ShouldDump(XAssetInfo<PhysCollmap>* asset) override;
|
bool ShouldDump(XAssetInfo<PhysCollmap>* asset) override;
|
||||||
void DumpAsset(AssetDumpingContext& context, XAssetInfo<PhysCollmap>* asset) override;
|
void DumpAsset(AssetDumpingContext& context, XAssetInfo<PhysCollmap>* asset) override;
|
||||||
};
|
};
|
||||||
} // namespace IW4
|
} // namespace IW4::phys_collmap
|
Reference in New Issue
Block a user