334 if (trimeshShape->getTriangleInfoMap())
337 trimeshShape->setTriangleInfoMap(triangleInfoMap);
340 const btVector3& meshScaling = meshInterface->getScaling();
342 for (
int partId = 0; partId < meshInterface->getNumSubParts(); partId++)
344 const unsigned char* vertexbase = 0;
348 const unsigned char* indexbase = 0;
355 meshInterface->getLockedReadOnlyVertexIndexBase(&vertexbase, numverts, type, stride, &indexbase, indexstride, numfaces, indicestype, partId);
358 for (
int triangleIndex = 0; triangleIndex < numfaces; triangleIndex++)
360 unsigned int* gfxbase = (
unsigned int*)(indexbase + triangleIndex * indexstride);
362 for (
int j = 2; j >= 0; j--)
365 switch (indicestype) {
366 case PHY_INTEGER: graphicsindex = gfxbase[j];
break;
367 case PHY_SHORT: graphicsindex = ((
unsigned short*)gfxbase)[j];
break;
368 case PHY_UCHAR: graphicsindex = ((
unsigned char*)gfxbase)[j];
break;
373 float* graphicsbase = (
float*)(vertexbase + graphicsindex * stride);
375 graphicsbase[0] * meshScaling.getX(),
376 graphicsbase[1] * meshScaling.getY(),
377 graphicsbase[2] * meshScaling.getZ());
381 double* graphicsbase = (
double*)(vertexbase + graphicsindex * stride);
382 triangleVerts[j] =
btVector3(
btScalar(graphicsbase[0] * meshScaling.getX()),
btScalar(graphicsbase[1] * meshScaling.getY()),
btScalar(graphicsbase[2] * meshScaling.getZ()));
387 aabbMin.setMin(triangleVerts[0]);
388 aabbMax.setMax(triangleVerts[0]);
389 aabbMin.setMin(triangleVerts[1]);
390 aabbMax.setMax(triangleVerts[1]);
391 aabbMin.setMin(triangleVerts[2]);
392 aabbMax.setMax(triangleVerts[2]);
395 connectivityProcessor.
m_partIdA = partId;
400 trimeshShape->processAllTriangles(&connectivityProcessor, aabbMin, aabbMax);
498 triangleInfoMapPtr = heightfield->getTriangleInfoMap();
501#ifdef USE_HEIGHTFIELD_TRIANGLES
506 tri_shape->calcNormal(tri_normal);
507 newNormal = tri_normal;
537 if (!triangleInfoMapPtr)
550 tri_shape->getVertex(0, v0);
551 tri_shape->getVertex(1, v1);
552 tri_shape->getVertex(2,
v2);
556 btVector3 red(1, 0, 0), green(0, 1, 0), blue(0, 0, 1), white(1, 1, 1), black(0, 0, 0);
558 tri_shape->calcNormal(tri_normal);
565#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
566 const btTransform& tr = colObj0->getWorldTransform();
570 bool isNearEdge =
false;
572 int numConcaveEdgeHits = 0;
573 int numConvexEdgeHits = 0;
576 localContactNormalOnB.normalize();
589 if (
len < disttobestedge)
592 disttobestedge =
len;
602 if (
len < disttobestedge)
605 disttobestedge =
len;
615 if (
len < disttobestedge)
618 disttobestedge =
len;
622#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
624 btDebugDrawLine(tr * v0 + upfix, tr * v1 + upfix, red);
628#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
629 btDebugDrawLine(tr * contact, tr * (contact + cp.
m_normalWorldOnB * 10), black);
640 numConcaveEdgeHits++;
646#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
647 btDebugDrawLine(tr * nearest, tr * (nearest + swapFactor * tri_normal * 10), white);
655 computedNormalB *= -1;
656 btVector3 nB = swapFactor * computedNormalB;
658 btScalar NdotA = localContactNormalOnB.dot(nA);
659 btScalar NdotB = localContactNormalOnB.dot(nB);
660 bool backFacingNormal = (NdotA < triangleInfoMapPtr->
m_convexEpsilon) && (NdotB < triangleInfoMapPtr->m_convexEpsilon);
662#ifdef DEBUG_INTERNAL_EDGE
668 if (backFacingNormal)
670 numConcaveEdgeHits++;
695#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
699#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
700 btDebugDrawLine(tr * v1 + upfix, tr *
v2 + upfix, green);
705#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
706 btDebugDrawLine(tr * contact, tr * (contact + cp.
m_normalWorldOnB * 10), black);
714#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
715 btDebugDrawLine(tr * nearest, tr * (nearest + tri_normal * 10), white);
724 numConcaveEdgeHits++;
730#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
731 btDebugDrawLine(tr * nearest, tr * (nearest + swapFactor * tri_normal * 10), white);
739 computedNormalB *= -1;
740 btVector3 nB = swapFactor * computedNormalB;
742#ifdef DEBUG_INTERNAL_EDGE
748 btScalar NdotA = localContactNormalOnB.dot(nA);
749 btScalar NdotB = localContactNormalOnB.dot(nB);
750 bool backFacingNormal = (NdotA < triangleInfoMapPtr->
m_convexEpsilon) && (NdotB < triangleInfoMapPtr->m_convexEpsilon);
752 if (backFacingNormal)
754 numConcaveEdgeHits++;
780#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
783#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
784 btDebugDrawLine(tr *
v2 + upfix, tr * v0 + upfix, blue);
789#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
790 btDebugDrawLine(tr * contact, tr * (contact + cp.
m_normalWorldOnB * 10), black);
798#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
799 btDebugDrawLine(tr * nearest, tr * (nearest + tri_normal * 10), white);
806 numConcaveEdgeHits++;
812#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
813 btDebugDrawLine(tr * nearest, tr * (nearest + swapFactor * tri_normal * 10), white);
820 computedNormalB *= -1;
821 btVector3 nB = swapFactor * computedNormalB;
823#ifdef DEBUG_INTERNAL_EDGE
829 btScalar NdotA = localContactNormalOnB.dot(nA);
830 btScalar NdotB = localContactNormalOnB.dot(nB);
831 bool backFacingNormal = (NdotA < triangleInfoMapPtr->
m_convexEpsilon) && (NdotB < triangleInfoMapPtr->m_convexEpsilon);
833 if (backFacingNormal)
835 numConcaveEdgeHits++;
862#ifdef DEBUG_INTERNAL_EDGE
871 if (numConcaveEdgeHits > 0)
876 if (tri_normal.dot(localContactNormalOnB) < 0)
884 btVector3 newNormal = tri_normal * frontFacing;
886 btScalar d = newNormal.dot(localContactNormalOnB);