From 46d263b5a8ec0b39526566e8ac51ab9cdc4837f7 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 27 Apr 2020 01:16:17 +0200 Subject: [PATCH] - header separation of model code. --- src/common/textures/texturemanager.h | 1 + src/r_data/models/model.h | 77 ++++ src/r_data/models/model_kvx.h | 61 ++++ src/r_data/models/model_md2.h | 136 +++++++ src/r_data/models/model_md3.h | 75 ++++ .../models/{models_obj.h => model_obj.h} | 4 +- .../models/{models_ue1.h => model_ue1.h} | 4 +- src/r_data/models/modelrenderer.h | 12 +- src/r_data/models/models.cpp | 33 +- src/r_data/models/models.h | 338 +----------------- src/r_data/models/models_md2.cpp | 4 + src/r_data/models/models_md3.cpp | 1 + src/r_data/models/models_obj.cpp | 2 +- src/r_data/models/models_ue1.cpp | 2 +- src/r_data/models/models_voxel.cpp | 1 + 15 files changed, 385 insertions(+), 366 deletions(-) create mode 100644 src/r_data/models/model.h create mode 100644 src/r_data/models/model_kvx.h create mode 100644 src/r_data/models/model_md2.h create mode 100644 src/r_data/models/model_md3.h rename src/r_data/models/{models_obj.h => model_obj.h} (98%) rename src/r_data/models/{models_ue1.h => model_ue1.h} (97%) diff --git a/src/common/textures/texturemanager.h b/src/common/textures/texturemanager.h index 9cdfa58b4..2aa53da24 100644 --- a/src/common/textures/texturemanager.h +++ b/src/common/textures/texturemanager.h @@ -10,6 +10,7 @@ class FxAddSub; struct BuildInfo; class FMultipatchTextureBuilder; +class FScanner; int PalCheck(int tex); // Texture manager diff --git a/src/r_data/models/model.h b/src/r_data/models/model.h new file mode 100644 index 000000000..1daf7c8c6 --- /dev/null +++ b/src/r_data/models/model.h @@ -0,0 +1,77 @@ +#pragma once + +#include +#include "textureid.h" + +class FModelRenderer; +class FGameTexture; +class IModelVertexBuffer; +class FModel; + +FTextureID LoadSkin(const char* path, const char* fn); +void FlushModels(); +extern TDeletingArray Models; + +#define MAX_MODELS_PER_FRAME 4 +#define MD3_MAX_SURFACES 32 + +struct FSpriteModelFrame +{ + int modelIDs[MAX_MODELS_PER_FRAME]; + FTextureID skinIDs[MAX_MODELS_PER_FRAME]; + FTextureID surfaceskinIDs[MAX_MODELS_PER_FRAME][MD3_MAX_SURFACES]; + int modelframes[MAX_MODELS_PER_FRAME]; + float xscale, yscale, zscale; + // [BB] Added zoffset, rotation parameters and flags. + // Added xoffset, yoffset + float xoffset, yoffset, zoffset; + float xrotate, yrotate, zrotate; + float rotationCenterX, rotationCenterY, rotationCenterZ; + float rotationSpeed; + unsigned int flags; + const void* type; // used for hashing, must point to something usable as identifier for the model's owner. + short sprite; + short frame; + int hashnext; + float angleoffset; + // added pithoffset, rolloffset. + float pitchoffset, rolloffset; // I don't want to bother with type transformations, so I made this variables float. + bool isVoxel; +}; + + +enum ModelRendererType +{ + GLModelRendererType, + SWModelRendererType, + PolyModelRendererType, + NumModelRendererTypes +}; + +class FModel +{ +public: + FModel(); + virtual ~FModel(); + + virtual bool Load(const char * fn, int lumpnum, const char * buffer, int length) = 0; + virtual int FindFrame(const char * name) = 0; + virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation=0) = 0; + virtual void BuildVertexBuffer(FModelRenderer *renderer) = 0; + virtual void AddSkins(uint8_t *hitlist) = 0; + virtual float getAspectFactor(float vscale) { return 1.f; } + + void SetVertexBuffer(int type, IModelVertexBuffer *buffer) { mVBuf[type] = buffer; } + IModelVertexBuffer *GetVertexBuffer(int type) const { return mVBuf[type]; } + void DestroyVertexBuffer(); + + const FSpriteModelFrame *curSpriteMDLFrame; + int curMDLIndex; + void PushSpriteMDLFrame(const FSpriteModelFrame *smf, int index) { curSpriteMDLFrame = smf; curMDLIndex = index; }; + + FString mFileName; + +private: + IModelVertexBuffer *mVBuf[NumModelRendererTypes]; +}; + diff --git a/src/r_data/models/model_kvx.h b/src/r_data/models/model_kvx.h new file mode 100644 index 000000000..c934491e8 --- /dev/null +++ b/src/r_data/models/model_kvx.h @@ -0,0 +1,61 @@ +#pragma once + +#include "model.h" + +struct FVoxelVertexHash +{ + // Returns the hash value for a key. + hash_t Hash(const FModelVertex &key) + { + int ix = xs_RoundToInt(key.x); + int iy = xs_RoundToInt(key.y); + int iz = xs_RoundToInt(key.z); + return (hash_t)(ix + (iy<<9) + (iz<<18)); + } + + // Compares two keys, returning zero if they are the same. + int Compare(const FModelVertex &left, const FModelVertex &right) + { + return left.x != right.x || left.y != right.y || left.z != right.z || left.u != right.u || left.v != right.v; + } +}; + +struct FIndexInit +{ + void Init(unsigned int &value) + { + value = 0xffffffff; + } +}; + +typedef TMap FVoxelMap; + + +class FVoxelModel : public FModel +{ +protected: + FVoxel *mVoxel; + bool mOwningVoxel; // if created through MODELDEF deleting this object must also delete the voxel object + FTextureID mPalette; + unsigned int mNumIndices; + TArray mVertices; + TArray mIndices; + + void MakeSlabPolys(int x, int y, kvxslab_t *voxptr, FVoxelMap &check); + void AddFace(int x1, int y1, int z1, int x2, int y2, int z2, int x3, int y3, int z3, int x4, int y4, int z4, uint8_t color, FVoxelMap &check); + unsigned int AddVertex(FModelVertex &vert, FVoxelMap &check); + +public: + FVoxelModel(FVoxel *voxel, bool owned); + ~FVoxelModel(); + bool Load(const char * fn, int lumpnum, const char * buffer, int length); + void Initialize(); + virtual int FindFrame(const char * name); + virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation=0); + virtual void AddSkins(uint8_t *hitlist); + FTextureID GetPaletteTexture() const { return mPalette; } + void BuildVertexBuffer(FModelRenderer *renderer); + float getAspectFactor(float vscale) override; +}; + + diff --git a/src/r_data/models/model_md2.h b/src/r_data/models/model_md2.h new file mode 100644 index 000000000..163631532 --- /dev/null +++ b/src/r_data/models/model_md2.h @@ -0,0 +1,136 @@ +#pragma once +#include "model.h" + +#define MD2_MAGIC 0x32504449 +#define DMD_MAGIC 0x4D444D44 + +class FDMDModel : public FModel +{ +protected: + + struct FTriangle + { + unsigned short vertexIndices[3]; + unsigned short textureIndices[3]; + }; + + + struct DMDHeader + { + int magic; + int version; + int flags; + }; + + struct DMDModelVertex + { + float xyz[3]; + }; + + struct FTexCoord + { + short s, t; + }; + + struct FGLCommandVertex + { + float s, t; + int index; + }; + + struct DMDInfo + { + int skinWidth; + int skinHeight; + int frameSize; + int numSkins; + int numVertices; + int numTexCoords; + int numFrames; + int numLODs; + int offsetSkins; + int offsetTexCoords; + int offsetFrames; + int offsetLODs; + int offsetEnd; + }; + + struct ModelFrame + { + char name[16]; + unsigned int vindex; + }; + + struct ModelFrameVertexData + { + DMDModelVertex *vertices; + DMDModelVertex *normals; + }; + + struct DMDLoDInfo + { + int numTriangles; + int numGlCommands; + int offsetTriangles; + int offsetGlCommands; + }; + + struct DMDLoD + { + FTriangle * triangles; + }; + + + int mLumpNum; + DMDHeader header; + DMDInfo info; + FTextureID * skins; + ModelFrame * frames; + bool allowTexComp; // Allow texture compression with this. + + // Temp data only needed for buffer construction + FTexCoord * texCoords; + ModelFrameVertexData *framevtx; + DMDLoDInfo lodInfo[MAX_LODS]; + DMDLoD lods[MAX_LODS]; + +public: + FDMDModel() + { + mLumpNum = -1; + frames = NULL; + skins = NULL; + for (int i = 0; i < MAX_LODS; i++) + { + lods[i].triangles = NULL; + } + info.numLODs = 0; + texCoords = NULL; + framevtx = NULL; + } + virtual ~FDMDModel(); + + virtual bool Load(const char * fn, int lumpnum, const char * buffer, int length); + virtual int FindFrame(const char * name); + virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation=0); + virtual void LoadGeometry(); + virtual void AddSkins(uint8_t *hitlist); + + void UnloadGeometry(); + void BuildVertexBuffer(FModelRenderer *renderer); + +}; + +// This uses the same internal representation as DMD +class FMD2Model : public FDMDModel +{ +public: + FMD2Model() {} + virtual ~FMD2Model(); + + virtual bool Load(const char * fn, int lumpnum, const char * buffer, int length); + virtual void LoadGeometry(); + +}; + + diff --git a/src/r_data/models/model_md3.h b/src/r_data/models/model_md3.h new file mode 100644 index 000000000..3e6630a5a --- /dev/null +++ b/src/r_data/models/model_md3.h @@ -0,0 +1,75 @@ +#pragma once +#include "model.h" + +#define MD3_MAGIC 0x33504449 + +class FMD3Model : public FModel +{ + struct MD3Tag + { + // Currently I have no use for this + }; + + struct MD3TexCoord + { + float s,t; + }; + + struct MD3Vertex + { + float x,y,z; + float nx,ny,nz; + }; + + struct MD3Triangle + { + int VertIndex[3]; + }; + + struct MD3Surface + { + unsigned numVertices; + unsigned numTriangles; + unsigned numSkins; + + TArray Skins; + TArray Tris; + TArray Texcoords; + TArray Vertices; + + unsigned int vindex = UINT_MAX; // contains numframes arrays of vertices + unsigned int iindex = UINT_MAX; + + void UnloadGeometry() + { + Tris.Reset(); + Vertices.Reset(); + Texcoords.Reset(); + } + }; + + struct MD3Frame + { + // The bounding box information is of no use in the Doom engine + // That will still be done with the actor's size information. + char Name[16]; + float origin[3]; + }; + + int numTags; + int mLumpNum; + + TArray Frames; + TArray Surfaces; + +public: + FMD3Model() = default; + + virtual bool Load(const char * fn, int lumpnum, const char * buffer, int length); + virtual int FindFrame(const char * name); + virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation=0); + void LoadGeometry(); + void BuildVertexBuffer(FModelRenderer *renderer); + virtual void AddSkins(uint8_t *hitlist); +}; + diff --git a/src/r_data/models/models_obj.h b/src/r_data/models/model_obj.h similarity index 98% rename from src/r_data/models/models_obj.h rename to src/r_data/models/model_obj.h index c58c30a5a..ed190c1cd 100644 --- a/src/r_data/models/models_obj.h +++ b/src/r_data/models/model_obj.h @@ -23,8 +23,10 @@ #ifndef __GL_MODELS_OBJ_H__ #define __GL_MODELS_OBJ_H__ -#include "models.h" +#include "model.h" #include "sc_man.h" +#include "tarray.h" +#include "vectors.h" class FOBJModel : public FModel { diff --git a/src/r_data/models/models_ue1.h b/src/r_data/models/model_ue1.h similarity index 97% rename from src/r_data/models/models_ue1.h rename to src/r_data/models/model_ue1.h index fb3c85483..5696cbf43 100644 --- a/src/r_data/models/models_ue1.h +++ b/src/r_data/models/model_ue1.h @@ -1,6 +1,8 @@ #pragma once -#include "models.h" +#include +#include "model.h" +#include "vectors.h" class FUE1Model : public FModel { diff --git a/src/r_data/models/modelrenderer.h b/src/r_data/models/modelrenderer.h index 848890c8e..96c8f2a71 100644 --- a/src/r_data/models/modelrenderer.h +++ b/src/r_data/models/modelrenderer.h @@ -1,17 +1,10 @@ #include "models.h" -#include "actor.h" -#include "p_pspr.h" -#include "info.h" -#include "g_levellocals.h" class FModelRenderer { public: - virtual ~FModelRenderer() { } - - void RenderModel(float x, float y, float z, FSpriteModelFrame *modelframe, AActor *actor, double ticFrac); - void RenderHUDModel(DPSprite *psp, float ofsx, float ofsy); + virtual ~FModelRenderer() = default; virtual ModelRendererType GetType() const = 0; @@ -30,8 +23,5 @@ public: virtual void DrawArrays(int start, int count) = 0; virtual void DrawElements(int numIndices, size_t offset) = 0; virtual void SetupFrame(FModel *model, unsigned int frame1, unsigned int frame2, unsigned int size) = 0; - -private: - void RenderFrameModels(FLevelLocals *Level, const FSpriteModelFrame *smf, const FState *curState, const int curTics, const PClass *ti, int translation); }; diff --git a/src/r_data/models/models.cpp b/src/r_data/models/models.cpp index 446a5840b..918af38fb 100644 --- a/src/r_data/models/models.cpp +++ b/src/r_data/models/models.cpp @@ -39,12 +39,16 @@ #include "g_levellocals.h" #include "r_utility.h" #include "r_data/models/models.h" -#include "r_data/models/models_ue1.h" -#include "r_data/models/models_obj.h" +#include "r_data/models/model_ue1.h" +#include "r_data/models/model_obj.h" +#include "r_data/models/model_md2.h" +#include "r_data/models/model_md3.h" +#include "r_data/models/model_kvx.h" #include "i_time.h" #include "texturemanager.h" #include "modelrenderer.h" + #ifdef _MSC_VER #pragma warning(disable:4244) // warning C4244: conversion from 'double' to 'float', possible loss of data #endif @@ -571,11 +575,12 @@ static void ParseModelDefLump(int Lump) smf.modelIDs[0] = smf.modelIDs[1] = smf.modelIDs[2] = smf.modelIDs[3] = -1; smf.xscale=smf.yscale=smf.zscale=1.f; - smf.type = PClass::FindClass(sc.String); - if (!smf.type || smf.type->Defaults == nullptr) + auto type = PClass::FindClass(sc.String); + if (!type || type->Defaults == nullptr) { sc.ScriptError("MODELDEF: Unknown actor type '%s'\n", sc.String); } + smf.type = type; sc.MustGetStringName("{"); while (!sc.CheckString("}")) { @@ -593,7 +598,7 @@ static void ParseModelDefLump(int Lump) index = sc.Number; if (index < 0 || index >= MAX_MODELS_PER_FRAME) { - sc.ScriptError("Too many models in %s", smf.type->TypeName.GetChars()); + sc.ScriptError("Too many models in %s", type->TypeName.GetChars()); } sc.MustGetString(); FixPathSeperator(sc.String); @@ -718,7 +723,7 @@ static void ParseModelDefLump(int Lump) index=sc.Number; if (index<0 || index>=MAX_MODELS_PER_FRAME) { - sc.ScriptError("Too many models in %s", smf.type->TypeName.GetChars()); + sc.ScriptError("Too many models in %s", type->TypeName.GetChars()); } sc.MustGetString(); FixPathSeperator(sc.String); @@ -732,7 +737,7 @@ static void ParseModelDefLump(int Lump) if (!smf.skinIDs[index].isValid()) { Printf("Skin '%s' not found in '%s'\n", - sc.String, smf.type->TypeName.GetChars()); + sc.String, type->TypeName.GetChars()); } } } @@ -745,12 +750,12 @@ static void ParseModelDefLump(int Lump) if (index<0 || index >= MAX_MODELS_PER_FRAME) { - sc.ScriptError("Too many models in %s", smf.type->TypeName.GetChars()); + sc.ScriptError("Too many models in %s", type->TypeName.GetChars()); } if (surface<0 || surface >= MD3_MAX_SURFACES) { - sc.ScriptError("Invalid MD3 Surface %d in %s", MD3_MAX_SURFACES, smf.type->TypeName.GetChars()); + sc.ScriptError("Invalid MD3 Surface %d in %s", MD3_MAX_SURFACES, type->TypeName.GetChars()); } sc.MustGetString(); @@ -765,7 +770,7 @@ static void ParseModelDefLump(int Lump) if (!smf.surfaceskinIDs[index][surface].isValid()) { Printf("Surface Skin '%s' not found in '%s'\n", - sc.String, smf.type->TypeName.GetChars()); + sc.String, type->TypeName.GetChars()); } } } @@ -789,7 +794,7 @@ static void ParseModelDefLump(int Lump) } if (smf.sprite==-1) { - sc.ScriptError("Unknown sprite %s in model definition for %s", sc.String, smf.type->TypeName.GetChars()); + sc.ScriptError("Unknown sprite %s in model definition for %s", sc.String, type->TypeName.GetChars()); } sc.MustGetString(); @@ -799,7 +804,7 @@ static void ParseModelDefLump(int Lump) index=sc.Number; if (index<0 || index>=MAX_MODELS_PER_FRAME) { - sc.ScriptError("Too many models in %s", smf.type->TypeName.GetChars()); + sc.ScriptError("Too many models in %s", type->TypeName.GetChars()); } if (isframe) { @@ -808,7 +813,7 @@ static void ParseModelDefLump(int Lump) { FModel *model = Models[smf.modelIDs[index]]; smf.modelframes[index] = model->FindFrame(sc.String); - if (smf.modelframes[index]==-1) sc.ScriptError("Unknown frame '%s' in %s", sc.String, smf.type->TypeName.GetChars()); + if (smf.modelframes[index]==-1) sc.ScriptError("Unknown frame '%s' in %s", sc.String, type->TypeName.GetChars()); } else smf.modelframes[index] = -1; } @@ -830,7 +835,7 @@ static void ParseModelDefLump(int Lump) if (map[c]) continue; smf.frame=c; SpriteModelFrames.Push(smf); - GetDefaultByType(smf.type)->hasmodel = true; + GetDefaultByType(type)->hasmodel = true; map[c]=1; } } diff --git a/src/r_data/models/models.h b/src/r_data/models/models.h index ad36f7190..eb67a0c92 100644 --- a/src/r_data/models/models.h +++ b/src/r_data/models/models.h @@ -30,320 +30,13 @@ #include "g_levellocals.h" #include "r_data/voxels.h" #include "i_modelvertexbuffer.h" +#include "model.h" class FModelRenderer; -#define MAX_LODS 4 - -enum { VX, VZ, VY }; - -#define MD2_MAGIC 0x32504449 -#define DMD_MAGIC 0x4D444D44 -#define MD3_MAGIC 0x33504449 -#define NUMVERTEXNORMALS 162 -#define MD3_MAX_SURFACES 32 - -FTextureID LoadSkin(const char * path, const char * fn); - struct FSpriteModelFrame; class IModelVertexBuffer; struct FLevelLocals; -class FModel; - -enum ModelRendererType -{ - GLModelRendererType, - SWModelRendererType, - PolyModelRendererType, - NumModelRendererTypes -}; - -class FModel -{ -public: - FModel(); - virtual ~FModel(); - - virtual bool Load(const char * fn, int lumpnum, const char * buffer, int length) = 0; - virtual int FindFrame(const char * name) = 0; - virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation=0) = 0; - virtual void BuildVertexBuffer(FModelRenderer *renderer) = 0; - virtual void AddSkins(uint8_t *hitlist) = 0; - virtual float getAspectFactor(float vscale) { return 1.f; } - - void SetVertexBuffer(int type, IModelVertexBuffer *buffer) { mVBuf[type] = buffer; } - IModelVertexBuffer *GetVertexBuffer(int type) const { return mVBuf[type]; } - void DestroyVertexBuffer(); - - const FSpriteModelFrame *curSpriteMDLFrame; - int curMDLIndex; - void PushSpriteMDLFrame(const FSpriteModelFrame *smf, int index) { curSpriteMDLFrame = smf; curMDLIndex = index; }; - - FString mFileName; - -private: - IModelVertexBuffer *mVBuf[NumModelRendererTypes]; -}; - -class FDMDModel : public FModel -{ -protected: - - struct FTriangle - { - unsigned short vertexIndices[3]; - unsigned short textureIndices[3]; - }; - - - struct DMDHeader - { - int magic; - int version; - int flags; - }; - - struct DMDModelVertex - { - float xyz[3]; - }; - - struct FTexCoord - { - short s, t; - }; - - struct FGLCommandVertex - { - float s, t; - int index; - }; - - struct DMDInfo - { - int skinWidth; - int skinHeight; - int frameSize; - int numSkins; - int numVertices; - int numTexCoords; - int numFrames; - int numLODs; - int offsetSkins; - int offsetTexCoords; - int offsetFrames; - int offsetLODs; - int offsetEnd; - }; - - struct ModelFrame - { - char name[16]; - unsigned int vindex; - }; - - struct ModelFrameVertexData - { - DMDModelVertex *vertices; - DMDModelVertex *normals; - }; - - struct DMDLoDInfo - { - int numTriangles; - int numGlCommands; - int offsetTriangles; - int offsetGlCommands; - }; - - struct DMDLoD - { - FTriangle * triangles; - }; - - - int mLumpNum; - DMDHeader header; - DMDInfo info; - FTextureID * skins; - ModelFrame * frames; - bool allowTexComp; // Allow texture compression with this. - - // Temp data only needed for buffer construction - FTexCoord * texCoords; - ModelFrameVertexData *framevtx; - DMDLoDInfo lodInfo[MAX_LODS]; - DMDLoD lods[MAX_LODS]; - -public: - FDMDModel() - { - mLumpNum = -1; - frames = NULL; - skins = NULL; - for (int i = 0; i < MAX_LODS; i++) - { - lods[i].triangles = NULL; - } - info.numLODs = 0; - texCoords = NULL; - framevtx = NULL; - } - virtual ~FDMDModel(); - - virtual bool Load(const char * fn, int lumpnum, const char * buffer, int length); - virtual int FindFrame(const char * name); - virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation=0); - virtual void LoadGeometry(); - virtual void AddSkins(uint8_t *hitlist); - - void UnloadGeometry(); - void BuildVertexBuffer(FModelRenderer *renderer); - -}; - -// This uses the same internal representation as DMD -class FMD2Model : public FDMDModel -{ -public: - FMD2Model() {} - virtual ~FMD2Model(); - - virtual bool Load(const char * fn, int lumpnum, const char * buffer, int length); - virtual void LoadGeometry(); - -}; - - -class FMD3Model : public FModel -{ - struct MD3Tag - { - // Currently I have no use for this - }; - - struct MD3TexCoord - { - float s,t; - }; - - struct MD3Vertex - { - float x,y,z; - float nx,ny,nz; - }; - - struct MD3Triangle - { - int VertIndex[3]; - }; - - struct MD3Surface - { - unsigned numVertices; - unsigned numTriangles; - unsigned numSkins; - - TArray Skins; - TArray Tris; - TArray Texcoords; - TArray Vertices; - - unsigned int vindex = UINT_MAX; // contains numframes arrays of vertices - unsigned int iindex = UINT_MAX; - - void UnloadGeometry() - { - Tris.Reset(); - Vertices.Reset(); - Texcoords.Reset(); - } - }; - - struct MD3Frame - { - // The bounding box information is of no use in the Doom engine - // That will still be done with the actor's size information. - char Name[16]; - float origin[3]; - }; - - int numTags; - int mLumpNum; - - TArray Frames; - TArray Surfaces; - -public: - FMD3Model() = default; - - virtual bool Load(const char * fn, int lumpnum, const char * buffer, int length); - virtual int FindFrame(const char * name); - virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation=0); - void LoadGeometry(); - void BuildVertexBuffer(FModelRenderer *renderer); - virtual void AddSkins(uint8_t *hitlist); -}; - -struct FVoxelVertexHash -{ - // Returns the hash value for a key. - hash_t Hash(const FModelVertex &key) - { - int ix = xs_RoundToInt(key.x); - int iy = xs_RoundToInt(key.y); - int iz = xs_RoundToInt(key.z); - return (hash_t)(ix + (iy<<9) + (iz<<18)); - } - - // Compares two keys, returning zero if they are the same. - int Compare(const FModelVertex &left, const FModelVertex &right) - { - return left.x != right.x || left.y != right.y || left.z != right.z || left.u != right.u || left.v != right.v; - } -}; - -struct FIndexInit -{ - void Init(unsigned int &value) - { - value = 0xffffffff; - } -}; - -typedef TMap FVoxelMap; - - -class FVoxelModel : public FModel -{ -protected: - FVoxel *mVoxel; - bool mOwningVoxel; // if created through MODELDEF deleting this object must also delete the voxel object - FTextureID mPalette; - unsigned int mNumIndices; - TArray mVertices; - TArray mIndices; - - void MakeSlabPolys(int x, int y, kvxslab_t *voxptr, FVoxelMap &check); - void AddFace(int x1, int y1, int z1, int x2, int y2, int z2, int x3, int y3, int z3, int x4, int y4, int z4, uint8_t color, FVoxelMap &check); - unsigned int AddVertex(FModelVertex &vert, FVoxelMap &check); - -public: - FVoxelModel(FVoxel *voxel, bool owned); - ~FVoxelModel(); - bool Load(const char * fn, int lumpnum, const char * buffer, int length); - void Initialize(); - virtual int FindFrame(const char * name); - virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation=0); - virtual void AddSkins(uint8_t *hitlist); - FTextureID GetPaletteTexture() const { return mPalette; } - void BuildVertexBuffer(FModelRenderer *renderer); - float getAspectFactor(float vscale) override; -}; - - - -#define MAX_MODELS_PER_FRAME 4 // // [BB] Model rendering flags. @@ -364,37 +57,8 @@ enum MDL_USEROTATIONCENTER = 512, }; -struct FSpriteModelFrame -{ - int modelIDs[MAX_MODELS_PER_FRAME]; - FTextureID skinIDs[MAX_MODELS_PER_FRAME]; - FTextureID surfaceskinIDs[MAX_MODELS_PER_FRAME][MD3_MAX_SURFACES]; - int modelframes[MAX_MODELS_PER_FRAME]; - float xscale, yscale, zscale; - // [BB] Added zoffset, rotation parameters and flags. - // Added xoffset, yoffset - float xoffset, yoffset, zoffset; - float xrotate, yrotate, zrotate; - float rotationCenterX, rotationCenterY, rotationCenterZ; - float rotationSpeed; - unsigned int flags; - const PClass * type; - short sprite; - short frame; - FState * state; // for later! - int hashnext; - float angleoffset; - // added pithoffset, rolloffset. - float pitchoffset, rolloffset; // I don't want to bother with type transformations, so I made this variables float. - bool isVoxel; -}; - FSpriteModelFrame * FindModelFrame(const PClass * ti, int sprite, int frame, bool dropped); bool IsHUDModelForPlayerAvailable(player_t * player); -void FlushModels(); - - -extern TDeletingArray Models; // Check if circle potentially intersects with node AABB inline bool CheckBBoxCircle(float *bbox, float x, float y, float radiusSquared) diff --git a/src/r_data/models/models_md2.cpp b/src/r_data/models/models_md2.cpp index 95a45c605..03130aacc 100644 --- a/src/r_data/models/models_md2.cpp +++ b/src/r_data/models/models_md2.cpp @@ -28,6 +28,7 @@ #include "filesystem.h" #include "r_data/models/models.h" +#include "r_data/models/model_md2.h" #include "texturemanager.h" #include "modelrenderer.h" @@ -35,6 +36,9 @@ #pragma warning(disable:4244) // warning C4244: conversion from 'double' to 'float', possible loss of data #endif +enum { VX, VZ, VY }; +#define NUMVERTEXNORMALS 162 + static float avertexnormals[NUMVERTEXNORMALS][3] = { #include "tab_anorms.h" }; diff --git a/src/r_data/models/models_md3.cpp b/src/r_data/models/models_md3.cpp index a50fa5eff..4eafdaede 100644 --- a/src/r_data/models/models_md3.cpp +++ b/src/r_data/models/models_md3.cpp @@ -23,6 +23,7 @@ #include "filesystem.h" #include "cmdlib.h" #include "r_data/models/models.h" +#include "r_data/models/model_md3.h" #include "texturemanager.h" #include "modelrenderer.h" diff --git a/src/r_data/models/models_obj.cpp b/src/r_data/models/models_obj.cpp index 6e8fcef8a..643fc64f2 100644 --- a/src/r_data/models/models_obj.cpp +++ b/src/r_data/models/models_obj.cpp @@ -20,7 +20,7 @@ //-------------------------------------------------------------------------- #include "filesystem.h" -#include "r_data/models/models_obj.h" +#include "r_data/models/model_obj.h" #include "texturemanager.h" #include "modelrenderer.h" diff --git a/src/r_data/models/models_ue1.cpp b/src/r_data/models/models_ue1.cpp index 5ac8ea52f..73733c9bb 100644 --- a/src/r_data/models/models_ue1.cpp +++ b/src/r_data/models/models_ue1.cpp @@ -22,7 +22,7 @@ #include "filesystem.h" #include "cmdlib.h" -#include "r_data/models/models_ue1.h" +#include "r_data/models/model_ue1.h" #include "texturemanager.h" #include "modelrenderer.h" diff --git a/src/r_data/models/models_voxel.cpp b/src/r_data/models/models_voxel.cpp index be83256ce..eccd863bd 100644 --- a/src/r_data/models/models_voxel.cpp +++ b/src/r_data/models/models_voxel.cpp @@ -32,6 +32,7 @@ #include "bitmap.h" #include "g_levellocals.h" #include "models.h" +#include "model_kvx.h" #include "image.h" #include "texturemanager.h" #include "modelrenderer.h"