public @Nullable Vector3 getIntersection(Vector3 r0, Vector3 r1, boolean cull, boolean segment) {

            Vector3 dir = r1.copy().subtract(r0);
            Vector3 w0 = r0.copy().subtract(v0);
            double a = -normal.dotProduct(w0);
            double b = normal.dotProduct(dir);

            // When b is zero, ray is parallel to triangle plane (within floating point error)
            if (Math.abs(b) < 0.00000001) return null;

            // When b is negative, ray points against the normal towards the front face. If culling is enabled, b must be negative
            if (cull && (b > 0)) return null;

            // Find line scalar r. This represents how from r0 towards r1 the intersection is:
            // - When r == 0, intersection is at r0
            // - When r == 1, intersection is at r1
            // - When r is negative, intersection is behind r0 (the wrong direction)
            // - When r is greater than 1, intersection is past r1 (okay only if ray is infinite and not a segment)
            double r = a / b;
            if (r < 0.0 || (segment && r > 1.0)) return null;

            // Intersection of ray against the triangle plane
            Vector3 intersection = r0.copy().add(dir.x * r, dir.y * r, dir.z * r);

            // Now check if I is inside the triangle
            Vector3 w = intersection.copy().subtract(v0);
            double wu = w.dotProduct(u);
            double wv = w.dotProduct(v);

            double s = (uv * wv - vv * wu) / D;
            if (s < 0.0 || s > 1.0) return null; // I is outside the triangle

            double t = (uv * wu - uu * wv) / D;
            if (t < 0.0 || (s + t) > 1.0) return null; // I is outside the triangle

            return intersection;
        }
Fast implementation of ray-triangle intersection using barycentric coordinates. Because
normal and uu/uv/vv are precomputed, this requires only 2 dot products to check for
plane intersection and 2 more to check for triangle intersection.
<p>
Source: Daniel Sunday <a href="http://www.geomalgorithms.com/algorithms.html">...</a>

@param r0      First ray point
@param r1      Second ray point
@param cull    If true, only intersections on triangle's front face are valid
@param segment If true, ray is treated as a segment (has a start and end). Otherwise, it is treated as infinite length
@return Intersection point or null if no intersection
core/src/main/java/mrtjp/projectred/lib/ModelVoxelShape.java