Cant create Terrain using Sample App Code

CrimsonGT

16-11-2009 13:55:38

Ive been trying to implement PCZSceneManager into my project for a couple days now, and after extensive debugging I am clueless as to whats wrong with it. I am using the createTerrainZone() function from the demo application, but its crashing out everytime. I setup my application as closely to the demo as possible, but so far no luck. Heres what my createScene() looks like...


void WorldState::createScene()
{
static const ColourValue skyColor(195.0 / 255, 232.0 / 255, 1);

// SCENE SKYBOX
gSceneManager->setSkyBox(true, "SkyBox", 1100);
// Put the Skybox in the Default Zone
((PCZSceneManager*)gSceneManager)->setSkyZone(0);

// SCENE LIGHT & FOG
gSceneManager->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
gSceneManager->setFog(FOG_LINEAR, skyColor, 0.001, 500, 1000);

// SCENE CAMERA & VIEWPORT
gCamera = gSceneManager->createCamera("MainCam");
gCamera->setFarClipDistance(2000);
gCamera->setNearClipDistance(12);
gViewport = gRenderWindow->addViewport(gCamera);
gViewport->setBackgroundColour(skyColor);
gCamera->setAspectRatio((float)gViewport->getActualWidth() / gViewport->getActualHeight());

// create a terrain zone
std::string terrain_cfg("terrain.cfg");
std::string zoneName("Terrain1_Zone");
PCZone * terrainZone = createTerrainZone(zoneName, terrain_cfg);
//gSceneManager->setWorldGeometry("terrain.cfg");

// SCENE SHADOW SETTINGS
gSceneManager->setShadowTechnique(Ogre::SHADOWTYPE_TEXTURE_MODULATIVE);
gSceneManager->setShadowFarDistance(200);
gSceneManager->setShadowColour(ColourValue(0.7, 0.73, 0.75));
gSceneManager->setShadowTextureSize(512);

// SCENE SUNLIGHT
Light* light = gSceneManager->createLight("Sun");
light->setType(Light::LT_DIRECTIONAL);
light->setDirection(Vector3(0, -1, -0.5));

// Create the Title Canvas that we will use to display actor titles
titleCanvas = new TitleCanvas(gCamera, "fonts/LucidaSans.ttf", gSceneManager);

// Create our 'walk-target' decal (indicates the point that the player is walking to)
targetDecal = new TerrainDecal("targetDecal", "Target", Vector2(10, 10), Vector2(), gSceneManager, .5, 6);

// Create the ray-scene-query for our target decal
raySceneQuery = gSceneManager->createRayQuery(Ray());
}


And for some reason when it calls createTerrainZone() it crashes. It was having issues with the first line giving me the error "No factory found for the zone of type 'ZoneType_Terrain' in PCZoneFactoryManager::createPCZone()" which is weird considering ZoneType_Terrain is used by the sample app. I changed it to "ZoneType_Default" since I knew that existed (even though I didnt expect it to work with that, was just a test), and it stopped crashing there, and now proceeds to crash on the line ((PCZSceneManager*)gSceneManager)->setZoneGeometry( zoneName, (PCZSceneNode*)gSceneManager->getRootSceneNode(), terrain_cfg ); when it calls setZoneGeometry.


PCZone *WorldState::createTerrainZone(String & zoneName, String & terrain_cfg)
{
PCZone *terrainZone = ((PCZSceneManager*)gSceneManager)->createZone(String("ZoneType_Terrain"), zoneName);
terrainZone->notifyCameraCreated(gCamera);
((PCZSceneManager*)gSceneManager)->setZoneGeometry( zoneName, (PCZSceneNode*)gSceneManager->getRootSceneNode(), terrain_cfg );

// create aab portal(s) around the terrain
String portalName;
Vector3 corners[2];
AxisAlignedBox aabb;

// make portal from terrain to default
Portal * p;
terrainZone->getAABB(aabb);
portalName = Ogre::String("PortalFrom"+zoneName+"ToDefault_Zone");
p = ((PCZSceneManager*)gSceneManager)->createPortal(portalName, Ogre::Portal::PORTAL_TYPE_AABB);
corners[0] = aabb.getMinimum();
corners[1] = aabb.getMaximum();
p->setCorner(0, corners[0]);
p->setCorner(1, corners[1]);
p->setDirection(Ogre::Vector3::NEGATIVE_UNIT_Z); // this indicates an "inward" pointing normal

// associate the portal with the terrain's main node
p->setNode(terrainZone->getEnclosureNode());
// IMPORTANT: Update the derived values of the portal
p->updateDerivedValues();
// add the portal to the zone
terrainZone->_addPortal(p);

// make portal from default to terrain
portalName = Ogre::String("PortalFromDefault_ZoneTo"+zoneName);
Portal * p2;
p2 = ((PCZSceneManager*)gSceneManager)->createPortal(portalName, Ogre::Portal::PORTAL_TYPE_AABB);
corners[0] = aabb.getMinimum();
corners[1] = aabb.getMaximum();
p2->setCorner(0, corners[0]);
p2->setCorner(1, corners[1]);
p2->setDirection(Ogre::Vector3::UNIT_Z); // this indicates an "outward" pointing normal
// associate the portal with the terrain's main node
p2->setNode(terrainZone->getEnclosureNode());
// IMPORTANT: Update the derived values of the portal
p2->updateDerivedValues();
// add the portal to the zone
((PCZSceneManager*)gSceneManager)->getDefaultZone()->_addPortal(p2);

// connect the portals manually
p->setTargetPortal(p2);
p2->setTargetPortal(p);
p->setTargetZone(((PCZSceneManager*)gSceneManager)->getDefaultZone());
p2->setTargetZone(terrainZone);

return terrainZone;
}


In setZoneGeometry, it crashes at the line i = mZones.find(zoneName);

void PCZSceneManager::setZoneGeometry(const String & zoneName,
PCZSceneNode * parentNode,
const String & filename)
{
ZoneMap::iterator i;
PCZone * zone;
i = mZones.find(zoneName);
if (i != mZones.end())
{
zone = i->second;
zone->setZoneGeometry( filename, parentNode );
return;
}

}

oiking

16-11-2009 14:52:06

I think you'll need the PCZM Plugin plus the OctreeZone plugin for terrain support, you loaded both?

CrimsonGT

16-11-2009 14:55:22

Yeah they are both loaded

CrimsonGT

16-11-2009 19:47:28

Heres what I really dont get, its crashing saying OGRE EXCEPTION(5:ItemIdentityException): No factory found for zone of type 'ZoneType_Terrain' in PCZoneFactoryManager::createPCZone at c:\dev\ogresdk\plugins\pczscenemanager\src\ogrepczonefactory.cpp (line 133) but no matter how hard I look, I cant find ogrepczonefactory.cpp in any of the downloads except for my own. The SDK doesnt have it, past source versions dont have it, just mine.

Fish

17-11-2009 04:15:11

Are you able to successfully build and run the PCZ sample app that comes with Ogre?

-Fish

CrimsonGT

17-11-2009 08:08:58

I got it working, the problem was I was not using the Plugin_OctreeZone.dll in conjunction with it. Thats what confused me as the wiki said I did not need anything except for the pczscenemanager plugin, but it seems its required when using ZoneType_Terrain at the very least. I appreciate the help guys!