I need the normal at a grid point on the heightfield.
I can already query the height with PxHeightfield::getHeight(x,z) and I could also draft a normal using multiple sample points. However, I want the normal to match whatever PhysX uses internally and don’t want to reproduce all the internal normal code. I also can’t due to several other functions not being exposed.
There is PxHeightfield::getTriangleNormal, which is perfect, but there seems to be no public way of mapping from grid co-ordinates to heightfield triangle ID.
There is physx::Gu::Heightfield::getTriangleIndex(x,z) which would solve all my issues but that’s not publicly exposed.
Is there any other way of getting the triangle normal other than adding a virtual forwarding call from PxHeightfield to getTriangleIndex?
Thanks,
Title should be getTriangleNormal, of course.
It should be easy to add missing functions to the heightfield API. I’ll add an internal task for this.
Now, HeightField::getTriangleIndex(x,z) is one thing, but I also see we have a HeightFieldUtil::getNormalAtShapePoint(x,z) that might be exactly what you want.
Thanks.
I’m using PhysX via UE4 right now and as far as I can see, no UE4 code uses physx::Gu::HeightFieldUtil. The header file is in the Source directory rather than the Include directory so I was unsure as to getNormalAtShapePoint’s accessibility.
My workaround right now is to add a differently-named getTriangleID to PxHeightfield as I don’t want the existing implementation to suddenly inherit the cost of the virtual call.
Ok good, if you have a workaround already I’ll just schedule this task as usual and the change should eventually appear in UE4.
Otherwise tell me and I can probably help create a temporary function to retrieve the normal.
All is good right now! The function is marked to be removed when any API updates come through.
Hi Pierre_Terdiman.
I have stumbled upon similar issue.
I need to retrieve the heightfield normal at given row/column, but the above problem makes me unable to do so.
Also, is it just me or Gu::Heightfield is not usable outside?
I get include errors in PhysX classes (in this case at GuHeightfield at the top includes) when I try to include directory.
dwilliamson any chance to share your solution?
Any help would be appreciated.
Thanks.
Ok, I think I get it now. :P
So Gu::Heightfield etc are for internal use only.
In case you are fine with building PhysX sources, here’s what you can do to retrieve the heightfield vertex normal:
PxHeightField.h
/**
\brief Returns vertex normal at vertex index or sample id (row * nbCols + Col)
\return Vertex normal vector
*/
PX_PHYSX_COMMON_API virtual PxVec3 getVertNormal(PxU32 vertIndex, const class PxHeightFieldGeometry& hfGeom) const = 0;
GuHeightField.h
PX_PHYSX_COMMON_API virtual PxVec3 getVertNormal(PxU32 vertIndex, const class PxHeightFieldGeometry& hfGeom) const;
GuHeightField.cpp
#include "GuHeightFieldUtil.h"
PxVec3 Gu::HeightField::getVertNormal(PxU32 vertIndex, const PxHeightFieldGeometry & hfGeom) const
{
Gu::HeightFieldUtil hfUtil(hfGeom, *this);
return hfUtil.getVertexNormal(vertIndex);
}
Then, from your project, you can simply do something like:
// Get the heightfield geometry from the heightfield shape
PxHeightFieldGeometry Geom;
gShape->getHeightFieldGeometry(Geom);
// Compute sample id
const uint32 SampleId = InRow * gHfNbCols + InColumn;
// Get the normal
const PxVec3 SampleNormal = gHeightField->getVertNormal(SampleId, Geom);
// Using UE4 here so, things are a little switched
return FVector(SampleNormal.z, SampleNormal.x, SampleNormal.y);
Would be nice if something like that could be introduced in the API by default.
Nelson Duarte,
Thanks!