VertexData and Index Data

fiesch

05-12-2005 14:27:16

Hey again..

i was wondering if you're planning to add these changes to your code:

http://www.ogre3d.org/phpBB2/viewtopic. ... &start=153

or if they were actually added already and I didn't see them...

tuan kuranes

05-12-2005 14:43:59

patch is welcome. But preferred way is not export but use the getOption() mechanism of scenemanager, as best is to avoid hard link at any cost, hence the complex delegates system for events.

fiesch

05-12-2005 21:09:53

hm i have the patch about ready with the mentionned changes along with changes in OgrePagingLandScapeSceneManager.cpp and adding 2 additional files (OgrePagingLandscapeVertexDataQuery .h and .cpp)

I need to run a few tests on it first...

about the lod levels... i guess it's been asked a lot before or even in the wiki..
is lod level 0 the one with maximum detail?

Jon

05-12-2005 21:10:57

Yes, LOD 0 is bizarrely the highest level of detail

fiesch

05-12-2005 21:51:56

well it does make sense, that one is well defined while you could have any number of detail levels below that going from 1 to whatever big number

fiesch

05-12-2005 22:03:08

this is the patch for now.. tested as far as compiling goes, didn't have the time to test it any further so far as I'm in the middle of switching from OgreOde to Newton...


? src/OgrePagingLandscapeVertexDataQuery.cpp
? src/OgrePagingLandscapeVertexDataQuery.h
Index: include/OgrePagingLandScapeIndexBuffer.h
===================================================================
RCS file: /cvsroot/ogre/ogreaddons/paginglandscape/PlugIns/PagingLandScape2/include/OgrePagingLandScapeIndexBuffer.h,v
retrieving revision 1.16
diff -u -p -r1.16 OgrePagingLandScapeIndexBuffer.h
--- include/OgrePagingLandScapeIndexBuffer.h 16 Nov 2005 10:44:14 -0000 1.16
+++ include/OgrePagingLandScapeIndexBuffer.h 5 Dec 2005 16:52:16 -0000
@@ -64,6 +64,9 @@ namespace Ogre
/// Internal method for generating triangle list terrain indexes
IndexData* generateTriListIndexes(const bool northStitch, const bool southStitch, const bool eastStitch, const bool westStitch, const int RenderLevel, PagingLandScapeRenderable** Neighbors) const;

+ //*******************
+ //Added by Fiesch adapted from a post by tonyhnz
+ IndexData* getRawIndexes(int renderLevel);
protected:

/** Returns the index into the height array for the given coordinates. */
Index: include/OgrePagingLandScapeRenderable.h
===================================================================
RCS file: /cvsroot/ogre/ogreaddons/paginglandscape/PlugIns/PagingLandScape2/include/OgrePagingLandScapeRenderable.h,v
retrieving revision 1.22
diff -u -p -r1.22 OgrePagingLandScapeRenderable.h
--- include/OgrePagingLandScapeRenderable.h 17 Nov 2005 10:51:01 -0000 1.22
+++ include/OgrePagingLandScapeRenderable.h 5 Dec 2005 16:47:08 -0000
@@ -160,6 +160,10 @@ namespace Ogre

bool isInUse() const {return mInUse;};

+ IndexData* getRawIndexData(const int renderlevel);
+ void getRawVertexData(Vector3* pVerts);
+ const uint PagingLandScapeRenderable::getVertexCount();
+
protected:

VertexData* mCurrVertexes;
@@ -220,6 +224,8 @@ namespace Ogre
// did LOD level changes this frame
bool mChangedRenderLevel;

+ Vector3 _getvertex(const int x, const int z) const;
+
private :

Image::Box mRect;
Index: src/OgrePagingLandScapeIndexBuffer.cpp
===================================================================
RCS file: /cvsroot/ogre/ogreaddons/paginglandscape/PlugIns/PagingLandScape2/src/OgrePagingLandScapeIndexBuffer.cpp,v
retrieving revision 1.23
diff -u -p -r1.23 OgrePagingLandScapeIndexBuffer.cpp
--- src/OgrePagingLandScapeIndexBuffer.cpp 28 Nov 2005 15:37:16 -0000 1.23
+++ src/OgrePagingLandScapeIndexBuffer.cpp 5 Dec 2005 16:52:20 -0000
@@ -567,4 +567,41 @@ namespace Ogre
return numIndexes;
}

+ //*******************
+ //Added by Fiesch adapted from a post by tonyhnz
+ IndexData *PagingLandScapeIndexBufferManager::getRawIndexes(int renderLevel)
+ {
+ // no stitching is done
+ // used to expose terrain vertex data
+
+ if (renderLevel >= static_cast <int> (mNumIndexes))
+ renderLevel = static_cast <int> (mNumIndexes)-1;
+
+ if (renderLevel < 0)
+ renderLevel =0 ;
+
+ const uint stitchFlags = 0;
+
+ assert (mLevelIndex.size() > (uint)renderLevel);
+
+ IndexMap::iterator ii = mLevelIndex[ renderLevel ]->find( stitchFlags );
+ if ( ii == mLevelIndex[ renderLevel ]->end())
+ {
+ // Create
+ IndexData* indexData = generateTriListIndexes( false,
+ false,
+ false,
+ false,
+ renderLevel,
+ 0);
+ mLevelIndex[ renderLevel ]->insert(
+ IndexMap::value_type(stitchFlags, indexData));
+
+ return indexData;
+ }
+ else
+ {
+ return ii->second;
+ }
+ }
} //namespace
Index: src/OgrePagingLandScapeRenderable.cpp
===================================================================
RCS file: /cvsroot/ogre/ogreaddons/paginglandscape/PlugIns/PagingLandScape2/src/OgrePagingLandScapeRenderable.cpp,v
retrieving revision 1.45
diff -u -p -r1.45 OgrePagingLandScapeRenderable.cpp
--- src/OgrePagingLandScapeRenderable.cpp 28 Nov 2005 15:37:16 -0000 1.45
+++ src/OgrePagingLandScapeRenderable.cpp 5 Dec 2005 16:52:22 -0000
@@ -1093,4 +1093,39 @@ namespace Ogre
mParentNode->needUpdate();
}
}
+
+ Vector3 PagingLandScapeRenderable::_getvertex(const int x, const int z) const
+ {
+ const uint tilesize = mOpt->TileSize - 1;
+ Vector3 vertex;
+
+ vertex.x = ((mInfo->tileX * tilesize) + x )* mOpt->scale.x;
+ vertex.y = mHeightfield[((mInfo->tileX * tilesize) + x) +
+ ((mInfo->tileZ * tilesize) + z) * mOpt->PageSize ];
+ vertex.z = ((mInfo->tileZ * tilesize) + z)* mOpt->scale.z;
+
+ return vertex;
+ }
+
+ IndexData* PagingLandScapeRenderable::getRawIndexData(const int renderlevel)
+ {
+ return PagingLandScapeIndexBufferManager::getSingleton().getRawIndexes( renderlevel);
+ }
+
+ void PagingLandScapeRenderable::getRawVertexData(Vector3* pVerts)
+ {
+ // pVerts should be pre-allocated to tilesize*tilesize
+ // using getVertexCount()
+ const uint tilesize = mOpt->TileSize ;
+
+ Vector3 *vert = pVerts;
+ for (uint i=0; i<tilesize; ++i)
+ for (uint j=0; j<tilesize; ++j)
+ *vert++ = _getvertex(i, j);
+ }
+
+ const uint PagingLandScapeRenderable::getVertexCount()
+ {
+ return mOpt->TileSize * mOpt->TileSize ;
+ }
} //namespace
Index: src/OgrePagingLandScapeSceneManager.cpp
===================================================================
RCS file: /cvsroot/ogre/ogreaddons/paginglandscape/PlugIns/PagingLandScape2/src/OgrePagingLandScapeSceneManager.cpp,v
retrieving revision 1.52
diff -u -p -r1.52 OgrePagingLandScapeSceneManager.cpp
--- src/OgrePagingLandScapeSceneManager.cpp 28 Nov 2005 15:37:16 -0000 1.52
+++ src/OgrePagingLandScapeSceneManager.cpp 5 Dec 2005 22:00:29 -0000
@@ -52,6 +52,9 @@

#include "OgrePagingLandScapeHorizon.h"

+//added for Vertex data retrieval
+#include "OgrePagingLandscapeVertexDataQuery.h"
+
namespace Ogre
{

@@ -199,7 +202,7 @@ namespace Ogre
if (!mPageManager)
{
mPageManager = new PagingLandScapePageManager();
- mPageManager->setWorldGeometryRenderQueue (SceneManager::getWorldGeometryRenderQueue());
+ mPageManager->setWorldGeometryRenderQueue (static_cast<Ogre::RenderQueueGroupID>(SceneManager::getWorldGeometryRenderQueue()));
Root::getSingleton().addFrameListener(mPageManager);
mData2DManager->setPageManager();
}
@@ -1133,6 +1136,31 @@ namespace Ogre
* static_cast < Real * > (pDestValue) = mBrushScale;
return true;
}
+ //added for Vertex data retrieval
+ if (strKey == "PageGetTileVertexData")
+ {
+ //todo: add the actual code
+ PagingLandScapeVertexDataQuery* vertexQuery = static_cast < PagingLandScapeVertexDataQuery * > (pDestValue);
+ Ogre::PagingLandScapePage* page = PagingLandScapePageManager::getSingleton().getPage(vertexQuery->pageX,vertexQuery->pageZ);
+ if(page)
+ {
+ Ogre::PagingLandScapeTile* tile = page->getTile(vertexQuery->tileX,vertexQuery->tileZ);
+ if(tile)
+ {
+ Ogre::PagingLandScapeRenderable* rend = tile->getRenderable();
+ if(rend)
+ {
+ vertexQuery->numVertices = rend->getVertexCount();
+ vertexQuery->indices = rend->getRawIndexData(vertexQuery->lodLevel);
+ vertexQuery->vertices = new Ogre::Vector3[vertexQuery->numVertices];
+ rend->getRawVertexData(vertexQuery->vertices);
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+ //end of addition
if (mOptions.getOption(strKey, pDestValue) == false)
{
return PagingLandScapeOctreeSceneManager::getOption (strKey, pDestValue);
@@ -1195,6 +1223,12 @@ namespace Ogre
{
return true;
}
+ //added for Vertex data retrieval
+ if (strKey == "PageGetTileVertexData")
+ {
+ return true;
+ }
+ //end of addition
if (mOptions.hasOption(strKey) == false)
{
return PagingLandScapeOctreeSceneManager::hasOption (strKey);




here are the two missing files
OgrePagingLandscapeVertexDataQuery.h

/*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/

Copyright © 2000-2004 The OGRE Team
Also see acknowledgements in Readme.html

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place - Suite 330, Boston, MA 02111-1307, USA, or go to
http://www.gnu.org/copyleft/lesser.txt.
-----------------------------------------------------------------------------
*/
/***************************************************************************
OgrePagingLandscapeVertexDataQuery.h - description
-------------------
begin : Mon Dec 05 2006
by : Matthias Fischaleck
email : m.fischaleck@gmx.net

***************************************************************************/

#ifndef _OGRE_PAGING_LANDSCAPE_VERTEX_DATA_QUERY_
#define _OGRE_PAGING_LANDSCAPE_VERTEX_DATA_QUERY_

#include <Ogre.h>

namespace Ogre
{
/**
* Helper class to pass a vertex data query through the getOption mechanism.
* As this is a very simple DataContainer i didn't use data hiding.
*/
class _OgrePagingLandScapeExport PagingLandScapeVertexDataQuery
{
private:
protected:
public:
IndexData* indices;
Ogre::Vector3* vertices;

Ogre::uint pageX;
Ogre::uint pageZ;
Ogre::uint tileX;
Ogre::uint tileZ;

Ogre::uint lodLevel;
Ogre::uint numVertices;

PagingLandScapeVertexDataQuery();
PagingLandScapeVertexDataQuery(Ogre::uint setPageX,Ogre::uint setPageZ,Ogre::uint setTileX,Ogre::uint setTileZ, Ogre::uint atLevel);
~PagingLandScapeVertexDataQuery();
};
}

#endif


OgrePagingLandscapeVertexDataQuery.cpp

#include "OgrePagingLandscapeVertexDataQuery.h"

using namespace Ogre;

/**
* Constructor. Simple var-init
*/
PagingLandScapeVertexDataQuery::PagingLandScapeVertexDataQuery()
{
pageX = 0;
pageZ = 0;
tileX = 0;
tileZ = 0;
lodLevel = 0;
numVertices = 0;
indices = NULL;
vertices = NULL;
}

/**
* Constructor. Simple var-init
* @param setPageX x value of the page to get the data for
* @param setPageY y value of the page to get the data for
* @param setTileX x value of the tile within the specified page to get the data for
* @param setTileY y value of the tile within the specified page to get the data for
* @param atLevel LodLevel to get the data at
*/
PagingLandScapeVertexDataQuery::PagingLandScapeVertexDataQuery(Ogre::uint setPageX,Ogre::uint setPageZ,Ogre::uint setTileX,Ogre::uint setTileZ, Ogre::uint atLevel)
{
pageX = setPageX;
pageZ = setPageZ;
tileX = setTileX;
tileZ = setTileZ;
lodLevel = atLevel;
numVertices = 0;
indices = NULL;
vertices = NULL;
}

/**
* Deconstructor. NOP
*/
PagingLandScapeVertexDataQuery::~PagingLandScapeVertexDataQuery()
{
}

fiesch

05-12-2005 22:08:45

ah - forgot to explain...
this addition is accessible through getOption("PageGetTileVertexData",Pointer)

Pointer being a valid pointer to a Ogre::PagingLandscapeVertexDataQuery instance which will get filled with the data

and i just realized that I'm missing init-code for the vertices field... damn.

I'll add that right away and correct the patch file above

fiesch

05-12-2005 22:19:55

fixed. the pointer for the vertices needs to be allocated based on the contained vertices. That could only be done in the getOption section itsself. Added that.

[Edit] Updated the patchcode again - the diff for the include folder was missing
[Edit] The PagingLandscapeVertexDataQuery class was missing the export macro...

fiesch

06-12-2005 11:45:13

hm damn i can't get my code past the linker..

can sb tell me how to resolve the vftable problems


------ Build started: Project: client_a2, Configuration: Release Win32 ------

Linking...
NewtonTerrainHelper.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) const Ogre::PagingLandScapeListener::`vftable'" (__imp_??_7PagingLandScapeListener@Ogre@@6B@) referenced in function "public: virtual __thiscall NewtonTerrainHelper::~NewtonTerrainHelper(void)" (??1NewtonTerrainHelper@@UAE@XZ)
Release/canipes.exe : fatal error LNK1120: 1 unresolved externals

Build log was saved at "file://c:\dev\client\Release\obj\BuildLog.htm"
client_a2 - 2 error(s), 0 warning(s)


------ Build started: Project: client_a2, Configuration: Debug Win32 ------

Linking...
NewtonTerrainHelper.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall Ogre::PagingLandScapeListener::PagingLandScapeListener(void)" (__imp_??0PagingLandScapeListener@Ogre@@QAE@XZ) referenced in function "public: __thiscall NewtonTerrainHelper::NewtonTerrainHelper(class OgreNewt::World *)" (??0NewtonTerrainHelper@@QAE@PAVWorld@OgreNewt@@@Z)
NewtonTerrainHelper.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall Ogre::PagingLandScapeListener::~PagingLandScapeListener(void)" (__imp_??1PagingLandScapeListener@Ogre@@UAE@XZ) referenced in function "public: virtual __thiscall NewtonTerrainHelper::~NewtonTerrainHelper(void)" (??1NewtonTerrainHelper@@UAE@XZ)
Debug/canipes.exe : fatal error LNK1120: 2 unresolved externals

fiesch

06-12-2005 12:54:45

Hm as i see it i can't get it to work that way because i would again have to use exports there...
does anybody have an idea how i can pass the parameters for the tile needed through the getOption mechanism?

tuan kuranes

06-12-2005 13:25:32

you doesn't have to derivate your terrain listener from
PagingLandScapeListener::PagingLandScapeListener(void) anymore.

Check how CVS demo make uses of delegates to listen to free yourself on that dependency.

fiesch

06-12-2005 14:18:54

yay that was what i was looking for - here is the "cleaner" verison of the patch, not using additional classes. It did however introduce 5 more member variables to the scene Manager and is less efficient than the other patch.

It now requires you to set the the desired page x/Z, tile X/Z and Lod Level through indivual calls to setOption.
After that you can get VertexCount, VertexData and IndexData through seperate calls to getOption

again, this is tested to compile, not to work as of now (need to get rid of that dependeny first)

additionally, it's a bit unsafe as it expects the caller to init the passed pointer to the right siez for the vertexData


Index: include/OgrePagingLandScapeIndexBuffer.h
===================================================================
RCS file: /cvsroot/ogre/ogreaddons/paginglandscape/PlugIns/PagingLandScape2/include/OgrePagingLandScapeIndexBuffer.h,v
retrieving revision 1.16
diff -u -p -r1.16 OgrePagingLandScapeIndexBuffer.h
--- include/OgrePagingLandScapeIndexBuffer.h 16 Nov 2005 10:44:14 -0000 1.16
+++ include/OgrePagingLandScapeIndexBuffer.h 5 Dec 2005 16:52:16 -0000
@@ -64,6 +64,9 @@ namespace Ogre
/// Internal method for generating triangle list terrain indexes
IndexData* generateTriListIndexes(const bool northStitch, const bool southStitch, const bool eastStitch, const bool westStitch, const int RenderLevel, PagingLandScapeRenderable** Neighbors) const;

+ //*******************
+ //Added by Fiesch adapted from a post by tonyhnz
+ IndexData* getRawIndexes(int renderLevel);
protected:

/** Returns the index into the height array for the given coordinates. */
Index: include/OgrePagingLandScapeRenderable.h
===================================================================
RCS file: /cvsroot/ogre/ogreaddons/paginglandscape/PlugIns/PagingLandScape2/include/OgrePagingLandScapeRenderable.h,v
retrieving revision 1.22
diff -u -p -r1.22 OgrePagingLandScapeRenderable.h
--- include/OgrePagingLandScapeRenderable.h 17 Nov 2005 10:51:01 -0000 1.22
+++ include/OgrePagingLandScapeRenderable.h 5 Dec 2005 16:47:08 -0000
@@ -160,6 +160,10 @@ namespace Ogre

bool isInUse() const {return mInUse;};

+ IndexData* getRawIndexData(const int renderlevel);
+ void getRawVertexData(Vector3* pVerts);
+ const uint PagingLandScapeRenderable::getVertexCount();
+
protected:

VertexData* mCurrVertexes;
@@ -220,6 +224,8 @@ namespace Ogre
// did LOD level changes this frame
bool mChangedRenderLevel;

+ Vector3 _getvertex(const int x, const int z) const;
+
private :

Image::Box mRect;
Index: include/OgrePagingLandScapeSceneManager.h
===================================================================
RCS file: /cvsroot/ogre/ogreaddons/paginglandscape/PlugIns/PagingLandScape2/include/OgrePagingLandScapeSceneManager.h,v
retrieving revision 1.27
diff -u -p -r1.27 OgrePagingLandScapeSceneManager.h
--- include/OgrePagingLandScapeSceneManager.h 9 Nov 2005 17:32:45 -0000 1.27
+++ include/OgrePagingLandScapeSceneManager.h 6 Dec 2005 13:25:47 -0000
@@ -328,6 +328,12 @@ namespace Ogre
uint mBrushSize;
Real mBrushScale;

+ uint requestPageX;
+ uint requestPageZ;
+ uint requestTileX;
+ uint requestTileZ;
+ uint requestLodLevel;
+
Real* mCraterArray;
Real* mBrushArray;

Index: src/OgrePagingLandScapeIndexBuffer.cpp
===================================================================
RCS file: /cvsroot/ogre/ogreaddons/paginglandscape/PlugIns/PagingLandScape2/src/OgrePagingLandScapeIndexBuffer.cpp,v
retrieving revision 1.23
diff -u -p -r1.23 OgrePagingLandScapeIndexBuffer.cpp
--- src/OgrePagingLandScapeIndexBuffer.cpp 28 Nov 2005 15:37:16 -0000 1.23
+++ src/OgrePagingLandScapeIndexBuffer.cpp 5 Dec 2005 16:52:20 -0000
@@ -567,4 +567,41 @@ namespace Ogre
return numIndexes;
}

+ //*******************
+ //Added by Fiesch adapted from a post by tonyhnz
+ IndexData *PagingLandScapeIndexBufferManager::getRawIndexes(int renderLevel)
+ {
+ // no stitching is done
+ // used to expose terrain vertex data
+
+ if (renderLevel >= static_cast <int> (mNumIndexes))
+ renderLevel = static_cast <int> (mNumIndexes)-1;
+
+ if (renderLevel < 0)
+ renderLevel =0 ;
+
+ const uint stitchFlags = 0;
+
+ assert (mLevelIndex.size() > (uint)renderLevel);
+
+ IndexMap::iterator ii = mLevelIndex[ renderLevel ]->find( stitchFlags );
+ if ( ii == mLevelIndex[ renderLevel ]->end())
+ {
+ // Create
+ IndexData* indexData = generateTriListIndexes( false,
+ false,
+ false,
+ false,
+ renderLevel,
+ 0);
+ mLevelIndex[ renderLevel ]->insert(
+ IndexMap::value_type(stitchFlags, indexData));
+
+ return indexData;
+ }
+ else
+ {
+ return ii->second;
+ }
+ }
} //namespace
Index: src/OgrePagingLandScapeRenderable.cpp
===================================================================
RCS file: /cvsroot/ogre/ogreaddons/paginglandscape/PlugIns/PagingLandScape2/src/OgrePagingLandScapeRenderable.cpp,v
retrieving revision 1.45
diff -u -p -r1.45 OgrePagingLandScapeRenderable.cpp
--- src/OgrePagingLandScapeRenderable.cpp 28 Nov 2005 15:37:16 -0000 1.45
+++ src/OgrePagingLandScapeRenderable.cpp 5 Dec 2005 16:52:22 -0000
@@ -1093,4 +1093,39 @@ namespace Ogre
mParentNode->needUpdate();
}
}
+
+ Vector3 PagingLandScapeRenderable::_getvertex(const int x, const int z) const
+ {
+ const uint tilesize = mOpt->TileSize - 1;
+ Vector3 vertex;
+
+ vertex.x = ((mInfo->tileX * tilesize) + x )* mOpt->scale.x;
+ vertex.y = mHeightfield[((mInfo->tileX * tilesize) + x) +
+ ((mInfo->tileZ * tilesize) + z) * mOpt->PageSize ];
+ vertex.z = ((mInfo->tileZ * tilesize) + z)* mOpt->scale.z;
+
+ return vertex;
+ }
+
+ IndexData* PagingLandScapeRenderable::getRawIndexData(const int renderlevel)
+ {
+ return PagingLandScapeIndexBufferManager::getSingleton().getRawIndexes( renderlevel);
+ }
+
+ void PagingLandScapeRenderable::getRawVertexData(Vector3* pVerts)
+ {
+ // pVerts should be pre-allocated to tilesize*tilesize
+ // using getVertexCount()
+ const uint tilesize = mOpt->TileSize ;
+
+ Vector3 *vert = pVerts;
+ for (uint i=0; i<tilesize; ++i)
+ for (uint j=0; j<tilesize; ++j)
+ *vert++ = _getvertex(i, j);
+ }
+
+ const uint PagingLandScapeRenderable::getVertexCount()
+ {
+ return mOpt->TileSize * mOpt->TileSize ;
+ }
} //namespace
Index: src/OgrePagingLandScapeSceneManager.cpp
===================================================================
RCS file: /cvsroot/ogre/ogreaddons/paginglandscape/PlugIns/PagingLandScape2/src/OgrePagingLandScapeSceneManager.cpp,v
retrieving revision 1.52
diff -u -p -r1.52 OgrePagingLandScapeSceneManager.cpp
--- src/OgrePagingLandScapeSceneManager.cpp 28 Nov 2005 15:37:16 -0000 1.52
+++ src/OgrePagingLandScapeSceneManager.cpp 6 Dec 2005 13:55:01 -0000
@@ -199,7 +199,7 @@ namespace Ogre
if (!mPageManager)
{
mPageManager = new PagingLandScapePageManager();
- mPageManager->setWorldGeometryRenderQueue (SceneManager::getWorldGeometryRenderQueue());
+ mPageManager->setWorldGeometryRenderQueue (static_cast<Ogre::RenderQueueGroupID>(SceneManager::getWorldGeometryRenderQueue()));
Root::getSingleton().addFrameListener(mPageManager);
mData2DManager->setPageManager();
}
@@ -852,6 +852,33 @@ namespace Ogre
// Now reload pages
//PagingLandScapePageManager::getSingleton().getPage(page.x, page.y)->reload();
}
+ //added for Vertex data retrieval
+ if (strKey == "PageGetVertexData_SourcePageX")
+ {
+ requestPageX = *static_cast < const uint * > (pValue);
+ return true;
+ }
+ if (strKey == "PageGetVertexData_SourcePageZ")
+ {
+ requestPageZ = *static_cast < const uint * > (pValue);
+ return true;
+ }
+ if (strKey == "PageGetVertexData_SourceTileX")
+ {
+ requestTileX = *static_cast < const uint * > (pValue);
+ return true;
+ }
+ if (strKey == "PageGetVertexData_SourceTileZ")
+ {
+ requestTileZ = *static_cast < const uint * > (pValue);
+ return true;
+ }
+ if (strKey == "PageGetVertexData_FromLodLevel")
+ {
+ requestLodLevel = *static_cast < const uint * > (pValue);
+ return true;
+ }
+ //addition ends
if (mOptions.setOption(strKey, pValue) == true)
{
return true;
@@ -1133,6 +1160,88 @@ namespace Ogre
* static_cast < Real * > (pDestValue) = mBrushScale;
return true;
}
+ //added for Vertex data retrieval
+ if (strKey == "PageGetVertexData_SourcePageX")
+ {
+ *static_cast < uint * > (pDestValue) = requestPageX;
+ return true;
+ }
+ if (strKey == "PageGetVertexData_SourcePageZ")
+ {
+ *static_cast < uint * > (pDestValue) = requestPageZ;
+ return true;
+ }
+ if (strKey == "PageGetVertexData_SourceTileX")
+ {
+ *static_cast < uint * > (pDestValue) = requestTileX;
+ return true;
+ }
+ if (strKey == "PageGetVertexData_SourceTileZ")
+ {
+ *static_cast < uint * > (pDestValue) = requestTileZ;
+ return true;
+ }
+ if (strKey == "PageGetVertexData_FromLodLevel")
+ {
+ *static_cast < uint * > (pDestValue) = requestLodLevel;
+ return true;
+ }
+ if (strKey == "PageGetTileVertexCount")
+ {
+ Ogre::PagingLandScapePage* page = PagingLandScapePageManager::getSingleton().getPage(requestPageX,requestPageZ);
+ if(page)
+ {
+ Ogre::PagingLandScapeTile* tile = page->getTile(requestTileX,requestTileZ);
+ if(tile)
+ {
+ Ogre::PagingLandScapeRenderable* rend = tile->getRenderable();
+ if(rend)
+ {
+ *static_cast < uint * > (pDestValue) = rend->getVertexCount();
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+ if (strKey == "PageGetTileVertexData")
+ {
+ Ogre::PagingLandScapePage* page = PagingLandScapePageManager::getSingleton().getPage(requestPageX,requestPageZ);
+ if(page)
+ {
+ Ogre::PagingLandScapeTile* tile = page->getTile(requestTileX,requestTileZ);
+ if(tile)
+ {
+ Ogre::PagingLandScapeRenderable* rend = tile->getRenderable();
+ if(rend)
+ {
+ //warning! make sure that the allocated space for the vertices is big enough!
+ rend->getRawVertexData(*static_cast < Ogre::Vector3 ** > (pDestValue));
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+ if (strKey == "PageGetTileVertexIndexData")
+ {
+ Ogre::PagingLandScapePage* page = PagingLandScapePageManager::getSingleton().getPage(requestPageX,requestPageZ);
+ if(page)
+ {
+ Ogre::PagingLandScapeTile* tile = page->getTile(requestTileX,requestTileZ);
+ if(tile)
+ {
+ Ogre::PagingLandScapeRenderable* rend = tile->getRenderable();
+ if(rend)
+ {
+ *static_cast < Ogre::IndexData** > (pDestValue) = rend->getRawIndexData(requestLodLevel);
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+ //end of addition
if (mOptions.getOption(strKey, pDestValue) == false)
{
return PagingLandScapeOctreeSceneManager::getOption (strKey, pDestValue);
@@ -1195,6 +1304,12 @@ namespace Ogre
{
return true;
}
+ //added for Vertex data retrieval
+ if (strKey == "PageGetTileVertexData")
+ {
+ return true;
+ }
+ //end of addition
if (mOptions.hasOption(strKey) == false)
{
return PagingLandScapeOctreeSceneManager::hasOption (strKey);

tuan kuranes

06-12-2005 14:56:23

To avoid the 5 member addtion using an array or std::vector of void pointers.

You'll end with one getOption call, returning results being stored in the array. Think of the array of void pointer as a "unnamed struct." (add a Comment on how to use it.)

I was thinking of a new Wiki page for all getoption/setOption documentation. It really begins to need it.

fiesch

06-12-2005 15:07:31

Hm yes i was going for that as first
but i thought of the current situation as being easier to understand
and the overhead isn't that big considering the frequency of that call...
but i see the drawback of the 5 member variables

fiesch

07-12-2005 13:11:03

hm is there a way to have the ListenerManager initialized at startup?
I assume it wouldn't do any harm and since it's loaded lateron anyway it shouldn't be an overhead, either

tuan kuranes

07-12-2005 13:48:26

seems fair.
By startup you mean setWorldGeometry ?
You want to add that to the patch or want me to do it ?

fiesch

07-12-2005 14:05:10

no i mean in the constructor... i'D rather have the tile listener set up before the geometry starts o load i guess i might miss out on some data the first time any other way..

hm i can add it to the patch, i need to change it anyway to get the performance i need, right now the loading really kicks in

tuan kuranes

07-12-2005 14:25:13

Interesting.

Constructor is hardly the good spot as in a multiscenemanager it would allocate things even when no used...

For now nothing is loaded before first frame so it's safe to put it in setWorldGeometry().

fiesch

07-12-2005 15:30:50

hm this is a bit strange - do i need to offset the coordinates i get out of the tiles by some amount or post-scale them?

i seem to have a single patch at 0/0 and nothing around that - and that mesh with some strange height values.. is it possible that yll the vertices are in their own local space?

[EDIT] hm k dumb me - of course they're bound to their nodes...

tuan kuranes

07-12-2005 15:40:02

it's related to Page space, not world space.

Add this at end of _getvertex, just before returning it :

const uint pSize = mOptions->PageSize - 1;
vertex.x +=mInfo->pageX * pSize - mOptions->maxUnScaledX;
vertex.z += mInfo->pageZ * pSize - mOptions->maxUnScaledZ;

fiesch

07-12-2005 16:02:14

nothing... still not mathcing up with the visuals i get and nothing in from -1/-1 on and below (negative coordinates) - i had a very similar problem before and couldn't solve it

tuan kuranes

07-12-2005 17:13:49

Sorry, wrong code posted above, following is better and clearer :

const uint pSize = mOptions->PageSize - 1;
const uint tilesize = mOpt->TileSize - 1;

Vector3 vertex;
// change coordinate system for local tile to local page
vertex.x = (mInfo->tileX * tilesize) + x );
vertex.z = (mInfo->tileX * tilesize) + z );

// y is already scaled and worldspace
vertex.y = mHeightfield[vertex.x + vertex.z * mOpt->PageSize ];

// change coordinate system for local page to world space
vertex.x + =mInfo->pageX * pSize - mOptions->maxUnScaledX;
vertex.z + = mInfo->pageZ * pSize - mOptions->maxUnScaledZ;

// then scale it
vertex.x *= mOpt->scale.x;
vertex.z *= mOpt->scale.z;

fiesch

08-12-2005 11:42:12

hm ok optimizing didn't go too well - i changed the getOption interface to the std::vector kind and added a description block

i tried using precalc techniques for opting the code out but that didn't go as expected... it's pretty ok from the load hit as it is now..


Index: include/OgrePagingLandScapeIndexBuffer.h
===================================================================
RCS file: /cvsroot/ogre/ogreaddons/paginglandscape/PlugIns/PagingLandScape2/include/OgrePagingLandScapeIndexBuffer.h,v
retrieving revision 1.16
diff -u -p -r1.16 OgrePagingLandScapeIndexBuffer.h
--- include/OgrePagingLandScapeIndexBuffer.h 16 Nov 2005 10:44:14 -0000 1.16
+++ include/OgrePagingLandScapeIndexBuffer.h 5 Dec 2005 16:52:16 -0000
@@ -64,6 +64,9 @@ namespace Ogre
/// Internal method for generating triangle list terrain indexes
IndexData* generateTriListIndexes(const bool northStitch, const bool southStitch, const bool eastStitch, const bool westStitch, const int RenderLevel, PagingLandScapeRenderable** Neighbors) const;

+ //*******************
+ //Added by Fiesch adapted from a post by tonyhnz
+ IndexData* getRawIndexes(int renderLevel);
protected:

/** Returns the index into the height array for the given coordinates. */
Index: include/OgrePagingLandScapeRenderable.h
===================================================================
RCS file: /cvsroot/ogre/ogreaddons/paginglandscape/PlugIns/PagingLandScape2/include/OgrePagingLandScapeRenderable.h,v
retrieving revision 1.22
diff -u -p -r1.22 OgrePagingLandScapeRenderable.h
--- include/OgrePagingLandScapeRenderable.h 17 Nov 2005 10:51:01 -0000 1.22
+++ include/OgrePagingLandScapeRenderable.h 5 Dec 2005 16:47:08 -0000
@@ -160,6 +160,10 @@ namespace Ogre

bool isInUse() const {return mInUse;};

+ IndexData* getRawIndexData(const int renderlevel);
+ void getRawVertexData(Vector3* pVerts);
+ const uint PagingLandScapeRenderable::getVertexCount();
+
protected:

VertexData* mCurrVertexes;
@@ -220,6 +224,8 @@ namespace Ogre
// did LOD level changes this frame
bool mChangedRenderLevel;

+ Vector3 _getvertex(const int x, const int z) const;
+
private :

Image::Box mRect;
Index: src/OgrePagingLandScapeIndexBuffer.cpp
===================================================================
RCS file: /cvsroot/ogre/ogreaddons/paginglandscape/PlugIns/PagingLandScape2/src/OgrePagingLandScapeIndexBuffer.cpp,v
retrieving revision 1.23
diff -u -p -r1.23 OgrePagingLandScapeIndexBuffer.cpp
--- src/OgrePagingLandScapeIndexBuffer.cpp 28 Nov 2005 15:37:16 -0000 1.23
+++ src/OgrePagingLandScapeIndexBuffer.cpp 5 Dec 2005 16:52:20 -0000
@@ -567,4 +567,41 @@ namespace Ogre
return numIndexes;
}

+ //*******************
+ //Added by Fiesch adapted from a post by tonyhnz
+ IndexData *PagingLandScapeIndexBufferManager::getRawIndexes(int renderLevel)
+ {
+ // no stitching is done
+ // used to expose terrain vertex data
+
+ if (renderLevel >= static_cast <int> (mNumIndexes))
+ renderLevel = static_cast <int> (mNumIndexes)-1;
+
+ if (renderLevel < 0)
+ renderLevel =0 ;
+
+ const uint stitchFlags = 0;
+
+ assert (mLevelIndex.size() > (uint)renderLevel);
+
+ IndexMap::iterator ii = mLevelIndex[ renderLevel ]->find( stitchFlags );
+ if ( ii == mLevelIndex[ renderLevel ]->end())
+ {
+ // Create
+ IndexData* indexData = generateTriListIndexes( false,
+ false,
+ false,
+ false,
+ renderLevel,
+ 0);
+ mLevelIndex[ renderLevel ]->insert(
+ IndexMap::value_type(stitchFlags, indexData));
+
+ return indexData;
+ }
+ else
+ {
+ return ii->second;
+ }
+ }
} //namespace
Index: src/OgrePagingLandScapeRenderable.cpp
===================================================================
RCS file: /cvsroot/ogre/ogreaddons/paginglandscape/PlugIns/PagingLandScape2/src/OgrePagingLandScapeRenderable.cpp,v
retrieving revision 1.45
diff -u -p -r1.45 OgrePagingLandScapeRenderable.cpp
--- src/OgrePagingLandScapeRenderable.cpp 28 Nov 2005 15:37:16 -0000 1.45
+++ src/OgrePagingLandScapeRenderable.cpp 8 Dec 2005 11:24:35 -0000
@@ -1093,4 +1093,65 @@ namespace Ogre
mParentNode->needUpdate();
}
}
+
+ Vector3 PagingLandScapeRenderable::_getvertex(const int x, const int z) const
+ {
+ const uint tilesize = mOpt->TileSize - 1;
+ const uint pSize = mOpt->PageSize -1;
+ Vector3 vertex;
+
+ vertex.x = (mInfo->tileX * tilesize) + x;
+
+ vertex.z = (mInfo->tileZ * tilesize) + z;
+
+ vertex.y = mHeightfield[static_cast<unsigned int>(vertex.x + (vertex.z *mOpt->PageSize) )];
+
+ vertex.x += mInfo->pageX * pSize - mOpt->maxUnScaledX;
+ vertex.z += mInfo->pageZ * pSize - mOpt->maxUnScaledZ;
+
+ vertex.x *= mOpt->scale.x;
+ vertex.z *= mOpt->scale.z;
+ return vertex;
+ }
+
+ /**
+ * This returns the actual Polygon assignments for this renderable at the given renderLevel
+ * @param renderlevel LODLevel to get the Index data at
+ * @return the queried IndexData
+ */
+ IndexData* PagingLandScapeRenderable::getRawIndexData(const int renderlevel)
+ {
+ return PagingLandScapeIndexBufferManager::getSingleton().getRawIndexes( renderlevel);
+ }
+
+ /**
+ * Returns the Vertices for this renderable in world space
+ * @param pVerts >Pre-allocated< buffer to hold the vertices. The number of Vertices can be
+ * retrieved by a call to getVertexCount
+ * @note no checking is done on the array whatsoever
+ */
+ void PagingLandScapeRenderable::getRawVertexData(Vector3* pVerts)
+ {
+ // pVerts should be pre-allocated to tilesize*tilesize
+ // using getVertexCount()
+ const uint tilesize = mOpt->TileSize -1 ;
+
+ Vector3 *vert = pVerts;
+ for (uint i=0; i<=tilesize; ++i)
+ {
+ for (uint j=0; j<=tilesize; ++j)
+ {
+ *vert++= _getvertex(i, j);
+ }
+ }
+ }
+
+ /**
+ * Returns the number of this Renderable's vertices
+ * @return the number of this Renderable's vertices
+ */
+ const uint PagingLandScapeRenderable::getVertexCount()
+ {
+ return mOpt->TileSize * mOpt->TileSize ;
+ }
} //namespace
Index: src/OgrePagingLandScapeSceneManager.cpp
===================================================================
RCS file: /cvsroot/ogre/ogreaddons/paginglandscape/PlugIns/PagingLandScape2/src/OgrePagingLandScapeSceneManager.cpp,v
retrieving revision 1.52
diff -u -p -r1.52 OgrePagingLandScapeSceneManager.cpp
--- src/OgrePagingLandScapeSceneManager.cpp 28 Nov 2005 15:37:16 -0000 1.52
+++ src/OgrePagingLandScapeSceneManager.cpp 8 Dec 2005 09:15:17 -0000
@@ -137,6 +137,8 @@ namespace Ogre
//-------------------------------------------------------------------------
void PagingLandScapeSceneManager::setWorldGeometry(DataStreamPtr& stream, const String& typeName)
{
+ if (!mListenerManager)
+ mListenerManager = new PagingLandScapeListenerManager();
// Clear out any existing world resources (if not default)
if (ResourceGroupManager::getSingleton().getWorldResourceGroupName() !=
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME)
@@ -199,7 +201,7 @@ namespace Ogre
if (!mPageManager)
{
mPageManager = new PagingLandScapePageManager();
- mPageManager->setWorldGeometryRenderQueue (SceneManager::getWorldGeometryRenderQueue());
+ mPageManager->setWorldGeometryRenderQueue (static_cast<Ogre::RenderQueueGroupID>(SceneManager::getWorldGeometryRenderQueue()));
Root::getSingleton().addFrameListener(mPageManager);
mData2DManager->setPageManager();
}
@@ -852,7 +854,7 @@ namespace Ogre
// Now reload pages
//PagingLandScapePageManager::getSingleton().getPage(page.x, page.y)->reload();
}
- if (mOptions.setOption(strKey, pValue) == true)
+ if (mOptions.setOption(strKey, pValue) == true)
{
return true;
}
@@ -1133,6 +1135,53 @@ namespace Ogre
* static_cast < Real * > (pDestValue) = mBrushScale;
return true;
}
+ //added for Vertex data retrieval
+ /**
+ * This is the optimized, yet a bit fuzzy implementation of the getVertexDataPatch
+ * Usage: Pass in a std::vector<void*> Pointer to the getOption call containing at least 5 Elements
+ * [0](Ogre::uint*) = X Index of the Page to retrieve data from
+ * [1](Ogre::uint*) = Z Index of the Page to retrieve data from
+ * [2](Ogre::uint*) = X Index of the Tile within the Page to retrieve data from
+ * [3](Ogre::uint*) = Z Index of the Tile within the Page to retrieve data from
+ * [4](Ogre::uint*) = LodLevel to get the data at (note that level 0 means highest detail)
+ * The getData call will then append 3 entries to the end of the vector. In Detail(in order)
+ * [End-2](Ogre::uint*) = Number of vertices returned
+ * [End-1] (Ogre::Vector3*) = The actual vertices, this is a array containing as many elements as returned in [End-2]
+ * [End] (Ogre::IndexData*) = The index data for the terrain polygons at the queried LodLevel
+ * @remark note that the caller is in charge of deleting the vector array
+ */
+ if (strKey == "PageGetTileVertexData_2")
+ {
+ uint requestPageX = *static_cast<uint *>((*static_cast<std::vector<void*>*>(pDestValue))[0]);
+ uint requestPageZ = *static_cast<uint *>((*static_cast<std::vector<void*>*>(pDestValue))[1]);
+ uint requestTileX = *static_cast<uint *>((*static_cast<std::vector<void*>*>(pDestValue))[2]);
+ uint requestTileZ = *static_cast<uint *>((*static_cast<std::vector<void*>*>(pDestValue))[3]);
+ uint requestLodLevel = *static_cast<uint *>((*static_cast<std::vector<void*>*>(pDestValue))[4]);
+ Ogre::PagingLandScapePage* page = PagingLandScapePageManager::getSingleton().getPage(requestPageX,requestPageZ);
+ if(page)
+ {
+ Ogre::PagingLandScapeTile* tile = page->getTile(requestTileX,requestTileZ);
+ if(tile)
+ {
+ Ogre::PagingLandScapeRenderable* rend = tile->getRenderable();
+ if(rend)
+ {
+ Ogre::Vector3* tempPointer; //This will hold the vertexData and needs to be deleted by the caller
+ uint* numPtr = new uint;
+ *numPtr = rend->getVertexCount();
+ (*static_cast<std::vector<void*>*>(pDestValue)).push_back(numPtr);
+ tempPointer = new Ogre::Vector3[*numPtr];
+ //warning! make sure that the allocated space for the vertices is big enough!
+ rend->getRawVertexData(tempPointer);
+ (*static_cast<std::vector<void*>*>(pDestValue)).push_back(tempPointer);
+ (*static_cast<std::vector<void*>*>(pDestValue)).push_back(rend->getRawIndexData(requestLodLevel));
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+ //end of addition
if (mOptions.getOption(strKey, pDestValue) == false)
{
return PagingLandScapeOctreeSceneManager::getOption (strKey, pDestValue);
@@ -1195,6 +1244,12 @@ namespace Ogre
{
return true;
}
+ //added for Vertex data retrieval
+ if (strKey == "PageGetTileVertexData")
+ {
+ return true;
+ }
+ //end of addition
if (mOptions.hasOption(strKey) == false)
{
return PagingLandScapeOctreeSceneManager::hasOption (strKey);

tuan kuranes

16-12-2005 14:26:18

committed.
Thanks.

dimatd

06-01-2006 22:42:08

Please add ..

It is impossible to use "PageGetTileVertexData_2" for it is created not correct NxTriangleMesh (Novodex....)



cvs diff: Diffing include
Index: include/OgrePagingLandScapeRenderable.h
===================================================================
RCS file: /cvsroot/ogre/ogreaddons/paginglandscape/PlugIns/PagingLandScape2/include/OgrePagingLandScapeRenderable.h,v
retrieving revision 1.23
diff -r1.23 OgrePagingLandScapeRenderable.h
166a167,168
> inline VertexData* getCurrVertexes(){return mCurrVertexes;}
>
cvs diff: Diffing misc
cvs diff: Diffing obj
cvs diff: Diffing obj/Debug
cvs diff: Diffing obj/Release
cvs diff: Diffing scripts
cvs diff: Diffing src
Index: src/OgrePagingLandScapeSceneManager.cpp
===================================================================
RCS file: /cvsroot/ogre/ogreaddons/paginglandscape/PlugIns/PagingLandScape2/src/OgrePagingLandScapeSceneManager.cpp,v
retrieving revision 1.56
diff -r1.56 OgrePagingLandScapeSceneManager.cpp
1194a1195,1230
> if (strKey == "PageGetTileCurrentVertexData")
> {
> uint requestPageX = *static_cast<uint *>((*static_cast<std::vector<void*>*>(pDestValue))[0]);
> uint requestPageZ = *static_cast<uint *>((*static_cast<std::vector<void*>*>(pDestValue))[1]);
> uint requestTileX = *static_cast<uint *>((*static_cast<std::vector<void*>*>(pDestValue))[2]);
> uint requestTileZ = *static_cast<uint *>((*static_cast<std::vector<void*>*>(pDestValue))[3]);
> uint requestLodLevel = *static_cast<uint *>((*static_cast<std::vector<void*>*>(pDestValue))[4]);
> Ogre::PagingLandScapePage* page = PagingLandScapePageManager::getSingleton().getPage(requestPageX,requestPageZ);
> if(page)
> {
> Ogre::PagingLandScapeTile* tile = page->getTile(requestTileX,requestTileZ);
> if(tile)
> {
> Ogre::PagingLandScapeRenderable* rend = tile->getRenderable();
> if(rend)
> {
> //Ogre::Vector3* tempPointer; //This will hold the vertexData and needs to be deleted by the caller
> //uint* numPtr = new uint;
> //*numPtr = rend->getVertexCount();
> //(*static_cast<std::vector<void*>*>(pDestValue)).push_back(numPtr);
> //tempPointer = new Ogre::Vector3[*numPtr];
> //warning! make sure that the allocated space for the vertices is big enough!
> //rend->getRawVertexData(tempPointer);
> static Ogre::Vector3 vera_tempPointer;
> //tempPointer = new Ogre::Vector3;
> vera_tempPointer = page->getPageNode()->getPosition();
> (*static_cast<std::vector<void*>*>(pDestValue)).push_back(rend->getCurrVertexes());
> (*static_cast<std::vector<void*>*>(pDestValue)).push_back(rend->getRawIndexData(requestLodLevel));
> (*static_cast<std::vector<void*>*>(pDestValue)).push_back(&vera_tempPointer);
> return true;
> }
> }
> }
> return false;
> }

tuan kuranes

07-01-2006 07:09:38

I can, but I need more explanations. What's the difference ?
(and why not add a wiki topic on novodex integration http://www.ogre3d.org/wiki/index.php/Pa ... cs_engines)

dimatd

16-01-2006 14:10:38

Not work code:

1. Get vectex and index data ...

void VeraWorldManager::tileLoaded(PagingLandscapeEvent *p)
{
std::vector<void*> tile;
Ogre::uint *q = new Ogre::uint [5];
Ogre::String name;
q[0] = static_cast<Ogre::uint>(p->mPagex);
q[1] = static_cast<Ogre::uint>(p->mPagez);
q[2] = static_cast<Ogre::uint>(p->mTilex);
q[3] = static_cast<Ogre::uint>(p->mTilez);
q[4] = 2;
for(Ogre::uint i=0; i < 5; i++){
tile.push_back(&q[i]);
name += Ogre::StringConverter::toString(q[i]);
}
nxTile &nxtile = mapTiles[name];
if(!nxtile.isLoad()){
nxtile.setLoad();
nxtile.setName(name);

mSceneMgr->getOption("PageGetTileVertexData_2", &tile);
uint* count = static_cast<uint*>(tile[5]);
Ogre::Vector3 *vectex = static_cast<Ogre::Vector3 *>(tile[6]);
Ogre::IndexData *mIndex = static_cast<Ogre::IndexData *>(tile[7]);

Vera::TriangleShapeDesc tmp_mesh(vectex, *count, mIndex);
mSceneNodeDescManager->createSceneNodeDesc(tmp_mesh, name);
mScenes[MainScene]->createSceneNode(tiles++, name.c_str());

}
delete [] q;

}


2. create TriangleShapeDesc

TriangleShapeDesc::TriangleShapeDesc(Ogre::Vector3 *vertex, Ogre::uint size, Ogre::IndexData* _index)
{
size_t index_offset = 0;
Ogre::uint _numVertices = size;
Ogre::uint mIndexCount = static_cast<Ogre::uint>(_index->indexCount);

NxVec3* mMeshVertices = new NxVec3[_numVertices];
NxU32* mMeshFaces = new NxU32[mIndexCount];
for(Ogre::uint i=0; i < size; i++){
mMeshVertices[i] = NxTools::convert(vertex[i]);
}

size_t numTris = _index->indexCount / 3;
Ogre::HardwareIndexBufferSharedPtr ibuf = _index->indexBuffer;

bool use32bitindexes = (ibuf->getType() == Ogre::HardwareIndexBuffer::IT_32BIT);


if ( use32bitindexes ) {

unsigned int* pInt = static_cast<unsigned int*>(ibuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
size_t offset = 0;

for ( size_t k = 0; k < numTris*3; ++k) {
mMeshFaces[index_offset++] = pInt[k];
}
}
else {
unsigned short* pShort = reinterpret_cast<unsigned short*>(ibuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
size_t offset = 0;

for ( size_t k = 0; k < numTris*3; ++k) {
mMeshFaces[index_offset++] = static_cast<unsigned int>(pShort[k]);
}
}
ibuf->unlock();

NxTriangleMeshDesc terrainDesc;
terrainDesc.numVertices = _numVertices;
terrainDesc.numTriangles = mIndexCount / 3;
terrainDesc.pointStrideBytes = sizeof(NxVec3);
terrainDesc.triangleStrideBytes = 3*sizeof(NxU32);
terrainDesc.points = mMeshVertices;
terrainDesc.triangles = mMeshFaces;
terrainDesc.flags = 0;

terrainDesc.heightFieldVerticalAxis = NX_Y;
terrainDesc.heightFieldVerticalExtent = -1000.0f;

MemoryWriteBuffer buf;
bool status = NxCookTriangleMesh(terrainDesc, buf);
MemoryReadBuffer readBuffer(buf.data);
NxTriangleMesh *mterrainMesh = mPhysicsSDK->createTriangleMesh(readBuffer);

triangleShapeDesc.meshData = mterrainMesh;
//triangleShapeDesc.shapeFlags = NX_SF_FEATURE_INDICES;

delete [] mMeshVertices;
delete [] mMeshFaces;
}


3. create NxActor

NxActorDesc ActorDesc;
ActorDesc.shapes.pushBack(&triangleShapeDesc);
gTerrain = gScene->createActor(ActorDesc);
gTerrain->userData = (void*)0;


4. move object

nScene->simulate(time); //Note: a real application would compute and pass the elapsed time here.
nScene->flushStream();
nScene->fetchResults(NX_RIGID_BODY_FINISHED, true);

int nbActors = nScene->getNbActors();
NxActor** actors = nScene->getActors();
while(nbActors--)
{
NxActor* actor = *actors++;

if(!actor->userData) continue;

Vera::SceneNode *mNode = static_cast<Vera::SceneNode *>(actor->userData);
mNode->simulate();
//mNode->setPosition( NxTools::convert( actor->getGlobalPosition()) ) ;
//mNode->setOrientation( NxTools::convert( actor->getGlobalOrientation() ) );
}


void SceneNode::simulate()
{
if(!type){
mSceneNode->setPosition( NxTools::convert( actor->getGlobalPosition()) ) ;
mSceneNode->setOrientation( NxTools::convert( actor->getGlobalOrientation() ) );
}
}





this code not correct work; why? I don`t now.

Result:

1.

C:\p4\release\novodex_2.3.1\novodex\SDKs\Core\Common\src\ContactMeshMesh.cpp (116) :warning : Trying to collide two pmap-less, nonconvex, nonheightfield meshes:
this is no longer supported!







dimatd

16-01-2006 14:23:05

Work code:

1. Get vectex and index data ...

void VeraWorldManager::tileLoaded(PagingLandscapeEvent *p)
{
std::vector<void*> tile;
Ogre::uint *q = new Ogre::uint [5];
Ogre::String name;
q[0] = static_cast<Ogre::uint>(p->mPagex);
q[1] = static_cast<Ogre::uint>(p->mPagez);
q[2] = static_cast<Ogre::uint>(p->mTilex);
q[3] = static_cast<Ogre::uint>(p->mTilez);
q[4] = 2;
for(Ogre::uint i=0; i < 5; i++){
tile.push_back(&q[i]);
name += Ogre::StringConverter::toString(q[i]);
}
nxTile &nxtile = mapTiles[name];
if(!nxtile.isLoad()){
nxtile.setLoad();
nxtile.setName(name);
mSceneMgr->getOption("PageGetTileCurrentVertexData", &tile);
Ogre::VertexData *mVertex = static_cast<Ogre::VertexData *>(tile[5]);
Ogre::IndexData *mIndex = static_cast<Ogre::IndexData *>(tile[6]);
Ogre::Vector3 *pos = static_cast<Ogre::Vector3 *>(tile[7]);
Vera::TriangleShapeDesc tmp_mesh(mVertex, mIndex);
mSceneNodeDescManager->createSceneNodeDesc(tmp_mesh, name);
mScenes[MainScene]->createSceneNode(tiles++, name.c_str(), *pos,Ogre::Quaternion::IDENTITY,
Ogre::Vector3::UNIT_SCALE, STATIC_NODE);
}
delete [] q;

}

2. create TriangleShapeDesc


TriangleShapeDesc::TriangleShapeDesc(Ogre::VertexData *_vertex, Ogre::IndexData* _index)
{
size_t index_offset = 0;
Ogre::uint _numVertices = static_cast<Ogre::uint>(_vertex->vertexCount);
Ogre::uint mIndexCount = static_cast<Ogre::uint>(_index->indexCount);

NxVec3* mMeshVertices = new NxVec3[_numVertices];
NxU32* mMeshFaces = new NxU32[mIndexCount];

const Ogre::VertexElement* posElem = _vertex->vertexDeclaration->findElementBySemantic(Ogre::VES_POSITION);
Ogre::HardwareVertexBufferSharedPtr vbuf = _vertex->vertexBufferBinding->getBuffer(posElem->getSource());
unsigned char* vertex = static_cast<unsigned char*>(vbuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));

float* pReal;

for( size_t j = 0; j < _numVertices; ++j, vertex += vbuf->getVertexSize()) {
posElem->baseVertexPointerToElement(vertex, &pReal);
mMeshVertices[j] = NxVec3(pReal[0],pReal[1],pReal[2]);
}

vbuf->unlock();


size_t numTris = _index->indexCount / 3;
Ogre::HardwareIndexBufferSharedPtr ibuf = _index->indexBuffer;

bool use32bitindexes = (ibuf->getType() == Ogre::HardwareIndexBuffer::IT_32BIT);


if ( use32bitindexes ) {

unsigned int* pInt = static_cast<unsigned int*>(ibuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
size_t offset = 0;

for ( size_t k = 0; k < numTris*3; ++k) {
mMeshFaces[index_offset++] = pInt[k];
}
}
else {
unsigned short* pShort = reinterpret_cast<unsigned short*>(ibuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
size_t offset = 0;

for ( size_t k = 0; k < numTris*3; ++k) {
mMeshFaces[index_offset++] = static_cast<unsigned int>(pShort[k]);
}
}
ibuf->unlock();

NxTriangleMeshDesc terrainDesc;
terrainDesc.numVertices = _numVertices;
terrainDesc.numTriangles = mIndexCount / 3;
terrainDesc.pointStrideBytes = sizeof(NxVec3);
terrainDesc.triangleStrideBytes = 3*sizeof(NxU32);
terrainDesc.points = mMeshVertices;
terrainDesc.triangles = mMeshFaces;
terrainDesc.flags = 0;

terrainDesc.heightFieldVerticalAxis = NX_Y;
terrainDesc.heightFieldVerticalExtent = -1000.0f;

MemoryWriteBuffer buf;
bool status = NxCookTriangleMesh(terrainDesc, buf);
MemoryReadBuffer readBuffer(buf.data);
NxTriangleMesh *mterrainMesh = mPhysicsSDK->createTriangleMesh(readBuffer);

triangleShapeDesc.meshData = mterrainMesh;
triangleShapeDesc.shapeFlags = NX_SF_FEATURE_INDICES;

delete [] mMeshVertices;
delete [] mMeshFaces;
}


3.

...
4.
...

work correct

dimatd

16-01-2006 14:36:23


(and why not add a wiki topic on novodex integration http://www.ogre3d.org/wiki/index.php/Pa ... cs_engines)


I`am bad speak English ...

tuan kuranes

17-01-2006 09:32:03

ok.

RB

30-01-2006 12:10:42

Good day,

I am trying to make working demo acording to tuan's wiki page http://www.ogre3d.org/wiki/index.php/Using_PLSM2_with_Newton Then i attached delegates for PageLoaded & TileLoaded events to PLSM i get PageLoaded event, but i can't get TileLoaded event. Maybe i am not doing necessary initialization?

PLSM2Listener::PLSM2Listener( Ogre::PagingLandScapeSceneManager * _sceneManager) :
sceneManager ( _sceneManager)
{
YAKE_LOG("Entered to PLSM2 constructor");

loadTileDelegate = new Ogre::PagingLandscapeDelegate();
loadTileDelegate->bind( &(*this), &PLSM2Listener::tileLoaded);

mpageloadlistener = new Ogre::PagingLandscapeDelegate(&(*this),
&PLSM2Listener::pageLoaded);

// hardwareBufferManager = new Ogre::DefaultHardwareBufferManager();

sceneManager->setWorldGeometry("paginglandScape2.cfg");

sceneManager->setOption( "addLoadPageListener", mpageloadlistener );
sceneManager->setOption( "addLoadTileListener", loadTileDelegate);

sceneManager->setOption( "LoadNow", NULL);
}

int main()
{
Ogre::Root * root;
Ogre::PagingLandScapeSceneManager * sceneMgr;

root = new Ogre::Root( "yake.graphics.ogre_plugins.cfg", "yake.graphics.ogre.cfg", "Ogre_Server.log" );

setupResources();

Ogre::RenderWindow * mWindow;

if( root->showConfigDialog())
mWindow = root->initialise(true, "Terrain Server");
Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

sceneMgr = (Ogre::PagingLandScapeSceneManager *) root->getSceneManager( Ogre::ST_EXTERIOR_REAL_FAR);
....

physics::PLSM2Listener * plsmManager = new physics::PLSM2Listener( sceneMgr);

....
}

The last question : can you help me with relationships of PLSM and Ogre::HardwareBufferManager classes?

tuan kuranes

30-01-2006 16:11:18

I'll suppose that you're on a "server only" configuration, no graphics?

In this very particular case, tile will never be loaded as they are graphic, pages are Heightmap file 1:1 mapping, but tiles are vertex grouping as batch call to be faster under GPU uses.

The last question : can you help me with relationships of PLSM and Ogre::HardwareBufferManager classes?

Ogre::HardwareBufferManager are initialised by the renderable manager when it creates its pool of renderables.
On the server it might not be that useful. Try to make the renderablepool and tilepool equal to 0 using config file parameters. (search wiki page.)

RB

30-01-2006 16:41:21

Thanks for replay. I'll grep through the wiki about tilepools.


... but tiles are vertex grouping as batch call to be faster under GPU uses.


This means what tile geometry can't be accessible without camera object? Should i create some dummy camera for loading tiles?

Is there any chance what this approach could work on graphics card less systems?

tuan kuranes

30-01-2006 16:58:48

This means what tile geometry can't be accessible without camera object? Should i create some dummy camera for loading tiles?

yes.
In your case it's Renderable that you needs as it's handling vertex data.
Camera make activate tiles and then load renderable of visible tiles.

Is there any chance what this approach could work on graphics card less systems?
Nope.
You'll have to patch plsm2 for that.

RB

30-01-2006 17:10:16

Thanks for explanation :)

tuan kuranes

30-01-2006 17:20:16

What you have to do is to add a modified method based on renderable::getvertexdata() that takes part of renderable::init() to compute "mInfo" on each possible renderable, iterating over all pages, all tiles.

Make sure you handle differences between Client Loded Renderables and server meshes being at full Lod.

RB

30-01-2006 17:49:08

I'll take a closer look at tile loading mechanizm and if i succed i'll post a patch for GPU less users :) Thanks!