-- lua ------------------------------ -- UnrealEd Actor Snap v1.0 -- ------------------------------ -- -- This script snaps to grid all actors and BSP vertices in an unreal engine map. -- -- Copy an unreal map (or part of a map), paste it to a txt file. -- You can modify the I/O file names and the grid size bellow. -- NOTE: You should use "/" in paths instead of "\". -- Run ActorSnap.bat. It will generate a Snapped.txt. Copy its contents, and paste -- back to UnrealEd. -- -- The script will automatically overwrite the existing Snapped.txt file. -- The BSP vertex snap could produce relative misalignment between brushes, -- so make sure that you check all brushes and reposition them if neccessary. -- It also replaces any "mylevel.mylevel." to the proper "mylevel.", so pasting -- the stuff back to UnrealEd won't result in a crash. -- ------------------------------- -- zoltan.erdokovy@gmail.com -- ------------------------------- -------------------------------------------------------------------------------- fileInName = "./SnapMe.txt" -- The input file. -- fileOutName = "./Snapped.txt" -- The output file. -- GridSize = 4 -- This should be an integer and bigger than 0. -- -------------------------------------------------------------------------------- --- GRIDSNAP --- function GridSnap (value) value = tonumber(value) value = value/GridSize value = math.floor(value+0.5) value = value*GridSize return value end --- FORMATNUMBER --- function FormatNumber (value) leadingzeros = "" -- Storing leading zeros. s = "" -- String to collect all pieces. sign = "+" -- Store the sign of the number. if (value < 0) then sign = "-" end for i=0, 3 do if (math.abs(value) < 10^(4-i)) then leadingzeros = "0"..leadingzeros end end s = sign..leadingzeros..math.abs(value)..".000000" return (s) end --- MAIN --- inputline = "" -- The lines of the input file fileIn = io.open(fileInName, "r") if (fileIn == nil) then error("Can't open "..fileInName.." !") end fileOut = io.open(fileOutName, "w+") if (fileOut == nil) then error("Can't open "..fileOutName.." !") end for inputline in fileIn:lines() do if (string.find(inputline, " Location=", 1, true) ~= nil) then -- Quantizing. endofx = string.find(inputline, ",",17,true) -- Getting the end position of the X position. valuex = string.sub(inputline, 17, endofx-1) -- Getting the actual value of X. valuex = GridSnap(valuex) endofy = string.find(inputline, ",",endofx+3,true) -- Getting the end position of the Y position. valuey = string.sub(inputline, endofx+3, endofy-1) -- Getting the actual value of Y. valuey = GridSnap(valuey) endofz = string.find(inputline, ")",endofy+3,true) -- Getting the end position of the Z position. valuez = string.sub(inputline, endofy+3, endofz-1) -- Getting the actual value of Z. valuez = GridSnap(valuez) fileOut:write(" Location=(X="..valuex..".00000,Y="..valuey..".00000,Z="..valuez..".00000)\n") elseif ((string.find(inputline, "Origin", 1, true) ~= nil) or (string.find(inputline, "Vertex", 1, true) ~= nil)) then linepart = string.sub(inputline, 0, 22) valuex = string.sub(inputline, 23, 35) -- Getting the actual value of X. valuex = FormatNumber(GridSnap(valuex)) valuey = string.sub(inputline, 37, 49) -- Getting the actual value of Y. valuey = FormatNumber(GridSnap(valuey)) valuez = string.sub(inputline, 51, 64) -- Getting the actual value of Z. valuez = FormatNumber(GridSnap(valuez)) fileOut:write(linepart..valuex..","..valuey..","..valuez.."\n") elseif (string.find(inputline, "myLevel.myLevel.", 1, true) ~= nil) then fileOut:write(string.gsub(inputline,"myLevel.myLevel.","mylevel.").."\n") else fileOut:write(inputline.."\n") end end