[Solved] Can you deform a tile that is not visible?

vanzu

24-03-2007 03:42:18

Hello.

I'm working on a deformation class that could sculpt spline ways into the terrain (like roads or riverbeds). It's working pretty well at the moment but when I try to carve something really big, like the size of a river into the terrain and the brush is bigger than the visible area, the deformation is only applyed to the visible tiles.
I get the better results by raising the camera to high altitude and looking down before applying the deformation.

Is there a way to apply the deformation to the tiles that are invisible?
how do you manually load a masked tile so that it becomes deformable via setHeight?

Would moving the camera along the spline, calling setOption("loadNow") before reapplying the deformation work? (should be much slower though)

I'm sorry to ask but, being quite new to PLSM I don't really know where to start looking =)

BTW if anyone's interested I can release the code. It works by definining waypoints within the world, then i transform these into a rasterized spline that is used as a deformation brush.

uzik

24-03-2007 14:20:50

It does load the tiles near the camera. The options

MaxAdjacentPages=2
MaxPreloadedPages=4

in the config file tell it how many around your camera
to preload.

I'd have to check the source code for the other question.
I might need to do that myself. I was wondering how to fill out the
radar and minimap if the page it displayed wasn't loaded.

nindim

24-03-2007 15:13:52


mScnMgr->setOption( "LoadNow", NULL );


This will load all the possible tiles as dfefined in your .cfg. I'm pretty sure you can get it to load individual tiles as well by passing something other than null. Best thing to do would just be to check the plsm2 source and see what it takes for its params value and see what it does with them.

vanzu

25-03-2007 02:51:45

Ok thanks to your answers I think I got it now.

First I had to modify the "LoadNow" part of PagingLandscapeSceneManager::setOption from

if (strKey == "LoadNow")
{
assert (mPageManager);
if (mOptions->max_preload_pages*mOptions->max_preload_pages >= mOptions->NumPages)
{
// Configuration file is telling us to pre-load all pages at startup.
for (unsigned int pageY = 0; pageY < mOptions->world_height; pageY++)
{
for (unsigned int pageX = 0; pageX < mOptions->world_width; pageX++)
{
PagingLandScapePage * const p = mPageManager->getPage(pageX, pageY);
p->load();
mPageManager->addLoadedPage(p);

}
}
if (mOptions->primaryCamera)
mPageManager->loadNow (mOptions->primaryCamera);
}
else if (pValue)
{
PagingLandScapeCamera *cam = const_cast <PagingLandScapeCamera *> (static_cast < const PagingLandScapeCamera * > (pValue));
mPageManager->loadNow (cam);
}
}


To


if (strKey == "LoadNow")
{
assert (mPageManager);
if (pValue)
{
PagingLandScapeCamera *cam = const_cast <PagingLandScapeCamera *> (static_cast < const PagingLandScapeCamera * > (pValue));
mPageManager->loadNow (cam);
}
else if (mOptions->max_preload_pages*mOptions->max_preload_pages >= mOptions->NumPages)
{
// Configuration file is telling us to pre-load all pages at startup.
for (unsigned int pageY = 0; pageY < mOptions->world_height; pageY++)
{
for (unsigned int pageX = 0; pageX < mOptions->world_width; pageX++)
{
PagingLandScapePage * const p = mPageManager->getPage(pageX, pageY);
p->load();
mPageManager->addLoadedPage(p);

}
}
if (mOptions->primaryCamera)
mPageManager->loadNow (mOptions->primaryCamera);
}

}


or else the pValue argument wasnt even ever tested to exist. And it seems to work now. The previously unloaded tiles are deformed if I call LoadNow before SetHeightCenter :


Camera *cam = mSceneMgr->createCamera("deformationCam");
cam->lookAt(Vector3::NEGATIVE_UNIT_Y);

waypoint = mWaypoints.begin();
cam->setPosition(waypoint->pos.x, waypoint->pos.y + 50000, waypoint->pos.z);
mSceneMgr->setOption("LoadNow", cam);

mSceneMgr->setOption("setHeightCenter", &impact);


There are still a few bugs because the deformation applyed on the invisible tiles is really strange and does'nt seem to make sense to me but I'm sure I will figure it out now .

Here are 2 screenshots. In the first one you can see a riverbed running down the slope. The tiles on this one were loaded by the regular camera.

On the second one , you can see the limit with the tiles loaded by the LoadNow option. As you can see the center of the riverbed is just like it should be while the borders are completely messed up. I'm still scratching my head wondering why, but the answer surely lies in my code :)

http://www.poudrerie.be/temp/screenshot_1.png
http://www.poudrerie.be/temp/screenshot_2.png

Thanks !

nindim

26-03-2007 00:59:34

Out of interest, why are you using "SetHeightCenter" instead of "DeformationCenter"?

vanzu

26-03-2007 17:20:16

Well I just think you have more control with setHeightCenter... I didn't even try with deformationCenter actually.

- 1: fill the brush with terrain values : fillBrushArray
- 2: fill the center of my way ( the points closest to the spline) with precomputed values (depends on the kind of slope control i want and the shape of the way)
- 3: smooth the borders of the way so that the final deformation looks natural, for this the first step is mandatory
- 4: apply the final deformation

BTW I found why the borders were messed up... It was because fillBrushArray would only fill the part of the brush with loaded tiles too. I needed to load the tiles before the fillBrushArray call or else the borders of the way were smoothed with uninitialized values instead of actual terrain values.