@ -383,4 +383,62 @@ typedef struct World
return outFaces ;
return outFaces ;
}
}
std : : vector < Vec3 > findTjunctions ( const Vec3 & point ) const
{
std : : vector < Vec3 > outTangents ;
for ( int faceIdx = 0 ; faceIdx < numFaces ; + + faceIdx )
{
const face_t * face = & faces [ faceIdx ] ;
const plane_t * plane = & planes [ face - > plane_id ] ;
/ / Check if the point lies on the face ' s plane ( it ' s not strictly necessary to do this , but this check makes the whole function a lot faster )
if ( fabs ( plane - > pointDistance ( point ) ) > 0.01 )
continue ;
Vec3 faceNormal = face - > side ? - plane - > normal : plane - > normal ;
/ / Check if the point is located on one of the face ' s edges
for ( int edgeListIdx = 0 ; edgeListIdx < face - > ledge_num ; + + edgeListIdx )
{
int edgeIdx = edgeList [ face - > ledge_id + edgeListIdx ] ;
Vec3 v0 , v1 ;
if ( edgeIdx > 0 )
{
const edge_t * edge = & edges [ edgeIdx ] ;
v0 = vertices [ edge - > vertex0 ] . toVec ( ) ;
v1 = vertices [ edge - > vertex1 ] . toVec ( ) ;
}
else
{
const edge_t * edge = & edges [ - edgeIdx ] ;
v0 = vertices [ edge - > vertex1 ] . toVec ( ) ;
v1 = vertices [ edge - > vertex0 ] . toVec ( ) ;
}
Vec3 p0 = v0 - point ;
Vec3 p1 = v1 - point ;
double m0 = p0 . magnitude ( ) ;
double m1 = p1 . magnitude ( ) ;
if ( ( m0 * m1 ) < = 0.01 )
{
/ / Point is on one of the face ' s vertices , this is not a T - junction
break ;
}
double dot = p0 . dotProduct ( p1 ) / ( m0 * m1 ) ;
if ( dot < = - 0.99 )
{
/ / Point is on one of the face ' s edges , in - between its two vertices . This is a T - junction .
Vec3 edgeDir = ( v1 - v0 ) . normalized ( ) ;
Vec3 tangent = faceNormal . crossProduct ( edgeDir ) ;
outTangents . push_back ( tangent ) ;
}
}
}
return outTangents ;
}
} world_t ;
} world_t ;