Using PLSM2 with PagedGeometry

This is a stab at describing what needs to be done to use JohnJ's PagedGeometry Engine add-on with PLSM2.
More information on this add-on can also be found on the forums in this topic.

A Brief Overview of the Engine

The PagedGeometry engine assists with displaying large numbers of billboarded objects on terrain. For example, flora and rocks.

To use this engine one needs to obtain the following:

  • the source for the PagedGeometry engine; directions are found on the PagedGeometry wiki page
  • models in mesh format

Modifying the Demo Application

To illustrate the process, the PLSM2 demo application was modified to support PagedGeometry. The following changes were made, with the goal of getting things working as quickly as possible. Improvements are welcomed.


The createScene() method was extended to populate terrain with some trees. This is how the PagedGeometry demo operates, and in practice model placement will be done elsewhere.

Add the header includes at the top:

#include "PagedGeometry.h"
#include "ImpostorPage.h"
#include "BatchPage.h"
#include "EntityPage.h"
#include "TreeLoader.h"

Add the following to createScene (towards the bottom of the file):

//Initialize the PagedGeometry engine
PagedGeometry *trees = new PagedGeometry(mCamera, 50);
//Set up LODs

//Set up a TreeLoader for easy use
TreeLoader *treeLoader = new TreeLoader(trees, TBounds(0, 0, 1500, 1500));

Entity *myTree = mSceneMgr->createEntity("MyTree", "tree2.mesh");

for (int i = 0; i < 2000; i++)
    float x, z, yaw, scale;
    yaw = Math::RangeRandom(0, 360);
    x = Math::RangeRandom(0, 1500);
    z = Math::RangeRandom(0, 1500);
    scale = Math::RangeRandom(0.9f, 1.1f);

    treeLoader->addTree(myTree, x, z, yaw, scale);
raySceneQuery = mSceneMgr->createRayQuery(Ray(mCamera->getPosition(), Vector3::NEGATIVE_UNIT_Y));

Add the following public member to PagingLandScapeApplication:

RaySceneQuery* raySceneQuery;

This member could likely be dispensed with, and a static used in the height lookup function. However the goal is to mirror the PagedGeometry demo as closely as possible, at least initially.


With apologies to JohnJ, the weakest part of the design of the PagedGeometry demo was the method used to locate terrain height. In fairness, one is expected to replace this code with something more suitable. However, once again we are going to mirror the demo and create a lookup function in the global namespace to locate terrain height. We are also going to store a RaySceneQuery object in the application (recall the public member added above).

To make it easy to access the application from the global namespace, move the declaration of the app into the global namespace, and change
it to a pointer:

myPagingLandScapeApplication *app;

To make it clear where this goes, the edited section of code will look like:

#include "windows.h"

myPagingLandScapeApplication *app;


Since the application is now a pointer instead of an object, changes will need to be made to main, below:

app = new myPagingLandScapeApplication;

    try {
        app -> go();

That is, create the application and change "app.go" to "app->go".

Finally, add a height lookup function at the end of the file:

float getTerrainHeight(float x, float z)
    static Ray updateRay;

    updateRay.setOrigin(Vector3(x, 10000, z));
    app -> raySceneQuery->setRay(updateRay);
    app -> raySceneQuery->setQueryTypeMask(Ogre::SceneManager::WORLD_GEOMETRY_TYPE_MASK);
    app -> raySceneQuery->setWorldFragmentType(SceneQuery::WFT_SINGLE_INTERSECTION); 

    RaySceneQueryResult& qryResult = app -> raySceneQuery->execute();
    RaySceneQueryResult::iterator i = qryResult.begin();
    if (i != qryResult.end() && i->worldFragment)
        return i->worldFragment->singleIntersection.y;
    return 0;

Note this has been changed slightly from the version provided in the PagedGeometry demo, and is based off of the terrain-following camera
in the PLSM2 demo.

Changes to the Visual Studio Project

Similar changes will need to be made in other build environments, the following should make it clear what needs to be done:

Add the PagedGeometry headers to the project (listed for completeness):

  • BatchPage.h
  • EntityPage.h
  • GrassLoader.h
  • ImpostorPage.h
  • PagedGeometry.h
  • StaticBillboardSet.h
  • Timer.h
  • TreeLoader.h

Add the following source files to the project:

  • BatchPage.cpp
  • EntityPage.cpp
  • GrassLoader.cpp
  • ImpostorPage.cpp
  • PagedGeometry.cpp
  • StaticBillboardSet.cpp
  • TreeLoader.cpp

In Conclusion

Place models to be loaded somewhere in the resource path, and modify the entity construction in createScene(). The above uses the
tree2 model supplied with PagedGeometry.

Also note, if there is a problem loading a model then an incomplete impostor bitmap may be created. Delete this file (from the current working directory) before re-running the demo. Once created the impostor bitmaps can be moved anywhere in the resource path, and they will not be recreated.

There are likely oversights in the above directions, and I apologize in advance. While I tried to keep accurate notes, sometimes one fixes obvious problems without being aware of it.