ogre代码学习——地形 手工和cfg创建

1. 配置文件创建地形 Terrain.cfg

# The main world texture (if you wish the terrain manager to create a material for you) 
WorldTexture=terrain_texture.jpg 
# The detail texture (if you wish the terrain manager to create a material for you) 
DetailTexture=terrain_detail.jpg 
#number of times the detail texture will tile in a terrain tile 
DetailTile=3 
# Heightmap source 
PageSource=Heightmap 
# Heightmap-source specific settings 
Heightmap.image=terrain.png 
# If you use RAW, fill in the below too 
# RAW-specific setting - size (horizontal/vertical) 
#Heightmap.raw.size=513 
# RAW-specific setting - bytes per pixel (1 = 8bit, 2=16bit) 
#Heightmap.raw.bpp=2 
# How large is a page of tiles (in vertices)? Must be (2^n)+1 
PageSize=513 
# How large is each tile? Must be (2^n)+1 and be smaller than PageSize 
TileSize=65 
# The maximum error allowed when determining which LOD to use 
MaxPixelError=3 
# The size of a terrain page, in world units 
PageWorldX=1500 
PageWorldZ=1500 
# Maximum height of the terrain 
MaxHeight=100 
# Upper LOD limit 
MaxMipMapLevel=5 
#VertexNormals=yes 
100
#VertexColors=yes 
#UseTriStrips=yes 
# Use vertex program to morph LODs, if available 
VertexProgramMorph=yes 
# The proportional distance range at which the LOD morph starts to take effect 
# This is as a proportion of the distance between the current LODs effective range, 
# and the effective range of the next lower LOD 
LODMorphStart=0.2 
# This following section is for if you want to provide your own terrain shading routine 
# Note that since you define your textures within the material this makes the 
# WorldTexture and DetailTexture settings redundant 
# The name of the vertex program parameter you wish to bind the morph LOD factor to 
# this is 0 when there is no adjustment (highest) to 1 when the morph takes it completely 
# to the same position as the next lower LOD 
# USE THIS IF YOU USE HIGH-LEVEL VERTEX PROGRAMS WITH LOD MORPHING 
#MorphLODFactorParamName=morphFactor 
# The index of the vertex program parameter you wish to bind the morph LOD factor to 
# this is 0 when there is no adjustment (highest) to 1 when the morph takes it completely 
# to the same position as the next lower LOD 
# USE THIS IF YOU USE ASSEMBLER VERTEX PROGRAMS WITH LOD MORPHING 
#MorphLODFactorParamIndex=4 
# The name of the material you will define to shade the terrain 
#CustomMaterialName=TestTerrainMaterial

键值对的配置文件,用来帮助Ogre生成高度场地形

作用1:根据高度场图片和参数,生成地形的网络模型

作用2:根据自定义材质和GPU程序,生成相应的地形材质纹理

Ogre的TerrainSceneManager 会把高度长地图 “切割” 成多个区域,每个区域成为 Page(页),通过 Tile 瓦片的数量决定页的大小,Tile代表正方形顶点组

Heightmap(高度场图)和WorldTextur(整个场景的纹理),不需要大小一样,可以通过PageWorldX 和 PageWorldZ来重新设置大小

MaxHeight 设置高度场图的高度元素与世界坐标的对应

DetailTexTure 制定一层纹理循环附着在地面上,如草地或沙场,如果需要层叠纹理半透明效果需要自定义材质


2. 不通过配置文件直接创建地形(没懂)

Ogre::DataStreamPtr Process_Loader::getSceneDataStream(SceneData& data){ 
//  为Ogre创建类似一个配置文件格式的数据
Std::string mem; 
SceneData::iterator it; 
for (it=data.bengin(); it!=data.end(); it++){ 
mem += it->first; 
mem += “=”; 
mem += it->second; 
mem+= “\n”; 

void *pMem = (void *)new unsigned char[mem.length()+1]; 
memset(pMem, 0, mem.length()+1); 
memcpy(pMem,mem.c_str(),mem.length()+1); 
//  把这些放入一个新创建的MemoryDataStream 
Ogre::DataStreamPtr pStr(new Ogre::MemoryDataStream(pMem, mem.length()+1)); 
return pStr; 

//  在创建世界时载入
Ogre::DataStreamPtr pStr = getSceneDataStream(terrainDef); 
m_sceneMgr->setWorldGeometry(pStr); 




















©️2020 CSDN 皮肤主题: 大白 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值