2018-09-07 14:11:04 +00:00
|
|
|
#include "btSdfCollisionShape.h"
|
|
|
|
#include "btMiniSDF.h"
|
|
|
|
#include "LinearMath/btAabbUtil2.h"
|
|
|
|
|
|
|
|
struct btSdfCollisionShapeInternalData
|
|
|
|
{
|
|
|
|
btVector3 m_localScaling;
|
|
|
|
btScalar m_margin;
|
|
|
|
btMiniSDF m_sdf;
|
|
|
|
|
|
|
|
btSdfCollisionShapeInternalData()
|
2019-01-03 13:26:51 +00:00
|
|
|
: m_localScaling(1, 1, 1),
|
|
|
|
m_margin(0)
|
2018-09-07 14:11:04 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
bool btSdfCollisionShape::initializeSDF(const char* sdfData, int sizeInBytes)
|
|
|
|
{
|
|
|
|
bool valid = m_data->m_sdf.load(sdfData, sizeInBytes);
|
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
btSdfCollisionShape::btSdfCollisionShape()
|
|
|
|
{
|
|
|
|
m_shapeType = SDF_SHAPE_PROXYTYPE;
|
|
|
|
m_data = new btSdfCollisionShapeInternalData();
|
|
|
|
|
|
|
|
//"E:/develop/bullet3/data/toys/ground_hole64_64_8.cdf");//ground_cube.cdf");
|
|
|
|
/*unsigned int field_id=0;
|
|
|
|
Eigen::Vector3d x (1,10,1);
|
|
|
|
Eigen::Vector3d gradient;
|
|
|
|
double dist = m_data->m_sdf.interpolate(field_id, x, &gradient);
|
|
|
|
printf("dist=%g\n", dist);
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
btSdfCollisionShape::~btSdfCollisionShape()
|
|
|
|
{
|
|
|
|
delete m_data;
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
void btSdfCollisionShape::getAabb(const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const
|
2018-09-07 14:11:04 +00:00
|
|
|
{
|
|
|
|
btAssert(m_data->m_sdf.isValid());
|
|
|
|
btVector3 localAabbMin = m_data->m_sdf.m_domain.m_min;
|
|
|
|
btVector3 localAabbMax = m_data->m_sdf.m_domain.m_max;
|
|
|
|
btScalar margin(0);
|
2019-01-03 13:26:51 +00:00
|
|
|
btTransformAabb(localAabbMin, localAabbMax, margin, t, aabbMin, aabbMax);
|
2018-09-07 14:11:04 +00:00
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
void btSdfCollisionShape::setLocalScaling(const btVector3& scaling)
|
2018-09-07 14:11:04 +00:00
|
|
|
{
|
|
|
|
m_data->m_localScaling = scaling;
|
|
|
|
}
|
|
|
|
const btVector3& btSdfCollisionShape::getLocalScaling() const
|
|
|
|
{
|
|
|
|
return m_data->m_localScaling;
|
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
void btSdfCollisionShape::calculateLocalInertia(btScalar mass, btVector3& inertia) const
|
2018-09-07 14:11:04 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
inertia.setValue(0, 0, 0);
|
2018-09-07 14:11:04 +00:00
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
const char* btSdfCollisionShape::getName() const
|
2018-09-07 14:11:04 +00:00
|
|
|
{
|
|
|
|
return "btSdfCollisionShape";
|
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
void btSdfCollisionShape::setMargin(btScalar margin)
|
2018-09-07 14:11:04 +00:00
|
|
|
{
|
|
|
|
m_data->m_margin = margin;
|
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
btScalar btSdfCollisionShape::getMargin() const
|
2018-09-07 14:11:04 +00:00
|
|
|
{
|
|
|
|
return m_data->m_margin;
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
void btSdfCollisionShape::processAllTriangles(btTriangleCallback* callback, const btVector3& aabbMin, const btVector3& aabbMax) const
|
2018-09-07 14:11:04 +00:00
|
|
|
{
|
|
|
|
//not yet
|
|
|
|
}
|
|
|
|
|
|
|
|
bool btSdfCollisionShape::queryPoint(const btVector3& ptInSDF, btScalar& distOut, btVector3& normal)
|
|
|
|
{
|
|
|
|
int field = 0;
|
|
|
|
btVector3 grad;
|
|
|
|
double dist;
|
2019-01-03 13:26:51 +00:00
|
|
|
bool hasResult = m_data->m_sdf.interpolate(field, dist, ptInSDF, &grad);
|
2018-09-07 14:11:04 +00:00
|
|
|
if (hasResult)
|
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
normal.setValue(grad[0], grad[1], grad[2]);
|
|
|
|
distOut = dist;
|
2018-09-07 14:11:04 +00:00
|
|
|
}
|
|
|
|
return hasResult;
|
|
|
|
}
|