mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-11-23 05:12:05 +00:00
WIP fix, loading is currently not working correctly
This commit is contained in:
@@ -1,3 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#define DYN_ENT_COUNT 0
|
#define DYN_ENT_COUNT 0
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -10,7 +10,7 @@ using namespace T6;
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
class CustomMapLoader final : public AssetCreator<AssetCustomMap>
|
class CustomMapLoader final : public AssetCreator<AssetGfxWorld>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CustomMapLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
|
CustomMapLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
|
||||||
@@ -32,7 +32,7 @@ namespace
|
|||||||
return AssetCreationResult::Failure();
|
return AssetCreationResult::Failure();
|
||||||
|
|
||||||
// linker will add all the assets needed
|
// linker will add all the assets needed
|
||||||
CustomMapLinker* linker = new CustomMapLinker(m_memory, m_search_path, m_zone);
|
CustomMapLinker* linker = new CustomMapLinker(m_memory, m_search_path, m_zone, context);
|
||||||
bool result = linker->linkCustomMap(mapInfo);
|
bool result = linker->linkCustomMap(mapInfo);
|
||||||
|
|
||||||
if (result)
|
if (result)
|
||||||
@@ -50,7 +50,7 @@ namespace
|
|||||||
|
|
||||||
namespace T6
|
namespace T6
|
||||||
{
|
{
|
||||||
std::unique_ptr<AssetCreator<AssetCustomMap>> CreateCustomMapLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
|
std::unique_ptr<AssetCreator<AssetGfxWorld>> CreateCustomMapLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
|
||||||
{
|
{
|
||||||
return std::make_unique<CustomMapLoader>(memory, searchPath, zone);
|
return std::make_unique<CustomMapLoader>(memory, searchPath, zone);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,5 +9,5 @@
|
|||||||
|
|
||||||
namespace T6
|
namespace T6
|
||||||
{
|
{
|
||||||
std::unique_ptr<AssetCreator<AssetCustomMap>> CreateCustomMapLoader(MemoryManager& memory, ISearchPath& searchPath);
|
std::unique_ptr<AssetCreator<AssetGfxWorld>> CreateCustomMapLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
|
||||||
} // namespace T6
|
} // namespace T6
|
||||||
|
|||||||
@@ -1,105 +1,105 @@
|
|||||||
#include "ProjectCreator.h"
|
#include "ProjectCreator.h"
|
||||||
|
|
||||||
class CustomMapLoader
|
#include "OBJ_Loader.h"
|
||||||
|
|
||||||
|
void parseMesh(objl::Mesh* OBJMesh, worldSurface* meshSurface, customMapInfo* projInfo)
|
||||||
{
|
{
|
||||||
void parseMesh(objl::Mesh* OBJMesh, worldSurface* meshSurface, customMapInfo* projInfo)
|
int meshVertexCount = OBJMesh->Vertices.size();
|
||||||
|
int meshIndexCount = OBJMesh->Indices.size();
|
||||||
|
int surfVertexStart = projInfo->gfxInfo.vertexCount;
|
||||||
|
int surfIndexStart = projInfo->gfxInfo.indexCount;
|
||||||
|
|
||||||
|
projInfo->gfxInfo.vertexCount += meshVertexCount;
|
||||||
|
projInfo->gfxInfo.indexCount += meshIndexCount;
|
||||||
|
|
||||||
|
projInfo->gfxInfo.vertices = (customMapVertex*)realloc(projInfo->gfxInfo.vertices, sizeof(customMapVertex) * projInfo->gfxInfo.vertexCount);
|
||||||
|
projInfo->gfxInfo.indices = (uint16_t*)realloc(projInfo->gfxInfo.indices, sizeof(uint16_t) * projInfo->gfxInfo.indexCount);
|
||||||
|
|
||||||
|
customMapVertex* surfVertices = &projInfo->gfxInfo.vertices[surfVertexStart];
|
||||||
|
uint16_t* surfIndices = &projInfo->gfxInfo.indices[surfIndexStart];
|
||||||
|
|
||||||
|
meshSurface->firstIndex_Index = surfIndexStart;
|
||||||
|
meshSurface->firstVertexIndex = surfVertexStart;
|
||||||
|
meshSurface->triCount = meshIndexCount / 3;
|
||||||
|
_ASSERT(meshIndexCount % 3 == 0);
|
||||||
|
|
||||||
|
for (int i = 0; i < meshIndexCount; i++)
|
||||||
{
|
{
|
||||||
int meshVertexCount = OBJMesh->Vertices.size();
|
_ASSERT(OBJMesh->Indices[i] < UINT16_MAX);
|
||||||
int meshIndexCount = OBJMesh->Indices.size();
|
surfIndices[i] = OBJMesh->Indices[i];
|
||||||
int surfVertexStart = projInfo->gfxInfo.vertexCount;
|
|
||||||
int surfIndexStart = projInfo->gfxInfo.indexCount;
|
|
||||||
|
|
||||||
projInfo->gfxInfo.vertexCount += meshVertexCount;
|
|
||||||
projInfo->gfxInfo.indexCount += meshIndexCount;
|
|
||||||
|
|
||||||
projInfo->gfxInfo.vertices = (customMapVertex*)realloc(projInfo->gfxInfo.vertices, sizeof(customMapVertex) * projInfo->gfxInfo.vertexCount);
|
|
||||||
projInfo->gfxInfo.indices = (uint16_t*)realloc(projInfo->gfxInfo.indices, sizeof(uint16_t) * projInfo->gfxInfo.indexCount);
|
|
||||||
|
|
||||||
customMapVertex* surfVertices = &projInfo->gfxInfo.vertices[surfVertexStart];
|
|
||||||
uint16_t* surfIndices = &projInfo->gfxInfo.indices[surfIndexStart];
|
|
||||||
|
|
||||||
meshSurface->firstIndex_Index = surfIndexStart;
|
|
||||||
meshSurface->firstVertexIndex = surfVertexStart;
|
|
||||||
meshSurface->triCount = meshIndexCount / 3;
|
|
||||||
_ASSERT(meshIndexCount % 3 == 0);
|
|
||||||
|
|
||||||
for (int i = 0; i < meshIndexCount; i++)
|
|
||||||
{
|
|
||||||
_ASSERT(OBJMesh->Indices[i] < UINT16_MAX);
|
|
||||||
surfIndices[i] = OBJMesh->Indices[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < meshVertexCount; i++)
|
|
||||||
{
|
|
||||||
objl::Vertex* meshVertex = &OBJMesh->Vertices[i];
|
|
||||||
customMapVertex* surfVertex = &surfVertices[i];
|
|
||||||
|
|
||||||
surfVertex->pos.x = meshVertex->Position.X;
|
|
||||||
surfVertex->pos.y = meshVertex->Position.Y;
|
|
||||||
surfVertex->pos.z = meshVertex->Position.Z;
|
|
||||||
|
|
||||||
surfVertex->color[0] = OBJMesh->MeshMaterial.Kd.X;
|
|
||||||
surfVertex->color[1] = OBJMesh->MeshMaterial.Kd.Y;
|
|
||||||
surfVertex->color[2] = OBJMesh->MeshMaterial.Kd.Z;
|
|
||||||
surfVertex->color[3] = 1.0f;
|
|
||||||
|
|
||||||
surfVertex->texCoord[0] = meshVertex->TextureCoordinate.X;
|
|
||||||
surfVertex->texCoord[1] = meshVertex->TextureCoordinate.Y;
|
|
||||||
|
|
||||||
surfVertex->normal.x = meshVertex->Normal.X;
|
|
||||||
surfVertex->normal.y = meshVertex->Normal.Y;
|
|
||||||
surfVertex->normal.z = meshVertex->Normal.Z;
|
|
||||||
|
|
||||||
// TODO: fix tangents, seems to work for now though
|
|
||||||
surfVertex->tangent.x = 1.0f;
|
|
||||||
surfVertex->tangent.y = 0.0f;
|
|
||||||
surfVertex->tangent.z = 0.0f;
|
|
||||||
|
|
||||||
surfVertex->packedLmapCoord = 0;
|
|
||||||
|
|
||||||
surfVertex->binormalSign = 0.0f;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
customMapInfo* createCustomMapInfo(std::string& projectName, ISearchPath& searchPath)
|
for (int i = 0; i < meshVertexCount; i++)
|
||||||
{
|
{
|
||||||
std::string objFilePath = searchPath.GetPath() + "custom_map/world.obj";
|
objl::Vertex* meshVertex = &OBJMesh->Vertices[i];
|
||||||
|
customMapVertex* surfVertex = &surfVertices[i];
|
||||||
|
|
||||||
objl::Loader OBJloader;
|
surfVertex->pos.x = meshVertex->Position.X;
|
||||||
bool isLoaded = OBJloader.LoadFile(objFilePath);
|
surfVertex->pos.y = meshVertex->Position.Y;
|
||||||
if (!isLoaded)
|
surfVertex->pos.z = meshVertex->Position.Z;
|
||||||
{
|
|
||||||
printf("OBJLoader: unable to load obj file %s\n", objFilePath.c_str());
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
customMapInfo* projInfo = new customMapInfo;
|
surfVertex->color[0] = OBJMesh->MeshMaterial.Kd.X;
|
||||||
|
surfVertex->color[1] = OBJMesh->MeshMaterial.Kd.Y;
|
||||||
|
surfVertex->color[2] = OBJMesh->MeshMaterial.Kd.Z;
|
||||||
|
surfVertex->color[3] = 1.0f;
|
||||||
|
|
||||||
projInfo->name = projectName;
|
surfVertex->texCoord[0] = meshVertex->TextureCoordinate.X;
|
||||||
projInfo->bspName = "maps/mp/" + projectName + ".d3dbsp";
|
surfVertex->texCoord[1] = meshVertex->TextureCoordinate.Y;
|
||||||
|
|
||||||
projInfo->gfxInfo.surfaceCount = OBJloader.LoadedMeshes.size();
|
surfVertex->normal.x = meshVertex->Normal.X;
|
||||||
projInfo->gfxInfo.surfaces = new worldSurface[projInfo->gfxInfo.surfaceCount];
|
surfVertex->normal.y = meshVertex->Normal.Y;
|
||||||
|
surfVertex->normal.z = meshVertex->Normal.Z;
|
||||||
|
|
||||||
projInfo->gfxInfo.vertexCount = 0;
|
// TODO: fix tangents, seems to work for now though
|
||||||
projInfo->gfxInfo.indexCount = 0;
|
surfVertex->tangent.x = 1.0f;
|
||||||
projInfo->gfxInfo.vertices = (customMapVertex*)malloc(1);
|
surfVertex->tangent.y = 0.0f;
|
||||||
projInfo->gfxInfo.indices = (uint16_t*)malloc(1);
|
surfVertex->tangent.z = 0.0f;
|
||||||
|
|
||||||
for (int i = 0; i < projInfo->gfxInfo.surfaceCount; i++)
|
surfVertex->packedLmapCoord = 0;
|
||||||
{
|
|
||||||
objl::Mesh* currMesh = &OBJloader.LoadedMeshes[i];
|
|
||||||
worldSurface* currSurface = &projInfo->gfxInfo.surfaces[i];
|
|
||||||
|
|
||||||
currSurface->materialName = currMesh->MeshMaterial.name;
|
surfVertex->binormalSign = 0.0f;
|
||||||
currSurface->reflectionProbeIndex = 0;
|
|
||||||
currSurface->primaryLightIndex = 0;
|
|
||||||
currSurface->lightmapIndex = 0;
|
|
||||||
currSurface->flags = 0;
|
|
||||||
|
|
||||||
parseMesh(currMesh, currSurface, projInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
return projInfo;
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
|
customMapInfo* CustomMapInfo::createCustomMapInfo(std::string& projectName, ISearchPath& searchPath)
|
||||||
|
{
|
||||||
|
std::string objFilePath = searchPath.GetPath() + "custom_map/world.obj";
|
||||||
|
|
||||||
|
objl::Loader OBJloader;
|
||||||
|
bool isLoaded = OBJloader.LoadFile(objFilePath);
|
||||||
|
if (!isLoaded)
|
||||||
|
{
|
||||||
|
printf("OBJLoader: unable to load obj file %s\n", objFilePath.c_str());
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
customMapInfo* projInfo = new customMapInfo;
|
||||||
|
|
||||||
|
projInfo->name = projectName;
|
||||||
|
projInfo->bspName = "maps/mp/" + projectName + ".d3dbsp";
|
||||||
|
|
||||||
|
projInfo->gfxInfo.surfaceCount = OBJloader.LoadedMeshes.size();
|
||||||
|
projInfo->gfxInfo.surfaces = new worldSurface[projInfo->gfxInfo.surfaceCount];
|
||||||
|
|
||||||
|
projInfo->gfxInfo.vertexCount = 0;
|
||||||
|
projInfo->gfxInfo.indexCount = 0;
|
||||||
|
projInfo->gfxInfo.vertices = (customMapVertex*)malloc(1);
|
||||||
|
projInfo->gfxInfo.indices = (uint16_t*)malloc(1);
|
||||||
|
|
||||||
|
for (int i = 0; i < projInfo->gfxInfo.surfaceCount; i++)
|
||||||
|
{
|
||||||
|
objl::Mesh* currMesh = &OBJloader.LoadedMeshes[i];
|
||||||
|
worldSurface* currSurface = &projInfo->gfxInfo.surfaces[i];
|
||||||
|
|
||||||
|
currSurface->materialName = currMesh->MeshMaterial.name;
|
||||||
|
currSurface->reflectionProbeIndex = 0;
|
||||||
|
currSurface->primaryLightIndex = 0;
|
||||||
|
currSurface->lightmapIndex = 0;
|
||||||
|
currSurface->flags = 0;
|
||||||
|
|
||||||
|
parseMesh(currMesh, currSurface, projInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
return projInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
#include "SearchPath/ISearchPath.h"
|
#include "SearchPath/ISearchPath.h"
|
||||||
#include "Utils/MemoryManager.h"
|
#include "Utils/MemoryManager.h"
|
||||||
#include "Game/T6/T6.h"
|
#include "Game/T6/T6.h"
|
||||||
using namespace T6;
|
using namespace T6;
|
||||||
|
|
||||||
#include "OBJ_Loader.h"
|
|
||||||
|
|
||||||
class CustomMapInfo
|
class CustomMapInfo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static void parseMesh(objl::Mesh* OBJMesh, worldSurface* meshSurface, customMapInfo* projInfo);
|
|
||||||
static customMapInfo* createCustomMapInfo(std::string& projectName, ISearchPath& searchPath);
|
static customMapInfo* createCustomMapInfo(std::string& projectName, ISearchPath& searchPath);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
#include "Game/T6/T6.h"
|
#include "Game/T6/T6.h"
|
||||||
using namespace T6;
|
using namespace T6;
|
||||||
|
|
||||||
|
|||||||
@@ -389,7 +389,7 @@ namespace T6
|
|||||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetFootstepTable>>(zone));
|
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetFootstepTable>>(zone));
|
||||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetFootstepFxTable>>(zone));
|
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetFootstepFxTable>>(zone));
|
||||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetZBarrier>>(zone));
|
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetZBarrier>>(zone));
|
||||||
collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetCustomMap>>(zone));
|
//collection.AddAssetCreator(std::make_unique<GlobalAssetPoolsLoader<AssetCustomMap>>(zone));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigureLoaders(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath, IGdtQueryable& gdt)
|
void ConfigureLoaders(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath, IGdtQueryable& gdt)
|
||||||
@@ -451,7 +451,7 @@ namespace T6
|
|||||||
collection.AddAssetCreator(CreateRawZBarrierLoader(memory, searchPath, zone));
|
collection.AddAssetCreator(CreateRawZBarrierLoader(memory, searchPath, zone));
|
||||||
collection.AddAssetCreator(CreateGdtZBarrierLoader(memory, searchPath, gdt, zone));
|
collection.AddAssetCreator(CreateGdtZBarrierLoader(memory, searchPath, gdt, zone));
|
||||||
|
|
||||||
collection.AddAssetCreator(CreateCustomMapLoader(memory, searchPath));
|
collection.AddAssetCreator(CreateCustomMapLoader(memory, searchPath, zone));
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user