Determine if a triangle has been intersected. That would most commonly be used for collision detection, click detection, or touch detection.

Arguments

point

  • The point in space we are checking (Vec3)

direction

  • The direction to cast a ray (Vec3)

triangle

  • The triangle we are checking for collision

Returns

boolean

  • True: The point intersects the triangle
  • False: The point does not intersect the triangle
local Vec3 = require("winged-edge.external.vector3d")
local we = require("winged-edge")

local object = we.new("some_object.obj")

local triangles = we.triangulate(1, object)

local point = Vec3(0.5, 0.5, 0.1)
local direction = Vec3(0, 0, 1)

for _, triangle in ipairs(triangles) do
    if we.triangulate(point, direction, triangle) then
        print("Intersect!")
        break
    end
end