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;
354 btVector3 triangleVerts[3];
355 meshInterface->getLockedReadOnlyVertexIndexBase(&vertexbase, numverts, type, stride, &indexbase, indexstride, numfaces, indicestype, partId);
356 btVector3 aabbMin, aabbMax;
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);
452bool btClampNormal(
const btVector3& edge,
const btVector3& tri_normal_org,
const btVector3& localContactNormalOnB,
btScalar correctedEdgeAngle, btVector3& clampedLocalNormal)
454 btVector3 tri_normal = tri_normal_org;
458 btVector3 edgeCross = edge.cross(tri_normal).normalize();
461 if (correctedEdgeAngle < 0)
463 if (curAngle < correctedEdgeAngle)
465 btScalar diffAngle = correctedEdgeAngle - curAngle;
467 clampedLocalNormal =
btMatrix3x3(rotation) * localContactNormalOnB;
472 if (correctedEdgeAngle >= 0)
474 if (curAngle > correctedEdgeAngle)
476 btScalar diffAngle = correctedEdgeAngle - curAngle;
478 clampedLocalNormal =
btMatrix3x3(rotation) * localContactNormalOnB;
498 triangleInfoMapPtr = heightfield->getTriangleInfoMap();
501#ifdef USE_HEIGHTFIELD_TRIANGLES
502 btVector3 newNormal =
btVector3(0, 0, 1);
504 const btTriangleShape* tri_shape =
static_cast<const btTriangleShape*
>(colObj0Wrap->
getCollisionShape());
505 btVector3 tri_normal;
506 tri_shape->calcNormal(tri_normal);
507 newNormal = tri_normal;
537 if (!triangleInfoMapPtr)
548 const btTriangleShape* tri_shape =
static_cast<const btTriangleShape*
>(colObj0Wrap->
getCollisionShape());
549 btVector3 v0, v1,
v2;
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);
557 btVector3 tri_normal;
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
623 btVector3 upfix = tri_normal *
btVector3(0.1f, 0.1f, 0.1f);
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);
635 btVector3 edge(v0 - v1);
640 numConcaveEdgeHits++;
646#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
647 btDebugDrawLine(tr * nearest, tr * (nearest + swapFactor * tri_normal * 10), white);
650 btVector3 nA = swapFactor * tri_normal;
653 btVector3 computedNormalB =
quatRotate(orn, tri_normal);
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++;
675 btVector3 clampedLocalNormal;
681 btVector3 newNormal = colObj0Wrap->
getWorldTransform().getBasis() * clampedLocalNormal;
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);
718 btVector3 edge(v1 -
v2);
724 numConcaveEdgeHits++;
730#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
731 btDebugDrawLine(tr * nearest, tr * (nearest + swapFactor * tri_normal * 10), white);
734 btVector3 nA = swapFactor * tri_normal;
737 btVector3 computedNormalB =
quatRotate(orn, tri_normal);
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++;
760 btVector3 clampedLocalNormal;
766 btVector3 newNormal = colObj0Wrap->
getWorldTransform().getBasis() * clampedLocalNormal;
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);
802 btVector3 edge(
v2 - v0);
806 numConcaveEdgeHits++;
812#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
813 btDebugDrawLine(tr * nearest, tr * (nearest + swapFactor * tri_normal * 10), white);
816 btVector3 nA = swapFactor * tri_normal;
818 btVector3 computedNormalB =
quatRotate(orn, tri_normal);
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++;
843 btVector3 clampedLocalNormal;
849 btVector3 newNormal = colObj0Wrap->
getWorldTransform().getBasis() * clampedLocalNormal;
862#ifdef DEBUG_INTERNAL_EDGE
864 btVector3
color(0, 1, 1);
871 if (numConcaveEdgeHits > 0)
876 if (tri_normal.dot(localContactNormalOnB) < 0)
884 btVector3 newNormal = tri_normal * frontFacing;
886 btScalar d = newNormal.dot(localContactNormalOnB);