I need many different materials to use with my terrain, and I have no idea on how to upload them to the NxHeightFieldSample vs. the examples I am seeing are for NxTriangleMeshDesc.
the sample that physx shows is this
NxTriangleMeshDesc terrainDesc;
//add the mesh material data:
terrainDesc.materialIndexStride = sizeof(NxMaterialIndex);
terrainDesc.materialIndices = gTerrainMaterials;
but I don't see this in the NxHeightFieldSample.
what I have is this
const int matrixSize = 3;
const NxMaterialIndex matrix[9][3] =
{
// {tesselation, material0, material1}
{0,1,1}, {0,1,1}, {0,1,1},
{0,1,1}, {0,1,1}, {0,1,1},
{0,1,1}, {0,1,1}, {0,1,1}
};
int size = mapData.mapSize * mapData.mapSize;//size of map width * height
NxHeightFieldSample* auiSample = new NxHeightFieldSample[size];
NxHeightFieldSample* currentSample = auiSample;
unsigned int index = 0;
for(unsigned int row = 0; row < mapData.mapSize; ++row)
{
for(unsigned int column = 0; column < mapData.mapSize; ++column)
{
NxU32 matrixOffset = (row % matrixSize) * matrixSize + (column % matrixSize);
currentSample->height = terrain->height_imageData[index];
currentSample->materialIndex0 = matrix[matrixOffset][1];
currentSample->materialIndex1 = matrix[matrixOffset][2];
currentSample->tessFlag = matrix[matrixOffset][0];
currentSample++; index++;
}
}
NxHeightFieldDesc kHeightFieldDesc;
kHeightFieldDesc.format = NX_HF_S16_TM;
kHeightFieldDesc.nbRows = mapData.mapSize;//width
kHeightFieldDesc.nbColumns = mapData.mapSize;//height
kHeightFieldDesc.thickness = -255.0f * heightScale;
kHeightFieldDesc.convexEdgeThreshold = 0;
kHeightFieldDesc.samples = auiSample;
kHeightFieldDesc.sampleStride = sizeof(NxHeightFieldSample);
NxHeightField* pkHeightField = pSDK->createHeightField(kHeightFieldDesc);
delete []auiSample;
// description
NxHeightFieldShapeDesc kHeightFieldShapeDesc;
kHeightFieldShapeDesc.heightField = pkHeightField;
kHeightFieldShapeDesc.shapeFlags = NX_SF_FEATURE_INDICES;
kHeightFieldShapeDesc.heightScale = heightScale;
kHeightFieldShapeDesc.rowScale = rowScale;
kHeightFieldShapeDesc.columnScale = colScale;
kHeightFieldShapeDesc.holeMaterial = 0;
kHeightFieldShapeDesc.meshFlags = NX_MESH_SMOOTH_SPHERE_COLLISIONS;
and would like to add these terrain materials to the NxHeightField example
NxMaterialDesc m;
m.restitution = 0.0;
m.staticFriction = 0.5;
m.dynamicFriction = 0.5;
NxMaterial* material = physXScene->getMaterialFromIndex(0);
material->loadFromDesc(m);
//terrain materials
m.restitution = 1.0f;
m.staticFriction = 0.0f;
m.dynamicFriction = 0.0f;
materialIce = physXScene->createMaterial(m)->getMaterialIndex();
m.restitution = 0.3f;
m.staticFriction = 1.2f;
m.dynamicFriction = 1.0f;
materialRock = physXScene->createMaterial(m)->getMaterialIndex();
m.restitution = 0.0f;
m.staticFriction = 3.0f;
m.dynamicFriction = 1.0f;
materialMud = physXScene->createMaterial(m)->getMaterialIndex();
m.restitution = 0.0f;
m.staticFriction = 0.0f;
m.dynamicFriction = 0.0f;
materialGrass = physXScene->createMaterial(m)->getMaterialIndex();