Terrain Editing

Involved development of the OpenMW construction set.
unelsson
Posts: 103
Joined: 17 Mar 2018, 14:57

Re: Terrain Editing

Post by unelsson » 06 Feb 2019, 14:33

So, the terrain texture selection -feature has it's basics done.
PR: https://github.com/OpenMW/openmw/pull/1769
Video showing what it does: https://youtu.be/D7Ya1McDwVw

These related issues (features) are still missing from the current PR.
https://gitlab.com/OpenMW/openmw/issues/3873
https://gitlab.com/OpenMW/openmw/issues/3869

Now thinking about transient change support, I've done a bit of research on how the terrain is drawn, and will post my findings also here. I'm not taking this issue yet, but maybe in the future.

At CSVRender::Cell::updateLand(), in file cell.cpp, mTerrain is used to draw stuff to CellNode, and load cell data, through component TerrainGrid (terraingrid.cpp) which uses component ChunkManager (chunkmanager.cpp) to create a grid of terrain by using component BufferCache (buffercache.cpp) which finally sets the diamond shapes for the vertices. Component ResourceManager is also involved, likely managing also other data than terrain.

Does anyone know if the openmw game engine uses Terrain::ChunkManager (openmw/components/chunkmanager.cpp) to render terrain? I get the feeling that for opencs being able to draw another "altered" terrain layer, the component level (chunkmanager, resourcemanager etc.) might require some changes, but I'd hate to burden the game engine with opencs-stuff. Overloading chunkmanager functions or making separate opencs-functions might do the job.

Another way would be to have two resourcemanagers/chunkmanagers handled by opencs (cell.cpp choosing which to use and when). Calling the new one perhaps TransientChangeResourceManager? One chunk/resourcemanger handling the actual data, another handling the temporary "altered data".

unelsson
Posts: 103
Joined: 17 Mar 2018, 14:57

Re: Terrain Editing

Post by unelsson » 09 Feb 2019, 02:01

Editor transient change pondering again: By implementing second versions of four or some functions responsible for managing the terrain I'm able to pass alternate height data to cell building. Same method should work for any data type. This method duplicates many functions, for example TerrainGrid::buildTerrain as TerrainGrid::buildAlteredTerrain and similarly ChunkManager::createAlteredChunk and Storage::fillAlteredVertexBuffers, only to pass some floats that override values at the lowermost layer. This method touches many components that are also used by openmw, but doesn't alter any functions used by openmw. It feels kind of ugly way to do it, but technically it works. AnyOldName3 hinted about using cull callback, and somehow changing the terrain data directly, but I can't get my hands on direct terrain drawables. That would most certainly require less hacky code...

In the end storage-code can be changed something like:
void Storage::fillAlteredVertexBuffers (int lodLevel, float size, const osg::Vec2f& center,
osg::ref_ptr<osg::Vec3Array> positions,
osg::ref_ptr<osg::Vec3Array> normals,
osg::ref_ptr<osg::Vec4Array> colours,
float alteredheightdata[])
{
...
height = alteredheightdata[col*ESM::Land::LAND_SIZE + row]; //instead of... heightData->mHeights[col*ESM::Land::LAND_SIZE + row];
...
}

unelsson
Posts: 103
Joined: 17 Mar 2018, 14:57

Re: Terrain Editing

Post by unelsson » 09 Feb 2019, 11:33

Here is a proof-of-concept -style branch made for testing various things where stuff happens. For testing purposes, it pushes empty heights data to cell visual whenever terrain texture editing is done. While I feel the method is ugly, and there are plenty of debug comments and std::cout -lines, I'm publishing this so I can get feedback for better options for the basic implementation.
https://github.com/unelsson/openmw/tree ... nsienthack

edit: here is my second try, a less intrusive method overriding the land drawing buffer function, and slightly less crap (based on terraintextureselection branch). This line adds "+ mAlteredHeight" to the calculation, similarly all changes could be injected into this function.
https://github.com/unelsson/openmw/tree ... ntransient

unelsson
Posts: 103
Joined: 17 Mar 2018, 14:57

Re: Terrain Editing

Post by unelsson » 12 Feb 2019, 13:59

Here is a monster of a PR (terrain selection, transient editing, land shape editing)
https://github.com/OpenMW/openmw/pull/2167

edit: This needs feedback, I'm keeping the up-to-date info on the first comment of that PR.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests