Problem with NxOgre::Scene::createSceneGeometr

sungoco

19-10-2009 08:42:45

I create heightfield as :


sceneMgr->setWorldGeometry("terrain.cfg");
NxOgre::ResourceSystem::getSingleton()->openArchive("Nx", "file:E:\\work\\Game\\Player_v2.0_Source\\Player\\Bin\\media");
NxOgre::HeightField* hf= NxOgre::HeightFieldManager::getSingleton()->load("Nx:terrain.xhf");
NxOgre::HeightFieldGeometry* hfg = new NxOgre::HeightFieldGeometry(hf,NxOgre::Real3(1500,150,1500));
hfg->setLocalPose(NxOgre::Matrix44(NxOgre::Real3(0,35,0)));
mScene->createSceneGeometry(hfg);


when I put my ninja, ninja keeps to fall.
Where is my problem?("terrain.xhf" is from "height.png" which is a grayscale)

(My ninja initial positon is:750.0, 10.0, 750.0
Ogre::Real Positiony = hf->getHeightField()->getHeight(750.0, 750.0);
the Positiony is 0.000)


terrain.cfg:
WorldTexture=terrain_texture.jpg

DetailTexture=terrain_detail.jpg

DetailTile=3

PageSource=Heightmap

Heightmap.image=terrain.png

PageSize=513

TileSize=33

MaxPixelError=3

PageWorldX=512

PageWorldZ=512

MaxHeight=30

MaxMipMapLevel=5

#VertexNormals=yes
#VertexColors=yes
#UseTriStrips=yes

# Use vertex program to morph LODs, if available
VertexProgramMorph=yes

LODMorphStart=0.2

# This following section is for if you want to provide your own terrain shading routine
# Note that since you define your textures within the material this makes the
# WorldTexture and DetailTexture settings redundant

# The name of the vertex program parameter you wish to bind the morph LOD factor to
# this is 0 when there is no adjustment (highest) to 1 when the morph takes it completely
# to the same position as the next lower LOD
# USE THIS IF YOU USE HIGH-LEVEL VERTEX PROGRAMS WITH LOD MORPHING
#MorphLODFactorParamName=morphFactor

# The index of the vertex program parameter you wish to bind the morph LOD factor to
# this is 0 when there is no adjustment (highest) to 1 when the morph takes it completely
# to the same position as the next lower LOD
# USE THIS IF YOU USE ASSEMBLER VERTEX PROGRAMS WITH LOD MORPHING
#MorphLODFactorParamIndex=4

# The name of the material you will define to shade the terrain
#CustomMaterialName=TestTerrainMaterial


betajaen

19-10-2009 10:20:36

Before I debug your Heightfield, what is your Ninja? Is it using a TriangleMeshGeometry as a Shape?

dgoldaraz

19-10-2009 10:28:05

I have the same problems with my Ball.
I create the same HeigthField and my ball keeps to fall.


OGRE3DBody* mSphere;
mSphere = mRenderSystem->createBody(new NxOgre::Sphere(3),NxOgre::Real3(750,100,750),"Sphere3.mesh");


I don't know where is the problem...

sungoco

19-10-2009 10:56:14


NxOgre::ResourceSystem::getSingleton()->openArchive("media", "file:E:/work/Game/Player_v2.0_Source/Player/Bin/Media");
NxOgre::Mesh* triangleMesh = NxOgre::MeshManager::getSingleton()->load("media:ninja.nxs");
NxOgre::TriangleGeometry* triangleGeometry = new NxOgre::TriangleGeometry(triangleMesh);


Yes, My ninja is TriangleMeshGeometry.
When I use Convex, My ninja falled down always.

betajaen

19-10-2009 11:10:35

TriangleMeshes should be never used in dynamic/kinematic Actors - ever. They also cannot collide with Heightfields.

sungoco

19-10-2009 14:58:34

Thanks,I'll try tomorrow.So many confuse to heightfield, where I can find wiki or sample about the heightfield ? except “BloodyMess Ogre::Terrain heightfield" which is so strange that I cannt find ogre::Terrain.

betajaen

19-10-2009 16:00:03

Have a look at the NxOgre Portal on the wiki.

There has also been a few threads in this forum recently about heightfields containing code that may help.

sungoco

20-10-2009 03:11:44

OK, When I change my ninja to convex, It doesn't keep to fall.
But the terrain doesn't match.

My test code is:

NxOgre::ResourceSystem::getSingleton()->openArchive("Nx", "file:E:\\work\\Game\\Player_v2.0_Source\\Player\\Bin\\media");
NxOgre::HeightField* hf= NxOgre::HeightFieldManager::getSingleton()->load("Nx:terrain.xhf");

//this is the terrain height
Ogre::Real TerrainHeight = hf->getHeightField()->getHeight(baseNode->getPosition().x, baseNode->getPosition().z);

rayQuery->setRay(Ray(baseNode->getPosition() + Vector3(0, 200, 0), Vector3::NEGATIVE_UNIT_Y));
RaySceneQueryResult &qryResult = rayQuery->execute();
RaySceneQueryResult::iterator i = qryResult.begin();
if(i != qryResult.end() && i->worldFragment)
{
baseNode->setPosition(baseNode->getPosition().x, i->worldFragment->singleIntersection.y + 1, baseNode->getPosition().z);
}

When I put my ninja at somplace the "TerrainHeight " is 0.00, but the " i->worldFragment->singleIntersection.y" is 43.0.
When I put my ninja at another place the "TerrainHeight " is more than 8000.0, but the " i->worldFragment->singleIntersection.y" is less than 100.0

By the way, when I convert my ninja, flour shows:

PhysX Error! NXE_DB_WARNING (f:\p4physx\experimental\PhysX_2.8.1_GPU\novodex\SDK
s\Core\Device\RegistryHardwareSelection.cpp:71)
CUDA not available
PhysX Error! NXE_DB_WARNING (f:\p4physx\experimental\PhysX_2.8.1_GPU\novodex\SDK
s\Core\Device\RegistryHardwareSelection.cpp:71)
CUDA not available

sungoco

20-10-2009 09:16:54

I can corret this problem by:
void MapManager::heightFromShape(const unsigned int numQueries, const Vector3& bounds){
RaySceneQuery* rq = GameRoot::getSingleton().getSceneMgr()->createRayQuery(Ray(Vector3(0,0,0),Vector3::NEGATIVE_UNIT_Y));

NxOgre::ManualHeightField* mhf = new NxOgre::ManualHeightField();
mhf->begin(numQueries,numQueries);

const Real normMin = 0.0f;
const Real normMax = 32767.0f;
short sample;

static int counter = 0;

unsigned int x,z;
for(x = 0;x<numQueries;++x){
for(z = 0;z<numQueries;++z){
Ray r = Ray(Vector3(x*(bounds.x-1)/(numQueries-1), bounds.y+1, z*(bounds.z-1)/(numQueries-1)), Vector3::NEGATIVE_UNIT_Y);
rq->setRay(r);
RaySceneQueryResult res = rq->execute();
RaySceneQueryResult::iterator it = res.begin();
while(it!=res.end()){
if(it->worldFragment){
// code based on Wiki Tutorial about Ogre::Terrain and NxOgre
sample = (short)(((it->worldFragment->singleIntersection.y)/(bounds.y)) * (normMax - normMin) + normMin);
mhf->sample(sample);
++counter;
}
++it;
}
}
}
NxOgre::HeightFieldGeometry* hfg = new NxOgre::HeightFieldGeometry(mhf->end(("hf_"+StringConverter::toString(counter)).c_str()),bounds);
if(mMapGeom)
GameRoot::getSingleton().getScene()->destroySceneGeometry(mMapGeom);
mMapGeom = GameRoot::getSingleton().getScene()->createSceneGeometry(hfg);

GameRoot::getSingleton().getSceneMgr()->destroyQuery(rq);
}



This section is from Druha's question.
But it's too slow, when I load a 1500 * 1500 map, it costs 96 seconds.
too slow, too slow.

So ,I doubt that if my terrain.xhf is wrong. It should not be form height.png wihic is a grayscale?

sungoco

20-10-2009 10:56:46

Any suggestions?

Druha

20-10-2009 16:39:29

Wait, you said 96 seconds? :shock:
In my app I force it to create 1536*1536 heightfield and overall game loading took only 9 seconds. Did you try it in debug mode or release mode?
By the way, this code was only an experiment :)

sungoco

21-10-2009 02:14:26

I did it in debug mode. Release will be so efficiency? :shock:

sungoco

21-10-2009 02:49:42

Yeah, It costs 3 seconds in release mode.......

sungoco

21-10-2009 02:53:38

Do you have any other method to create the terrain?
In Nxogre0.9 I can create it as:
m_sceneMgr->setWorldGeometry(terrainConfigurationFilename);

Ogre::ConfigFile* terrainCfg = new Ogre::ConfigFile();

terrainCfg->loadFromResourceSystem(terrainConfigurationFilename,
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);

int pageSize = Ogre::StringConverter::parseInt(terrainCfg->getSetting("PageSize"));
float PageWorldX = Ogre::StringConverter::parseReal(terrainCfg->getSetting("PageWorldX"));
float PageWorldZ = Ogre::StringConverter::parseReal(terrainCfg->getSetting("PageWorldZ"));
float maxHeight = Ogre::StringConverter::parseReal(terrainCfg->getSetting("MaxHeight"));
Ogre::String heightmap = terrainCfg->getSetting("Heightmap.image");

NxOgre::ShapeParams sp(shapeParams);
sp.mMeshScale.x = PageWorldX/(pageSize-1);
sp.mMeshScale.y = 1;
sp.mMeshScale.z = PageWorldZ/(pageSize-1);

NxOgre::Body* terrain = m_nxscene->createBody(
NxOgre::NxCreateID(m_nxscene->getNbActors(), heightmap),
new NxOgre::TerrainShape(heightmap, maxHeight, sp), pose, actorParams );

delete terrainCfg;

return terrain;

But now, I cannt find NxOgre::TerrainShape. There is only NxOgre::HeightField;
So my problem comes, and it cannt be solved until now.

sungoco

22-10-2009 06:07:10

????

Druha

22-10-2009 06:36:03

Nope, only 2 ways as far as I know:
- through .xhf generated file
- manual mesh generation based on actual terrain
I generate height data only first time and dump it to disk, later just load it from here and work with it.
I have to store heightfield data in other fornat then .xhf cause flour somehow flips heightfield image, so I had to transform it before passing to flour.

[Edit]
Oh... wait! You can also process heightfield image yourself, and generate ManualHeightField based on it

sungoco

22-10-2009 13:43:43

Thanks,
through .xhf generated file

can you give me a sample.