How to get to the vertex data at some LOD level[SOLVED]

fiesch

15-10-2005 10:02:31

Hi..

I was wondering how you can actually get to the vertex data in the terrain Pages.
I realize that i need to access Renderables, but i can't figure out how.

I'm trying to get the pagingTerrain to work with ODE, that's why i wanna access the data..

or is there a better way to do that?

fiesch

15-10-2005 11:22:16

Hm ok i noticed that I was being dumb again and that i do have access to the renderables through a rootNode Traversal...

but how can i get access to the vertex data?

tuan kuranes

15-10-2005 11:46:33

use ogreodeterrain callback system (uses query) as demoed in ogreode terrain

fiesch

15-10-2005 12:03:42

I'll look into that, thank you

fiesch

15-10-2005 21:00:27

hm i tried for a full day now, still no luck.

Actually i do get my character (no ragdoll) to collide with something, but it's way above the terrain and the reaction to the collision is just not understandable.
The same code works with the EXTERIOR_CLOSE manager perfectly.

To get the height data from the terrain i tried


String mapDef = "./Media/TsmTerrain.cfg";
physTerrain = new OgreOde::TerrainGeometry(mapDef, physWorld->getDefaultSpace());
physTerrain->setHeightListener(this);
physWorld->setCollisionListener(this);


which is of course an extremely ugly hack.
The TsmTerrain.cfg mentionned there is the copy of the PLSM2 one with the appropriate changes for MaxHeight, PageWorldX, etc...

Like I said the very same code works for the normal terrain and I just can't figure out what I'm doing wrong.

has anyone a quick hint for me?

here is the modified .cfg file for the TsmTerrain:


### WARNING
## read Data2dLoader.txt, Mapsplitterreadme.txt
## in ogreaddons paginglandscape root folder before anything here.
##
# resource group name
GroupName=PLSM2

################## HeightMap OPTIONS.

Data2DFormat=HeightField
LandScapeFileName=terrain
LandScapeExtension=png

TextureFormat=Image
ImageFilename=terrain_texture
TextureExtension=jpg

PageSize=513
TileSize=65

MaxPixelError=3

PageWorldX=15000
MaxHeight=1000
PageWorldZ=15000

VisibleRenderables=256
CameraThreshold=5
HorizonVisibilityComputing=no

Deformable=yes
#VertexCompression=yes
VertexCompression=no


VertexProgramMorph=yes
LODMorphStart=0.2


and sorry to be such a pain in the ass

tuan kuranes

15-10-2005 21:12:22

You should check ogre ode heightlistener use of query mask and check them against plsm2 height query mask used in Demo.

is it CVS Head version or latest SDK compatible or old plsm2 source ?

fiesch

15-10-2005 21:43:44

it's current cvs, this afternoon

fiesch

16-10-2005 08:58:22

another long night of trying.. i do get the feeling that if i actually get it to collide it collides with the BBox of the terrain rather the terrain itsself..

I couldn't get a definitive answer for myself... do you think this results in the right intersection / distance val?


Real TerrainGeometry::getHeightAt(const Vector3& position)
{
_ray.setOrigin(position);
_ray_query->setRay(_ray);

_height_at = 0.0;

_ray_query->execute(this);
return position.y - _height_at;
}

bool TerrainGeometry::queryResult(MovableObject *obj,Real distance)
{
return false;
}

bool TerrainGeometry::queryResult(SceneQuery::WorldFragment *fragment,Real distance)
{
_height_at = distance;
return false;
}


i did try different approaches, with and without the query callback.. no luck. either no collision at all or in mid-air

tuan kuranes

16-10-2005 13:16:20

from plsm2 demo:


//cast a ray into scene and get intersection point
Ray pickRay (mCamera->getPosition(), Vector3::NEGATIVE_UNIT_Y);
mRayQuery->setRay(pickRay);
mRayQuery->setQueryMask(RSQ_Height); //PLSM2 mask
mRayQuery->execute ();
RaySceneQueryResult& result = mRayQuery->execute();
RaySceneQueryResult::iterator i = result.begin();
if (i != result.end() && i->worldFragment)
{
position = i->worldFragment->singleIntersection;
}


position.y is height.

fiesch

16-10-2005 14:00:38

yup i also tried that... but I'll give it another try - i'm not sure how i handeled position.y

fiesch

16-10-2005 14:44:18

must have had some mixup - it >finally< works.

Thank you very much!

tuan kuranes

17-10-2005 08:17:46

can you post a patch for ogreOde ?

fiesch

17-10-2005 10:22:32

basically exactly what you wrote ;)


//TODO: This is a very ugly hack - change it!
String mapDef = "./Media/TsmTerrain.cfg";
physTerrain = new OgreOde::TerrainGeometry(mapDef, physWorld->getDefaultSpace());
physTerrain->setHeightListener(this);


in the following checkRay is a normal Ogre::Ray, and rayQuery is a normal Ogre::RaySceneQuery

(in the same class)
Real [SOME CLASS NAME]::heightAt(const Vector3& position)
{
Vector3 resPosition;
//cast a ray into scene and get intersection point
checkRay = Ray(position, Vector3::NEGATIVE_UNIT_Y);
rayQuery->setRay(checkRay);
rayQuery->setQueryMask(RSQ_Height); //PLSM2 mask
rayQuery->execute ();
RaySceneQueryResult& result = rayQuery->execute();
RaySceneQueryResult::iterator i = result.begin();
if (i != result.end() && i->worldFragment)
{
resPosition = i->worldFragment->singleIntersection;
}
return resPosition.y;
}


the class needs to be subclassed from public OgreOde::TerrainGeometryHeightListener

that's basically all there is to it, easy as pie.
Don't ask me why i tok so long to get it to work but now at least i know a bit more about Ogre's and PLSM2's Nuts and Bolts

tuan kuranes

17-10-2005 10:30:23

Thanks, hope it will help Other OgreOde users.

SuperMegaMau

21-02-2006 00:06:24

hi,

Here is another OgreOde user :) I have some problems understanding the cfg files between PSLM and OgreOde. Using Terrain SM or PLSM2 we must have a cfg file where that 3 directives PageWorldX, MaxHeight and PageWorldZ are defined.

So, I can place them into my cfg file or load another cfg, but how can I create a physics geometry of the terrain that fits the visible terrain?

tuan kuranes

21-02-2006 08:29:16

Don't crosspost.

So, I can place them into my cfg file or load another cfg, but how can I create a physics geometry of the terrain that fits the visible terrain?

Best would be to patch OgreOde instead...
So that it take a SM option on init, and can use plsm2 config file and syntax, and use origin terrain as center (as Terrain and plsm2 differs on origin terrain) ?

SuperMegaMau

21-02-2006 14:22:27

Don't crosspost.

ok, sorry, but I thought that the two questions were quite different! :?

So I will change the Terrain geometry of OgreOde to get ScaleX, ScaleY and ScaleZ from PLSM2 cfg files instead of PageSizeX, etc from Terrain SM. And now, the other question I've post on the other thread, is the origin of the terrain SM different from the origin og the PLSM2?

tuan kuranes

21-02-2006 14:43:58

Sorry, it looked similar to me.

As posted above, best would be to make OgreOde use origin terrain as center when using plsm2 (as yes, Terrain and plsm2 differs on origin terrain)

SuperMegaMau

21-02-2006 17:17:46

ok, now I have another problem, I get this message when doing a ray query:

../../../PlugIns/PagingLandScape2/include/OgrePagingLandScapeData2D.h:140: const Ogre::Real Ogre::PagingLandScapeData2D::getHeight(int, int) const: Assertion `mHeightData' failed.
Aborted


Don't know what this means!

tuan kuranes

21-02-2006 17:26:56

Page data is not loaded.
You need to load page before using it.
you can preload entire landscape using LoadNow getOption scene manager mechanism.

SuperMegaMau

21-02-2006 18:51:30

if I use the setOption from the plsm example,
setOption("LoadNow", camera);
the program stops there, and I have to kill the process. If I use the same method but NULL instead of camera, the program does not stop but I get the same error I've posted earlier.

tuan kuranes

21-02-2006 19:59:37

Do you use a standard map from datasrcs ?
if not, how many pages do you have ?

SuperMegaMau

21-02-2006 21:21:58

I have my own map, currently using just one Page, but because you mentioned this, I changed it to use 2x2 pages, with the same result...

edit: I realize that with the Alpes terrain I did not get this error!

tuan kuranes

22-02-2006 08:32:40

edit: I realize that with the Alpes terrain I did not get this error!
In your app ?
Can you post the terrain cfg file you have ?

SuperMegaMau

22-02-2006 15:42:49


GroupName=PLSM2
FileSystem=./datafiles/paginglandscape2/terrains/favela

LandScapeFileName=favela
LandScapeExtension=png

Width=2
Height=2

PageSize=129
TileSize=33

Data2DFormat=HeightFieldN

MaxValue=3000
MinValue=0

ScaleX=2500
ScaleY=300
ScaleZ=2500

Deformable=yes
VertexCompression=no
VertexProgramMorph=no

LODMorphStart=0.2
MaxPixelError=3

VertexNormals=yes
VertexLit=yes

TextureExtension=png
TextureStretchFactor=2

NumTextureFormatSupported=19

TextureFormatSupported0=Image
TextureFormatSupported1=BaseTexture
TextureFormatSupported2=BaseTexture2
TextureFormatSupported3=InstantBaseTexture
TextureFormatSupported4=InstantBaseTextureEdit
TextureFormatSupported5=Splatting
TextureFormatSupported6=Splatting2
TextureFormatSupported7=Splatting2Edit
TextureFormatSupported8=Splatting4
TextureFormatSupported9=Splatting6
TextureFormatSupported10=Splatting7
TextureFormatSupported11=Splatting7Edit
TextureFormatSupported12=BaseTexture
TextureFormatSupported13=BaseTexture2
TextureFormatSupported14=InstantBaseTexture
TextureFormatSupported15=Splatting3
TextureFormatSupported16=Splatting5
TextureFormatSupported17=SplattingShader
TextureFormatSupported18=InstantBaseTextureShadowed

TextureFormat=Image
ImageFilename=favela_texture

VertexColors=no
CoverageVertexColor=no
BaseVertexColor=no
BaseVertexShadow=no
BaseVertexInstantColor=no

NumMatHeightSplat=4
MaterialHeight0=0
MaterialHeight1=12
MaterialHeight2=60
MaterialHeight3=75

SplatFilename0=splatting_sand.jpg
SplatFilename1=splatting_grass.jpg
SplatFilename2=splatting_rock.jpg
SplatFilename3=splatting_snow.jpg

VisibleRenderables=200

DistanceLOD=5
MaxRenderLevel=5
NumRenderablesLoading=50

MaxAdjacentPages=2
MaxPreloadedPages=3
ChangeFactor=1.5
CameraThreshold=5

MaxNumRenderables=256
IncrementRenderables=256
MaxNumTiles=256
IncrementTiles=256

HorizonVisibilityComputing=yes

BaseCameraViewpoint.x=0.0f
BaseCameraViewpoint.y=0.0f
BaseCameraViewpoint.z=0.0f

Baselookat.x=0.0f
Baselookat.y=0.0f
Baselookat.z=0.0f


Don't know if I understand it right, but my height map, the png file is 257x257 in size, but I set it to 129 in the cfg because it has 2 pages on each side!

tuan kuranes

22-02-2006 15:52:01

If you change pagesize, it means you have to re-run mapsplitter.
You did splitted it in 4 heighmaps using mapsplitter before launching your app ?

SuperMegaMau

22-02-2006 15:56:58

yes, of course...

SuperMegaMau

22-02-2006 18:16:41

Well, problem solved, I made some changes on the .gen.cfg file related with some light variables, and now I can see the terrain and its height too :)...

thanks a lot...