mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 23:46:03 +01:00
fix(client/zones): abort triangle creation if polygon is not simple
This commit is contained in:
@@ -26,6 +26,14 @@ local function nextFreePoint(points, b, len)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function unableToSplit(polygon)
|
||||||
|
print('The following polygon is malformed and has failed to be split into triangles for debug')
|
||||||
|
|
||||||
|
for k, v in pairs(polygon) do
|
||||||
|
print(k, v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function getTriangles(polygon)
|
local function getTriangles(polygon)
|
||||||
local triangles = {}
|
local triangles = {}
|
||||||
|
|
||||||
@@ -33,43 +41,49 @@ local function getTriangles(polygon)
|
|||||||
for i = 2, #polygon - 1 do
|
for i = 2, #polygon - 1 do
|
||||||
triangles[#triangles + 1] = mat(polygon[1], polygon[i], polygon[i + 1])
|
triangles[#triangles + 1] = mat(polygon[1], polygon[i], polygon[i + 1])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return triangles
|
||||||
|
end
|
||||||
|
|
||||||
|
if not polygon:isSimple() then
|
||||||
|
unableToSplit(polygon)
|
||||||
|
|
||||||
return triangles
|
return triangles
|
||||||
end
|
end
|
||||||
|
|
||||||
local points = {}
|
local points = {}
|
||||||
|
local polygonN = #polygon
|
||||||
|
|
||||||
for i = 1, #polygon do
|
for i = 1, polygonN do
|
||||||
points[i] = polygon[i]
|
points[i] = polygon[i]
|
||||||
end
|
end
|
||||||
|
|
||||||
local a, b, c = 1, 2, 3
|
local a, b, c = 1, 2, 3
|
||||||
local len = #points
|
|
||||||
local zValue = polygon[1].z
|
local zValue = polygon[1].z
|
||||||
local count = 0
|
local count = 0
|
||||||
|
|
||||||
while len - #triangles > 2 do
|
while polygonN - #triangles > 2 do
|
||||||
if polygon:containsSegment(vec3(glm.segment2d.getPoint(polygon[a].xy, polygon[c].xy, 0.01), zValue), vec3(glm.segment2d.getPoint(polygon[a].xy, polygon[c].xy, 0.99), zValue)) then
|
local a2d = polygon[a].xy
|
||||||
|
local c2d = polygon[c].xy
|
||||||
|
|
||||||
|
if polygon:containsSegment(vec3(glm.segment2d.getPoint(a2d, c2d, 0.01), zValue), vec3(glm.segment2d.getPoint(a2d, c2d, 0.99), zValue)) then
|
||||||
triangles[#triangles + 1] = mat(polygon[a], polygon[b], polygon[c])
|
triangles[#triangles + 1] = mat(polygon[a], polygon[b], polygon[c])
|
||||||
points[b] = false
|
points[b] = false
|
||||||
|
|
||||||
b = c
|
b = c
|
||||||
c = nextFreePoint(points, b, len)
|
c = nextFreePoint(points, b, polygonN)
|
||||||
else
|
else
|
||||||
a = b
|
a = b
|
||||||
b = c
|
b = c
|
||||||
c = nextFreePoint(points, b, len)
|
c = nextFreePoint(points, b, polygonN)
|
||||||
end
|
end
|
||||||
|
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
if count > len and #triangles == 0 then
|
if count > polygonN and #triangles == 0 then
|
||||||
print('The following polygon failed to be split into triangles for debug')
|
unableToSplit(polygon)
|
||||||
|
|
||||||
for k, v in pairs(polygon) do
|
return triangles
|
||||||
print(k, v)
|
|
||||||
end
|
|
||||||
|
|
||||||
break
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user