mirror of
https://github.com/jmarshall23/DoomRTX.git
synced 2026-08-12 08:11:10 +02:00
94 lines
2.8 KiB
C++
94 lines
2.8 KiB
C++
/*
|
|
===========================================================================
|
|
|
|
Shared terrain source model
|
|
|
|
===========================================================================
|
|
*/
|
|
#ifndef __MODEL_TERRAIN_H__
|
|
#define __MODEL_TERRAIN_H__
|
|
|
|
#define TERRAIN_DEFAULT_VERTS 65
|
|
#define TERRAIN_DEFAULT_CELL_SIZE 512.0f
|
|
#define TERRAIN_DEFAULT_PAINT_SIZE 257
|
|
#define TERRAIN_MAX_LAYERS 4
|
|
|
|
class idTerrainPatch {
|
|
public:
|
|
idTerrainPatch();
|
|
|
|
idStr name;
|
|
idStr material;
|
|
idStr layerMaterials[TERRAIN_MAX_LAYERS];
|
|
idVec3 origin;
|
|
int width;
|
|
int height;
|
|
float cellSize;
|
|
idList<float> heights;
|
|
int paintWidth;
|
|
int paintHeight;
|
|
idList<idVec4> paintWeights;
|
|
|
|
// Editor preview cache state. Runtime code ignores this, but keeping it on the
|
|
// source object lets Radiant edit the exact model data that gets parsed/written.
|
|
unsigned int paintTexture;
|
|
bool paintTextureDirty;
|
|
int paintDirtyMinX;
|
|
int paintDirtyMinY;
|
|
int paintDirtyMaxX;
|
|
int paintDirtyMaxY;
|
|
|
|
idBounds bounds;
|
|
|
|
int SampleIndex( int x, int y ) const;
|
|
int PaintIndex( int x, int y ) const;
|
|
float SampleHeight( int x, int y ) const;
|
|
void SetHeight( int x, int y, float height );
|
|
bool SetHeightBySample( int sample, float height );
|
|
idVec4 SamplePaintWeight( int x, int y ) const;
|
|
void SetPaintWeight( int x, int y, const idVec4 &weight );
|
|
bool SetPaintWeightBySample( int sample, const idVec4 &weight );
|
|
float WorldWidth() const;
|
|
float WorldHeight() const;
|
|
float BilinearHeight( float u, float v ) const;
|
|
idVec3 VertexUV( float u, float v ) const;
|
|
idVec3 Vertex( int x, int y ) const;
|
|
idVec3 VertexNormal( int x, int y ) const;
|
|
void UpdateBounds();
|
|
void EnsureLayerData( const char *defaultMaterial );
|
|
void ClearLayerWeight( int layer );
|
|
bool SetLayerMaterials( const idStr layerMaterials[TERRAIN_MAX_LAYERS], const char *defaultMaterial );
|
|
void MarkPaintTextureDirty();
|
|
void ClearPaintTextureDirtyRect();
|
|
void MarkPaintTextureDirtyRect( int minX, int minY, int maxX, int maxY );
|
|
|
|
static idVec4 BaseLayerWeight();
|
|
static idVec4 NormalizeLayerWeight( const idVec4 &weight );
|
|
};
|
|
|
|
class idTerrainModel {
|
|
public:
|
|
idTerrainModel();
|
|
~idTerrainModel();
|
|
|
|
void Clear();
|
|
int NumTerrains() const;
|
|
idTerrainPatch * Terrain( int index );
|
|
const idTerrainPatch * Terrain( int index ) const;
|
|
idList<idTerrainPatch *> &Terrains();
|
|
const idList<idTerrainPatch *> &Terrains() const;
|
|
|
|
idTerrainPatch * AllocDefaultTerrain( const idVec3 ¢er, const char *defaultMaterial, float gridSize );
|
|
void AddTerrain( idTerrainPatch *terrain );
|
|
|
|
bool LoadFile( const char *filename, const char *defaultMaterial );
|
|
bool SaveFile( const char *filename );
|
|
|
|
static idStr FileNameForMap( const char *mapFileName );
|
|
|
|
private:
|
|
idList<idTerrainPatch *> terrains;
|
|
};
|
|
|
|
#endif
|