[BloodyMess 1.5.4] Heightfield creation error and .raw files

Oceax

08-06-2009 01:33:05

I am trying to create a heightfield for my terrain but i get an error i dont know how to solve.
The program fails in the following code in NxOgreManualHeightField.cpp with "access violation reading location 0x00000000" when trying to set the heightfield pointer to sdk->createHeightField(description);


NxHeightField* ManualHeightField::cook(void)
{

NxHeightField* heightfield = 0;
NxHeightFieldDesc description;

description.setToDefault();
description.nbRows = mHeightField->mNbRows;
description.nbColumns = mHeightField->mNbColumns;
description.samples = mHeightField->mSamples.first();
description.format = NX_HF_S16_TM;
description.thickness = mHeightField->mThickness;
description.verticalExtent = mHeightField->mVerticalExtent;
description.flags = 0;
description.convexEdgeThreshold = mHeightField->mConvexEdgeThreshold;
description.format = NX_HF_S16_TM;
description.sampleStride = sizeof(unsigned int);
description.flags = 0;

if (description.isValid() == false)
{
SharedStringStream message(SharedStringStream::_LARGE);
message << "An error occured creating the NxHeightFieldDesc.\nThe reason(s) and cause(s) could be:\n\n" << Reason::whyAsStream(description);
NxOgre_ThrowError(message.get());

return 0;
}

NxPhysicsSDK* sdk = NxGetPhysicsSDK();
heightfield = sdk->createHeightField(description);

return heightfield;
}


I would prefer to just use an xhf file created with flour but i dont know how to create valid .raw file for input. I have created a game editor but there i save the terrain in image format. I tried to convert an image to raw with photoshop but flour just crashes when i try to convert. How can i create a valid raw file?

Oceax

08-06-2009 12:32:22

I have fixed the problem with "access violation" , but i still would like to know how to create a valid raw file for flour. :?

betajaen

08-06-2009 13:32:23

Basically, using Photoshop as a guide (although this can apply to Gimp).

- Make it a greyscale image
- It can be 8-bit or 16-bit.
- The image size doesn't have to be the power of 2, and it doesn't have to be square.
- File, Save as (Photoshop RAW), with no header information.

You know if your raw image is correct, if you multiply the width and height, and it's the exact file size of the image. Or if it's 16-bit times it by two.


----

Also; If you don't want to use flour and raw images, but prefer to use your own system. The ManualHeightField class is an alternate way of generating heightfields for you.

Oceax

08-06-2009 16:43:59

I followed your raw guide, i tested with both 8bit and 16 bit
i used grayscale and header: 0, i checked the file size and its correct. (513*513) = 263169
i also tried with different image sizeĀ“s, etc..

nothing works, flour just crashes. :cry:

Im also trying to use ManualHeightField but i am not sure of how it works. I am using the following code and it compiles fine but it doesnt work as intended (objects dont collide with terrain)



Ogre::LogManager::getSingleton().logMessage("TerrainManager: Creating terrain physics.",LML_CRITICAL);
PhysicsManager *physicsMgr = PhysicsManager::getSingletonPtr();

std::size_t rows, cols;
rows = mTerrainMgr->getTerrainInfo().getWidth();
cols = mTerrainMgr->getTerrainInfo().getHeight();

//Start the heighfield creation by initializing the manual heightfield
mhf = new NxOgre::ManualHeightField();

mhf->begin(cols, rows);
short maxShort = 32767;
//Add each data point to the heightfield (row major order)
for(size_t i = 0; i < rows; ++i)
for(size_t j = 0; j < cols; ++j)
{

NxOgre::MaterialIdentifier matInd = 0;
short datum = short( maxShort * mTerrainMgr->getTerrainInfo().at(i,j) );
//Add sample to heightfield
mhf->sample(datum, matInd);
}
//Set how far down the bottom of the heighfield extends
// mhf->setThickness(-100);
mhf->setVerticalExtent(18000);

NxOgre::HeightField *hf = mhf->end("terrainphysics");

//Calculate size of the terrain
Vector3 extents_size = mTerrainMgr->getTerrainInfo().getExtents().getSize();

NxOgre::HeightFieldGeometry *heightFieldGeometry = new NxOgre::HeightFieldGeometry(hf,NxOgre::Real3(extents_size.x,extents_size.y,extents_size.z));
physicsMgr->getNxScene()->createSceneGeometry(heightFieldGeometry);



I would like to know what the terrain actor looks like but if i turn on visual debugger the program becomes eXtremly slow (release mode). I will try not updating the visual debugger in the framelistener, maybe that helps.