PagedGeometry and Advanced terrain


12-09-2008 01:36:46

Hi all, I'm trying to use pagedgeometry with a terrain managed by advantage terrain.

but I have some problem, after I had include the headers into my project, and linked the paged geometry library, I tried to load a single tree but I can't see it.

here the code:
#include "ExampleApplication.h"
#include "OgreAVTerrainSceneManager.h"
//Include PagedGeometry headers that will be needed
#include "PagedGeometry.h"
#include "BatchPage.h"
#include "ImpostorPage.h"
#include "TreeLoader3D.h"

//Include "HeightFunction.h", a header that provides some useful functions for quickly and easily
//getting the height of the terrain at a given point.
//#include "HeightFunction.h"
//PagedGeometry's classes and functions are under the "Forests" namespace
using namespace Forests;

/** Application class */
class AdVantageTerrainApplication : public ExampleApplication

PagedGeometry *trees;

RaySceneQuery* getRaySceneQuery() const { return mRaySceneQuery; }

AVTerrainSceneManager* getTerrainSceneManager() const { return static_cast<AVTerrainSceneManager*>(mSceneMgr); }


void createScene();

void createFrameListener();

void chooseSceneManager();

RaySceneQuery* mRaySceneQuery;

//Update lod trees

void AdVantageTerrainApplication::createScene()

Real viewRange = 200000;

//mSceneMgr->setFog(FOG_LINEAR, ColourValue(0.598f, 0.496f, 0.375), 0.001, viewRange * 0.6, viewRange * 0.9);
mSceneMgr->setOption("ViewRange", &viewRange);
mSceneMgr->setOption("PrimaryCamera", mCamera);

mCamera->setPosition(Vector3(19734.6, 56566.5, 204230.0));

Light *sunLight = mSceneMgr->createLight("Sun");
Vector3 sundir(1,-1,0);

mSceneMgr->setSkyBox(true, "sky");

Entity* ogreHead = mSceneMgr->createEntity("Head", "ogrehead.mesh");
SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();

mRaySceneQuery = mSceneMgr->createRayQuery(Ray(mCamera->getPosition(), Vector3::NEGATIVE_UNIT_Y));

//-------------------------------------- LOAD TREES --------------------------------------
//Create and configure a new PagedGeometry instance
trees = new PagedGeometry();
trees->setCamera(mCamera); //Set the camera so PagedGeometry knows how to calculate LODs
trees->setPageSize(80); //Set the size of each page of geometry
trees->setInfinite(); //Use infinite paging mode
trees->addDetailLevel<BatchPage>(150, 50); //Use batches up to 150 units away, and fade for 30 more units
trees->addDetailLevel<ImpostorPage>(500, 50); //Use impostors up to 400 units, and for for 50 more units

//Create a new TreeLoader3D object
TreeLoader3D *treeLoader = new TreeLoader3D(trees, TBounds(0, 0, 1500, 1500));
trees->setPageLoader(treeLoader); //Assign the "treeLoader" to be used to load geometry for the PagedGeometry instance

//Setup the height function (so the Y values of trees can be calculated when they are placed on the terrain)

//Randomly place 20,000 copies of the tree on the terrain

Vector3 position;
Radian yaw= Degree(Math::RangeRandom(0, 360));
Real scale=Math::RangeRandom(50, 80);;

treeLoader->addTree(ogreHead, position, yaw, scale);

I tried to load a single tree (really an ogre head), but I can't see it.

note: I can see the ogre head loaded as normal scenenode.

next step will be, load a lot of trees with random position and runtime-calculated height of terrain in a x,z point. However I should first resolve this problem.

can you help me? thanks


12-09-2008 04:24:10

I'm no expert... but it looks like your camera is just too far away to see it. You're final Impostor Page fades out after 500 units, but you are dealing with units much larger than this. Speaking of which, why the huge units.

For example, instead of positioning your camera at (19734.6, 56566.5, 204230.0), why not at something more workable like (197, 565, 204)? I think you should scale down all your world coordinates both for simplicity and float precision. Especially if you want to integrate physics.

Also, are you updating the trees PagedGeometry every frame?


12-09-2008 05:40:13

Yeah, your coordinates are huge (24885.4, etc.), while the PagedGeometry code seems to be a stock cut-and-paste from the examples. You either need to scale down your world size, or adjust the PagedGeometry view distances and batch size to fit your world, because right now PagedGeometry is operating with a few hundred units (anything beyond that doesn't get displayed), while your world seems to be many thousand units large. The tutorials should explain this I think, and how to proper configure it.

Also, like rubasurex said, having a unit scale like this is usually a bad idea, especially when you get into physics engines. As a general rule, you should try to keep 1 unit = 1 meter or somewhere around there, because that's what most physics engines use.


12-09-2008 08:47:27

the scale of the mesh is so larger because I wanted see it :P

I follow the first tutorial and after, I see that the code is similar to example1.

myApp->trees->update(); is called in the framelistener under framestarted.

so, mesh don't appears because camera is too far.. I suspect this, then I tried to add this code:
treeLoader->addTree(ogreHead, position, yaw, scale);

mCamera->setPosition(Vector3(position.x+20, position.y+20,position.z+20));

and I can't still see the ogre head. any idea?

ps: I need a world 20km x 20km larger, so my terrain size is 20000x20000x1500 (in advantage terrain the z axis is up). there is other way to obtain this?


15-09-2008 03:27:44

ps: I need a world 20km x 20km larger, so my terrain size is 20000x20000x1500 (in advantage terrain the z axis is up). there is other way to obtain this?
Those measurements should work, but if you're using a non-standard coordinate system (like Z for up), you'll need to un-comment the "//#define PAGEDGEOMETRY_ALTERNATE_COORDSYSTEM" in PagedGeometry.h, and call "trees->setCoordinateSystem(Vector3::UNIT_Z);" Otherwise the LOD system will be all messed up and won't work properly.

Also make sure you have PagedGeometry's viewing ranges set up as you like; the code you gave won't draw anything farther than 500 meters, so that may or may not be what you want). Then, scale the Ogre head to a reasonable level (if it's too big and too close, the camera may actually end up inside the Ogre head, in which case you probably won't see anything).

If that still doesn't work, let me know.


24-09-2008 09:58:02

I resolved, thanks, but now I have another problem.

I'll open a thread for this.