Bake models into the level mesh

This commit is contained in:
Magnus Norddahl 2025-06-11 03:38:40 +02:00
commit 3f1dcce970
5 changed files with 188 additions and 28 deletions

View file

@ -42,6 +42,7 @@ struct SurfaceAllocInfo
{
LevelMeshSurface* Surface = nullptr;
int Index = 0;
int Count = 0;
};
struct LightAllocInfo
@ -124,14 +125,14 @@ public:
GeometryAllocInfo AllocGeometry(int vertexCount, int indexCount);
UniformsAllocInfo AllocUniforms(int count);
SurfaceAllocInfo AllocSurface();
SurfaceAllocInfo AllocSurface(int count = 1);
LightAllocInfo AllocLight();
LightListAllocInfo AllocLightList(int count);
int AllocTile(const LightmapTile& tile);
void FreeGeometry(int vertexStart, int vertexCount, int indexStart, int indexCount);
void FreeUniforms(int start, int count);
void FreeSurface(unsigned int surfaceIndex);
void FreeSurface(unsigned int surfaceIndex, int count = 1);
void FreeLightList(int start, int count);
void FreeTile(int index);
@ -288,12 +289,13 @@ inline LightAllocInfo LevelMesh::AllocLight()
return info;
}
inline SurfaceAllocInfo LevelMesh::AllocSurface()
inline SurfaceAllocInfo LevelMesh::AllocSurface(int count)
{
SurfaceAllocInfo info;
info.Index = FreeLists.Surface.Alloc(1);
info.Index = FreeLists.Surface.Alloc(count);
info.Surface = &Mesh.Surfaces[info.Index];
UploadRanges.Surface.Add(info.Index, 1);
info.Count = count;
UploadRanges.Surface.Add(info.Index, info.Count);
return info;
}
@ -333,9 +335,9 @@ inline void LevelMesh::FreeLightList(int start, int count)
FreeLists.LightIndex.Free(start, count);
}
inline void LevelMesh::FreeSurface(unsigned int surfaceIndex)
inline void LevelMesh::FreeSurface(unsigned int surfaceIndex, int count)
{
FreeLists.Surface.Free(surfaceIndex, 1);
FreeLists.Surface.Free(surfaceIndex, count);
}
inline void LevelMesh::FreeTile(int index)

View file

@ -102,7 +102,9 @@ void MeshBuilderModelRender::BeginDrawModel(FRenderStyle style, int smf_flags, c
void MeshBuilderModelRender::EndDrawModel(FRenderStyle style, int smf_flags)
{
renderstate.SetBoneIndexBase(-1);
renderstate.SetModelMatrix(VSMatrix::identity(), VSMatrix::identity());
// Don't do this so we don't have to track matrix changes in MeshBuilder (only models uses matrices like this)
//renderstate.SetModelMatrix(VSMatrix::identity(), VSMatrix::identity());
}
IModelVertexBuffer* MeshBuilderModelRender::CreateVertexBuffer(bool needindex, bool singleframe)

View file

@ -111,7 +111,7 @@ public:
// Buffers
int SetViewpoint(const HWViewpointUniforms& vp) override { return 0; }
void SetViewpoint(int index) override { }
void SetModelMatrix(const VSMatrix& matrix, const VSMatrix& normalMatrix) override { }
void SetModelMatrix(const VSMatrix& matrix, const VSMatrix& normalMatrix) override { objectToWorld = matrix; normalToWorld = normalMatrix; }
void SetTextureMatrix(const VSMatrix& matrix) override { mTextureMatrix = matrix; }
int UploadLights(const FDynLightData& lightdata) override { return -1; }
int UploadBones(const TArray<VSMatrix>& bones) override { return -1; }
@ -150,6 +150,9 @@ public:
TArray<FFlatVertex> mVertices;
TArray<uint32_t> mIndexes;
VSMatrix objectToWorld = VSMatrix::identity();
VSMatrix normalToWorld = VSMatrix::identity();
private:
void Apply();