mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-03-18 02:43:03 +00:00
feat: add embedded image loader for every supported game
This commit is contained in:
@@ -1,133 +0,0 @@
|
||||
#include "AssetLoaderImageIW3.h"
|
||||
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "Image/DdsLoader.h"
|
||||
#include "Image/IwiTypes.h"
|
||||
#include "Pool/GlobalAssetPool.h"
|
||||
#include "Utils/Logging/Log.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
|
||||
using namespace IW3;
|
||||
using namespace image;
|
||||
|
||||
namespace
|
||||
{
|
||||
class ImageLoader final : public AssetCreator<AssetImage>
|
||||
{
|
||||
public:
|
||||
ImageLoader(MemoryManager& memory, ISearchPath& searchPath)
|
||||
: m_memory(memory),
|
||||
m_search_path(searchPath)
|
||||
{
|
||||
}
|
||||
|
||||
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
|
||||
{
|
||||
// Do not load any GfxImages from raw for now that are not loaded
|
||||
// TODO: Load iwis and add streaming info to asset
|
||||
if (assetName.empty() || assetName[0] != '*')
|
||||
return AssetCreationResult::NoAction();
|
||||
|
||||
std::string safeAssetName = assetName;
|
||||
std::ranges::replace(safeAssetName, '*', '_');
|
||||
|
||||
const auto file = m_search_path.Open(std::format("images/{}.dds", safeAssetName));
|
||||
if (!file.IsOpen())
|
||||
return AssetCreationResult::NoAction();
|
||||
|
||||
const auto texture = image::LoadDds(*file.m_stream);
|
||||
if (!texture)
|
||||
{
|
||||
con::error("Failed to load dds file for image asset \"{}\"", assetName);
|
||||
return AssetCreationResult::Failure();
|
||||
}
|
||||
|
||||
auto* image = m_memory.Alloc<GfxImage>();
|
||||
image->name = m_memory.Dup(assetName.c_str());
|
||||
image->picmip.platform[0] = 0;
|
||||
image->picmip.platform[1] = 0;
|
||||
image->noPicmip = !texture->HasMipMaps();
|
||||
image->semantic = TS_FUNCTION;
|
||||
image->track = 0;
|
||||
image->cardMemory.platform[0] = 0;
|
||||
image->cardMemory.platform[1] = 0;
|
||||
image->width = static_cast<uint16_t>(texture->GetWidth());
|
||||
image->height = static_cast<uint16_t>(texture->GetHeight());
|
||||
image->depth = static_cast<uint16_t>(texture->GetDepth());
|
||||
image->category = IMG_CATEGORY_AUTO_GENERATED;
|
||||
image->delayLoadPixels = false;
|
||||
|
||||
switch (texture->GetTextureType())
|
||||
{
|
||||
case TextureType::T_2D:
|
||||
image->mapType = MAPTYPE_2D;
|
||||
break;
|
||||
|
||||
case TextureType::T_3D:
|
||||
image->mapType = MAPTYPE_3D;
|
||||
break;
|
||||
|
||||
case TextureType::T_CUBE:
|
||||
image->mapType = MAPTYPE_CUBE;
|
||||
break;
|
||||
|
||||
default:
|
||||
image->mapType = MAPTYPE_NONE;
|
||||
break;
|
||||
}
|
||||
|
||||
const auto mipCount = texture->HasMipMaps() ? texture->GetMipMapCount() : 1;
|
||||
const auto faceCount = texture->GetFaceCount();
|
||||
|
||||
auto dataSize = 0uz;
|
||||
for (auto mipLevel = 0; mipLevel < mipCount; mipLevel++)
|
||||
dataSize += texture->GetSizeOfMipLevel(mipLevel) * faceCount;
|
||||
|
||||
auto* loadDef = static_cast<GfxImageLoadDef*>(m_memory.AllocRaw(offsetof(GfxImageLoadDef, data) + dataSize));
|
||||
image->texture.loadDef = loadDef;
|
||||
loadDef->levelCount = static_cast<char>(mipCount);
|
||||
loadDef->flags = 0;
|
||||
if (!texture->HasMipMaps())
|
||||
loadDef->flags |= image::iwi6::IMG_FLAG_NOMIPMAPS;
|
||||
if (texture->GetTextureType() == TextureType::T_CUBE)
|
||||
loadDef->flags |= image::iwi6::IMG_FLAG_CUBEMAP;
|
||||
if (texture->GetTextureType() == TextureType::T_3D)
|
||||
loadDef->flags |= image::iwi6::IMG_FLAG_VOLMAP;
|
||||
loadDef->dimensions[0] = image->width;
|
||||
loadDef->dimensions[1] = image->height;
|
||||
loadDef->dimensions[2] = image->depth;
|
||||
loadDef->format = static_cast<int>(texture->GetFormat()->GetD3DFormat());
|
||||
loadDef->resourceSize = static_cast<unsigned>(dataSize);
|
||||
|
||||
char* currentDataBuffer = loadDef->data;
|
||||
for (auto mipLevel = 0; mipLevel < mipCount; mipLevel++)
|
||||
{
|
||||
const auto mipSize = texture->GetSizeOfMipLevel(mipLevel);
|
||||
|
||||
for (auto face = 0; face < faceCount; face++)
|
||||
{
|
||||
memcpy(currentDataBuffer, texture->GetBufferForMipLevel(mipLevel, face), mipSize);
|
||||
currentDataBuffer += mipSize;
|
||||
}
|
||||
}
|
||||
|
||||
return AssetCreationResult::Success(context.AddAsset<AssetImage>(assetName, image));
|
||||
}
|
||||
|
||||
private:
|
||||
MemoryManager& m_memory;
|
||||
ISearchPath& m_search_path;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace image
|
||||
{
|
||||
std::unique_ptr<AssetCreator<AssetImage>> CreateLoaderIW3(MemoryManager& memory, ISearchPath& searchPath)
|
||||
{
|
||||
return std::make_unique<ImageLoader>(memory, searchPath);
|
||||
}
|
||||
} // namespace image
|
||||
@@ -1,13 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Asset/IAssetCreator.h"
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
#include "Utils/MemoryManager.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace image
|
||||
{
|
||||
std::unique_ptr<AssetCreator<IW3::AssetImage>> CreateLoaderIW3(MemoryManager& memory, ISearchPath& searchPath);
|
||||
} // namespace image
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "Game/IW3/AssetMarkerIW3.h"
|
||||
#include "Game/IW3/GameIW3.h"
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "Game/IW3/Image/ImageLoaderEmbeddedIW3.h"
|
||||
#include "Game/IW3/Image/ImageLoaderExternalIW3.h"
|
||||
#include "Game/IW3/XModel/LoaderXModelIW3.h"
|
||||
#include "Localize/AssetLoaderLocalizeIW3.h"
|
||||
@@ -95,6 +96,7 @@ namespace
|
||||
collection.AddAssetCreator(xmodel::CreateLoaderIW3(memory, searchPath, zone));
|
||||
collection.AddAssetCreator(material::CreateLoaderIW3(memory, searchPath));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderTechniqueSet>(memory));
|
||||
collection.AddAssetCreator(image::CreateLoaderEmbeddedIW3(memory, searchPath));
|
||||
collection.AddAssetCreator(image::CreateLoaderExternalIW3(memory, searchPath));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderSound>(memory));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderSoundCurve>(memory));
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "Game/IW4/AssetMarkerIW4.h"
|
||||
#include "Game/IW4/GameIW4.h"
|
||||
#include "Game/IW4/IW4.h"
|
||||
#include "Game/IW4/Image/ImageLoaderEmbeddedIW4.h"
|
||||
#include "Game/IW4/Image/ImageLoaderExternalIW4.h"
|
||||
#include "Game/IW4/XModel/LoaderXModelIW4.h"
|
||||
#include "Leaderboard/LoaderLeaderboardIW4.h"
|
||||
@@ -131,6 +132,7 @@ namespace
|
||||
collection.AddAssetCreator(shader::CreatePixelShaderLoaderIW4(memory, searchPath));
|
||||
collection.AddAssetCreator(shader::CreateVertexShaderLoaderIW4(memory, searchPath));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderTechset>(memory));
|
||||
collection.AddAssetCreator(image::CreateLoaderEmbeddedIW4(memory, searchPath));
|
||||
collection.AddAssetCreator(image::CreateLoaderExternalIW4(memory, searchPath));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderSound>(memory));
|
||||
collection.AddAssetCreator(sound_curve::CreateLoaderIW4(memory, searchPath));
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "Game/IW5/AssetMarkerIW5.h"
|
||||
#include "Game/IW5/GameIW5.h"
|
||||
#include "Game/IW5/IW5.h"
|
||||
#include "Game/IW5/Image/ImageLoaderEmbeddedIW5.h"
|
||||
#include "Game/IW5/Image/ImageLoaderExternalIW5.h"
|
||||
#include "Game/IW5/XModel/LoaderXModelIW5.h"
|
||||
#include "Leaderboard/LoaderLeaderboardIW5.h"
|
||||
@@ -132,6 +133,7 @@ namespace
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderVertexShader>(memory));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderVertexDecl>(memory));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderTechniqueSet>(memory));
|
||||
collection.AddAssetCreator(image::CreateLoaderEmbeddedIW5(memory, searchPath));
|
||||
collection.AddAssetCreator(image::CreateLoaderExternalIW5(memory, searchPath));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderSound>(memory));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderSoundCurve>(memory));
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "Asset/GlobalAssetPoolsLoader.h"
|
||||
#include "Game/T5/AssetMarkerT5.h"
|
||||
#include "Game/T5/GameT5.h"
|
||||
#include "Game/T5/Image/ImageLoaderEmbeddedT5.h"
|
||||
#include "Game/T5/Image/ImageLoaderExternalT5.h"
|
||||
#include "Game/T5/T5.h"
|
||||
#include "Game/T5/XModel/LoaderXModelT5.h"
|
||||
@@ -109,6 +110,7 @@ namespace
|
||||
collection.AddAssetCreator(xmodel::CreateLoaderT5(memory, searchPath, zone));
|
||||
collection.AddAssetCreator(material::CreateLoaderT5(memory, searchPath));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderTechniqueSet>(memory));
|
||||
collection.AddAssetCreator(image::CreateLoaderEmbeddedT5(memory, searchPath));
|
||||
collection.AddAssetCreator(image::CreateLoaderExternalT5(memory, searchPath));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderSoundBank>(memory));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderSoundPatch>(memory));
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "Game/T6/CommonT6.h"
|
||||
#include "Game/T6/GameAssetPoolT6.h"
|
||||
#include "Game/T6/GameT6.h"
|
||||
#include "Game/T6/Image/ImageLoaderEmbeddedT6.h"
|
||||
#include "Game/T6/Image/ImageLoaderExternalT6.h"
|
||||
#include "Game/T6/T6.h"
|
||||
#include "Game/T6/XModel/LoaderXModelT6.h"
|
||||
@@ -394,6 +395,7 @@ namespace T6
|
||||
collection.AddAssetCreator(xmodel::CreateLoaderT6(memory, searchPath, zone));
|
||||
collection.AddAssetCreator(material::CreateLoaderT6(memory, searchPath));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderTechniqueSet>(memory));
|
||||
collection.AddAssetCreator(image::CreateLoaderEmbeddedT6(memory, searchPath));
|
||||
collection.AddAssetCreator(image::CreateLoaderExternalT6(memory, searchPath));
|
||||
collection.AddAssetCreator(sound::CreateSoundBankLoaderT6(memory, searchPath));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderSoundPatch>(memory));
|
||||
|
||||
Reference in New Issue
Block a user