ET and PhysX

BigB

10-06-2008 10:32:07

Hi,

I'm tryng to integrate PhysX with ET, but so far i haven't had much sucess with it :(
I have been browsing this forums, and altough i found some information about it, i haven't been able to make this work.
The code i'm using to get the heightmap into PhysX is the following :


//Copy image data into PhysX as a heightfield
NxHeightFieldDesc mNxHeightFieldDesc;

mNxHeightFieldDesc.nbColumns = 512;
mNxHeightFieldDesc.nbRows = 512;
mNxHeightFieldDesc.verticalExtent = -1000;
mNxHeightFieldDesc.convexEdgeThreshold = 0;
mNxHeightFieldDesc.flags = NX_SF_FEATURE_INDICES | NX_SF_VISUALIZATION;
//Allocate storage for data
mNxHeightFieldDesc.samples = new NxU32[mNxHeightFieldDesc.nbColumns * mNxHeightFieldDesc.nbRows];
mNxHeightFieldDesc.sampleStride = sizeof(NxU32);

NxU8* currentByte = (NxU8*)mNxHeightFieldDesc.samples;
NxU32 index = 0;
NxI16 height = 0;
const Ogre::uchar* pSrc = mRawData->getPtr();

for (NxU32 row = 0; row < mNxHeightFieldDesc.nbRows; row++)
{
for (NxU32 column = 0; column < mNxHeightFieldDesc.nbColumns; column++)
{
NxHeightFieldSample* currentSample = (NxHeightFieldSample*)currentByte;

index = row + (column * mNxHeightFieldDesc.nbRows);
index *= 2;
height = pSrc[index];
height += pSrc[index + 1] * 256.0;
height -= 32768;

currentSample->height = height;
currentSample->materialIndex0 = 0;
currentSample->materialIndex1 = 0;

currentSample->tessFlag = 0;

currentByte += mNxHeightFieldDesc.sampleStride;
}
}
NxHeightField* mHeightField = NXmWorld->getPhysXDriver()->getSDK()->createHeightField(mNxHeightFieldDesc);
//Data has been copied, buffer can be deleted
delete[] mNxHeightFieldDesc.samples;




And then, i create my actor :


static NxReal sixtyFourKb = 65536.0f;
static NxReal thirtyTwoKb = 32767.5f;

NxVec3 size = NxVec3(512,100,512);
// shape
NxHeightFieldShapeDesc heightFieldShapeDesc;
heightFieldShapeDesc.heightField = mHeightField;
heightFieldShapeDesc.shapeFlags = NX_SF_FEATURE_INDICES | NX_SF_VISUALIZATION;
heightFieldShapeDesc.heightScale = size.y / sixtyFourKb;
heightFieldShapeDesc.rowScale = size.x / NxReal(513-1);
heightFieldShapeDesc.columnScale = size.z / NxReal(513-1);
heightFieldShapeDesc.meshFlags = NX_MESH_SMOOTH_SPHERE_COLLISIONS;
heightFieldShapeDesc.materialIndexHighBits = 0;
heightFieldShapeDesc.holeMaterial = 2;

// ator
NxActorDesc actorTerrainDesc;


actorTerrainDesc.globalPose.t = NxVec3(0, 0, 0);
NxActor *newActor = NXpmScene->getNxScene()->createActor(actorTerrainDesc);


Now, the problem, i don't see the heightmap anywhere, neither inside Ogre, or in Remote Debugging, i see all the other bodys falling, but not the heightmap.

Is there some trivial mistake in my code ?
thanks for any help,
Bruno

kungfoomasta

10-06-2008 18:24:42

Its been a while, but two things come to mind:


heightFieldShapeDesc.rowScale = size.x / NxReal(513-1);
heightFieldShapeDesc.columnScale = size.z / NxReal(513-1);


In my code, I use NxReal(numRows-1) and numColumns-1. Your number of columns is 512, so this doesn't match what I had.

Also, are you using a 16 bit raw file? I believe thats what I used, I think the code will vary if you are using other formats.

Sorry I couldn't help more.

BigB

10-06-2008 18:43:20

Thanks kungfoomasta.
numRows and numColumns it's the resolution of the raw file, right ?
So, if my heightmap is 512x512, numRows and numColumns will have those values ?
If it's not the resolution values, where do i get this values from ?
Yes, i'm using a 16bit raw file.

thanks,
Bruno

kungfoomasta

10-06-2008 20:51:59

I got the 512 numbers from your code:


mNxHeightFieldDesc.nbColumns = 512;
mNxHeightFieldDesc.nbRows = 512;


You should reuse them in your code to avoid any synch problems like this. (less hardcoding as well)

Anyway this probably isn't the cause of why its not broken. I'd have to look at your code more in depth, but unfortunately I don't have the time to do that. :(

What are you using to render your shapes in debug? I have some code I could give you if you want it.

BigB

10-06-2008 22:27:44

Hi,

Yes, that's not the problem, altough it wasn't correct either.
The rigid bodys shapes, i just let it render with the regulat physX debug, the heightmap i try to see it with Remote Debugging, but doens't show anywhere.
Any source you could supply, would be a great help.

thanks

SongOfTheWeave

12-06-2008 00:57:44

index = row + (column * mNxHeightFieldDesc.nbRows);
index *= 2;
height = pSrc[index];
height += pSrc[index + 1] * 256.0;
height -= 32768;


This looks wrong to me.

I didn't use a raw when I did this but it seems fishy that you're multiplying your index by 2. Why are you doing that?

Also, why are you checking two pixels to get your height? Each PhysX sample should correspond to exactly one pixel in your image. The section I quoted doesn't seem to make any sense. I'm guessing that's where your problem lies.

BigB

13-06-2008 14:07:28

index = row + (column * mNxHeightFieldDesc.nbRows);
index *= 2;
height = pSrc[index];
height += pSrc[index + 1] * 256.0;
height -= 32768;


This looks wrong to me.

I didn't use a raw when I did this but it seems fishy that you're multiplying your index by 2. Why are you doing that?

Also, why are you checking two pixels to get your height? Each PhysX sample should correspond to exactly one pixel in your image. The section I quoted doesn't seem to make any sense. I'm guessing that's where your problem lies.



Hi,
What you see there it's what is called the desesperation phase of not being able to get this to work.
That piece of the code should look like this :


index = row + (column * mNxHeightFieldDesc.nbRows);
height = pSrc[index];
height -= 32768;


But whatever i do, i see nothing on the screen. I think i should be able to see wrong data or something, the problem is i don't see absolutely anything, it's like if physX is ignoring me. I can place 0's on the height, i can place 128 on the height, i still get nothing on the Remote Debugger.
Am i missing something there, that actually makes the physic shape with all this data ?

thanks

SongOfTheWeave

15-06-2008 00:00:33

Are you specifying all your sizes in Ogre units? It looks like you might be calculating your height/row/column scales based on ETM vertex units, this wont work unless your verticies are 1.0 ogre unit apart (which is a special case.) You SHOULD have a TERRAIN_SCALE factor in there. If your terrain scale (in ogre units) is larger than 1.0 ogre units / vertex then this might be your problem, because your physics mesh will be very tiny. If your scale is 1.0 then you've got some other problem.

Red Noise

19-06-2008 16:52:10

Hi,

Your problem is here:

currentSample->materialIndex0 = 0;
currentSample->materialIndex1 = 0;


Use material indexes 1, they'll work, at least you'll see you shape in the remote debugger.