Detecting if inside mesh using line traces

Hello! I want to use a volume and populate it with points, and for each point decide if it is inside or outside the mesh. This is for a 3D Nav-Volume that I am creating. I have a max distance, so most line traces from inside the mesh rightly return false because there is no hit when the line trace goes through the back face. The problem is that right now, I have the issue of nodes close inside the mesh, close to a concave corner will go through the backface, and then hit a front face and therefore say that the node should exist. Illustration below:


And in practice:

The camera is inside the mesh, and the ones below the concave corner should be identified as invalid points.

What I would love is if I could simply detect a hit for the backface, and I could just check if the dot with the line trace direction is > 0. in that case, I would know that I am hitting a backface. Is something like that possible?

The other naive solution I can think of is doing a flood fill of the nodes (they are correctly connected), and I send a line trace between each node, and if is blocked from each connection, the node is pruned. However, this seems unnecessarily complicated for the problem at hand.

Would be very thankful for a solution!

As a bonus, if it is relevant, My mesh uses the complex collision as its simple collision.

Just as I published the question, I came up with a solution! This fringe case can be solved simply by tracing back from the hit location towards the start. If it hits something, it has gone through a back face. Example in c++ below.

bool bHit = UKismetSystemLibrary::LineTraceSingle(
		GetWorld(),
		Start, End,
		UEngineTypes::ConvertToTraceType(TraceChannel),
		false,
		Ignore,
		EDrawDebugTrace::None,
		OutHit,
		true);
	FHitResult BackTrace;
	if(bHit) {
		bool bBackTraceHit = UKismetSystemLibrary::LineTraceSingle(
		GetWorld(),
		OutHit.Location, Start,
		UEngineTypes::ConvertToTraceType(TraceChannel),
		true,
		Ignore,
		EDrawDebugTrace::None,
		BackTrace,
		true);
		if(bBackTraceHit)
			return false;
	}
	return bHit;

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.