29 #ifndef __Ogre_Terrain_H__
30 #define __Ogre_Terrain_H__
401 : terrainAlign(ALIGN_X_Z)
410 , deleteInputData(false)
418 : terrainAlign(ALIGN_X_Z)
427 , deleteInputData(false)
461 memcpy(inputFloat, rhs.
inputFloat,
sizeof(
float) * terrainSize*terrainSize);
499 NEIGHBOUR_NORTHEAST = 1,
501 NEIGHBOUR_NORTHWEST = 3,
503 NEIGHBOUR_SOUTHWEST = 5,
505 NEIGHBOUR_SOUTHEAST = 7,
565 uint16 skirtRowColSkip) = 0;
568 virtual void freeAllBuffers() = 0;
582 void freeAllBuffers();
587 void warmStart(
size_t numInstances,
uint16 terrainSize,
uint16 maxBatchSize,
614 static size_t _getNumIndexesForBatchSize(
uint16 batchSize);
626 static void _populateIndexBuffer(
uint16* pIndexes,
uint16 batchSize,
676 const String& _getDerivedResourceGroup()
const;
686 void save(
const String& filename);
700 bool prepare(
const String& filename);
721 bool prepare(
const ImportData& importData);
728 void load(
const String& filename);
743 void load(
int lodLevel = 0,
bool synchronous =
true);
788 float* getHeightData()
const;
792 float* getHeightData(
long x,
long y)
const;
798 float getHeightAtPoint(
long x,
long y)
const;
806 void setHeightAtPoint(
long x,
long y,
float h);
811 float getHeightAtTerrainPosition(
Real x,
Real y);
825 float getHeightAtWorldPosition(
const Vector3& pos);
833 const float* getDeltaData();
837 const float* getDeltaData(
long x,
long y);
843 void getPoint(
long x,
long y,
Vector3* outpos);
850 void getPointFromSelfOrNeighbour(
long x,
long y,
Vector3* outpos);
856 void getPoint(
long x,
long y,
float height,
Vector3* outpos);
860 void getPointTransform(
Matrix4* outXform)
const;
870 void getTerrainVectorAlign(
const Vector3& inVec, Alignment align,
Vector3* outVec);
892 void getVectorAlign(
const Vector3& inVec, Alignment align,
Vector3* outVec);
943 void getPositionAlign(
const Vector3& TSpos, Alignment align,
Vector3* outWSpos);
958 void getTerrainPositionAlign(
const Vector3& WSpos, Alignment align,
Vector3* outTSpos);
969 Alignment getAlignment()
const;
976 void setSize(
uint16 newSize);
978 uint16 getMaxBatchSize()
const;
980 uint16 getMinBatchSize()
const;
982 Real getWorldSize()
const;
986 void setWorldSize(
Real newWorldSize);
1013 void removeLayer(
uint8 index);
1024 void replaceLayer(
uint8 index,
bool keepBlends,
Real worldSize = 0,
const StringVector* textureNames = 0);
1029 uint8 getMaxLayers()
const;
1035 Real getLayerWorldSize(
uint8 index)
const;
1041 void setLayerWorldSize(
uint8 index,
Real size);
1051 Real getLayerUVMultiplier(
uint8 index)
const;
1058 const String& getLayerTextureName(
uint8 layerIndex,
uint8 samplerIndex)
const;
1065 void setLayerTextureName(
uint8 layerIndex,
uint8 samplerIndex,
const String& textureName);
1098 void setPosition(
const Vector3& pos);
1117 void dirtyRect(
const Rect& rect);
1124 void _dirtyCompositeMapRect(
const Rect& rect);
1136 void dirtyLightmapRect(
const Rect& rect);
1148 void dirtyLightmap();
1172 void update(
bool synchronous =
false);
1178 void updateGeometry();
1184 void updateGeometryWithoutNotifyNeighbours();
1203 void updateDerivedData(
bool synchronous =
false,
uint8 typeMask = 0xFF);
1213 void updateCompositeMap();
1228 void updateCompositeMapWithDelay(
Real delay = 2);
1249 Rect calculateHeightDeltas(
const Rect& rect);
1258 void finaliseHeightDeltas(
const Rect& rect,
bool cpuData);
1274 void finaliseNormals(
const Rect& rect,
PixelBox* normalsBox);
1283 PixelBox* calculateLightmap(
const Rect& rect,
const Rect& extraTargetRect,
Rect& outFinalRect);
1292 void finaliseLightmap(
const Rect& rect,
PixelBox* lightmapBox);
1310 std::pair<bool, Vector3> rayIntersects(
const Ray& ray,
1311 bool cascadeToNeighbours =
false,
Real distanceLimit = 0);
1318 Real getMinHeight()
const;
1320 Real getMaxHeight()
const;
1322 Real getBoundingRadius()
const;
1329 const MaterialPtr& getCompositeMapMaterial()
const;
1389 uint8 getBlendTextureIndex(
uint8 layerIndex)
const;
1392 uint8 getBlendTextureCount()
const;
1394 uint8 getBlendTextureCount(
uint8 numLayers)
const;
1401 const String& getBlendTextureName(
uint8 textureIndex)
const;
1415 void setGlobalColourMapEnabled(
bool enabled,
uint16 size = 0);
1428 void widenRectByVector(
const Vector3& vec,
const Rect& inRect,
Rect& outRect);
1437 void widenRectByVector(
const Vector3& vec,
const Rect& inRect,
1449 void freeTemporaryResources();
1463 std::pair<uint8,uint8> getLayerBlendTextureIndex(
uint8 layerIndex)
const;
1490 void _setNormalMapRequired(
bool normalMap);
1505 void _setLightMapRequired(
bool lightMap,
bool shadowsOnly =
false);
1525 void _setCompositeMapRequired(
bool compositeMap);
1528 bool _getUseVertexCompression()
const;
1545 uint16 getLODLevelWhenVertexEliminated(
long x,
long y);
1547 uint16 getLODLevelWhenVertexEliminated(
long rowOrColulmn);
1563 Terrain* getNeighbour(NeighbourIndex index);
1582 void setNeighbour(NeighbourIndex index,
Terrain* neighbour,
bool recalculate =
false,
bool notifyOther =
true);
1588 static NeighbourIndex getOppositeNeighbour(NeighbourIndex index);
1592 static NeighbourIndex getNeighbourIndex(
long offsetx,
long offsety);
1601 void notifyNeighbours();
1610 void neighbourModified(NeighbourIndex index,
const Rect& edgerect,
const Rect& shadowrect);
1617 Terrain* raySelectNeighbour(
const Ray& ray,
Real distanceLimit = 0);
1623 void _dumpTextures(
const String& prefix,
const String& suffix);
1630 static void convertWorldToTerrainAxes(Alignment align,
const Vector3& worldVec,
Vector3* terrainVec);
1632 static void convertTerrainToWorldAxes(Alignment align,
const Vector3& terrainVec,
Vector3* worldVec);
1659 return (lodLevel>=0) ? lodLevel : mNumLodLevels+lodLevel;
1663 void freeCPUResources();
1664 void freeGPUResources();
1665 void determineLodLevels();
1666 void distributeVertexData();
1667 void updateBaseScale();
1668 void createGPUBlendTextures();
1669 void createLayerBlendMaps();
1670 void createOrDestroyGPUNormalMap();
1671 void createOrDestroyGPUColourMap();
1672 void createOrDestroyGPULightmap();
1673 void createOrDestroyGPUCompositeMap();
1674 void waitForDerivedProcesses();
1675 void convertSpace(Space inSpace,
const Vector3& inVec, Space outSpace,
Vector3& outVec,
bool translation)
const;
1681 void getPointAlign(
long x,
long y, Alignment align,
Vector3* outpos);
1686 void getPointAlign(
long x,
long y,
float height, Alignment align,
Vector3* outpos);
1687 void calculateCurrentLod(
Viewport* vp);
1689 std::pair<bool, Vector3> checkQuadIntersection(
int x,
int y,
const Ray& ray);
1692 void deleteBlendMaps(
uint8 lowIndex);
1694 void shiftUpGPUBlendChannels(
uint8 index);
1696 void shiftDownGPUBlendChannels(
uint8 index);
1698 void copyBlendTextureChannel(
uint8 srcIndex,
uint8 srcChannel,
uint8 destIndex,
uint8 destChannel );
1700 void clearGPUBlendChannel(
uint8 index,
uint channel);
1702 void copyGlobalOptions();
1703 void checkLayers(
bool includeGPUResources);
1704 void checkDeclaration();
1705 void deriveUVMultipliers();
1708 void updateDerivedDataImpl(
const Rect& rect,
const Rect& lightmapExtraRect,
bool synchronous,
uint8 typeMask);
1710 void getEdgeRect(NeighbourIndex index,
long range,
Rect* outRect);
1712 void getNeighbourEdgeRect(NeighbourIndex index,
const Rect& inRect,
Rect* outRect);
1714 void getNeighbourPoint(NeighbourIndex index,
long x,
long y,
long *outx,
long *outy);
1716 void getNeighbourPointOverflow(
long x,
long y, NeighbourIndex *outindex,
long *outx,
long *outy);
1719 void removeFromNeighbours();
1800 GEN_COMPOSITE_MAP_MATERIAL
1876 size_t getPositionBufVertexSize()
const;
1877 size_t getDeltaBufVertexSize()
const;
1885 void increaseLodLevel(
bool synchronous =
false);
1889 void decreaseLodLevel();