fix convex-plane for > 4 vertices
improve compound demo
This commit is contained in:
3725
data/teddy2_VHACD_CHs.obj
Normal file
3725
data/teddy2_VHACD_CHs.obj
Normal file
File diff suppressed because it is too large
Load Diff
@@ -39,7 +39,7 @@ public:
|
|||||||
preferredOpenCLPlatformIndex(-1),
|
preferredOpenCLPlatformIndex(-1),
|
||||||
preferredOpenCLDeviceIndex(-1),
|
preferredOpenCLDeviceIndex(-1),
|
||||||
arraySizeX(10),
|
arraySizeX(10),
|
||||||
arraySizeY(31),
|
arraySizeY(30),
|
||||||
arraySizeZ(10),
|
arraySizeZ(10),
|
||||||
m_useConcaveMesh(false),
|
m_useConcaveMesh(false),
|
||||||
gapX(14.3),
|
gapX(14.3),
|
||||||
|
|||||||
@@ -65,7 +65,9 @@ btAlignedObjectArray<const char*> demoNames;
|
|||||||
int selectedDemo = 0;
|
int selectedDemo = 0;
|
||||||
GpuDemo::CreateFunc* allDemos[]=
|
GpuDemo::CreateFunc* allDemos[]=
|
||||||
{
|
{
|
||||||
|
GpuBoxPlaneScene::MyCreateFunc,
|
||||||
GpuConvexPlaneScene::MyCreateFunc,
|
GpuConvexPlaneScene::MyCreateFunc,
|
||||||
|
|
||||||
|
|
||||||
GpuCompoundScene::MyCreateFunc,
|
GpuCompoundScene::MyCreateFunc,
|
||||||
GpuCompoundPlaneScene::MyCreateFunc,
|
GpuCompoundPlaneScene::MyCreateFunc,
|
||||||
|
|||||||
@@ -353,12 +353,11 @@ void ConcaveCompoundScene::createDynamicObjects(const ConstructionInfo& ci)
|
|||||||
int childColIndex = m_data->m_np->registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling);
|
int childColIndex = m_data->m_np->registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling);
|
||||||
|
|
||||||
|
|
||||||
btVector3 childPositions[3] = {
|
btVector3 childPositions[3] = {
|
||||||
btVector3(0,-2,0),
|
btVector3(0,-2,0),
|
||||||
btVector3(0,0,0),
|
btVector3(0,0,0),
|
||||||
btVector3(0,2,0)
|
btVector3(0,0,2)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
btAlignedObjectArray<btGpuChildShape> childShapes;
|
btAlignedObjectArray<btGpuChildShape> childShapes;
|
||||||
int numChildShapes = 3;
|
int numChildShapes = 3;
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ void GpuCompoundScene::setupScene(const ConstructionInfo& ci)
|
|||||||
btVector3 childPositions[3] = {
|
btVector3 childPositions[3] = {
|
||||||
btVector3(0,-2,0),
|
btVector3(0,-2,0),
|
||||||
btVector3(0,0,0),
|
btVector3(0,0,0),
|
||||||
btVector3(0,2,0)
|
btVector3(0,0,2)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -22,17 +22,49 @@
|
|||||||
void GpuConvexScene::setupScene(const ConstructionInfo& ci)
|
void GpuConvexScene::setupScene(const ConstructionInfo& ci)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
int index=0;
|
||||||
createStaticEnvironment(ci);
|
createStaticEnvironment(ci);
|
||||||
|
|
||||||
|
index+=createDynamicsObjects(ci);
|
||||||
|
|
||||||
|
|
||||||
|
float camPos[4]={ci.arraySizeX,ci.arraySizeY/2,ci.arraySizeZ,0};
|
||||||
|
//float camPos[4]={1,12.5,1.5,0};
|
||||||
|
m_instancingRenderer->setCameraTargetPosition(camPos);
|
||||||
|
m_instancingRenderer->setCameraDistance(40);
|
||||||
|
|
||||||
|
|
||||||
|
char msg[1024];
|
||||||
|
int numInstances = index;
|
||||||
|
sprintf(msg,"Num objects = %d",numInstances);
|
||||||
|
ci.m_gui->setStatusBarMessage(msg,true);
|
||||||
|
}
|
||||||
|
|
||||||
|
int GpuConvexScene::createDynamicsObjects(const ConstructionInfo& ci)
|
||||||
|
{
|
||||||
|
int strideInBytes = 9*sizeof(float);
|
||||||
|
int numVertices = sizeof(barrel_vertices)/strideInBytes;
|
||||||
|
int numIndices = sizeof(barrel_indices)/sizeof(int);
|
||||||
|
return createDynamicsObjects2(ci,barrel_vertices,numVertices,barrel_indices,numIndices);
|
||||||
|
}
|
||||||
|
|
||||||
|
int GpuBoxPlaneScene::createDynamicsObjects(const ConstructionInfo& ci)
|
||||||
|
{
|
||||||
int strideInBytes = 9*sizeof(float);
|
int strideInBytes = 9*sizeof(float);
|
||||||
int numVertices = sizeof(cube_vertices)/strideInBytes;
|
int numVertices = sizeof(cube_vertices)/strideInBytes;
|
||||||
int numIndices = sizeof(cube_indices)/sizeof(int);
|
int numIndices = sizeof(cube_indices)/sizeof(int);
|
||||||
|
return createDynamicsObjects2(ci,cube_vertices,numVertices,cube_indices,numIndices);
|
||||||
|
}
|
||||||
|
|
||||||
int shapeId = ci.m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices);
|
|
||||||
//int shapeId = ci.m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices);
|
int GpuConvexScene::createDynamicsObjects2(const ConstructionInfo& ci, const float* vertices, int numVertices, const int* indices, int numIndices)
|
||||||
|
{
|
||||||
|
int strideInBytes = 9*sizeof(float);
|
||||||
|
|
||||||
|
int shapeId = ci.m_instancingRenderer->registerShape(&vertices[0],numVertices,indices,numIndices);
|
||||||
int group=1;
|
int group=1;
|
||||||
int mask=1;
|
int mask=1;
|
||||||
int index=10;
|
int index=0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -49,7 +81,7 @@ void GpuConvexScene::setupScene(const ConstructionInfo& ci)
|
|||||||
|
|
||||||
int curColor = 0;
|
int curColor = 0;
|
||||||
float scaling[4] = {1,1,1,1};
|
float scaling[4] = {1,1,1,1};
|
||||||
int colIndex = m_data->m_np->registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling);
|
int colIndex = m_data->m_np->registerConvexHullShape(&vertices[0],strideInBytes,numVertices, scaling);
|
||||||
//int colIndex = m_data->m_np->registerSphereShape(1);
|
//int colIndex = m_data->m_np->registerSphereShape(1);
|
||||||
for (int i=0;i<ci.arraySizeX;i++)
|
for (int i=0;i<ci.arraySizeX;i++)
|
||||||
{
|
{
|
||||||
@@ -76,21 +108,10 @@ void GpuConvexScene::setupScene(const ConstructionInfo& ci)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
float camPos[4]={ci.arraySizeX,ci.arraySizeY/2,ci.arraySizeZ,0};
|
return index;
|
||||||
//float camPos[4]={1,12.5,1.5,0};
|
|
||||||
m_instancingRenderer->setCameraTargetPosition(camPos);
|
|
||||||
m_instancingRenderer->setCameraDistance(40);
|
|
||||||
|
|
||||||
|
|
||||||
char msg[1024];
|
|
||||||
int numInstances = index;
|
|
||||||
sprintf(msg,"Num objects = %d",numInstances);
|
|
||||||
ci.m_gui->setStatusBarMessage(msg,true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void GpuConvexScene::createStaticEnvironment(const ConstructionInfo& ci)
|
void GpuConvexScene::createStaticEnvironment(const ConstructionInfo& ci)
|
||||||
{
|
{
|
||||||
int strideInBytes = 9*sizeof(float);
|
int strideInBytes = 9*sizeof(float);
|
||||||
@@ -126,7 +147,7 @@ void GpuConvexPlaneScene::createStaticEnvironment(const ConstructionInfo& ci)
|
|||||||
btQuaternion orn(0,0,0,1);
|
btQuaternion orn(0,0,0,1);
|
||||||
// btQuaternion orn(btVector3(1,0,0),0.3);
|
// btQuaternion orn(btVector3(1,0,0),0.3);
|
||||||
btVector4 color(0,0,1,1);
|
btVector4 color(0,0,1,1);
|
||||||
btVector4 scaling(100,0.1,100,1);
|
btVector4 scaling(100,0.001,100,1);
|
||||||
int strideInBytes = 9*sizeof(float);
|
int strideInBytes = 9*sizeof(float);
|
||||||
int numVertices = sizeof(cube_vertices)/strideInBytes;
|
int numVertices = sizeof(cube_vertices)/strideInBytes;
|
||||||
int numIndices = sizeof(cube_indices)/sizeof(int);
|
int numIndices = sizeof(cube_indices)/sizeof(int);
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ public:
|
|||||||
|
|
||||||
virtual void setupScene(const ConstructionInfo& ci);
|
virtual void setupScene(const ConstructionInfo& ci);
|
||||||
|
|
||||||
|
virtual int createDynamicsObjects(const ConstructionInfo& ci);
|
||||||
|
|
||||||
|
virtual int createDynamicsObjects2(const ConstructionInfo& ci,const float* vertices, int numVertices, const int* indices,int numIndices);
|
||||||
|
|
||||||
virtual void createStaticEnvironment(const ConstructionInfo& ci);
|
virtual void createStaticEnvironment(const ConstructionInfo& ci);
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -48,4 +52,27 @@ public:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class GpuBoxPlaneScene : public GpuConvexPlaneScene
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
GpuBoxPlaneScene(){}
|
||||||
|
virtual ~GpuBoxPlaneScene(){}
|
||||||
|
virtual const char* getName()
|
||||||
|
{
|
||||||
|
return "GRBBoxPlane";
|
||||||
|
}
|
||||||
|
|
||||||
|
static GpuDemo* MyCreateFunc()
|
||||||
|
{
|
||||||
|
GpuDemo* demo = new GpuBoxPlaneScene;
|
||||||
|
return demo;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual int createDynamicsObjects(const ConstructionInfo& ci);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
#endif //GPU_CONVEX_SCENE_H
|
#endif //GPU_CONVEX_SCENE_H
|
||||||
|
|||||||
@@ -493,6 +493,98 @@ void computeContactSphereConvex(int pairIndex,
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int extractManifoldSequential(const float4* p, int nPoints, float4 nearNormal, int4* contactIdx)
|
||||||
|
{
|
||||||
|
if( nPoints == 0 )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (nPoints <=4)
|
||||||
|
return nPoints;
|
||||||
|
|
||||||
|
|
||||||
|
if (nPoints >64)
|
||||||
|
nPoints = 64;
|
||||||
|
|
||||||
|
float4 center = make_float4(0.f);
|
||||||
|
{
|
||||||
|
|
||||||
|
for (int i=0;i<nPoints;i++)
|
||||||
|
center += p[i];
|
||||||
|
center /= (float)nPoints;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// sample 4 directions
|
||||||
|
|
||||||
|
float4 aVector = p[0] - center;
|
||||||
|
float4 u = cross3( nearNormal, aVector );
|
||||||
|
float4 v = cross3( nearNormal, u );
|
||||||
|
u = normalize3( u );
|
||||||
|
v = normalize3( v );
|
||||||
|
|
||||||
|
|
||||||
|
//keep point with deepest penetration
|
||||||
|
float minW= FLT_MAX;
|
||||||
|
|
||||||
|
int minIndex=-1;
|
||||||
|
|
||||||
|
float4 maxDots;
|
||||||
|
maxDots.x = FLT_MIN;
|
||||||
|
maxDots.y = FLT_MIN;
|
||||||
|
maxDots.z = FLT_MIN;
|
||||||
|
maxDots.w = FLT_MIN;
|
||||||
|
|
||||||
|
// idx, distance
|
||||||
|
for(int ie = 0; ie<nPoints; ie++ )
|
||||||
|
{
|
||||||
|
if (p[ie].w<minW)
|
||||||
|
{
|
||||||
|
minW = p[ie].w;
|
||||||
|
minIndex=ie;
|
||||||
|
}
|
||||||
|
float f;
|
||||||
|
float4 r = p[ie]-center;
|
||||||
|
f = dot3F4( u, r );
|
||||||
|
if (f<maxDots.x)
|
||||||
|
{
|
||||||
|
maxDots.x = f;
|
||||||
|
contactIdx[0].x = ie;
|
||||||
|
}
|
||||||
|
|
||||||
|
f = dot3F4( -u, r );
|
||||||
|
if (f<maxDots.y)
|
||||||
|
{
|
||||||
|
maxDots.y = f;
|
||||||
|
contactIdx[0].y = ie;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
f = dot3F4( v, r );
|
||||||
|
if (f<maxDots.z)
|
||||||
|
{
|
||||||
|
maxDots.z = f;
|
||||||
|
contactIdx[0].z = ie;
|
||||||
|
}
|
||||||
|
|
||||||
|
f = dot3F4( -v, r );
|
||||||
|
if (f<maxDots.w)
|
||||||
|
{
|
||||||
|
maxDots.w = f;
|
||||||
|
contactIdx[0].w = ie;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (contactIdx[0].x != minIndex && contactIdx[0].y != minIndex && contactIdx[0].z != minIndex && contactIdx[0].w != minIndex)
|
||||||
|
{
|
||||||
|
//replace the first contact with minimum (todo: replace contact with least penetration)
|
||||||
|
contactIdx[0].x = minIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 4;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#define MAX_PLANE_CONVEX_POINTS 64
|
#define MAX_PLANE_CONVEX_POINTS 64
|
||||||
|
|
||||||
@@ -593,10 +685,10 @@ void computeContactPlaneConvex(int pairIndex,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int numReducedPoints = numPoints;
|
int numReducedPoints = numPoints;
|
||||||
//if (numPoints>4)
|
if (numPoints>4)
|
||||||
//{
|
{
|
||||||
// numReducedPoints = extractManifoldSequentialGlobal( contactPoints, numPoints, planeNormalInConvex, &contactIdx);
|
numReducedPoints = extractManifoldSequential( contactPoints, numPoints, planeNormalInConvex, &contactIdx);
|
||||||
//}
|
}
|
||||||
|
|
||||||
if (numReducedPoints>0)
|
if (numReducedPoints>0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -495,6 +495,98 @@ static const char* primitiveContactsKernelsCL= \
|
|||||||
" \n"
|
" \n"
|
||||||
"\n"
|
"\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
"int extractManifoldSequential(const float4* p, int nPoints, float4 nearNormal, int4* contactIdx)\n"
|
||||||
|
"{\n"
|
||||||
|
" if( nPoints == 0 )\n"
|
||||||
|
" return 0;\n"
|
||||||
|
" \n"
|
||||||
|
" if (nPoints <=4)\n"
|
||||||
|
" return nPoints;\n"
|
||||||
|
" \n"
|
||||||
|
" \n"
|
||||||
|
" if (nPoints >64)\n"
|
||||||
|
" nPoints = 64;\n"
|
||||||
|
" \n"
|
||||||
|
" float4 center = make_float4(0.f);\n"
|
||||||
|
" {\n"
|
||||||
|
" \n"
|
||||||
|
" for (int i=0;i<nPoints;i++)\n"
|
||||||
|
" center += p[i];\n"
|
||||||
|
" center /= (float)nPoints;\n"
|
||||||
|
" }\n"
|
||||||
|
" \n"
|
||||||
|
" \n"
|
||||||
|
" \n"
|
||||||
|
" // sample 4 directions\n"
|
||||||
|
" \n"
|
||||||
|
" float4 aVector = p[0] - center;\n"
|
||||||
|
" float4 u = cross3( nearNormal, aVector );\n"
|
||||||
|
" float4 v = cross3( nearNormal, u );\n"
|
||||||
|
" u = normalize3( u );\n"
|
||||||
|
" v = normalize3( v );\n"
|
||||||
|
" \n"
|
||||||
|
" \n"
|
||||||
|
" //keep point with deepest penetration\n"
|
||||||
|
" float minW= FLT_MAX;\n"
|
||||||
|
" \n"
|
||||||
|
" int minIndex=-1;\n"
|
||||||
|
" \n"
|
||||||
|
" float4 maxDots;\n"
|
||||||
|
" maxDots.x = FLT_MIN;\n"
|
||||||
|
" maxDots.y = FLT_MIN;\n"
|
||||||
|
" maxDots.z = FLT_MIN;\n"
|
||||||
|
" maxDots.w = FLT_MIN;\n"
|
||||||
|
" \n"
|
||||||
|
" // idx, distance\n"
|
||||||
|
" for(int ie = 0; ie<nPoints; ie++ )\n"
|
||||||
|
" {\n"
|
||||||
|
" if (p[ie].w<minW)\n"
|
||||||
|
" {\n"
|
||||||
|
" minW = p[ie].w;\n"
|
||||||
|
" minIndex=ie;\n"
|
||||||
|
" }\n"
|
||||||
|
" float f;\n"
|
||||||
|
" float4 r = p[ie]-center;\n"
|
||||||
|
" f = dot3F4( u, r );\n"
|
||||||
|
" if (f<maxDots.x)\n"
|
||||||
|
" {\n"
|
||||||
|
" maxDots.x = f;\n"
|
||||||
|
" contactIdx[0].x = ie;\n"
|
||||||
|
" }\n"
|
||||||
|
" \n"
|
||||||
|
" f = dot3F4( -u, r );\n"
|
||||||
|
" if (f<maxDots.y)\n"
|
||||||
|
" {\n"
|
||||||
|
" maxDots.y = f;\n"
|
||||||
|
" contactIdx[0].y = ie;\n"
|
||||||
|
" }\n"
|
||||||
|
" \n"
|
||||||
|
" \n"
|
||||||
|
" f = dot3F4( v, r );\n"
|
||||||
|
" if (f<maxDots.z)\n"
|
||||||
|
" {\n"
|
||||||
|
" maxDots.z = f;\n"
|
||||||
|
" contactIdx[0].z = ie;\n"
|
||||||
|
" }\n"
|
||||||
|
" \n"
|
||||||
|
" f = dot3F4( -v, r );\n"
|
||||||
|
" if (f<maxDots.w)\n"
|
||||||
|
" {\n"
|
||||||
|
" maxDots.w = f;\n"
|
||||||
|
" contactIdx[0].w = ie;\n"
|
||||||
|
" }\n"
|
||||||
|
" \n"
|
||||||
|
" }\n"
|
||||||
|
" \n"
|
||||||
|
" if (contactIdx[0].x != minIndex && contactIdx[0].y != minIndex && contactIdx[0].z != minIndex && contactIdx[0].w != minIndex)\n"
|
||||||
|
" {\n"
|
||||||
|
" //replace the first contact with minimum (todo: replace contact with least penetration)\n"
|
||||||
|
" contactIdx[0].x = minIndex;\n"
|
||||||
|
" }\n"
|
||||||
|
" \n"
|
||||||
|
" return 4;\n"
|
||||||
|
" \n"
|
||||||
|
"}\n"
|
||||||
"\n"
|
"\n"
|
||||||
"#define MAX_PLANE_CONVEX_POINTS 64\n"
|
"#define MAX_PLANE_CONVEX_POINTS 64\n"
|
||||||
"\n"
|
"\n"
|
||||||
@@ -595,10 +687,10 @@ static const char* primitiveContactsKernelsCL= \
|
|||||||
" }\n"
|
" }\n"
|
||||||
"\n"
|
"\n"
|
||||||
" int numReducedPoints = numPoints;\n"
|
" int numReducedPoints = numPoints;\n"
|
||||||
" //if (numPoints>4)\n"
|
" if (numPoints>4)\n"
|
||||||
" //{\n"
|
" {\n"
|
||||||
"// numReducedPoints = extractManifoldSequentialGlobal( contactPoints, numPoints, planeNormalInConvex, &contactIdx);\n"
|
" numReducedPoints = extractManifoldSequential( contactPoints, numPoints, planeNormalInConvex, &contactIdx);\n"
|
||||||
" //}\n"
|
" }\n"
|
||||||
"\n"
|
"\n"
|
||||||
" if (numReducedPoints>0)\n"
|
" if (numReducedPoints>0)\n"
|
||||||
" {\n"
|
" {\n"
|
||||||
|
|||||||
Reference in New Issue
Block a user