mirror of
https://github.com/ZDoom/ZDRay.git
synced 2024-11-21 19:50:54 +00:00
Port over more of DoomLevelMesh
This commit is contained in:
parent
3fa88a1447
commit
f905d37cd7
10 changed files with 1522 additions and 99 deletions
|
@ -56,6 +56,7 @@ set(ZDRAY_SOURCES
|
|||
src/lightmapper/vk_lightmap.h
|
||||
src/lightmapper/vk_raytrace.cpp
|
||||
src/lightmapper/vk_raytrace.h
|
||||
src/lightmapper/textureid.cpp
|
||||
src/lightmapper/textureid.h
|
||||
src/lightmapper/doom_levelmesh.cpp
|
||||
src/lightmapper/doom_levelmesh.h
|
||||
|
|
|
@ -1796,7 +1796,9 @@ class Plane
|
|||
public:
|
||||
void Set(float a, float b, float c, float d) { this->a = a; this->b = b; this->c = c; this->d = d; }
|
||||
|
||||
float zAt(float x, float y) const { return (d - a * x - b * y) / c; }
|
||||
float ZatPoint(float x, float y) const { return (d - a * x - b * y) / c; }
|
||||
float ZatPoint(const FVector2& pt) const { return ZatPoint(pt.X, pt.Y); }
|
||||
float ZatPoint(const DVector2& pt) const { return ZatPoint((float)pt.X, (float)pt.Y); }
|
||||
|
||||
FVector3 Normal() const { return FVector3(a, b, c); }
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "framework/zdray.h"
|
||||
#include "framework/tarray.h"
|
||||
#include "framework/templates.h"
|
||||
#include "framework/zstring.h"
|
||||
|
@ -393,9 +394,9 @@ struct ThingLight
|
|||
{
|
||||
float originZ;
|
||||
if (!bCeiling)
|
||||
originZ = sector->floorplane.zAt(origin.X, origin.Y) + height;
|
||||
originZ = sector->floorplane.ZatPoint(origin.X, origin.Y) + height;
|
||||
else
|
||||
originZ = sector->ceilingplane.zAt(origin.X, origin.Y) - height;
|
||||
originZ = sector->ceilingplane.ZatPoint(origin.X, origin.Y) - height;
|
||||
return FVector3(origin.X, origin.Y, originZ);
|
||||
}
|
||||
|
||||
|
|
|
@ -213,7 +213,7 @@ void FProcessor::SpawnSlopeMakers(IntThing* firstmt, IntThing* lastmt, const int
|
|||
ceiling = false;
|
||||
}
|
||||
|
||||
pos.Z = double(refplane->zAt(float(pos.X), float(pos.Y))) + pos.Z;
|
||||
pos.Z = double(refplane->ZatPoint(pos)) + pos.Z;
|
||||
|
||||
/*if (mt->type <= SMT_SlopeCeilingPointLine)
|
||||
{ // SlopeFloorPointLine and SlopCeilingPointLine
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "framework/zstring.h"
|
||||
#include "hw_levelmesh.h"
|
||||
#include "level/doomdata.h"
|
||||
|
||||
struct FLevel;
|
||||
class FWadWriter;
|
||||
|
@ -16,3 +17,125 @@ public:
|
|||
|
||||
void AddLightmapLump(FWadWriter& out);
|
||||
};
|
||||
|
||||
enum DoomLevelMeshSurfaceType
|
||||
{
|
||||
ST_UNKNOWN,
|
||||
ST_MIDDLESIDE,
|
||||
ST_UPPERSIDE,
|
||||
ST_LOWERSIDE,
|
||||
ST_CEILING,
|
||||
ST_FLOOR
|
||||
};
|
||||
|
||||
enum class ETexpart
|
||||
{
|
||||
Mid,
|
||||
Top,
|
||||
Bottom
|
||||
};
|
||||
|
||||
struct DoomLevelMeshSurface : public LevelMeshSurface
|
||||
{
|
||||
DoomLevelMeshSurfaceType Type = ST_UNKNOWN;
|
||||
int TypeIndex = 0;
|
||||
|
||||
MapSubsectorEx* Subsector = nullptr;
|
||||
IntSideDef* Side = nullptr;
|
||||
IntSector* ControlSector = nullptr;
|
||||
|
||||
float* TexCoords = nullptr;
|
||||
};
|
||||
|
||||
class DoomLevelSubmesh : public LevelSubmesh
|
||||
{
|
||||
public:
|
||||
void CreateStatic(FLevel& doomMap);
|
||||
|
||||
LevelMeshSurface* GetSurface(int index) override { return &Surfaces[index]; }
|
||||
unsigned int GetSurfaceIndex(const LevelMeshSurface* surface) const override { return (unsigned int)(ptrdiff_t)(static_cast<const DoomLevelMeshSurface*>(surface) - Surfaces.Data()); }
|
||||
int GetSurfaceCount() override { return Surfaces.Size(); }
|
||||
|
||||
void DumpMesh(const FString& objFilename, const FString& mtlFilename) const;
|
||||
|
||||
// Used by Maploader
|
||||
void BindLightmapSurfacesToGeometry(FLevel& doomMap);
|
||||
void PackLightmapAtlas(int lightmapStartIndex);
|
||||
void CreatePortals();
|
||||
void DisableLightmaps() { Surfaces.Clear(); } // Temp hack that disables lightmapping
|
||||
|
||||
TArray<DoomLevelMeshSurface> Surfaces;
|
||||
TArray<FVector2> LightmapUvs;
|
||||
TArray<int> sectorGroup; // index is sector, value is sectorGroup
|
||||
|
||||
private:
|
||||
void BuildSectorGroups(const FLevel& doomMap);
|
||||
|
||||
void CreateSubsectorSurfaces(FLevel& doomMap);
|
||||
void CreateCeilingSurface(FLevel& doomMap, MapSubsectorEx* sub, IntSector* sector, IntSector* controlSector, int typeIndex);
|
||||
void CreateFloorSurface(FLevel& doomMap, MapSubsectorEx* sub, IntSector* sector, IntSector* controlSector, int typeIndex);
|
||||
void CreateSideSurfaces(FLevel& doomMap, IntSideDef* side);
|
||||
void CreateLinePortalSurface(FLevel& doomMap, IntSideDef* side);
|
||||
void CreateLineHorizonSurface(FLevel& doomMap, IntSideDef* side);
|
||||
void CreateFrontWallSurface(FLevel& doomMap, IntSideDef* side);
|
||||
void CreateTopWallSurface(FLevel& doomMap, IntSideDef* side);
|
||||
void CreateMidWallSurface(FLevel& doomMap, IntSideDef* side);
|
||||
void CreateBottomWallSurface(FLevel& doomMap, IntSideDef* side);
|
||||
void Create3DFloorWallSurfaces(FLevel& doomMap, IntSideDef* side);
|
||||
void SetSideTextureUVs(DoomLevelMeshSurface& surface, IntSideDef* side, ETexpart texpart, float v1TopZ, float v1BottomZ, float v2TopZ, float v2BottomZ);
|
||||
|
||||
void SetSubsectorLightmap(DoomLevelMeshSurface* surface);
|
||||
void SetSideLightmap(DoomLevelMeshSurface* surface);
|
||||
|
||||
void SetupLightmapUvs(FLevel& doomMap);
|
||||
|
||||
void CreateIndexes();
|
||||
|
||||
static bool IsTopSideSky(IntSector* frontsector, IntSector* backsector, IntSideDef* side);
|
||||
static bool IsTopSideVisible(IntSideDef* side);
|
||||
static bool IsBottomSideVisible(IntSideDef* side);
|
||||
static bool IsSkySector(IntSector* sector, int plane);
|
||||
|
||||
static FVector4 ToPlane(const FVector3& pt1, const FVector3& pt2, const FVector3& pt3)
|
||||
{
|
||||
FVector3 n = ((pt2 - pt1) ^ (pt3 - pt2)).Unit();
|
||||
float d = pt1 | n;
|
||||
return FVector4(n.X, n.Y, n.Z, d);
|
||||
}
|
||||
|
||||
static FVector4 ToPlane(const FVector3& pt1, const FVector3& pt2, const FVector3& pt3, const FVector3& pt4)
|
||||
{
|
||||
if (pt1.ApproximatelyEquals(pt3))
|
||||
{
|
||||
return ToPlane(pt1, pt2, pt4);
|
||||
}
|
||||
else if (pt1.ApproximatelyEquals(pt2) || pt2.ApproximatelyEquals(pt3))
|
||||
{
|
||||
return ToPlane(pt1, pt3, pt4);
|
||||
}
|
||||
|
||||
return ToPlane(pt1, pt2, pt3);
|
||||
}
|
||||
|
||||
// Lightmapper
|
||||
|
||||
enum PlaneAxis
|
||||
{
|
||||
AXIS_YZ = 0,
|
||||
AXIS_XZ,
|
||||
AXIS_XY
|
||||
};
|
||||
|
||||
static PlaneAxis BestAxis(const FVector4& p);
|
||||
BBox GetBoundsFromSurface(const LevelMeshSurface& surface) const;
|
||||
|
||||
inline int AllocUvs(int amount) { return LightmapUvs.Reserve(amount); }
|
||||
|
||||
void BuildSurfaceParams(int lightMapTextureWidth, int lightMapTextureHeight, LevelMeshSurface& surface);
|
||||
|
||||
static bool IsDegenerate(const FVector3& v0, const FVector3& v1, const FVector3& v2);
|
||||
|
||||
static FVector2 ToFVector2(const DVector2& v) { return FVector2((float)v.X, (float)v.Y); }
|
||||
static FVector3 ToFVector3(const DVector3& v) { return FVector3((float)v.X, (float)v.Y, (float)v.Z); }
|
||||
static FVector4 ToFVector4(const DVector4& v) { return FVector4((float)v.X, (float)v.Y, (float)v.Z, (float)v.W); }
|
||||
};
|
||||
|
|
5
src/lightmapper/textureid.cpp
Normal file
5
src/lightmapper/textureid.cpp
Normal file
|
@ -0,0 +1,5 @@
|
|||
|
||||
#include "textureid.h"
|
||||
|
||||
FFileSystem fileSystem;
|
||||
FTextureManager TexMan;
|
|
@ -1,5 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include "framework/tarray.h"
|
||||
#include "framework/templates.h"
|
||||
#include "framework/zstring.h"
|
||||
|
||||
class FGameTexture;
|
||||
|
||||
enum class ETextureType : uint8_t
|
||||
{
|
||||
Any,
|
||||
|
@ -63,3 +69,64 @@ public:
|
|||
constexpr FSetTextureID(int v) : FTextureID(v) {}
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct FileData
|
||||
{
|
||||
char* GetMem() { return nullptr; }
|
||||
};
|
||||
|
||||
class FFileSystem
|
||||
{
|
||||
public:
|
||||
int CheckNumForFullName(const FString& fullname) { return -1; }
|
||||
int FileLength(int lump) { return 0; }
|
||||
FileData ReadFile(int lump) { return {}; }
|
||||
const char* GetFileFullName(int lump, bool returnshort = true) const { return ""; }
|
||||
};
|
||||
|
||||
extern FFileSystem fileSystem;
|
||||
|
||||
class FTextureManager
|
||||
{
|
||||
public:
|
||||
FGameTexture* GetGameTexture(FTextureID, bool)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
enum
|
||||
{
|
||||
TEXMAN_TryAny = 1,
|
||||
TEXMAN_Overridable = 2,
|
||||
TEXMAN_ReturnFirst = 4,
|
||||
TEXMAN_AllowSkins = 8,
|
||||
TEXMAN_ShortNameOnly = 16,
|
||||
TEXMAN_DontCreate = 32,
|
||||
TEXMAN_Localize = 64,
|
||||
TEXMAN_ForceLookup = 128,
|
||||
TEXMAN_NoAlias = 256,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
HIT_Wall = 1,
|
||||
HIT_Flat = 2,
|
||||
HIT_Sky = 4,
|
||||
HIT_Sprite = 8,
|
||||
|
||||
HIT_Columnmode = HIT_Wall | HIT_Sky | HIT_Sprite
|
||||
};
|
||||
|
||||
FTextureID CheckForTexture(const char* name, ETextureType usetype, uint32_t flags = TEXMAN_TryAny) { return {}; }
|
||||
};
|
||||
|
||||
extern FTextureManager TexMan;
|
||||
|
||||
class FGameTexture
|
||||
{
|
||||
public:
|
||||
bool isValid() const { return false; }
|
||||
float GetDisplayWidth() const { return 64.0f; }
|
||||
float GetDisplayHeight() const { return 64.0f; }
|
||||
};
|
||||
|
|
|
@ -31,9 +31,6 @@
|
|||
#include "model_md3.h"
|
||||
#include "modelrenderer.h"
|
||||
|
||||
FFileSystem fileSystem;
|
||||
FTextureManager TexMan;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
FModel::FModel()
|
||||
|
|
|
@ -4,106 +4,16 @@
|
|||
#include "framework/templates.h"
|
||||
#include "framework/zstring.h"
|
||||
#include "framework/vectors.h"
|
||||
#include "lightmapper/textureid.h"
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
class FModelRenderer;
|
||||
class FGameTexture;
|
||||
class IModelVertexBuffer;
|
||||
class FModel;
|
||||
struct FSpriteModelFrame;
|
||||
|
||||
struct FileData
|
||||
{
|
||||
char* GetMem() { return nullptr; }
|
||||
};
|
||||
|
||||
class FFileSystem
|
||||
{
|
||||
public:
|
||||
int CheckNumForFullName(const FString& fullname) { return -1; }
|
||||
int FileLength(int lump) { return 0; }
|
||||
FileData ReadFile(int lump) { return {}; }
|
||||
const char* GetFileFullName(int lump, bool returnshort = true) const { return ""; }
|
||||
};
|
||||
|
||||
extern FFileSystem fileSystem;
|
||||
|
||||
class FTextureID
|
||||
{
|
||||
public:
|
||||
bool isValid() const { return false; }
|
||||
int GetIndex() const { return 0; }
|
||||
};
|
||||
|
||||
class FNullTextureID : public FTextureID
|
||||
{
|
||||
public:
|
||||
};
|
||||
|
||||
class FGameTexture
|
||||
{
|
||||
public:
|
||||
};
|
||||
|
||||
enum class ETextureType : uint8_t
|
||||
{
|
||||
Any,
|
||||
Wall,
|
||||
Flat,
|
||||
Sprite,
|
||||
WallPatch,
|
||||
Build, // no longer used but needs to remain for ZScript
|
||||
SkinSprite,
|
||||
Decal,
|
||||
MiscPatch,
|
||||
FontChar,
|
||||
Override, // For patches between TX_START/TX_END
|
||||
Autopage, // Automap background - used to enable the use of FAutomapTexture
|
||||
SkinGraphic,
|
||||
Null,
|
||||
FirstDefined,
|
||||
Special,
|
||||
SWCanvas,
|
||||
};
|
||||
|
||||
class FTextureManager
|
||||
{
|
||||
public:
|
||||
FGameTexture* GetGameTexture(FTextureID, bool)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
enum
|
||||
{
|
||||
TEXMAN_TryAny = 1,
|
||||
TEXMAN_Overridable = 2,
|
||||
TEXMAN_ReturnFirst = 4,
|
||||
TEXMAN_AllowSkins = 8,
|
||||
TEXMAN_ShortNameOnly = 16,
|
||||
TEXMAN_DontCreate = 32,
|
||||
TEXMAN_Localize = 64,
|
||||
TEXMAN_ForceLookup = 128,
|
||||
TEXMAN_NoAlias = 256,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
HIT_Wall = 1,
|
||||
HIT_Flat = 2,
|
||||
HIT_Sky = 4,
|
||||
HIT_Sprite = 8,
|
||||
|
||||
HIT_Columnmode = HIT_Wall | HIT_Sky | HIT_Sprite
|
||||
};
|
||||
|
||||
FTextureID CheckForTexture(const char* name, ETextureType usetype, uint32_t flags = TEXMAN_TryAny) { return {}; }
|
||||
};
|
||||
|
||||
extern FTextureManager TexMan;
|
||||
|
||||
struct FModelVertex
|
||||
{
|
||||
float x, y, z; // world position
|
||||
|
|
Loading…
Reference in a new issue