本文整理汇总了C++中ogre::Image::resize方法的典型用法代码示例。如果您正苦于以下问题:C++ Image::resize方法的具体用法?C++ Image::resize怎么用?C++ Image::resize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ogre::Image
的用法示例。
在下文中一共展示了Image::resize方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initBlendMaps
void SnowTerrain::initBlendMaps(Terrain* terrain)
{
TextureLayerFileList blendImages = mSnowConfig->terrainSettings.textureBlendFileList;
// load those blendmaps into the layers
for(int j = 0;j < terrain->getLayerCount();j++)
{
// skip first layer
if(j==0)
continue;
// no blend map for this layer
if(blendImages.size() >= j && blendImages[j].length() == 0)
continue;
Ogre::TerrainLayerBlendMap *blendmap = terrain->getLayerBlendMap(j);
Ogre::Image img;
img.load(blendImages[j],"General");
int blendmapsize = terrain->getLayerBlendMapSize();
if(img.getWidth() != blendmapsize)
img.resize(blendmapsize, blendmapsize);
float *ptr = blendmap->getBlendPointer();
Ogre::uint8 *data = static_cast<Ogre::uint8*>(img.getPixelBox().data);
for(int bp = 0;bp < blendmapsize * blendmapsize;bp++)
ptr[bp] = static_cast<float>(data[bp]) / 255.0f;
blendmap->dirty();
blendmap->update();
}
}
示例2: setDatablockIdAndTexture
//.........这里部分代码省略.........
#include <fstream>
#include <ctime>
//****************************************************************************/
TextureLayer::TextureLayer(void) :
mTextureOnWhichIsPaintedWidth(0),
mTextureOnWhichIsPaintedHeight(0),
mTextureOnWhichIsPaintedHasAlpha(false),
mNumMipMaps(0),
mTextureTypeDefined(false),
mMaxSequence(0)
{
mTextureType = Ogre::PBSM_DIFFUSE;
mDatablockId = "";
mTextureFileName = "";
}
//****************************************************************************/
TextureLayer::~TextureLayer(void)
{
}
//****************************************************************************/
void TextureLayer::setDatablockIdAndTexture (const Ogre::IdString& datablockId,
Ogre::PbsTextureTypes textureType,
const Ogre::String& textureFileName)
{
mDatablockId = datablockId;
mTextureType = textureType;
mTextureFileName = textureFileName;
mTextureTypeDefined = true;
// Load the texture as image; assume it can be loaded, because it was already loaded as part of the material
setFirstTextureGeneration();
// Create the pixelbox of the original texture; this MUST be a separate image
mOriginalTexture.load(textureFileName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
mPixelboxOriginalTexture = mOriginalTexture.getPixelBox(0, 0);
// Debug texture
//Ogre::LogManager::getSingleton().logMessage("Debug texture: " + textureFileName);
//Ogre::LogManager::getSingleton().logMessage("Depth: " + Ogre::StringConverter::toString(mOriginalTexture.getDepth()));
//Ogre::LogManager::getSingleton().logMessage("Pixel format: " + Ogre::StringConverter::toString(mOriginalTexture.getFormat()));
//Ogre::LogManager::getSingleton().logMessage("Alpha: " + Ogre::StringConverter::toString(mOriginalTexture.getHasAlpha()));
//Ogre::LogManager::getSingleton().logMessage("Height: " + Ogre::StringConverter::toString(mOriginalTexture.getHeight()));
//Ogre::LogManager::getSingleton().logMessage("Number of faces: " + Ogre::StringConverter::toString(mOriginalTexture.getNumFaces()));
//Ogre::LogManager::getSingleton().logMessage("Number of mipmaps: " + Ogre::StringConverter::toString(mOriginalTexture.getNumMipmaps()));
//Ogre::LogManager::getSingleton().logMessage("Width: " + Ogre::StringConverter::toString(mOriginalTexture.getWidth()));
}
//****************************************************************************/
void TextureLayer::blitTexture (void)
{
/* Always get the actual pointers, because they may change. That is the reason why the datablock pointer cannot be cached.
* The same seems to apply to the texture pointer.
*/
Ogre::HlmsDatablock* datablock;
Ogre::HlmsPbsDatablock* datablockPbs;
Ogre::TexturePtr texture;
Ogre::HlmsManager* hlmsManager = Ogre::Root::getSingletonPtr()->getHlmsManager();
Ogre::HlmsPbs* hlmsPbs = static_cast<Ogre::HlmsPbs*>(hlmsManager->getHlms(Ogre::HLMS_PBS));
datablock = hlmsPbs->getDatablock(mDatablockId);
if (!datablock)
return;
datablockPbs = static_cast<Ogre::HlmsPbsDatablock*>(datablock);
try
{
// Get texture on GPU
if (!datablockPbs->getTexture(mTextureType).isNull())
{
texture = datablockPbs->getTexture(mTextureType); // TextureType MUST exist, otherwise the application crashes
mNumMipMaps = texture->getNumMipmaps();
}
}
catch (Ogre::Exception e){}
if (texture.isNull())
return;
Ogre::uint8 maxMipMaps = mNumMipMaps + 1; // Increase with one, because there is always one image to blit
maxMipMaps = maxMipMaps > PAINT_MAX_MIP_MAPS ? PAINT_MAX_MIP_MAPS : maxMipMaps; // Just paint a few mipmaps (not all)
Ogre::Image textureOnWhichIsPaintedScaled = mTextureOnWhichIsPainted; // Temporary image must be used, otherwise painting doesn't work
size_t w = mTextureOnWhichIsPaintedWidth;
size_t h = mTextureOnWhichIsPaintedHeight;
Ogre::v1::HardwarePixelBuffer* buffer;
for (Ogre::uint8 i = 0; i < maxMipMaps; ++i)
{
buffer = texture->getBuffer(0, i).getPointer();
buffer->blitFromMemory(textureOnWhichIsPaintedScaled.getPixelBox(0, 0), Ogre::Box(0, 0, 0, w, h, 1));
w*=0.5f; // Mipmaps always are half of the previous one
h*=0.5f;
if (w < 1.0f || h < 1.0f)
break; // Stop when the mipmaps are too small
textureOnWhichIsPaintedScaled.resize(w, h);
}
textureOnWhichIsPaintedScaled.freeMemory();
}
示例3: processBlendmaps
void DotSceneLoader::processBlendmaps(rapidxml::xml_node<>* XMLNode)
{
int pageX = Ogre::StringConverter::parseInt(XMLNode->first_attribute("pageX")->value());
int pageY = Ogre::StringConverter::parseInt(XMLNode->first_attribute("pageY")->value());
Ogre::String filename = mTerrainGroup->generateFilename(pageX, pageY);
// skip this is terrain page has been saved already
if (!Ogre::ResourceGroupManager::getSingleton().resourceExists(mTerrainGroup->getResourceGroup(), filename))
{
rapidxml::xml_node<>* pElement;
// Process blendmaps (*)
std::vector<Ogre::String> blendMaps;
rapidxml::xml_node<>* pBlendmap;
pElement = XMLNode->first_node("blendMaps");
pBlendmap = pElement->first_node("blendMap");
while(pBlendmap)
{
blendMaps.push_back(getAttrib(pBlendmap, "texture",""));
pBlendmap = pBlendmap->next_sibling("blendMap");
}
for(int j = 1;j < mTerrainGroup->getTerrain(pageX, pageY)->getLayerCount();j++)
{
Ogre::TerrainLayerBlendMap *blendmap = mTerrainGroup->getTerrain(pageX, pageY)->getLayerBlendMap(j);
Ogre::Image img;
img.load(blendMaps[j-1],"General");
int blendmapsize = mTerrainGroup->getTerrain(pageX, pageY)->getLayerBlendMapSize();
if(img.getWidth() != blendmapsize)
img.resize(blendmapsize, blendmapsize);
float *ptr = blendmap->getBlendPointer();
Ogre::uint8 *data = static_cast<Ogre::uint8*>(img.getPixelBox().data);
for(int bp = 0;bp < blendmapsize * blendmapsize;bp++)
ptr[bp] = static_cast<float>(data[bp]) / 255.0f;
blendmap->dirty();
blendmap->update();
}
}
}
示例4: initBlendMaps
void TerrainGeometryManager::initBlendMaps(int x, int z, Ogre::Terrain* terrain )
{
bool debugBlendMaps = BOPT("DebugBlendMaps", false);
int layerCount = terrain->getLayerCount();
for (int i = 1; i < layerCount; i++)
{
blendLayerInfo_t &bi = blendInfo[i];
if(bi.blendMapTextureFilename.empty()) continue;
Ogre::Image img;
//std::pair<uint8,uint8> textureIndex = terrain->getLayerBlendTextureIndex(i);
//uint8 bti = terrain->getBlendTextureIndex(i);
try
{
img.load(bi.blendMapTextureFilename, ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);
} catch(Exception &e)
{
LOG("Error loading blendmap: " + bi.blendMapTextureFilename + " : " + e.getFullDescription());
continue;
}
TerrainLayerBlendMap *blendmap = terrain->getLayerBlendMap(i);
// resize that blending map so it will fit
Ogre::uint32 blendmapSize = terrain->getLayerBlendMapSize();
if (img.getWidth() != blendmapSize)
img.resize(blendmapSize, blendmapSize);
// now to the ugly part
float* ptr = blendmap->getBlendPointer();
for (Ogre::uint32 z = 0; z != blendmapSize; z++)
{
for (Ogre::uint32 x = 0; x != blendmapSize; x++)
{
Ogre::ColourValue c = img.getColourAt(x, z, 0);
float alpha = bi.alpha;
if (bi.blendMode == 'R')
*ptr++ = c.r * alpha;
else if (bi.blendMode == 'G')
*ptr++ = c.g * alpha;
else if (bi.blendMode == 'B')
*ptr++ = c.b * alpha;
else if (bi.blendMode == 'A')
*ptr++ = c.a * alpha;
}
}
blendmap->dirty();
blendmap->update();
}
if (debugBlendMaps)
{
for (int i = 1; i < layerCount; i++)
{
Ogre::TerrainLayerBlendMap* blendMap = terrain->getLayerBlendMap(i);
Ogre::uint32 blendmapSize = terrain->getLayerBlendMapSize();
Ogre::Image img;
unsigned short *idata = OGRE_ALLOC_T(unsigned short, blendmapSize * blendmapSize, Ogre::MEMCATEGORY_RESOURCE);
float scale = 65535.0f;
for (unsigned int x = 0; x < blendmapSize; x++)
for (unsigned int z = 0; z < blendmapSize; z++)
idata[x + z * blendmapSize] = (unsigned short)(blendMap->getBlendValue(x, blendmapSize - z) * scale);
img.loadDynamicImage((Ogre::uchar*)(idata), blendmapSize, blendmapSize, Ogre::PF_L16);
std::string fileName = "blendmap_layer_" + Ogre::StringConverter::toString(i) + ".png";
img.save(fileName);
OGRE_FREE(idata, Ogre::MEMCATEGORY_RESOURCE);
}
}
}
示例5: getTerrainNormalData
Vector4* SnowTerrain::getTerrainNormalData()
{
PixelBox* terrainNormals;
// load from normals file
if(mSnowConfig->terrainSettings.normalsDataFile.length() > 0)
{
// get terrain normal data using image
Ogre::Image img;
img.load(mSnowConfig->terrainSettings.normalsDataFile, "General");
//img.flipAroundY();
//img.flipAroundX();
size_t size = img.getWidth();
assert(img.getWidth() == img.getHeight());
if (img.getWidth() != mTerrainSize || img.getHeight() != mTerrainSize)
img.resize(mTerrainSize, mTerrainSize);
terrainNormals = &img.getPixelBox();
Vector4* floats = convertNormalsToFloats(terrainNormals, true);
//OGRE_FREE(terrainNormals->data, Ogre::MEMCATEGORY_GENERAL);
// need to swap z and y vector due to different vertical axis in normal map and world space!
for(size_t i = 0;i<mTerrainSize*mTerrainSize;i++)
{
Vector4 v = floats[i];
floats[i].z = v.y;
floats[i].y = v.z;
}
return floats;
}
else
{
// need to wait until terrain is loaded
while (getTerrain()->isDerivedDataUpdateInProgress())
{
// we need to wait for this to finish
OGRE_THREAD_SLEEP(50);
Root::getSingleton().getWorkQueue()->processResponses();
}
// Get terrain normal data using official method
//terrainNormals = getTerrain()->calculateNormals(Ogre::Rect(0,0,mTerrainSize,mTerrainSize),Rect(0,0,mTerrainSize,mTerrainSize));
Ogre::Image img;
getTerrain()->getTerrainNormalMap()->convertToImage(img);
//img.flipAroundY();
img.flipAroundX();
//img.save("test_normals.bmp");
terrainNormals = &img.getPixelBox();
Vector4* floats = convertNormalsToFloats(terrainNormals, true);
//OGRE_FREE(terrainNormals->data, Ogre::MEMCATEGORY_GENERAL);
return floats;
}
}
示例6: GetSceneManipulator
void
BrushSelector::buildPreviewBitmap( const Fairy::TextureInfo texInfo )
{
const Ogre::uchar BytePerPixel = 8;
// 读取原始image
Ogre::Image *oriImage = GetSceneManipulator()->getPreviewImage(texInfo.ownerTextureName);
// 源大纹理的大小
size_t oriImageHeight = oriImage->getHeight();
size_t oriImageWidth = oriImage->getWidth();
Ogre::uchar *oriImageData = oriImage->getData();
// 所选纹理的大小
size_t newImageWidth = texInfo.width*TexTileSize;
size_t newImageHeight = texInfo.height*TexTileSize;
// 分配一个足够大的空间来保存新建的image的数据
size_t newImagegetRowSpan = newImageWidth*oriImage->getBPP()/BytePerPixel; // 新建的image的行宽(单位为字节)
Ogre::uchar *newImageData = OGRE_ALLOC_T(Ogre::uchar, oriImageHeight*newImagegetRowSpan, Ogre::MEMCATEGORY_GENERAL);//new Ogre::uchar[newImageHeight*newImagegetRowSpan];
Ogre::uchar *newImageDataPointer = newImageData;
// 得知起始像素点
size_t startPoint = ( oriImageWidth * texInfo.topCorner + texInfo.leftCorner )
* TexTileSize * oriImage->getBPP()/BytePerPixel;
Ogre::uchar *oriImagedataPointer = oriImageData + startPoint;
// 把所选的纹理的数据提取出来,并创建一个新的image
for ( Ogre::uint i=0; i<newImageHeight; ++i )
{
memcpy(newImageDataPointer, oriImagedataPointer, newImagegetRowSpan);
newImageDataPointer += newImagegetRowSpan;
oriImagedataPointer += oriImage->getRowSpan();
}
Ogre::Image newImage;
newImage.loadDynamicImage(newImageData,newImageWidth,newImageHeight,1,oriImage->getFormat(),true);
// 如果所选纹理大于64*64,就先resize
if ( texInfo.width > 1 || texInfo.height > 1 )
newImage.resize(mPreviewImageWidth, mPreviewImageHeight);
// 如果有alpha,要与黑白图进行混合
if ( newImage.getHasAlpha() )
{
Ogre::ColourValue col;
for ( int i=0; i<mPreviewImageWidth; ++i )
{
for ( int j=0; j<mPreviewImageWidth; ++j )
{
col = newImage.getColourAt(j,i,0);
float alphaValue = col.a;
unsigned char r = col.r*255 * alphaValue + mBlackWhitePreviewImage.GetRed(i,j) * ( 1.0f - alphaValue);
unsigned char g = col.g*255 * alphaValue + mBlackWhitePreviewImage.GetGreen(i,j) * ( 1.0f - alphaValue);
unsigned char b = col.b*255 * alphaValue + mBlackWhitePreviewImage.GetBlue(i,j) * ( 1.0f - alphaValue);
// 设置到image中
mCurrentPreviewImage.SetRGB(j,i,r,g,b);
}
}
// 设置到缩略图控件中
mBrushesPreview->SetBitmap(mCurrentPreviewImage);
}
// 没有alpha,就直接拷贝数据
else
{
Ogre::ColourValue col;
for ( int i=0; i<mPreviewImageWidth; ++i )
{
for ( int j=0; j<mPreviewImageWidth; ++j )
{
col = newImage.getColourAt(j,i,0);
unsigned char r = col.r*255;
unsigned char g = col.g*255;
unsigned char b = col.b*255;
// 设置到image中
mCurrentPreviewImage.SetRGB(j,i,r,g,b);
}
}
mBrushesPreview->SetBitmap(mCurrentPreviewImage);
}
}
示例7: displayMap
void NavViewPanel::displayMap(const nav_msgs::OccupancyGrid& map)
{
boost::mutex::scoped_lock lock(map_lock_);
map_resolution_ = map.info.resolution;
// Pad dimensions to power of 2
map_width_ = map.info.width;//(int)pow(2,ceil(log2(map.info.width)));
map_height_ = map.info.height;//(int)pow(2,ceil(log2(map.info.height)));
map_origin_x_ = map.info.origin.position.x;
map_origin_y_ = map.info.origin.position.y;
//ROS_INFO("Padded dimensions to %d X %d\n", map_width_, map_height_);
// Expand it to be RGB data
int pixels_size = map_width_ * map_height_ * 3;
unsigned char* pixels = new unsigned char[pixels_size];
memset(pixels, 255, pixels_size);
for(unsigned int j=0;j<map.info.height;j++)
{
for(unsigned int i=0;i<map.info.width;i++)
{
unsigned char val;
if(map.data[j*map.info.width+i] == 100)
val = 0;
else if(map.data[j*map.info.width+i] == 0)
val = 255;
else
val = 127;
int pidx = 3*(j*map_width_ + i);
pixels[pidx+0] = val;
pixels[pidx+1] = val;
pixels[pidx+2] = val;
}
}
Ogre::DataStreamPtr pixel_stream;
pixel_stream.bind(new Ogre::MemoryDataStream( pixels, pixels_size ));
static int tex_count = 0;
std::stringstream ss;
ss << "NavViewMapTexture" << tex_count++;
try
{
map_texture_ = Ogre::TextureManager::getSingleton().loadRawData( ss.str(), Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
pixel_stream, map_width_, map_height_, Ogre::PF_BYTE_RGB, Ogre::TEX_TYPE_2D,
0);
}
catch(Ogre::RenderingAPIException&)
{
Ogre::Image image;
pixel_stream->seek(0);
float width = map_width_;
float height = map_height_;
if (map_width_ > map_height_)
{
float aspect = height / width;
width = 2048;
height = width * aspect;
}
else
{
float aspect = width / height;
height = 2048;
width = height * aspect;
}
ROS_WARN("Failed to create full-size map texture, likely because your graphics card does not support textures of size > 2048. Downsampling to [%d x %d]...", (int)width, (int)height);
image.loadRawData(pixel_stream, map_width_, map_height_, Ogre::PF_BYTE_RGB);
image.resize(width, height, Ogre::Image::FILTER_NEAREST);
ss << "Downsampled";
map_texture_ = Ogre::TextureManager::getSingleton().loadImage(ss.str(), Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, image);
}
delete [] pixels;
Ogre::SceneNode* map_node = NULL;
if ( !map_object_ )
{
static int map_count = 0;
std::stringstream ss;
ss << "NavViewMapObject" << map_count++;
map_object_ = scene_manager_->createManualObject( ss.str() );
map_node = root_node_->createChildSceneNode();
map_node->attachObject( map_object_ );
ss << "Material";
map_material_ = Ogre::MaterialManager::getSingleton().create( ss.str(), Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME );
map_material_->setReceiveShadows(false);
map_material_->getTechnique(0)->setLightingEnabled(false);
}
else
{
map_node = map_object_->getParentSceneNode();
}
Ogre::Pass* pass = map_material_->getTechnique(0)->getPass(0);
Ogre::TextureUnitState* tex_unit = NULL;
if (pass->getNumTextureUnitStates() > 0)
//.........这里部分代码省略.........
示例8: getPreviewImage
void
MaterialPreviewDialog::buildPreviewBitmap( const Ogre::String &texName )
{
const Ogre::uchar BytePerPixel = 8;
// 读取原始image
Ogre::Image *oriImage = getPreviewImage(texName);
// 源大纹理的大小
size_t oriImageHeight = oriImage->getHeight();
size_t oriImageWidth = oriImage->getWidth();
Ogre::uchar *oriImageData = oriImage->getData();
// 分配一个足够大的空间来保存新建的image的数据
size_t newImagegetRowSpan = oriImageWidth*oriImage->getBPP()/BytePerPixel; // 新建的image的行宽(单位为字节)
Ogre::uchar *newImageData = new Ogre::uchar[oriImageHeight*newImagegetRowSpan];
Ogre::uchar *newImageDataPointer = newImageData;
Ogre::uchar *oriImagedataPointer = oriImageData;
// 把所选的纹理的数据提取出来,并创建一个新的image
for ( Ogre::uint i=0; i<oriImageHeight; ++i )
{
memcpy(newImageDataPointer, oriImagedataPointer, newImagegetRowSpan);
newImageDataPointer += newImagegetRowSpan;
oriImagedataPointer += oriImage->getRowSpan();
}
Ogre::Image newImage;
newImage.loadDynamicImage(newImageData,oriImageWidth,oriImageHeight,1,oriImage->getFormat(),true);
// 如果所选纹理大于64*64,就先resize
if ( oriImageWidth > mPreviewImageWidth || oriImageHeight > mPreviewImageHeight )
newImage.resize(mPreviewImageWidth, mPreviewImageHeight);
// 如果有alpha,要与黑白图进行混合
if ( newImage.getHasAlpha() )
{
Ogre::uchar *tempPtr = newImage.getData();
assert (tempPtr);
for ( size_t i=0; i<mPreviewImageHeight; ++i )
for ( size_t j=0; j<mPreviewImageWidth; ++j )
{
// 取出alpha值
float alphaValue = (float)tempPtr[3] / 255.0f;
// 计算出经过alpha混合后的颜色值
unsigned char r = tempPtr[2] * alphaValue;
unsigned char g = tempPtr[1] * alphaValue;
unsigned char b = tempPtr[0] * alphaValue;
// 设置到image中
mCurrentPreviewImage.SetRGB(j,i,r,g,b);
tempPtr += 4;
}
// 要把指针移回到图片数据的
tempPtr -= mPreviewImageHeight * mPreviewImageWidth * 4;
// 设置到缩略图控件中
}
// 没有alpha,就直接拷贝数据
else
{
memcpy ( mCurrentPreviewImage.GetData(), newImage.getData(), newImage.getSize() );
}
}
示例9: _tmain
//.........这里部分代码省略.........
}
// Terrain initialization
Ogre::TerrainGlobalOptions* terrainglobals = OGRE_NEW Ogre::TerrainGlobalOptions();
terrainglobals->setMaxPixelError(1);
//terrainglobals->setCompositeMapDistance(30000);
//terrainglobals->setLightMapDirection(lightdir);
//terrainglobals->setCompositeMapAmbient(scenemgr->getAmbientLight());
//terrainglobals->setCompositeMapDiffuse(l->getDiffuseColour());
Ogre::TerrainMaterialGeneratorA::SM2Profile* pMatProfile =
static_cast<Ogre::TerrainMaterialGeneratorA::SM2Profile*>(terrainglobals->getDefaultMaterialGenerator()->getActiveProfile());
pMatProfile->setLightmapEnabled(false);
pMatProfile->setCompositeMapEnabled(false);
Ogre::TerrainGroup* terraingroup = OGRE_NEW Ogre::TerrainGroup(scenemgr, Ogre::Terrain::ALIGN_X_Z, terrainsize, worldsize);
terraingroup->setFilenameConvention(Ogre::String("terrain"), Ogre::String("ogt"));
terraingroup->setOrigin(Ogre::Vector3::ZERO);
Ogre::Terrain* terrain = OGRE_NEW Ogre::Terrain(scenemgr);
// terrainsettings
Ogre::Terrain::ImportData& imp = terraingroup->getDefaultImportSettings();
imp.terrainSize = terrainsize;
imp.worldSize = worldsize;
imp.minBatchSize = 33;
imp.maxBatchSize = 65;
// use float RAW heightmap as input
imp.inputFloat = buffer;
// process texture layers
imp.layerList.resize(layercount);
Ogre::StringVector blendmaps(layercount);
for(int i=0;i<layercount;i++)
{
// load layer info
Ogre::String sectionStr = Ogre::StringConverter::toString(i);
Ogre::Real layerworldsize = Ogre::StringConverter::parseReal(terrainconfig->getSetting("worldsize", sectionStr));
if (i==0)
{
// no blendmap at layer 0 (baselayer)
Ogre::String specular = terrainconfig->getSetting("specular", sectionStr);
Ogre::String normal = terrainconfig->getSetting("normal", sectionStr);
// add layer
imp.layerList[i].textureNames.push_back(specular);
imp.layerList[i].textureNames.push_back(normal);
imp.layerList[i].worldSize = layerworldsize;
}
else
{
Ogre::String specular = terrainconfig->getSetting("specular", sectionStr);
Ogre::String normal = terrainconfig->getSetting("normal", sectionStr);
Ogre::String blend = terrainconfig->getSetting("blend", sectionStr);
// add layer
imp.layerList[i].textureNames.push_back(specular);
imp.layerList[i].textureNames.push_back(normal);
imp.layerList[i].worldSize = layerworldsize;
blendmaps[i] = blend;
}
}
示例10: getPreviewImage
void
MaterialPreviewDialog::buildPreviewBitmap( const Ogre::String &texName )
{
const Ogre::uchar BytePerPixel = 8;
// 读取原始image
Ogre::Image *oriImage = getPreviewImage(texName);
// 源大纹理的大小
size_t oriImageHeight = oriImage->getHeight();
size_t oriImageWidth = oriImage->getWidth();
Ogre::uchar *oriImageData = oriImage->getData();
// 分配一个足够大的空间来保存新建的image的数据
size_t newImagegetRowSpan = oriImageWidth*oriImage->getBPP()/BytePerPixel; // 新建的image的行宽(单位为字节)
Ogre::uchar *newImageData = OGRE_ALLOC_T(Ogre::uchar, oriImageHeight*newImagegetRowSpan, Ogre::MEMCATEGORY_GENERAL);//new Ogre::uchar[oriImageHeight*newImagegetRowSpan];
Ogre::uchar *newImageDataPointer = newImageData;
Ogre::uchar *oriImagedataPointer = oriImageData;
// 把所选的纹理的数据提取出来,并创建一个新的image
for ( Ogre::uint i=0; i<oriImageHeight; ++i )
{
memcpy(newImageDataPointer, oriImagedataPointer, newImagegetRowSpan);
newImageDataPointer += newImagegetRowSpan;
oriImagedataPointer += oriImage->getRowSpan();
}
Ogre::Image newImage;
newImage.loadDynamicImage(newImageData,oriImageWidth,oriImageHeight,1,oriImage->getFormat(),true);
// 如果所选纹理大于64*64,就先resize
if ( oriImageWidth > mPreviewImageWidth || oriImageHeight > mPreviewImageHeight )
newImage.resize(mPreviewImageWidth, mPreviewImageHeight);
// 如果有alpha,要与黑白图进行混合
if ( newImage.getHasAlpha() )
{
Ogre::ColourValue col;
for ( int i=0; i<mPreviewImageWidth; ++i )
{
for ( int j=0; j<mPreviewImageWidth; ++j )
{
col = newImage.getColourAt(j,i,0);
float alphaValue = col.a;
unsigned char r = col.r*255 * alphaValue;
unsigned char g = col.g*255 * alphaValue;
unsigned char b = col.b*255 * alphaValue;
// 设置到image中
mCurrentPreviewImage.SetRGB(j,i,r,g,b);
}
}
}
// 没有alpha,就直接拷贝数据
else
{
Ogre::ColourValue col;
for ( int i=0; i<mPreviewImageWidth; ++i )
{
for ( int j=0; j<mPreviewImageWidth; ++j )
{
col = newImage.getColourAt(j,i,0);
unsigned char r = col.r*255;
unsigned char g = col.g*255;
unsigned char b = col.b*255;
// 设置到image中
mCurrentPreviewImage.SetRGB(j,i,r,g,b);
}
}
}
}
示例11: btHeightfieldTerrainShape
/* -----------------------------------------------------------------------
| build bullet height field shape and generate ogre mesh from grayscale image
|
| @param in :
| @param out: raw data of height field terrain
| ToDo: adjest grid scale, grid height, local scale, max/min height
----------------------------------------------------------------------- */
bool
buildHeightFieldTerrainFromImage(const Ogre::String& filename,
btDynamicsWorld* dynamicsWorld,
btAlignedObjectArray<btCollisionShape*>& collisionShapes,
void* &data)
{
Ogre::Image img;
try
{
img.load(filename, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
}
catch(Ogre::Exception err)
{
LOG(err.what());
return false;
}
size_t grid_w = 65, grid_h = 65; // must be (2^N) + 1
size_t grid_max_w = 129, grid_max_h = 129; // must be (2^N) + 1
size_t img_w = img.getWidth();
size_t img_h = img.getHeight();
// validate image size is (2^N) + 1
if ((img_w-1) & (img_w-2)) img_w = grid_w;
if ((img_h-1) & (img_h-2)) img_h = grid_h;
//if (img_w > grid_max_w) img_w = grid_max_w;
//if (img_h > grid_max_h) img_h = grid_max_h;
LOG("LoadImage name=%s, width=%d, height=%d, width^2+1=%d, height^2+1=%d",
filename.c_str(), img.getWidth(), img.getHeight(), img_w, img_h);
img.resize(img_w, img_h);
size_t pixelSize = Ogre::PixelUtil::getNumElemBytes(img.getFormat());
size_t bufSize = img.getSize() / pixelSize;
data = new Ogre::Real[ bufSize ];
Ogre::Real* dest = static_cast<Ogre::Real*>(data);
memset(dest, 0, bufSize);
/*
| @ Notice the alignment problem
| - uchar to float alignment
| - pixel format in bytes as rawdata type, also affects alignment
*/
Ogre::uchar* src = img.getData();
for (size_t i=0;i<bufSize;++i)
{
dest[i] = ((Ogre::Real)src[i * pixelSize] - 127.0f)/16.0f;
}
// parameter
int upAxis = 1;
btScalar gridSpacing = 5.0f;
btScalar gridHeightScale = 0.2f;
btScalar minHeight = -10.0f;
btScalar maxHeight = 10.0f;
btScalar defaultContactProcessingThreshold = BT_LARGE_FLOAT;
btHeightfieldTerrainShape *heightfieldShape =
new btHeightfieldTerrainShape(img_w, img_h,
dest,
gridHeightScale,
minHeight, maxHeight,
upAxis, PHY_FLOAT, false);
btAssert(heightfieldShape && "null heightfield");
// shape
btVector3 localScaling(1.0f, 1.0f, 1.0f);
heightfieldShape->setLocalScaling(localScaling);
collisionShapes.push_back(heightfieldShape);
// rigidBody
btDefaultMotionState* motionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,0,0)));
btRigidBody::btRigidBodyConstructionInfo cInfo(0, motionState, heightfieldShape, btVector3(0,0,0));
btRigidBody* rigidBody = new btRigidBody(cInfo);
rigidBody->setContactProcessingThreshold(defaultContactProcessingThreshold);
int flags = rigidBody->getCollisionFlags();
rigidBody->setCollisionFlags(flags | btCollisionObject::CF_DISABLE_VISUALIZE_OBJECT);
dynamicsWorld->addRigidBody(rigidBody);
// add ogre height field mesh
Ogre::SceneManager* sceneMgr = Ogre::Root::getSingletonPtr()->getSceneManager("DefaultSceneManager");
btAssert(sceneMgr);
Ogre::ManualObject* obj = sceneMgr->createManualObject("btHeightFieldEntity");
btVector3 aabbMin, aabbMax;
heightfieldShape->getAabb(btTransform(btQuaternion(0,0,0,1),btVector3(0,0,0)), aabbMin, aabbMax);
btHeightFieldProcessor callback(obj, "DefaultPlane");
heightfieldShape->processAllTriangles(&callback, aabbMin, aabbMax);
sceneMgr->getRootSceneNode()->attachObject(obj);
//.........这里部分代码省略.........