check_normal.lua


NAME
    check_normal

FUNCTION
    check_normal(xyz, nor)

NOTES
    Check whether vertex normals point outward
NPUTS
    xyz - zeVertex as vertex
    nor - zeVertex as normal

OUTPUTS
    a zeVertex object containing new normals.

SOURCE

require("register")

function check_normal(xyz, nor)
    local n = xyz:size() - 1
    local nr = zeGrf.new("vertex")
    for k = 0, n do
        local x, y, z = xyz:get(k)
        local nx, ny, nz = nor:get(k)
        if nx ~= 0 and x/nx < 0 then nx = -nx end
        if ny ~= 0 and y/ny < 0 then ny = -ny end
        if nz ~= 0 and z/nz < 0 then nz = -nz end
        nr:add(nx, ny, nz)
    end
    return nr
end