2 #include "IAttributeFields.h" 3 #include "TerrainBuffer.h" 4 #define INVALID_TEXTURE_ID (1000000) 265 class ReloadMaskRequest;
267 class CTerrainRegions;
298 enum TERRAIN_MODIFIED_BITS
303 MODIFIED_TEXTURE = 0x1,
305 MODIFIED_HEIGHTMAP = 0x1<<1,
307 MODIFIED_CONFIGURATION = 0x1<<2,
309 MODIFIED_HOLES = 0x1<<3,
311 MODIFIED_ON_LOAD_SCRIPT = 0x1<<4,
313 MODIFIED_ALL = 0xffff
319 class TextureFactory;
324 class TextureGenerator;
328 #include "TerrainCommon.h" 329 #include "TerrainException.h" 330 #include "Settings.h" 332 #include "ShapeAABB.h" 333 #include "TextureFactory.h" 334 #include "TextureCell.h" 335 #include "TextureSet.h" 336 #include "TextureGenerator.h" 337 #include "TerrainBlock.h" 338 #include "TriangleStrip.h" 339 #include "TriangleFan.h" 340 #include "TerrainLattice.h" 341 #include "TerrainVertex.h" 342 #include "DetailTextureFactory.h" 343 #include "IAttributeFields.h" 349 struct TextureEntity;
352 struct AssetFileEntry;
358 class CDetailTextureFactory;
368 void OnMaskFileDownloaded(
int nResult,
AssetFileEntry* pAssetFileEntry);
376 tit_walkWaypoint = 2,
423 Terrain(
const float *pElevations,
int elevWidth,
int elevHeight,
const uint8 * pTextureImage,
int textureWidth,
int textureHeight,
const uint8 * pDetailTextureImage,
int detailWidth,
int detailHeight,
float vertexSpacing,
float elevationScale,
int maxNumTriangles,
float offsetX = 0.0f,
float offsetY = 0.0f);
439 Terrain(
int widthVertices,
int heightVertices,
float vertexSpacing,
int maxNumTriangles);
448 Terrain(
int maxNumTriangles,
float offsetX,
float offsetY);
468 virtual bool InvokeEditor(
int nFieldID,
const string& sParameters);
470 ATTRIBUTE_METHOD1(
Terrain, IsModified_s,
bool*) {*p1 = cls->IsModified();
return S_OK;}
471 ATTRIBUTE_METHOD1(
Terrain, SetModified_s,
bool) {cls->SetModified(p1);
return S_OK;}
473 ATTRIBUTE_METHOD1(
Terrain, IsEmpty_s,
bool*) {*p1 = cls->IsEmpty();
return S_OK;}
475 ATTRIBUTE_METHOD1(
Terrain, GetSize_s,
float*) {*p1 = cls->GetWidth();
return S_OK;}
477 ATTRIBUTE_METHOD1(
Terrain, GetOnloadScript_s,
const char**) {*p1 = cls->GetOnloadScript().c_str();
return S_OK;}
479 ATTRIBUTE_METHOD1(
Terrain, GetTerrainElevFile_s,
const char**) {*p1 = cls->GetTerrainElevFile().c_str();
return S_OK;}
481 ATTRIBUTE_METHOD1(
Terrain, GetTerrainConfigFile_s,
const char**) {*p1 = cls->GetTerrainConfigFile().c_str();
return S_OK;}
483 ATTRIBUTE_METHOD1(
Terrain, GetTerrainBaseTextureFile_s,
const char**) {*p1 = cls->GetTerrainBaseTextureFile().c_str();
return S_OK;}
484 ATTRIBUTE_METHOD1(
Terrain, SetTerrainBaseTextureFile_s,
const char*) {cls->SetTerrainBaseTextureFile(p1);
return S_OK;}
486 ATTRIBUTE_METHOD1(
Terrain, GetTerrainCommonTextureFile_s,
const char**) {*p1 = cls->GetTerrainCommonTextureFile().c_str();
return S_OK;}
487 ATTRIBUTE_METHOD1(
Terrain, SetTerrainCommonTextureFile_s,
const char*) {cls->SetTerrainCommonTextureFile(p1);
return S_OK;}
489 ATTRIBUTE_METHOD1(
Terrain, GetNumOfRegions_s,
int*) {*p1 = cls->GetNumOfRegions();
return S_OK;}
491 ATTRIBUTE_METHOD1(
Terrain, GetCurrentRegionIndex_s,
int*) {*p1 = cls->GetCurrentRegionIndex();
return S_OK;}
492 ATTRIBUTE_METHOD1(
Terrain, SetCurrentRegionIndex_s,
int) {cls->SetCurrentRegionIndex(p1);
return S_OK;}
494 ATTRIBUTE_METHOD1(
Terrain, GetCurrentRegionName_s,
const char**) {*p1 = cls->GetCurrentRegionName().c_str();
return S_OK;}
495 ATTRIBUTE_METHOD1(
Terrain, SetCurrentRegionName_s,
const char*) {cls->SetCurrentRegionName(p1);
return S_OK;}
497 ATTRIBUTE_METHOD1(
Terrain, GetCurrentRegionFilepath_s,
const char**) {*p1 = cls->GetCurrentRegionFilepath().c_str();
return S_OK;}
498 ATTRIBUTE_METHOD1(
Terrain, SetCurrentRegionFilepath_s,
const char*) {cls->SetCurrentRegionFilepath(p1);
return S_OK;}
509 bool IsModified(DWORD dwModifiedBits);
513 void SetModified(
bool bIsModified, DWORD dwModifiedBits);
519 void SetModified(
bool bIsModified);
522 void InitDeviceObjects();
524 void DeleteDeviceObjects();
526 void InvalidateDeviceObjects();
549 void RebuildRenderBuffer();
560 string GetRenderReport();
569 void SetDetailThreshold(
float threshold);
571 float GetDetailThreshold()
const;
578 void SetMaximumVisibleBlockSize(
int stride);
579 int GetMaximumVisibleBlockSize();
581 int GetWidthVertices()
const;
583 int GetHeightVertices()
const;
585 float GetWidth()
const;
587 float GetHeight()
const;
589 float GetVertexSpacing()
const;
594 float GetElevation(
float x,
float y)
const;
599 float GetElevationW(
float x,
float y)
const;
605 DWORD GetRegionValue(
const string& sLayerName,
float x,
float y);
611 DWORD GetRegionValueW(
const string& sLayerName,
float x,
float y);
616 float GetElevation(
int index)
const;
623 void GetNormal(
float x,
float y,
float &normalX,
float &normalY,
float &normalZ)
const;
630 void GetNormalW(
float x,
float y,
float &normalX,
float &normalY,
float &normalZ)
const;
632 float GetMaxElevation()
const;
636 int GetVertex(
float x,
float y)
const;
640 int GetVertexW(
float x,
float y)
const;
643 float GetVertexElevation(
int index)
const;
648 void SetVertexElevation(
int index,
float newElevation,
bool recalculate_geometry =
true);
653 void SetVertexElevation(
float x,
float y,
float newElevation);
661 void SetHole(
float x,
float y,
bool bIsHold);
669 void SetHoleLocal(
float x,
float y,
bool bIsHold);
677 void SetHoleScale(
int nHoleScale);
684 bool IsHole(
float x,
float y);
690 bool IsHoleW(
float x,
float y);
695 void CreateHoleMap(BYTE* pHoleData=NULL,
int nLength = 0);
700 void RecalcGeometry(
int index1,
int index2);
702 void RecalcGeometry();
706 void RecalcNormal(
float x,
float y);
709 void RecalcNormal(
int vertexIndex);
720 void SetAllElevations(
const float *pElevations,
int elevWidth,
int elevHeight,
float fTerrainSize,
float elevationScale = 1.0f);
722 int GetNumberOfVertices()
const;
724 float GetTextureTileWidth()
const;
726 float GetTextureTileHeight()
const;
728 int GetNumberOfTextureTilesWidth()
const;
730 int GetNumberOfTextureTilesHeight()
const;
743 bool SetTexture(
const uint8 * pTextureImage,
int width,
int height);
750 bool SetBaseTexture(
const string& filename,
int numTextureCellsX=8,
int numTextureCellsY=8);
764 bool SetCommonTexture(
const uint8 * pImage,
int width,
int height);
774 void SetCommonTexture(
const char* fileName);
781 void SetCommonTexture(
Texture * pTexture);
783 Texture *GetCommonTexture()
const;
791 int ModelViewMatrixChanged();
801 int CuboidInFrustum(
const CShapeBox & cuboid)
const;
806 bool CuboidInFogRadius(
const CShapeBox & cuboid)
const;
812 void BoxToRenderCoordinate(
CShapeBox & cuboid)
const;
815 float GetBoxToEyeMatrics(
const CShapeBox & cuboid)
const;
831 float IntersectRayW(
float startX,
float startY,
float startZ,
float dirX,
float dirY,
float dirZ,
float &intersectX,
float &intersectY,
float &intersectZ,
float fMaxDistance = INFINITY);
847 float IntersectRay(
float startX,
float startY,
float startZ,
float dirX,
float dirY,
float dirZ,
float &intersectX,
float &intersectY,
float &intersectZ,
float fMaxDistance = INFINITY);
865 float IntersectRay(
float startX,
float startY,
float startZ,
float dirX,
float dirY,
float dirZ,
float &intersectX,
float &intersectY,
float &intersectZ,
int &textureCellX,
int &textureCellY,
float &texU,
float &texV,
float fMaxDistance = INFINITY);
878 bool Pick(
int screenX,
int screenY,
float &pickedX,
float &pickedY,
float &pickedZ)
const;
895 bool Pick(
int screenX,
int screenY,
float &pickedX,
float &pickedY,
float &pickedZ,
int &textureCellX,
int &textureCellY,
float &texU,
float &texV)
const;
903 void GetTextureCoordinates(
float x,
float y,
int &textureCellX,
int &textureCellY,
float &texU,
float &texV)
const;
914 void Paint(
ParaEngine::TextureEntity* detailTexture,
float brushRadius,
float brushIntensity,
float maxIntensity,
bool erase,
float x,
float y);
915 void Paint(
int detailTextureIndex,
float brushRadius,
float brushIntensity,
float maxIntensity,
bool erase,
float x,
float y);
917 bool IsMultiTextureSupported()
const;
921 void SetLatticePosition(
int x,
int y);
925 void GetLatticePosition(
int &x,
int &y);
940 TextureCell * GetTextureCell(
int textureCellX,
int textureCellY);
944 void Write(
char *szFilename);
948 void Read(
char *szFilename);
959 void SetTextureCell(
int index,
TextureCell * pCell);
962 void WriteRawTextures(
const char *szTerrainName);
965 void WriteRawElevations(
const char *szFilename);
982 void AllocateTextureCells(
int numTextureCellsX,
int numTextureCellsY);
984 void GenerateTexture(
int widthTexels,
int heightTexels,
const char *szGeneratorName);
986 void GenerateTexture(
int widthTexels,
int heightTexels,
TextureGenerator * pGenerator);
988 static void RegisterTextureGenerator(std::string name,
TextureGenerator * pGenerator);
990 static void RegisterDefaultGenerators();
992 int GetBaseTextureWidth();
994 int GetBaseTextureHeight();
1011 if (m_refCount <= 0)
1015 uint8 *GetMaskBits(
int textureCellX,
int textureCellY,
int detailIndex,
int &maskWidth,
int &maskHeight);
1017 void ReloadMask(
int textureCellX,
int textureCellY,
int detailIndex);
1023 void LoadMaskFromDisk(
bool bForceReload =
false);
1032 int NormalizeMask(
int textureCellX,
int textureCellY,
int detailIndex,
bool bReload=
true);
1036 void SetOffset(
float x,
float y);
1040 float GetOffsetX()
const;
1044 float GetOffsetY()
const;
1046 void DigCrater(
float centerX,
float centerY,
float radius,
int textureId = -1);
1048 void GetVertices(
float centerX,
float centerY,
float radius, std::vector < TerrainVertex > &vertices);
1051 const string& GetOnloadScript();
1054 const string& GetTerrainElevFile();
1061 void SetTerrainBaseTextureFile(
const string& str);
1065 void SetTerrainCommonTextureFile(
const string& str);
1080 void GetBoundingBoxes(vector<CShapeAABB>& boxes,
const Matrix4* modelView,
const CShapeFrustum& frustum,
int nMaxBoxesNum=1024,
int nSmallestBoxStride=4);
1091 int GetNumOfRegions();
1095 void SetCurrentRegionIndex(
int nRegion);
1099 int GetCurrentRegionIndex();
1104 void SetCurrentRegionName(
const string& name);
1107 const string& GetCurrentRegionName();
1110 void SetCurrentRegionFilepath(
const string& filename);
1113 const string& GetCurrentRegionFilepath();
1118 string m_sConfigFile;
1120 string m_sBaseTextureFile;
1122 string m_sCommonTextureFile;
1124 string m_sOnLoadScript;
1133 int m_WidthVertices;
1134 int m_HeightVertices;
1136 float m_fHighResTextureRadius;
1137 float m_DetailThreshold;
1138 float m_VertexSpacing;
1141 byte* m_pVertexStatus;
1145 int m_nNumOfHoleVertices;
1155 int m_NumberOfVertices;
1159 std::vector < TextureCell * >m_TextureCells;
1160 float m_TextureTileWidth, m_TextureTileHeight;
1161 uint32 m_NumberOfTextureTilesWidth;
1162 uint32 m_NumberOfTextureTilesHeight;
1165 uint32 m_NumberOfTextureTiles;
1167 float m_FogColorRed, m_FogColorGreen, m_FogColorBlue, m_FogColorAlpha;
1168 int m_MaximumVisibleBlockSize;
1169 vector<TriangleStrip> m_pTriangleStrips;
1170 vector<TriangleFan> m_pTriangleFans;
1171 uint32 m_CountStrips, m_CountFans;
1172 bool m_bMultiTextureSupported;
1173 uint32 m_MaxNumberOfPrimitives;
1174 float m_MaxElevation;
1175 float m_OffsetX, m_OffsetY;
1176 int m_LatticePositionX, m_LatticePositionY;
1177 float m_fTerrainSize;
1179 float *m_pTextureMain;
1180 float *m_pTextureDetail;
1182 mutable int m_refCount;
1185 static std::map < std::string, TextureGenerator * >m_TextureGenerators;
1186 int m_BaseTextureWidth, m_BaseTextureHeight;
1187 std::map < std::string, ReloadMaskRequest * >m_ReloadMaskRequests;
1189 float m_fLowestVisibleHeight;
1191 static float m_DetailTextureRepeats;
1194 bool m_bMaskFileInited;
1205 Vector3 m_vRenderOffset_internal;
1209 inline void SetRenderOffset(
const Vector3& vOffset)
1211 m_vRenderOffset = vOffset;
1212 m_vRenderOffset_internal.x = vOffset.x;
1213 m_vRenderOffset_internal.y = vOffset.z;
1214 m_vRenderOffset_internal.z = vOffset.y;
1218 void SetEyePosition(
const Vector3& vEye);
1220 void Init(
int maxNumPrims,
float offX,
float offY);
1221 void Init(
const uint8 * pTextureImage,
int textureWidth,
int textureHeight,
const uint8 * pDetailTextureImage,
int detailWidth,
int detailHeight,
float offsetX = 0.0f,
float offsetY = 0.0f);
1222 void UpdateNeighbor(
Terrain * pTerrain, DIRECTION direction);
1224 inline void SetVertexStatus(
int index, byte status){
if(m_pVertexStatus != NULL) m_pVertexStatus[index] = status;};
1225 inline byte GetVertexStatus(
int index){
return m_pVertexStatus[index];};
1228 void ChopTexture(
const uint8 * pImage,
int width,
int height,
int tileSize);
1229 void PreloadTextures();
1230 void BuildVertices(
int widthVertices,
int heightVertices,
float vertexSpacing);
1236 inline void GetRenderVertex(
int nIndex,
Vector3& v){
1237 Vector3& vec = m_pVertices[nIndex];
1238 v.x = vec.x+m_vRenderOffset.x;
1239 v.y = vec.z+m_vRenderOffset.y;
1240 v.z = vec.y+m_vRenderOffset.z;
1246 void GetRenderNorm(
int nIndex,
Vector3& v)
1248 Vector3& vec= m_pNormals[nIndex];
1254 inline TriangleStrip* GetTriStrip(
int nIndex){
return &(m_pTriangleStrips[nIndex]);}
1256 if(nIndex< (
int)m_pTriangleStrips.size())
1257 return &(m_pTriangleStrips[nIndex]);
1259 m_pTriangleStrips.resize(nIndex+100);
1260 return &(m_pTriangleStrips[nIndex]);
1263 inline TriangleFan* GetTriFan(
int nIndex){
return &(m_pTriangleFans[nIndex]);}
1265 if(nIndex< (
int)m_pTriangleFans.size())
1266 return &(m_pTriangleFans[nIndex]);
1268 m_pTriangleFans.resize(nIndex+100);
1269 return &(m_pTriangleFans[nIndex]);
1279 int GetTextureIDbyPoint(
float x,
float y,
float& tileX,
float& tileY);
1285 const Vector2& uv = s_LowResTexCords[nIndex];
1291 const Vector2& uv = s_HighResTexCords[nIndex];
1296 inline void GetTexCord(
int nIndex,
float& lowU,
float& lowV,
float& detailU,
float& detailV){
1297 const Vector2& uv = s_LowResTexCords[nIndex];
1300 const Vector2& uv2 = s_HighResTexCords[nIndex];
1311 static void StaticInitUV(
int nWidthVertices,
int nNumberOfTextureTiles,
int nDetailTextureRepeats);
1325 void SetHighResTextureRadius(
float radius);
1327 float GetHighResTextureRadius();
1329 void SetDetailTextureRepeats(
float repeats);
1331 float GetDetailTextureRepeats();
1334 void SetLowestVisibleHeight(
float fHeight);
1336 float GetLowestVisibleHeight();
1342 void GetMaskFile(
string& sMaskFile,
const string& sConfigFile);
1347 bool SaveConfig(
const string& filePath);
1352 bool SaveElevation(
const string& filePath);
1357 bool SaveDetailTexture(
const string& filePath);
1366 bool LoadFromConfigFile(
const char* sFileName,
float fSize=0,
const char* relativePath=NULL);
1385 bool SaveToFile(
const char* filename=NULL);
1391 void ResizeTextureMaskWidth(
int nWidth);
1401 bool GenerateTerrainNormal(
bool bForceRegenerate=
false);
1425 bool m_useGeoMipmap;
1426 void SetSharedIndexInfoGroup(
GeoMipmapIndicesGroup* geoMipmapIndicesGroup){m_pGeoMipmapIndicesGroup = geoMipmapIndicesGroup;}
1427 void BuildGeoMipmapBuffer();
1428 void RenderGeoMipmap();
1429 void TessellateGeoMipmap();
1430 void BuildGeoMipmapBlocks();
1431 void SetBlockLod(
int indexX,
int indexY,
int level,GeoMipmapChunkType chunkType);
1433 bool IsWalkable(
float x,
float y)
const;
1434 bool IsWalkableW(
float x,
float y)
const;
1438 bool m_isEditorMode;
1439 bool m_enableTerrainCollision;
1441 bool m_bChopBaseTexture;
1442 string m_terrInfoFile;
1446 uint32* m_pTerrainInfoData;
1448 void BuildHelperMeshBuffer();
1449 void SaveInfoData(
const string& filePath);
1450 void CreateTerrainInfoData();
1452 int m_visibleEditorMeshFlag;
1453 uint32 m_visibleDataMask;
1454 uint8 m_visibleDataBitOffset;
1457 void SetTerrainInfoData(
const uint32* pInfoData,
int width);
1458 void SetVertexInfo(
int idx,uint32 data,uint32 bitMask,uint32 bitOffset);
1459 uint32 GetVertexInfo(
int idx,uint32 bitMask,uint8 bitOffset);
1460 void RefreshTerrainInfo();
1461 bool IsWalkable(
float x,
float y,
Vector3& oNormal)
const;
1462 void SetVisibleDataMask(uint32 mask,uint8 bitOffset);
1463 void SetEditorMode(
bool enable);
1472 int m_TextureCellX, m_TextureCellY, m_DetailIndex;
Which DXT Compression to Use? Obviously, there are some trade-offs between the different formats whic...
Definition: TextureEntity.h:29
this is a dummy object that to ensure static objects are destroyed properly
Definition: Terrain.h:1314
Definition: SceneObject.h:15
Definition: TerrainGeoMipmapIndices.h:36
an attribute class is a collection of attribute fields.
Definition: AttributeClass.h:10
void unref() const
Decrement the reference count by one, indicating that a pointer to this object is referencing it...
Definition: Terrain.h:1008
light-weighted file record header in memory.
Definition: AssetManifest.h:10
The Loader is a Singleton object that provides access to ElevationLoaders and TextureLoaders.
Definition: Loader.h:14
different physics engine has different winding order.
Definition: EventBinding.h:32
virtual int GetAttributeClassID()
attribute class ID should be identical, unless one knows how overriding rules work.
Definition: Terrain.h:455
A TextureSet is a pool of Texture objects that are used by a Terrain to do detail texture rendering...
Definition: TextureSet.h:29
ParaTerrain::CDetailTextureFactory * m_pDetailedTextureFactory
for high-res texture of terrain surfaces
Definition: Terrain.h:1394
virtual const char * GetAttributeClassDescription()
a static string, describing the attribute class object
Definition: Terrain.h:459
this class implements a texture factory class for detailed tile based terrain surface texture...
Definition: DetailTextureFactory.h:27
cross platform vertex/index buffer.
Definition: ParaVertexBuffer.h:18
Standard 3-dimensional vector.
Definition: ParaVector3.h:16
void GetLowResTexCord(int nIndex, float &u, float &v)
load detailed (high-res) textures, which is usually a large collection of files
Definition: Terrain.h:1284
terrain mask file callback data
Definition: Terrain.h:361
An abstract factory for managing terrain textures.
Definition: TextureFactory.h:25
Side
The "positive side" of the plane is the half space to which the plane normal points.
Definition: ParaPlane.h:32
Standard 2-dimensional vector.
Definition: ParaVector2.h:16
void GetTexCord(int nIndex, float &lowU, float &lowV, float &detailU, float &detailV)
get both low resolution and detailed texture coordinates
Definition: Terrain.h:1296
Definition: Terrain.h:1467
Represents a square region on a Terrain surface that is textured.
Definition: TextureCell.h:26
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: ParaMatrix4.h:23
virtual const char * GetAttributeClassName()
a static string, describing the attribute class object's name
Definition: Terrain.h:457
in OpenGL, there is no different between vertex and index buffer.
Definition: ParaVertexBuffer.h:78
it contains all the necessary dynamic information to render the terrain for the current frame...
Definition: TerrainBuffer.h:31
A common interface for all classes implementing IAttributeFields By implementing this class's virtual...
Definition: IAttributeFields.h:59
it presents a real or virtual file in ParaEngine.
Definition: ParaFile.h:31
void ref() const
Increment the reference count by one, indicating that this object has another pointer which is refere...
Definition: Terrain.h:999
A DetailTexture is a "layer" that can be painted onto to put texture "splats" on a terrain surface...
Definition: DetailTexture.h:23
const string & GetTerrainCommonTextureFile()
get the terrain common texture file
Definition: Terrain.h:1064
Definition: TriangleFan.h:8
it represents the quad tree node of LOD terrain data
Definition: TerrainBlock.h:22
the editable terrain regions associated with a terrain tile.
Definition: TerrainRegions.h:57
This class represents a single, contiguous chunk of terrain and is the primary public interface to De...
Definition: Terrain.h:386
Definition: TriangleStrip.h:9
void GetHighResTexCord(int nIndex, float &u, float &v)
Get the high-res texture coordinate at a specified vertex index.
Definition: Terrain.h:1290
const string & GetTerrainConfigFile()
get the terrain elevation file
Definition: Terrain.h:1057
static Vector2 * s_LowResTexCords
array of low resolution texture coordinates.
Definition: Terrain.h:1306
const string & GetTerrainBaseTextureFile()
get the terrain base texture file
Definition: Terrain.h:1060
Manages a network of Terrain objects arranged in a grid pattern to model extremely large worlds that ...
Definition: TerrainLattice.h:57
a general view frustum class.
Definition: ShapeFrustum.h:9
static Vector2 * s_HighResTexCords
array of high resolution texture coordinates.
Definition: Terrain.h:1308
Definition: TextureGenerator.h:7
a min max box.
Definition: ShapeAABB.h:190