Grass problems with ETM

NoodlesOnMyBack

13-05-2008 01:32:09

I modified the heightFunction to work with ETM and it seems to work fine, the grass its position where it should be, but when i get near to the edges of the map, Paged Geometry gets traped inside the "for" of GrassLoader::loadPage(PageInfo &page), im only using grass for the test, and it seems that its due to invalid Map Bounds values.

Im setting GrassLayer *l->setMapBounds(TBounds(0, 0, 1500, 1500));
But the grass its getting rendered everywhere, and i mean everywhere i move, even outside those limits.
I tried with the last version from SVN but its the same, im confused.

Im still trying to figure out whats going on, so i promise to provide more info.

JohnJ

13-05-2008 17:58:13

Yeah, more info would be helpful. Do you know where in loadPage() it's getting trapped? Or what loop is not exiting?

I'm not sure why ETM would cause problems, since the only difference from the demo grass is the implementation of the height function, so as long as that returns proper values and doesn't hang (and it can, if you don't use scene queries right), it should be fine.

But let me know what you find, and I'll try to help as much as I can.

NoodlesOnMyBack

13-05-2008 20:28:09

Well... i discovered some very odd things :roll:, the good news are that i solved the problem, but this is whats happening:

First, if i dont set the desity map for the grass, no matter what map bounds i set, it gets trapped.

Secondly, my terrain is 1000x1000, so i was setting


mapboundX = mapboundY = 1000;
l->setMapBounds(TBounds(0, 0, mapboundX, mapboundY));


Like this PG gets trapped, but if i set: (and here comes the odd part)


mapboundX = mapboundY = 993;
l->setMapBounds(TBounds(0, 0, mapboundX, mapboundY));


Works fine, but if i set it to >=994, it gets trapped :shock:
I thought it was my HeightFunction, but its working fine, even casting rays outside the map limits.

Heres is the code with the problem, inside the For:


void GrassLoader::loadPage(PageInfo &page)
{
//Seed random number generator based on page indexes
uint16 xSeed = static_cast<uint16>(page.xIndex % 0xFFFF);
uint16 zSeed = static_cast<uint16>(page.zIndex % 0xFFFF);
uint32 seed = (xSeed << 16) | zSeed;
srand(seed);

//Keep a list of a generated meshes
std::vector<Mesh*> *meshList = new std::vector<Mesh*>();
page.userData = (void*)meshList;

//Generate meshes
std::list<GrassLayer*>::iterator it;
for (it = layerList.begin(); it != layerList.end(); ++it){
GrassLayer *layer = *it;

//Calculate how much grass needs to be added
float volume = page.bounds.width() * page.bounds.height();
unsigned int grassCount = layer->density * densityFactor * volume;

//The vertex buffer can't be allocated until the exact number of polygons is known,
//so the locations of all grasses in this page must be precalculated.

//Precompute grass locations into an array of floats. A plain array is used for speed;
//there's no need to use a dynamic sized array since a maximum size is known.
float *position = new float[grassCount*2];
if (layer->densityMap){
if (layer->densityMap->getFilter() == MAPFILTER_NONE)
grassCount = layer->_populateGrassList_UnfilteredDM(page, position, grassCount);
else if (layer->densityMap->getFilter() == MAPFILTER_BILINEAR)
grassCount = layer->_populateGrassList_BilinearDM(page, position, grassCount);
} else {
grassCount = layer->_populateGrassList_Uniform(page, position, grassCount);
}

//Don't build a mesh unless it contains something
if (grassCount != 0){
Mesh *mesh = NULL;
switch (layer->renderTechnique){
case GRASSTECH_QUAD:
mesh = generateGrass_QUAD(page, layer, position, grassCount);
break;
case GRASSTECH_CROSSQUADS:
mesh = generateGrass_CROSSQUADS(page, layer, position, grassCount);
break;
case GRASSTECH_SPRITE:
mesh = generateGrass_SPRITE(page, layer, position, grassCount);
break;
}
assert(mesh);

//Add the mesh to PagedGeometry
Entity *entity = geom->getCamera()->getSceneManager()->createEntity(getUniqueID(), mesh->getName());
entity->setRenderQueueGroup(renderQueue);
entity->setCastShadows(false);
addEntity(entity, page.centerPoint, Quaternion::IDENTITY, Vector3::UNIT_SCALE);
geom->getSceneManager()->destroyEntity(entity);

//Store the mesh pointer
meshList->push_back(mesh);
}

//Delete the position list
delete[] position;
}
}


Probably not of very much help, since i cant reproduce the same error with the forest example, but if you want i can put logs in my app.

JohnJ

14-05-2008 04:19:37

Hmm... well I'll look over the code when I can and I'll try to spot possible hang-ups. Have you tried stepping through the code so you can pinpoint the exact line / area that's hanging up?

NoodlesOnMyBack

14-05-2008 14:03:38

I dont want you waste your time so i took the ETM sample and i added PG with the grass, the problem of course persist, so i uploaded the solution so you can see it by yourself, just move to the edges of the map and you'll see.

http://rapidshare.com/files/114833735/etm-2.2_PG.rar.html

JohnJ

15-05-2008 15:44:03

Ok, thanks, that should help a lot. It seems to be missing resources.cfg (and plugins.cfg), but hopefully I'll be able to figure it out.

Gillian_Seed

22-05-2008 00:06:13

Hi,


first, congratulations to JohnJ for the "Paged Geometry" plugin !
It's soooo easy to install and use : very nice, very smooth, very cool !
And the documentation (".pdf" + comments in the code) is just perfect !
Well done, JohnJ (I would like all the plugins would be so easy to install and use :) ) !
Useless to say that I'm waiting for your Planet Rendering Engine: it seems very cool too !


Actually, I also used ETM with PagedGeometry, but I can't succeed in using HeightFunction with ETM (I'm not a very skilled C++ developper, but I keep on learning !).


NoodlesOnMyBack, since you successfuly hacked ETM for using HeightFunction, could you, please, help me to achieve this hack, too ?

Sorry to bother you with this, but before reading your post I was thinking about turning back to Ogre's default terrain manager...


Thanks !

NoodlesOnMyBack

22-05-2008 19:53:51

Hi,


first, congratulations to JohnJ for the "Paged Geometry" plugin !
It's soooo easy to install and use : very nice, very smooth, very cool !
And the documentation (".pdf" + comments in the code) is just perfect !
Well done, JohnJ (I would like all the plugins would be so easy to install and use :) ) !
Useless to say that I'm waiting for your Planet Rendering Engine: it seems very cool too !


Actually, I also used ETM with PagedGeometry, but I can't succeed in using HeightFunction with ETM (I'm not a very skilled C++ developper, but I keep on learning !).


NoodlesOnMyBack, since you successfuly hacked ETM for using HeightFunction, could you, please, help me to achieve this hack, too ?

Sorry to bother you with this, but before reading your post I was thinking about turning back to Ogre's default terrain manager...


Thanks !


No bothering bro, thats why the forum exists in the first place :)
The HeightFunction its only to get the Y value of the paged objects, so you just use the rayIntersects function of ETM.
Did you checked the rapidshare link i posted above? There you have the modified function, but if you are very lazy like me, here it is:


//This provides functions that can be used to easily get the height of Ogre's terrain at any x/z point.
//Simply call HeightFunction::initialize(), then use HeightFunction::getTerrainHeight() as needed.

//This file is used by the PagedGeometry examples to place trees on the terrain.

#include "Ogre.h"
using namespace Ogre;

#include "GameSystemManager.h"

namespace HeightFunction
{
class MyRaySceneQueryListener: public RaySceneQueryListener
{
public:
inline bool queryResult(SceneQuery::WorldFragment *fragment, Real distance)
{
resultDistance = distance;
return false;
}
inline bool queryResult(MovableObject *obj, Real distance)
{
resultDistance = distance;
return false;
}

float resultDistance;
};

bool initialized = false;
RaySceneQuery* raySceneQuery;
Ray updateRay;
MyRaySceneQueryListener *raySceneQueryListener;

//Initializes the height function. Call this before calling getTerrainHeight()
void initialize(SceneManager *sceneMgr){
if (!initialized){
initialized = true;

}
}

//Gets the height of the terrain at the specified x/z coordinate
//The userData parameter isn't used in this implementation of a height function, since
//there's no need for extra data other than the x/z coordinates.
inline float getTerrainHeight(const float x, const float z, void *userData = NULL){

Real result = getTerrainHeightAt(x,z); //This is the important line

return result;
}
}


The getTerrainHeightAt function i made is this:



Ogre::Real TerrainSystem::getTerrainHeightAt(Real x,Real z) {

Ray ray;
ray.setOrigin(Vector3(x, 0.0f, z));
ray.setDirection(Vector3::UNIT_Y);

std::pair<bool, Vector3> result = mTerrainInfo->rayIntersects(ray);
if (result.first)
{
return result.second.y;
}
return 0.0f;
}

Gillian_Seed

23-05-2008 19:12:01

Thank you very much, for your help, NoodlesOnMyBack !

I'm on it ! :) ... and it worked (I will tweak the scene later ;) )





Thanks again, guys !

MOROHEUZ

26-05-2008 16:03:21

ok it works... i have the freeze too...

@ the edge freeze .... :twisted:

have some the answer ??

i will test the dynamic tree this days ..
perhaps with cegui menu to change the trees ??

think everyone this is IMpossible ??

NoodlesOnMyBack

26-05-2008 21:39:32

ok it works... i have the freeze too...

@ the edge freeze .... :twisted:

have some the answer ??

i will test the dynamic tree this days ..
perhaps with cegui menu to change the trees ??

think everyone this is IMpossible ??


About the freezing, i didnt keep looking at the code of Paged Geometry, but it seems its related with the size of the mesh you are trying to add.
I solved it substracting the map bounds values:


mapboundX = mapboundY = 993; //This is variable depending on the mesh
l->setMapBounds(TBounds(0, 0, mapboundX, mapboundY));


A quick hack actually than a fix, but at least works, i was hoping someone more experienced with PG try to fix this *cof JohnJ cof*. :D

I made a little CEGUI window to handle Paged Geometry, if you want i can share the code.
You can change all properties of grass and trees, and choose any resource you have, you'll have to change some things tho.

MOROHEUZ

27-05-2008 07:44:12

If you could publish it, I would be happy.
Would I save some time ...
with CEGUi I already know better how to deal with Ogre.

load youthe *. mesh on the Resource_Group or mesh in the C + + code deposited. (I think probably the first one)

I can you at the moment for this project does not offer much except in demo Save the Load function, a NEWTerrain function and just different brushes and slider for Speed, Brush Size, Inensity and a model for loading combo function of objects on the Resource Group (which you probably already have :-)

How would you like it because the best? E-mail, or PN Rapidshare?

here is an Link to an Picture from my CEGUI work (only few Weeks my beginn :-( (sorry no Thumbnail)

http://www.x4.crykand.de/gallery/images/1_38.jpg


iam very Interrestet how you solved the CEGUI & Resourcegroup inserts for PG ... for single Meshes i have use a code so like in Demo_Ocean .. with Insert button too..

Greetz Moroheuz

JohnJ

27-05-2008 15:17:19

i was hoping someone more experienced with PG try to fix this *cof JohnJ cof*.
Sorry about that. I've been really busy lately, and had trouble getting the example working due to some missing files. I'll try again today if I can.

NoodlesOnMyBack

27-05-2008 20:35:40

i was hoping someone more experienced with PG try to fix this *cof JohnJ cof*.
Sorry about that. I've been really busy lately, and had trouble getting the example working due to some missing files. I'll try again today if I can.


ha! np John, life comes first, take your time.
I just checked the .zip again and in the BIN folder i see all .cfg's needed, what other file you need?

JohnJ

28-05-2008 16:04:29

Ok, thanks, I got it working now. I was looking in the release folder after I compiled, and somehow I missed that the zip only included data for the debug folder.

Anyway, I think I found the problem. When I go to the map edge with the code you sent me, it freezes. When I disable setting a height function, it no longer freezes near the edges, beyond the edges, or anywhere. When I reenable the height function, and comment out the code in the height function and replace with "return 0;", the freezing is also stopped.

Unless I'm missing something here, the freezing problem is entirely the fault of the ray scene query implementation (probably by ETM), since removing that code solves the freeze problem as I originally suspected it would. In other words it's not freezing in PagedGeometry, but most likely ETM.

P.S. I notice in the height function you're using some logging functions. I would not recommend this if you want good performance - with dense grass this would result in thousands of file writes per second. Not good.

sisyphus

09-09-2008 20:55:34

@NoodlesOnMyBack - I would like to get a chance to look at the CEGUI code you have for handling Paged Geometry....