convexTrimesh method

bool convexTrimesh(
  1. ConvexPolyhedron si,
  2. Trimesh sj,
  3. Vec3 xi,
  4. Vec3 xj,
  5. Quaternion qi,
  6. Quaternion qj,
  7. Body bi,
  8. Body bj, [
  9. Shape? rsi,
  10. Shape? rsj,
  11. bool justTest = false,
  12. List<int>? faceListA,
  13. List<int>? faceListB,
])

Implementation

bool convexTrimesh(
  ConvexPolyhedron si,
  Trimesh sj,
  Vec3 xi,
  Vec3 xj,
  Quaternion qi,
  Quaternion qj,
  Body bi,
  Body bj,
  [
    Shape? rsi,
    Shape? rsj,
    bool justTest = false,
    List<int>? faceListA,
    List<int>? faceListB
  ]
){
  final sepAxis = _convexConvexSepAxis;
  if(xi.distanceTo(xj) > si.boundingSphereRadius + sj.boundingSphereRadius){
    return false;
  }

  // Construct a temp hull for each triangle
  final hullB = ConvexPolyhedron();

  hullB.faces = [[0,1,2]];
  final va = Vec3();
  final vb = Vec3();
  final vc = Vec3();

  // final na = Vec3();
  // final nb = Vec3();
  // final nc = Vec3();

  final triangleNormal = Vec3();

  hullB.vertices = [va,vb,vc];
  //hullB.faceNormals = [na,nb,nc];

  for (int i = 0; i < sj.indices.length / 3; i++) {
    sj.getTriangleVertices(i, va, vb, vc);
    sj.getFaceNormal(i, triangleNormal);
    //sj.getTriangleNormals(i, na,nb,nc);

    final d = si.testSepAxis(triangleNormal, hullB, xi, qi, xj, qj);
    hullB.faceNormals = [triangleNormal];

    if(d != null && si.findSeparatingAxis(hullB, xi, qi, xj, qj, sepAxis, faceListA, faceListB)){
      int numContacts = 0;
      triangleNormal.scale(1, triangleNormal);

      final List<ConvexPolyhedronContactPoint> res = [];
      final q = _convexConvexQ;
      si.clipAgainstHull(xi,qi,hullB,xj,qj,triangleNormal,-100,100,res);
      for(int j = 0; j != res.length; j++){
        if (justTest) {
          return true;
        }
        final r = createContactEquation(bi,bj,si,sj,rsi,rsj);
        final ri = r.ri;
        final rj = r.rj;
        r.ni.copy(triangleNormal);
        //r.ni.negate(r.ni);
        //res[j].normal.negate(q);

        sepAxis.negate(r.ni);

        q.scale(res[j].depth, q);
        res[j].point.vadd(q, ri);
        rj.copy(res[j].point);

        //Contact points are in world coordinates. Transform back to relative
        ri.vsub(xi,ri);
        rj.vsub(xj,rj);

        // Make relative to bodies
        ri.vadd(xi, ri);
        ri.vsub(bi.position, ri);
        rj.vadd(xj, rj);
        rj.vsub(bj.position, rj);

        result.add(r);
        numContacts++;
        if (!enableFrictionReduction) {
          createFrictionEquationsFromContact(r, frictionResult);
        }
      }
      if (enableFrictionReduction && numContacts != 0) {
        createFrictionFromAverage(numContacts);
      }
    }
  }
  return false;
}