Last active
June 22, 2024 07:11
-
-
Save Vorschreibung/ba7652b877936d0c1ae7c67dd33af309 to your computer and use it in GitHub Desktop.
luadiant POC - clip all terrain to breadth of 2 units
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- clip all terrain to breadth of 2 units | |
local hits = {} | |
-- find all terrain brushes | |
for _,b in ipairs(rad.allBrushes()) do | |
local terrain_face = nil | |
for _,f in ipairs(b:getFaces()) do | |
local texture = f:getTexture() | |
if texture == "textures/common/caulk" then | |
else | |
-- we skip brushes with more than 1 non-caulk face | |
if terrain_face ~= nil then | |
goto skip_brush | |
end | |
-- we skip brushes with any non-terrain face | |
if not string.find(texture, ".*terrain.*") then | |
goto skip_brush | |
end | |
terrain_face = f | |
end | |
end | |
-- we skip brushes with no terrain-face at all | |
if terrain_face == nil then | |
goto skip_brush | |
end | |
table.insert(hits, {b, terrain_face}) | |
::skip_brush:: | |
end | |
rad.deselectAll() | |
-- clip em all | |
for _,hit in ipairs(hits) do | |
local brush = hit[1] | |
local face = hit[2] | |
-- determine normal vector and scale by 2 and invert | |
local nv3d = face:getNormalVector() | |
do | |
local nv3dv = nv3d:getValues() | |
local x = nv3dv[1] * 2 *-1 | |
local y = nv3dv[2] * 2 *-1 | |
local z = nv3dv[3] * 2 *-1 | |
nv3d:setValues({x, y, z}) | |
end | |
-- get terrain plane and translate by previous normal vector | |
local terrain_plane = face:getPlanePoints() | |
terrain_plane[1]:add(nv3d) | |
terrain_plane[2]:add(nv3d) | |
terrain_plane[3]:add(nv3d) | |
-- clip the brush (@TODO without selecting/deselecting and UndoableCommand which makes things really slow) | |
brush:select() | |
rad.clip(ClipperPoints(terrain_plane[3], terrain_plane[2], terrain_plane[1], 3), false) | |
brush:deselect() | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment