2020-05-30 22:01:00 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "model.h"
|
|
|
|
#include "i_modelvertexbuffer.h"
|
|
|
|
#include "tarray.h"
|
|
|
|
#include "xs_Float.h"
|
|
|
|
|
|
|
|
struct FVoxel;
|
|
|
|
struct kvxslab_t;
|
|
|
|
class FModelRenderer;
|
|
|
|
class FGameTexture;
|
|
|
|
|
|
|
|
struct FVoxelVertexHash
|
|
|
|
{
|
|
|
|
// Returns the hash value for a key.
|
|
|
|
hash_t Hash(const FModelVertex &key)
|
|
|
|
{
|
2022-10-20 20:24:25 +00:00
|
|
|
int ix = int(key.x);
|
|
|
|
int iy = int(key.y);
|
|
|
|
int iz = int(key.z);
|
2020-05-30 22:01:00 +00:00
|
|
|
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<FModelVertex, unsigned int, FVoxelVertexHash, FIndexInit> 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<FModelVertex> mVertices;
|
|
|
|
TArray<unsigned int> mIndices;
|
2021-12-30 09:30:21 +00:00
|
|
|
|
2020-05-30 22:01:00 +00:00
|
|
|
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();
|
2020-07-23 14:35:54 +00:00
|
|
|
bool Load(const char * fn, int lumpnum, const char * buffer, int length) override;
|
2020-05-30 22:01:00 +00:00
|
|
|
void Initialize();
|
2022-10-20 20:24:25 +00:00
|
|
|
virtual int FindFrame(const char* name, bool nodefault) override;
|
|
|
|
virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation, const FTextureID* surfaceskinids, const TArray<VSMatrix>& boneData, int boneStartPosition) override;
|
2022-07-23 10:05:27 +00:00
|
|
|
virtual void AddSkins(uint8_t *hitlist, const FTextureID* surfaceskinids) override;
|
2020-05-30 22:01:00 +00:00
|
|
|
FTextureID GetPaletteTexture() const { return mPalette; }
|
2020-07-23 14:35:54 +00:00
|
|
|
void BuildVertexBuffer(FModelRenderer *renderer) override;
|
2020-05-30 22:01:00 +00:00
|
|
|
float getAspectFactor(float vscale) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
|