How to Create a Heightmap Based Terrain to Actor

kungfoomasta

04-07-2007 00:05:06

Hi! I'm working from the 0.9 SVN, and trying to get my terrain into a shape.

Previously, I've been creating a Terrain Collision Object via the terrain vertices, but I think nxOgre can do it based off the heightmap.


TerrainShape(
const NxString& imageFilename,
NxReal size,
NxReal maxHeight,
NxReal imageSize,
unsigned int rows = 40,
const ShapeParams& = "");


Is Size referring to the size of the terrain in Ogre units? The ETM is capable of creating terrain that is not square.. is there a way we can add another parametere for xSize and zSize? I think we'd also need this for the image as well. What does "rows" represent?

From another post I see the following code:
mActor = mNxScene->createActor("terrain", new TerrainShape("terrain.png", 4096, 100, 513,513, "material:terrain_texture.jpg"), Vector3::ZERO, "static: yes");

What do the parameters represent? is terrain.png the name of the greyscale image? (heightmap) What does "material:terrain_texture.jpg" do?

Will I have to look through the code to figure out what each parameter does, or is there a location that briefly describes the parameters and what they do/enable/disable?

Thanks for any information. Aside from documentation, the code looks great! :)

betajaen

04-07-2007 09:33:40

If you wait until later on today, or even tomorrow. I've cleaned up the terrainCode. It's only two arguments now.

It can even use the traditional 8-bit images, and 8-bit and 16-bit raw images now.

But for the record it goes:

new TerrainShape("nameofgreyscaleimage", size in metres(4096x4096), maxheight, image width, image height, optional params)

The "material:terrain_texture.jpg", is refering to the Physics Material of the terrain, I don't know why the material name is like a JPEG file name though. I expect somebody is confused.

kungfoomasta

04-07-2007 20:57:42

Ok, thanks for the information. I'll wait a short while, update from SVN, and see if I can get farther. I have another big project to work on.. :wink:

kungfoomasta

06-07-2007 20:13:41

9-28 TerrainShape:


TerrainShape(
const NxString& RawImageFilename,
NxReal maxHeight,
const ShapeParams& = "");


My code, using ETM for my terrain:


Ogre::Real terrainHeight = (mTerrainInfo->getExtents().getMaximum() - mTerrainInfo->getExtents().getMinimum()).y;
mTerrainActor = mNXScene->createActor(mName+"Actor", new NxOgre::TerrainShape(mName+".heightmap.png",terrainHeight), Ogre::Vector3::ZERO, "static: yes");


I get a crash:


Actor* Scene::createActor(const NxString& identifier, ShapeDescription *firstShapeDescription, const Pose& pose, ActorParams params) {
----> Actor* actor = new Actor(identifier, this, firstShapeDescription, pose, params);
mActors.lock(actor->getName(), true);
return actor;
}



Actor::Actor(const NxString& name, Scene* scene, ShapeDescription *shape, const Pose& pose, ActorParams params) : mName(name), mOwner(scene) {
_createActor(shape,pose,params);
----> mOwner->_registerActor(mName, this);
}


What is the correct way to be creating an actor out of the terrain?

Thanks in advance,

KungFooMasta

betajaen

06-07-2007 20:31:38

Bizzare. That should work. Your code crashes on inserting the Actor instance into the Container, which has never crashed.

Here is my variation on your code, and it works fine:

mScene->createActor(mName+"Actor", new SphereShape(1), Ogre::Vector3::ZERO, "static: yes");

See how it works for you, and if it crashes, we'll work from there.

kungfoomasta

07-07-2007 01:57:41

It's crashing on SphereShape also. When I get more time I'll find the line that it's crashing on, although it may take a bit of absorbing, since I don't know anything about actors. :wink:

betajaen

07-07-2007 09:44:32

I'm thinking it may be the name for some reason.

Would you find the time, would you try this piece of code?

mScene->createActor("", new CubeShape(1), Ogre::Vector3::ZERO, "static: yes");

If that doesn't work, we'll have to start comparing compilers, versions, etc.

kungfoomasta

08-07-2007 05:22:27

That didn't work also.

Here is what I'm using:
- Ogre 1.4.2 SDK
- nxOgre 9-28
- PhysX 2.7.2

I think there is a 2.7.3 out, right? The website is currently down, so I'll check it out tomorrow.

betajaen

08-07-2007 11:44:22

2.7.2 is the latest. Your using Visual Studio 2005 SP 1 right?

BloodyFanatic

08-07-2007 13:29:05

i've an other problem relating terrain heighmaps:


->createActor("terrainActor", new NxOgre::TerrainShape("terrain.png", 100 ), Ogre::Vector3::ZERO, "static: yes" );

doesn't work correct ( fps dropped below 1 fps), but

->createActor("test", new NxOgre::SphereShape(5), Ogre::Vector3::ZERO, "static: yes" );

works flawlessly...

terrain.png is the heighmap from the ogre samples

i'm using NxOgre 0.9-28 with PhysX 2.7.2 and newest Ogre CVS.

i've no clue what is wrong with it, debugging of NxOgre doesn't help... maybe you can help me... please

Edit:
debug renderer is on, and it doesn't show anything... PhysX's Remote Debugger too

betajaen

08-07-2007 13:41:07

The Debug Render is the reason why it's running at 1 FPS. ;)

If you goto NxOgreShapeDescriptionTerrain.cpp, to the function "TerrainShape::_bindToActorDescription".

Comment the lines:

#if (NX_USE_DEBUG_RENDERER_API == 1)
mShapeDescription.shapeFlags |= NX_SF_VISUALIZATION;
#endif

BloodyFanatic

08-07-2007 14:58:45

thx for the fast reply, although it doesn't solved my problem ;)
i tried this before, but had no success...
I tried to disable the debug renderer and that works :P

now to another "problem": is heighmap scaling already supported by NxOgre?
'cause i'd to set the terrain to 513x513 world units (which is the image size) to match the NxHeighmap, but the terrain itself can be easily scaled by Ogre's TSM :roll:

betajaen

08-07-2007 15:17:35

I've never liked having the Debug Render in 0.9, it's slow and not really informative. The Remote Debugger is miles better.

Anyway, 1 pixel =1 metre and sadly no terrain scaling as of yet.

kungfoomasta

09-07-2007 00:20:29

2.7.2 is the latest. Your using Visual Studio 2005 SP 1 right?

Yep.

I tried to disable the debug renderer and that works

How do you do this?

'cause i'd to set the terrain to 513x513 world units (which is the image size) to match the NxHeighmap, but the terrain itself can be easily scaled by Ogre's TSM

I don't understand this.. does this mean that the terrain size must be the same as the heightmap size? (1025 x 1025 heightmap means you have a terrain that is 1025 Ogre units by 1025 Ogre units? It's impossible to have something like (3000,100,3000) dimensions?)

betajaen

09-07-2007 00:29:48

I can't see how NxOgre doesn't work with you. My suspect is STL or Visual Studio. But if that was the case QuickGUI would of exploded by now. ;)

So I'm going to ask you to start again, delete the NxOgre directory and checkout NxOgre again.

Debug Render is automatically disabled in NxOgre. To enable it you need to turn on a compiler flag, and then you call a function in World to set it up.

Height map scaling will be in the next commit, it seems more people need it than I thought. Support will be done via the params to avoid interface changes.

kungfoomasta

09-07-2007 06:42:41

Thanks for your help so far, Betajaen. Not sure why I'm having problems, but tomorrow I'll wipe nxOgre and checkout again.

Is there a shape that can be created by a list of vertices? I'm able to get this data using ETM.

betajaen

09-07-2007 09:10:55

Not really.

You could create your own TerrainShape Shape for NxOgre. HexiDave did with his SPT NxOgre example.

BloodyFanatic

09-07-2007 11:35:29

Height map scaling will be in the next commit, it seems more people need it than I thought. Support will be done via the params to avoid interface changes.

You're my hero :D
Edit:
I don't understand this.. does this mean that the terrain size must be the same as the heightmap size? (1025 x 1025 heightmap means you have a terrain that is 1025 Ogre units by 1025 Ogre units? It's impossible to have something like (3000,100,3000) dimensions?)
Yep (for now)

luis

12-07-2007 11:49:10


Height map scaling will be in the next commit, it seems more people need it than I thought. Support will be done via the params to avoid interface changes.

I really need to scale the heightmap... In fact i prefer the old constructor for NxOgre::TerrainShape

kungfoomasta

12-08-2007 04:33:42

Was there any progress with this? We need a character controller demo for nxOgre users. :twisted:

If there already exists somebody's solution to capsule shaped characters moving over terrain, please point me in that direction. :)

KungFooMasta

betajaen

12-08-2007 10:09:32

What heightmap scaling? Yep, it's in the "mesh-scale" parameter in the shape params.

new TerrainShape("filename", maxHeight, "mesh-scale: 2 0 2")

Or if you want some sort of example for a capsule based character over terrain, I can conjure up around 10 line example for you. ;)

milacao

31-05-2008 11:22:59

Hi Betajaen,
I'm trying to create a terrain from ET, from where I get a raw image file. I think I create all the things as I should:

Within my class Scenery:

m_pWorld = new World("log: yes, time-controller: ogre");
m_pWorld->createScene("ChickenGameScene", Game::getSingleton().getCurrentSceneMgr(), "floor: yes, gravity: yes, renderer: ogre");
NxOgre::Scenes* pScenes = m_pWorld->getScenes();
NxOgre::Scene* pScene = (*pScenes)["ChickenGameScene"];
pScene->setGravity(Vector3(0.0f, -100.0f, 0.0f));
pScene->createActor("ChickenTerrain", new TerrainShape("Etterrain.raw", 100, "mesh-scale: 2 1 2"), Vector3::ZERO, "static: yes");


And then, I create a character, this way, within my class Character:

NxOgre::World* pWorld = Scenery::getSingleton().getWorld();
NxOgre::Scenes* pScenes = pWorld->getScenes();
NxOgre::Scene* pScene = (*pScenes)["ChickenGameScene"];
NxOgre::Pose pose(Vector3(650.0, 1500, 650.0), Quaternion::IDENTITY);
NxOgre::CharacterParams charParams;
charParams.setToDefault();
charParams.mType = NxOgre::CharacterParams::CT_Capsule;
charParams.mSkinWidth = 0.5;
NxOgre::Character* pCharacter = pScene->createCharacter(strName + "-PhysX", pose, charParams);
pCharacter->createNode();
pCharacter->attachMesh(strMesh);


Hardcoded position for the character is just for debuggin purposes.
When the character appears, it is far above from the terrain, and, as expected, it starts falling. But then, it reaches the floor and goes through it, stopping some amount below it. What am I doing wrong? And more, could I see what is really being used as the floor, something like wireframe mesh or so?

Thanks!

xadh00m

31-05-2008 14:08:50

You could use the remote debugger from PhysX to look into the "real" physical world of your scene...

milacao

31-05-2008 16:52:37

How?

I have already the character over the terrain, but sometimes, misteriously, he falls through the terrain and disappears... When loading the terrain I scaled it but I'm not sure, where the limits of the physX terrain are.

Thanks!

betajaen

31-05-2008 16:57:14

It's the mesh-scale and height are probably wrong. I posted a formula around here somewhere to calculate it.

http://www.ogre3d.org/phpBB2addons/view ... 7960#37960

milacao

31-05-2008 19:52:08

I've checked with RemoteDebugger. I put the two characters far over the terrain. They start falling until they reach the terrain. One of them continues falling. The other seems to stay well, but after a couple of seconds, it starts falling as well. I'm lost, because the collision should be detected and the characters should stay on the terrain, shouldn't they?

Edit: Well, as you said, there were problems with the scale :-) Now I have other issues, but they must go in other threads. Thanks!

milacao

14-06-2008 16:33:59

Thanks, Betajaen,
You were completely right, the problem was the mesh scale and the height, but also the characters's skin, which was set to 0.0f. When I set it to 0.01, they didn't fall through the floor again :-)