private void AddRayInTri(Tri triProj, RayTrans rayTrans, ref List<RayHit> rayHits)
{
// Check for hit in triangle
Vector3 posHitProj;
Vector3 normalProj;
if (HitRayInTri(triProj, rayTrans.Position1RayProj, rayTrans.VectorRayProj, out posHitProj, out normalProj))
{
// Hack to circumvent ghost face bug in PrimMesher by removing hits in (ghost) face plane through shape center
if (Math.Abs(Vector3.Dot(posHitProj, normalProj)) < m_floatToleranceInCastRay && !rayTrans.ShapeNeedsEnds)
return;
// Transform hit and normal to region coordinate system
Vector3 posHit = rayTrans.PositionPart + (posHitProj * rayTrans.ScalePart) * rayTrans.RotationPart;
Vector3 normal = Vector3.Normalize((normalProj * rayTrans.ScalePart) * rayTrans.RotationPart);
// Remove duplicate hits at triangle intersections
float distance = Vector3.Distance(rayTrans.Position1Ray, posHit);
for (int i = rayHits.Count - 1; i >= 0; i--)
{
if (rayHits[i].PartId != rayTrans.PartId)
break;
if (Math.Abs(rayHits[i].Distance - distance) < m_floatTolerance2InCastRay)
return;
}
// Build result data set
RayHit rayHit = new RayHit();
rayHit.PartId = rayTrans.PartId;
rayHit.GroupId = rayTrans.GroupId;
rayHit.Link = rayTrans.Link;
rayHit.Position = posHit;
rayHit.Normal = normal;
rayHit.Distance = distance;
rayHits.Add(rayHit);
}
}