Using nxOgre with PLSM2

leonardoaraujo.santos

03-10-2007 20:45:15

Hi guys does someone already worked with PLSM2 and nxOgre?

daedar

03-10-2007 21:11:47

I do. I'm generating a PNG file (named terrain.physics.png), which is in fact the entire heightmap (alpha.0.0.png, alpha.0.1.png, ....). Then you can use the TerrainShape.
With this method, you can have the level of detail you want for your terrain shape by changing the resolution of the png file. I'm using a 512x512 resolution.

betajaen

03-10-2007 21:28:30

Grom did some work (actually I believe he got it working) with PLSM2.

leonardoaraujo.santos

03-10-2007 22:31:04

Hi daedar could you tell me how you generate a big PNG file from each png file (alpha.0.0.png, alpha.0.1.png, ....)? Did you use some Photo editor software (Photoshop, Paint or something)

daedar

04-10-2007 08:32:37

To concatenate the PNG file you can either use a program like Photoshop or Gimp and do it manually or do it programaticaly. We've got a level editor that generates the physic heightmap while saving the map. It's really simple with Ogre to read and write images:

string currentile = "terrain.Alpha."+StringConverter::toString(k)+"."+StringConverter::toString(i)+"."+StringConverter::toString(j)+".png";
Texture* texture = (Texture*)TextureManager::getSingleton().getByName(currentile).getPointer();
HardwarePixelBufferSharedPtr pixelBuffer = texture->getBuffer();
pixelBuffer->lock(HardwareBuffer::HBL_NORMAL);
const PixelBox& pixelBox = pixelBuffer->getCurrentLock();
unsigned char* pDest = static_cast<unsigned char*>(pixelBox.data);
Image img;
img.loadDynamicImage(pDest, texture->getWidth(), texture->getHeight(), texture->getFormat());
img.save("Editor/"+currentile);
pixelBuffer->unlock();


and of course yes, you can generate the physic terrain with only one heightmap with NxOgre using the TerrainShape.

uberglitch

24-10-2007 09:59:33

Hey folks, I'm also in the beginning stages of attempting to combine PLSM and NxOgre. Is there a limit to how large the terrain heightmap file can be?

For example, in my testing I'm trying to use the grand canyon map (gcanyon_height_4k2k.png). The terrain is rendering just fine, the problem of course comes with trying to get Characters to collide with it.

Since that file is a heightmap already I just figured I could do

mSceneMgr->setWorldGeometry("paginglandscape2.cfg");
mScene->createActor("ground", new TerrainShape("gcanyon_height_4k2k.png", 2000), Vector3::ZERO, "static: yes");

I sort of pulled the "2000" maxHeight out of nowhere >.>

But obviously it's not that easy :(

I tried scaling down the image to 512x512 but that didn't work either.

Can someone help point me in the right direction?

Thank you for your time, we're all in this together :D

betajaen

24-10-2007 11:59:19

http://www.ogre3d.org/phpBB2addons/view ... 1648#31648

uberglitch

25-10-2007 19:06:15

Alrighty, that link helped a bit, but my actor and terrain aren't lining up. I've tried loading it into the remote debugger, but it's so big that the debugger crashes (wtb more RAM).

The terrain stretches between (XZ) -16384, -4096 and (XZ) 16384, 4096

The file I'm loading is 4096x2048 pixels, so the final terrain is being multiplied by PLSM by 4 on both the X and Z axes.

I set the height to 1000 in the cfg file, so I know that maxheight is correct.

Given this, my actor code now looks like this:

mScene->createActor("ground", new TerrainShape("gcanyon_height_4k2k.png", 1000, "mesh-scale: 4 1 4"), Vector3(-4096, 0, -2048), "static: yes");


I'm thinking at this point that I must be off in my Pose location, I tried Vector3::Zero for the pose as well but it was way off still.

Thanks in advance for any advice you can offer :)

uberglitch

26-10-2007 16:02:39

I thought it would also be helpful to post the .cfg file I'm loading:


GroupName=PLSM2

LandScapeFileName=gcanyon_height_4k2k
FileSystem=LandScapeFileName

Width=8
Height=4

ScaleX=4096
ScaleY=1000
ScaleZ=2048

Deformable=no
VertexCompression=yes
VertexProgramMorph=yes
MaxPixelError=8

TextureStretchFactor=1

NumTextureFormatSupported=1

TextureFormatSupported0=ImagePaging
TextureFormat=ImagePaging
ImageFilename=gcanyon_texture_4k2k

NumMatHeightSplat=4

MaterialHeight1=5
MaterialHeight2=95

VisibleRenderables=75

MaxAdjacentPages=2
MaxPreloadedPages=3
MaxNumRenderables=256
MaxNumTiles=256

NumRenderablesLoading=10
PageLoadInterval=5
RenderableLoadInterval=3


IncrementRenderables=256
IncrementTiles=256

HorizonVisibilityComputing=yes

uberglitch

26-10-2007 21:43:24

Sorry for the triple post but I did it! I figured I should document it for anyone else who needs it.

Ok, I'm loading a heightmap that is 4096x2048 pixels into PLSM2 using a simple call to setWorldGeometry("configfilename.cfg");

The scaling lines in the config file look like:


ScaleX=4096
ScaleY=1000
ScaleZ=2048


This gives us our height of 1000 for the TerrainShape parameter.

The call to create the actor looks like this:


mScene->createActor("ground", new TerrainShape("terrainFileName.png", 1000, "mesh-scale: 8 1 4"), Vector3(-16384, 0, -4096), "static: yes");


When I flew around my world I was able to see that the terrain stretched from -16384X, -4096Z to +16384X, +4096Z. Since the total size is 32768 x 8192 from a 4096 x 2048 file, the appropriate scaling is 8 1 4.

Now the tricky part, my heightmap has 8x4 pages, meaning the PLSM2 assigns the origin in the very middle, so the actor needs to be offset to begin at the corner of the map, hence the Pose of "Vector3(-16384, 0, -4096)"

I hope this post can help others who are struggling with getting their landscapes to line up. At the very least you get really really good at powers of 2 :D