local l_Parent_0 = script.Parent.Parent.Parent;
local v1 = require(l_Parent_0.Src.Util.Constants);
local v2 = require(l_Parent_0.Src.Util.TerrainEnums);
local l_BrushMode_0 = v2.BrushMode;
local l_BrushShape_0 = v2.BrushShape;
local l_FlattenMode_0 = v2.FlattenMode;
local l_ToolId_0 = v2.ToolId;
local v7 = require(l_Parent_0.Src.Util.applyPivot);
local v8 = require(script.Parent.OperationHelper);
local v9 = require(script.Parent.smartLargeSculptBrush);
local v10 = require(script.Parent.smartColumnSculptBrush);
local v11 = require(script.Parent.SculptOperations);
local v12 = require(l_Parent_0.Src.Util.PruneWaterVoxels);
local l_Air_0 = Enum.Material.Air;
local l_Water_0 = Enum.Material.Water;
local l_TerrainEditorOverhaul_0 = game:GetFastFlag("TerrainEditorOverhaul");
local l_TerrainSmoothToolFix_0 = game:GetFastFlag("TerrainSmoothToolFix");
local l_TerrainVoxelChannelNewApi_0 = game:GetFastFlag("TerrainVoxelChannelNewApi");
local l_TerrainToolsPaintToolFix_0 = game:GetFastFlag("TerrainToolsPaintToolFix");
local v19 = game:DefineFastFlag("TerrainToolsReplaceWithWaterFix", false);
return function(v20, v21)
    local v22 = v21.cursorHeight * v1.VOXEL_RESOLUTION;
    local l_cursorSize_0 = v21.cursorSize;
    local v24 = l_cursorSize_0 * v1.VOXEL_RESOLUTION;
    local v25 = v7(v21.pivot, v21.centerPoint, v22);
    local l_autoMaterial_0 = v21.autoMaterial;
    local l_brushMode_0 = v21.brushMode;
    local l_brushShape_0 = v21.brushShape;
    local l_ignoreWater_0 = v21.ignoreWater;
    local l_material_0 = v21.material;
    local v31 = v24 * 0.5;
    local l_replaceMaterial_0 = v21.replaceMaterial;
    local l_source_0 = v21.source;
    local l_target_0 = v21.target;
    local l_currentTool_0 = v21.currentTool;
    assert(v20 ~= nil, "performTerrainBrushOperation requires a terrain instance");
    local v36 = false;
    if l_currentTool_0 ~= nil then
        v36 = type(l_currentTool_0) == "string";
    end;
    assert(v36, "performTerrainBrushOperation requires a currentTool parameter");
    local v37 = Vector3.new(v8.clampDownToVoxel(v25.x - v31), v8.clampDownToVoxel(v25.y - v22 * 0.5), v8.clampDownToVoxel(v25.z - v31));
    v36 = Vector3.new(v8.clampUpToVoxel(v25.x + v31), v8.clampUpToVoxel(v25.y + v22 * 0.5), v8.clampUpToVoxel(v25.z + v31));
    if not l_TerrainEditorOverhaul_0 then
        if l_currentTool_0 == l_ToolId_0.Add then
            v20.LastUsedModificationMethod = Enum.TerrainAcquisitionMethod.EditAddTool;
        elseif not (l_TerrainEditorOverhaul_0 and l_currentTool_0 == l_ToolId_0.Paint) or not l_replaceMaterial_0 then
            if not l_TerrainEditorOverhaul_0 and l_currentTool_0 == l_ToolId_0.Replace then
                v20.LastUsedModificationMethod = Enum.TerrainAcquisitionMethod.EditReplaceTool;
            end;
        else
            v20.LastUsedModificationMethod = Enum.TerrainAcquisitionMethod.EditReplaceTool;
        end;
        if not (l_currentTool_0 ~= l_ToolId_0.Add and (not (l_currentTool_0 == l_ToolId_0.Subtract) or l_ignoreWater_0) or l_autoMaterial_0) then
            if l_currentTool_0 == l_ToolId_0.Subtract then
                l_material_0 = l_Air_0;
            end;
            if l_brushShape_0 == l_BrushShape_0.Sphere then
                v20:FillBall(v25, v31, l_material_0);
                return ;
            elseif l_brushShape_0 == l_BrushShape_0.Cube then
                v20:FillBlock(CFrame.new(v25), Vector3.new(v24, v22, v24), l_material_0);
                return ;
            elseif l_brushShape_0 == l_BrushShape_0.Cylinder then
                if (v36 - v37).x <= 2 * v1.VOXEL_RESOLUTION then
                    v20:FillBall(v25, v31, l_material_0);
                    return ;
                else
                    v20:FillCylinder(CFrame.new(v25), v22, v31, l_material_0);
                    return ;
                end;
            else
                assert(false, "Invalid brush shape in performTerrainBrushOperation quick path");
                return ;
            end;
        end;
    else
        if l_currentTool_0 == l_ToolId_0.Draw and l_brushMode_0 == l_BrushMode_0.Add then
            v20.LastUsedModificationMethod = Enum.TerrainAcquisitionMethod.EditAddTool;
        elseif not (l_TerrainEditorOverhaul_0 and l_currentTool_0 == l_ToolId_0.Paint) or not l_replaceMaterial_0 then
            if not l_TerrainEditorOverhaul_0 and l_currentTool_0 == l_ToolId_0.Replace then
                v20.LastUsedModificationMethod = Enum.TerrainAcquisitionMethod.EditReplaceTool;
            end;
        else
            v20.LastUsedModificationMethod = Enum.TerrainAcquisitionMethod.EditReplaceTool;
        end;
        if not ((not (l_currentTool_0 == l_ToolId_0.Draw) or l_brushMode_0 ~= l_BrushMode_0.Add and (not (l_brushMode_0 == l_BrushMode_0.Subtract) or l_ignoreWater_0)) or l_autoMaterial_0) then
            local v38 = -1;
            if l_brushMode_0 == l_BrushMode_0.Subtract then
                l_material_0 = l_Air_0;
                v38 = 0;
            end;
            if l_brushShape_0 == l_BrushShape_0.Sphere then
                v20:FillBall(v25, v31 + v38, l_material_0);
                return ;
            elseif l_brushShape_0 == l_BrushShape_0.Cube then
                v20:FillBlock(CFrame.new(v25), Vector3.new(v24 + v38, v22 + v38, v24 + v38), l_material_0);
                return ;
            elseif l_brushShape_0 == l_BrushShape_0.Cylinder then
                if (v36 - v37).x <= 2 * v1.VOXEL_RESOLUTION then
                    v20:FillBall(v25, v31 + v38, l_material_0);
                    return ;
                else
                    v20:FillCylinder(CFrame.new(v25), v22 + v38, v31 + v38, l_material_0);
                    return ;
                end;
            else
                assert(false, "Invalid brush shape in performTerrainBrushOperation quick path");
                return ;
            end;
        end;
    end;
    local l_strength_0 = v21.strength;
    local v40 = Region3.new(v37, v36);
    local v41 = nil;
    local v42 = nil;
    local v43 = nil;
    if not l_TerrainVoxelChannelNewApi_0 then
        local v44 = v20:ReadVoxelChannels(v40, v1.VOXEL_RESOLUTION, {
            "Material",
            "Occupancy",
            "WaterOccupancy"
        });
        v41 = v44.Material;
        v42 = v44.Occupancy;
        v43 = v44.WaterOccupancy;
    else
        local v45 = v20:ReadVoxelChannels(v40, v1.VOXEL_RESOLUTION, {
            "SolidMaterial",
            "SolidOccupancy",
            "LiquidOccupancy"
        });
        v41 = v45.SolidMaterial;
        v42 = v45.SolidOccupancy;
        v43 = v45.LiquidOccupancy;
    end;
    local v46 = nil;
    local v47 = nil;
    local v48 = nil;
    if not (l_currentTool_0 == l_ToolId_0.Smooth) or not l_TerrainSmoothToolFix_0 then
        if not l_TerrainVoxelChannelNewApi_0 then
            local v49 = v20:ReadVoxelChannels(v40, v1.VOXEL_RESOLUTION, {
                "Material",
                "Occupancy",
                "WaterOccupancy"
            });
            v46 = v49.Material;
            v47 = v49.Occupancy;
            v48 = v49.WaterOccupancy;
        else
            local v50 = v20:ReadVoxelChannels(v40, v1.VOXEL_RESOLUTION, {
                "SolidMaterial",
                "SolidOccupancy",
                "LiquidOccupancy"
            });
            v46 = v50.SolidMaterial;
            v47 = v50.SolidOccupancy;
            v48 = v50.LiquidOccupancy;
        end;
    else
        local v51, v52 = v20:SmoothRegion(v40, v1.VOXEL_RESOLUTION, l_strength_0);
        v46 = v51;
        v47 = v52;
        v48 = if not l_TerrainVoxelChannelNewApi_0 then v20:ReadVoxelChannels(v40, v1.VOXEL_RESOLUTION, {
            "WaterOccupancy"
        }).WaterOccupancy else v20:ReadVoxelChannels(v40, v1.VOXEL_RESOLUTION, {
            "LiquidOccupancy"
        }).LiquidOccupancy;
    end;
    local v53;
    if not l_TerrainEditorOverhaul_0 then
        v53 = true;
        if l_currentTool_0 ~= l_ToolId_0.Grow then
            v53 = true;
            if l_currentTool_0 ~= l_ToolId_0.Erode then
                v53 = true;
                if l_currentTool_0 ~= l_ToolId_0.Flatten then
                    v53 = l_ToolId_0.Smooth and not l_TerrainSmoothToolFix_0;
                end;
            end;
        end;
    else
        v53 = true;
        if l_currentTool_0 ~= l_ToolId_0.Sculpt then
            v53 = true;
            if l_currentTool_0 ~= l_ToolId_0.Flatten then
                v53 = l_ToolId_0.Smooth and not l_TerrainSmoothToolFix_0;
            end;
        end;
    end;
    if l_currentTool_0 == l_ToolId_0.Flatten then
        v10(v21, v37, v36, v41, v42, v43, v46, v47, v48);
        v12(v46, v47, v48);
        if not l_TerrainVoxelChannelNewApi_0 then
            v20:WriteVoxelChannels(v40, v1.VOXEL_RESOLUTION, {
                Material = v46,
                Occupancy = v47,
                WaterOccupancy = v48
            });
            return ;
        else
            v20:WriteVoxelChannels(v40, v1.VOXEL_RESOLUTION, {
                SolidMaterial = v46,
                SolidOccupancy = v47,
                LiquidOccupancy = v48
            });
            return ;
        end;
    elseif not (l_cursorSize_0 > 32) or not v53 then
        local l_flattenMode_0 = v21.flattenMode;
        local l_x_0 = v25.x;
        local l_y_0 = v25.y;
        local l_z_0 = v25.z;
        local l_x_1 = v37.x;
        local l_y_1 = v37.y;
        local l_z_1 = v37.z;
        local l_x_2 = v36.x;
        local l_l_Air_0_0 = l_Air_0;
        local v63 = 0;
        if l_ignoreWater_0 then
            local v64, v65 = v8.getWaterHeightAndAirFillerMaterial(v41);
            v63 = v64;
            l_l_Air_0_0 = v65;
        end;
        local v66 = #v42;
        local v67 = #v42[1];
        local v68 = #v42[1][1];
        local v69 = (l_x_2 - l_x_1) * 0.5;
        local l_planeNormal_0 = v21.planeNormal;
        local l_x_3 = l_planeNormal_0.x;
        local l_y_2 = l_planeNormal_0.y;
        local l_z_2 = l_planeNormal_0.z;
        local l_planePoint_0 = v21.planePoint;
        local l_x_4 = l_planePoint_0.x;
        local l_y_3 = l_planePoint_0.y;
        local l_z_3 = l_planePoint_0.z;
        local v78 = {
            readMaterials = v41,
            readOccupancies = v42,
            readWaterOccupancies = v43,
            writeMaterials = v46,
            writeOccupancies = v47,
            writeWaterOccupancies = v48,
            sizeX = v66,
            sizeY = v67,
            sizeZ = v68,
            strength = l_strength_0,
            ignoreWater = l_ignoreWater_0,
            desiredMaterial = l_material_0,
            autoMaterial = l_autoMaterial_0,
            filterSize = 1,
            maxOccupancy = 1
        };
        l_cursorSize_0 = l_cursorSize_0 + ((l_currentTool_0 == l_ToolId_0.Draw and l_brushMode_0 == l_BrushMode_0.Subtract) and 0 or -1);
        v69 = v69 + ((l_currentTool_0 == l_ToolId_0.Draw and l_brushMode_0 == l_BrushMode_0.Subtract) and 0 or -1);
        for v79, v80 in ipairs(v42) do
            local v81 = l_x_1 + (v79 - 0.5) * v1.VOXEL_RESOLUTION;
            local v82 = v81 - l_x_0;
            local v83 = (v81 - l_x_4) * l_x_3;
            for v84, v85 in ipairs(v80) do
                local v86 = l_y_1 + (v84 - 0.5) * v1.VOXEL_RESOLUTION;
                local v87 = v86 - l_y_0;
                local v88 = v83 + (v86 - l_y_3) * l_y_2;
                for v89, v90 in ipairs(v85) do
                    local v91 = l_z_1 + (v89 - 0.5) * v1.VOXEL_RESOLUTION;
                    local v92 = v91 - l_z_0;
                    local v93 = v88 + (v91 - l_z_3) * l_z_2;
                    local v94, v95 = v8.calculateBrushPowerForCell(v82, v87, v92, l_cursorSize_0, l_brushShape_0, v69, not (l_currentTool_0 == l_ToolId_0.Smooth));
                    local v96 = v41[v79][v84][v89];
                    local v97 = v43[v79][v84][v89];
                    local v98 = false;
                    if v96 == l_Air_0 then
                        v98 = v97 > 0;
                    end;
                    l_l_Air_0_0 = v84 <= v63 and l_l_Air_0_0 or l_Air_0;
                    v78.x = v79;
                    v78.y = v84;
                    v78.z = v89;
                    v78.brushOccupancy = v94;
                    v78.magnitudePercent = v95;
                    v78.cellOccupancy = v90;
                    v78.cellMaterial = v96;
                    v78.cellWaterOccupancy = v97;
                    v78.airFillerMaterial = l_l_Air_0_0;
                    if not l_TerrainEditorOverhaul_0 then
                        if l_currentTool_0 == l_ToolId_0.Add then
                            if v90 < v94 then
                                v47[v79][v84][v89] = v94;
                            end;
                            if v94 >= 0.5 and v96 == l_Air_0 then
                                local l_l_material_0_0 = l_material_0;
                                if l_autoMaterial_0 then
                                    l_l_material_0_0 = v8.getMaterialForAutoMaterial(v41, v43, v79, v84, v89, v66, v67, v68, v96);
                                end;
                                v46[v79][v84][v89] = l_l_material_0_0;
                            end;
                        elseif l_currentTool_0 == l_ToolId_0.Subtract then
                            if v96 ~= l_Air_0 then
                                local v100 = 1 - v94;
                                if v100 < v90 then
                                    if v100 <= v8.one256th then
                                        v47[v79][v84][v89] = l_l_Air_0_0 == l_Water_0 and 1 or 0;
                                        v46[v79][v84][v89] = l_l_Air_0_0;
                                    else
                                        v47[v79][v84][v89] = v100;
                                    end;
                                end;
                            end;
                        elseif l_currentTool_0 == l_ToolId_0.Grow then
                            v11.grow(v78);
                        elseif l_currentTool_0 == l_ToolId_0.Erode then
                            v11.erode(v78);
                        elseif l_currentTool_0 == l_ToolId_0.Flatten then
                            v78.maxOccupancy = math.abs(v93);
                            if v1.FLATTEN_PLANE_TOLERANCE < v93 and l_flattenMode_0 ~= l_FlattenMode_0.Grow then
                                v11.erode(v78);
                            elseif v93 < -v1.FLATTEN_PLANE_TOLERANCE and l_flattenMode_0 ~= l_FlattenMode_0.Erode then
                                v11.grow(v78);
                            end;
                        elseif l_currentTool_0 == l_ToolId_0.Paint then
                            if not l_TerrainEditorOverhaul_0 or not l_replaceMaterial_0 then
                                if v94 > 0 and v90 > 0 then
                                    v46[v79][v84][v89] = l_material_0;
                                end;
                            else
                                local v101 = v41[v79][v84][v89];
                                if v94 > 0 and v101 == l_source_0 then
                                    v46[v79][v84][v89] = l_target_0;
                                    if v101 == l_Air_0 then
                                        v47[v79][v84][v89] = v94;
                                    end;
                                end;
                            end;
                        elseif l_currentTool_0 == l_ToolId_0.Replace then
                            local v102 = v41[v79][v84][v89];
                            if v94 > 0 and v102 == l_source_0 then
                                v46[v79][v84][v89] = l_target_0;
                                if v102 == l_Air_0 then
                                    v47[v79][v84][v89] = v94;
                                end;
                            end;
                        elseif l_currentTool_0 == l_ToolId_0.Smooth then
                            if l_TerrainSmoothToolFix_0 then
                                v78.smoothVoxelsUpgraded = v20.SmoothVoxelsUpgraded;
                                v11.smooth(v78);
                            else
                                v11.smooth(v78);
                            end;
                        end;
                    elseif l_currentTool_0 == l_ToolId_0.Draw then
                        if l_brushMode_0 == l_BrushMode_0.Add then
                            if v90 < v94 then
                                v47[v79][v84][v89] = v94;
                            end;
                            local l_l_material_0_1 = l_material_0;
                            local v104 = false;
                            if not (not ((not (v96 ~= l_Water_0) or v96 == l_Air_0) and v94 > 0) or not l_autoMaterial_0) then
                                local v105, v106 = v8.getMaterialForAutoMaterial(v41, v43, v79, v84, v89, v66, v67, v68, v96);
                                l_l_material_0_1 = v105;
                                v104 = v106;
                            end;
                            if v104 then
                                if v94 > 0 and l_l_material_0_1 == l_Water_0 then
                                    v48[v79][v84][v89] = v94;
                                    v47[v79][v84][v89] = v90;
                                    v46[v79][v84][v89] = l_Air_0;
                                end;
                                if v94 >= 0.5 and v96 == l_Air_0 then
                                    v46[v79][v84][v89] = l_l_material_0_1;
                                end;
                            end;
                        elseif l_brushMode_0 == l_BrushMode_0.Subtract and v96 ~= l_Air_0 then
                            local v107 = 1 - v94;
                            if v107 < v90 then
                                if v107 <= v8.one256th then
                                    v47[v79][v84][v89] = l_l_Air_0_0 == l_Water_0 and 1 or 0;
                                    v46[v79][v84][v89] = l_l_Air_0_0;
                                else
                                    v47[v79][v84][v89] = v107;
                                end;
                            end;
                        end;
                    elseif l_currentTool_0 == l_ToolId_0.Sculpt then
                        if l_brushMode_0 == l_BrushMode_0.Add then
                            v11.grow(v78);
                        elseif l_brushMode_0 == l_BrushMode_0.Subtract then
                            v11.erode(v78);
                        end;
                    elseif l_currentTool_0 == l_ToolId_0.Flatten then
                        v78.maxOccupancy = math.abs(v93);
                        if v1.FLATTEN_PLANE_TOLERANCE < v93 and l_flattenMode_0 ~= l_FlattenMode_0.Grow then
                            v11.erode(v78);
                        elseif v93 < -v1.FLATTEN_PLANE_TOLERANCE and l_flattenMode_0 ~= l_FlattenMode_0.Erode then
                            v11.grow(v78);
                        end;
                    elseif l_currentTool_0 == l_ToolId_0.Paint then
                        if not l_TerrainToolsPaintToolFix_0 then
                            if not l_TerrainEditorOverhaul_0 or not l_replaceMaterial_0 then
                                if v94 > 0 and l_material_0 == l_Water_0 then
                                    if v46[v79][v84][v89] ~= l_Air_0 then
                                        v46[v79][v84][v89] = l_Air_0;
                                        v48[v79][v84][v89] = v47[v79][v84][v89];
                                        v47[v79][v84][v89] = 0;
                                    end;
                                else
                                    if (v94 > 0 and v90 > 0) and v96 ~= l_Air_0 then
                                        v46[v79][v84][v89] = l_material_0;
                                    end;
                                    if not l_ignoreWater_0 then
                                        if v47[v79][v84][v89] < v48[v79][v84][v89] then
                                            v47[v79][v84][v89] = v48[v79][v84][v89];
                                        end;
                                        v48[v79][v84][v89] = 0;
                                    end;
                                end;
                            elseif v94 > 0 and v96 == l_source_0 then
                                if l_source_0 == l_Water_0 and v90 < v97 then
                                    v46[v79][v84][v89] = l_target_0;
                                    v48[v79][v84][v89] = 0;
                                    v47[v79][v84][v89] = v97;
                                else
                                    v46[v79][v84][v89] = l_target_0;
                                    if v96 == l_Air_0 then
                                        v47[v79][v84][v89] = v94;
                                    end;
                                end;
                            end;
                        elseif v94 > 0 then
                            if not l_TerrainEditorOverhaul_0 or not l_replaceMaterial_0 then
                                if l_material_0 == l_Water_0 then
                                    if v46[v79][v84][v89] ~= l_Air_0 then
                                        v46[v79][v84][v89] = l_Air_0;
                                        v48[v79][v84][v89] = math.max(v90, v97);
                                        v47[v79][v84][v89] = 0;
                                    end;
                                elseif not (v90 <= 0 and not v98) then
                                    v46[v79][v84][v89] = l_material_0;
                                    if not l_ignoreWater_0 then
                                        v47[v79][v84][v89] = math.max(v90, v97);
                                        v48[v79][v84][v89] = 0;
                                    end;
                                end;
                            elseif not (v96 ~= l_source_0 and (not (l_source_0 == l_Water_0) or not v98)) then
                                if l_source_0 == l_Water_0 then
                                    v48[v79][v84][v89] = 0;
                                end;
                                if l_source_0 == l_Water_0 and v90 < v97 then
                                    v46[v79][v84][v89] = l_target_0;
                                    v47[v79][v84][v89] = l_target_0 == l_Air_0 and 0 or v97;
                                elseif l_target_0 == l_Water_0 then
                                    v46[v79][v84][v89] = l_Air_0;
                                    v47[v79][v84][v89] = 0;
                                    if not v19 then
                                        v47[v79][v84][v89] = math.max(v90, v97);
                                    else
                                        v48[v79][v84][v89] = math.max(v90, v97);
                                    end;
                                else
                                    v46[v79][v84][v89] = l_target_0;
                                    if v96 == l_Air_0 then
                                        v47[v79][v84][v89] = v94;
                                    end;
                                end;
                            end;
                        end;
                    elseif l_currentTool_0 == l_ToolId_0.Replace then
                        local v108 = v41[v79][v84][v89];
                        if v94 > 0 and v108 == l_source_0 then
                            v46[v79][v84][v89] = l_target_0;
                            if v108 == l_Air_0 then
                                v47[v79][v84][v89] = v94;
                            end;
                        end;
                    elseif l_currentTool_0 == l_ToolId_0.Smooth then
                        if l_TerrainSmoothToolFix_0 then
                            v78.smoothVoxelsUpgraded = v20.SmoothVoxelsUpgraded;
                            v11.smooth(v78);
                        else
                            v11.smooth(v78);
                        end;
                    end;
                end;
            end;
        end;
        v12(v46, v47, v48);
        if not l_TerrainVoxelChannelNewApi_0 then
            v20:WriteVoxelChannels(v40, v1.VOXEL_RESOLUTION, {
                Material = v46,
                Occupancy = v47,
                WaterOccupancy = v48
            });
            return ;
        else
            v20:WriteVoxelChannels(v40, v1.VOXEL_RESOLUTION, {
                SolidMaterial = v46,
                SolidOccupancy = v47,
                LiquidOccupancy = v48
            });
            return ;
        end;
    else
        v9(v21, v37, v36, v41, v42, v43, v46, v47, v48);
        v12(v46, v47, v48);
        if not l_TerrainVoxelChannelNewApi_0 then
            v20:WriteVoxelChannels(v40, v1.VOXEL_RESOLUTION, {
                Material = v46,
                Occupancy = v47,
                WaterOccupancy = v48
            });
            return ;
        else
            v20:WriteVoxelChannels(v40, v1.VOXEL_RESOLUTION, {
                SolidMaterial = v46,
                SolidOccupancy = v47,
                LiquidOccupancy = v48
            });
            return ;
        end;
    end;
end;


local l_Parent_0 = script.Parent.Parent.Parent;
local v1 = require(l_Parent_0.Src.Util.Constants);
local v2 = require(l_Parent_0.Src.Util.TerrainEnums);
local l_FlattenMode_0 = v2.FlattenMode;
local l_ToolId_0 = v2.ToolId;
local v5 = require(l_Parent_0.Src.Util.applyPivot);
local v6 = require(script.Parent.OperationHelper);
local v7 = require(script.Parent.SculptOperations);
local l_Air_0 = Enum.Material.Air;
return function(v9, v10, v11, v12, v13, v14, v15, v16, v17)
    local l_currentTool_0 = v9.currentTool;
    local l_brushShape_0 = v9.brushShape;
    local l_cursorSize_0 = v9.cursorSize;
    local v21 = v5(v9.pivot, v9.centerPoint, v9.cursorHeight * v1.VOXEL_RESOLUTION);
    local l_autoMaterial_0 = v9.autoMaterial;
    local l_material_0 = v9.material;
    local l_flattenMode_0 = v9.flattenMode;
    local l_ignoreWater_0 = v9.ignoreWater;
    local l_strength_0 = v9.strength;
    local l_x_0 = v21.x;
    local l_y_0 = v21.y;
    local l_z_0 = v21.z;
    local l_x_1 = v10.x;
    local l_y_1 = v10.y;
    local l_z_1 = v10.z;
    local l_x_2 = v11.x;
    local l_l_Air_0_0 = l_Air_0;
    local v35 = 0;
    if l_ignoreWater_0 then
        local v36, v37 = v6.getWaterHeightAndAirFillerMaterial(v12);
        v35 = v36;
        l_l_Air_0_0 = v37;
    end;
    local v38 = (l_x_2 - l_x_1) * 0.5;
    local v39 = #v13;
    local v40 = #v13[1];
    local v41 = #v13[1][1];
    local l_planeNormal_0 = v9.planeNormal;
    local l_planePoint_0 = v9.planePoint;
    local v44 = {
        readMaterials = v12,
        readOccupancies = v13,
        readWaterOccupancies = v14,
        writeMaterials = v15,
        writeOccupancies = v16,
        writeWaterOccupancies = v17,
        sizeX = v39,
        sizeY = v40,
        sizeZ = v41,
        strength = l_strength_0,
        ignoreWater = l_ignoreWater_0,
        desiredMaterial = l_material_0,
        autoMaterial = l_autoMaterial_0,
        filterSize = 1,
        maxOccupancy = 1
    };
    for v45 = 1, v39 do
        local v46 = (l_x_1 + (v45 - 0.5) * v1.VOXEL_RESOLUTION) - l_x_0;
        for v47 = 1, v41 do
            local v48 = (l_z_1 + (v47 - 0.5) * v1.VOXEL_RESOLUTION) - l_z_0;
            if l_currentTool_0 == l_ToolId_0.Flatten then
                local v49, v50 = v6.getDesiredOccupancy(l_planePoint_0, l_planeNormal_0, v45, v47, l_y_1);
                local v51 = true;
                v44.x = v45;
                v44.z = v47;
                if v49 < 1 then
                    v49 = 1;
                    v51 = false;
                end;
                if v40 < v49 then
                    v49 = v40;
                    v51 = false;
                end;
                if not (l_flattenMode_0 ~= l_FlattenMode_0.Erode) or l_flattenMode_0 == l_FlattenMode_0.Both then
                    for v52 = v49 + 1, v40 do
                        local v53 = 0;
                        local l_l_Air_0_1 = l_Air_0;
                        local v55 = 0;
                        local v56 = false;
                        local v57, v58 = v6.calculateBrushPowerForCell(v46, (l_y_1 + (v52 - 0.5) * v1.VOXEL_RESOLUTION) - l_y_0, v48, l_cursorSize_0, l_brushShape_0, v38, true);
                        if v57 ~= 0 then
                            if v52 ~= v40 then
                                v53 = v13[v45][v52 + 1][v47];
                                l_l_Air_0_1 = v12[v45][v52 + 1][v47];
                                v55 = v14[v45][v52 + 1][v47];
                                local v59;
                                if l_ignoreWater_0 then
                                    v59 = true;
                                    if not (l_l_Air_0_1 ~= l_Air_0) then
                                        goto label0;
                                    end;
                                end;
                                v59 = not l_ignoreWater_0;
                                if v59 then
                                    v59 = false;
                                    if v55 == 0 then
                                        v59 = l_l_Air_0_1 == l_Air_0;
                                    end;
                                end;
                                ::label0::;
                                v56 = v59;
                            end;
                            if v56 then
                                v53 = v13[v45][v52][v47];
                                l_l_Air_0_1 = v12[v45][v52][v47];
                                v55 = v14[v45][v52][v47];
                                l_l_Air_0_0 = v52 <= v35 and l_l_Air_0_0 or l_Air_0;
                                v44.y = v52;
                                v44.brushOccupancy = v57;
                                v44.magnitudePercent = v58;
                                v44.cellOccupancy = v53;
                                v44.cellMaterial = l_l_Air_0_1;
                                v44.cellWaterOccupancy = v55;
                                v44.airFillerMaterial = l_l_Air_0_0;
                                v7.erode(v44);
                                break;
                            end;
                        else
                            break;
                        end;
                    end;
                end;
                if not (l_flattenMode_0 ~= l_FlattenMode_0.Grow) or l_flattenMode_0 == l_FlattenMode_0.Both then
                    for v60 = v49 - 1, 1, -1 do
                        local v61 = 0;
                        local l_l_Air_0_2 = l_Air_0;
                        local v63 = 0;
                        local v64 = false;
                        local v65, v66 = v6.calculateBrushPowerForCell(v46, (l_y_1 + (v60 - 0.5) * v1.VOXEL_RESOLUTION) - l_y_0, v48, l_cursorSize_0, l_brushShape_0, v38, true);
                        if v65 ~= 0 then
                            if v60 > 1 then
                                v61 = v13[v45][v60 - 1][v47];
                                l_l_Air_0_2 = v12[v45][v60 - 1][v47];
                                v63 = v14[v45][v60 - 1][v47];
                                local v67 = false;
                                if v61 == 1 then
                                    local v68 = false;
                                    if l_l_Air_0_2 == l_Air_0 then
                                        v68 = v63 > 0;
                                    end;
                                    v67 = not v68;
                                end;
                                v67 = v67;
                                if not v67 then
                                    v67 = not l_ignoreWater_0;
                                    if v67 then
                                        v67 = false;
                                        if l_l_Air_0_2 == l_Air_0 then
                                            v67 = v63 > 0;
                                        end;
                                    end;
                                end;
                                v64 = v67;
                            end;
                            if v64 then
                                v61 = v13[v45][v60][v47];
                                l_l_Air_0_2 = v12[v45][v60][v47];
                                v63 = v14[v45][v60][v47];
                                l_l_Air_0_0 = v60 <= v35 and l_l_Air_0_0 or l_Air_0;
                                v44.y = v60;
                                v44.brushOccupancy = v65;
                                v44.magnitudePercent = v66;
                                v44.cellOccupancy = v61;
                                v44.cellMaterial = l_l_Air_0_2;
                                v44.cellWaterOccupancy = v63;
                                v44.airFillerMaterial = l_l_Air_0_0;
                                v7.grow(v44);
                                break;
                            end;
                        else
                            break;
                        end;
                    end;
                end;
                local l_v49_0 = v49;
                if v51 then
                    local v70 = v13[v45][v49][v47];
                    local v71 = v12[v45][v49][v47];
                    local v72 = v14[v45][v49][v47];
                    local v73, v74 = v6.calculateBrushPowerForCell(v46, (l_y_1 + (v49 - 0.5) * v1.VOXEL_RESOLUTION) - l_y_0, v48, l_cursorSize_0, l_brushShape_0, v38, true);
                    v44.y = l_v49_0;
                    v44.brushOccupancy = v73;
                    v44.magnitudePercent = v74;
                    v44.cellOccupancy = v70;
                    v44.cellMaterial = v71;
                    v44.airFillerMaterial = l_l_Air_0_0;
                    local v75 = true;
                    if l_flattenMode_0 ~= l_FlattenMode_0.Grow then
                        v75 = v70 < 1;
                    end;
                    if not (not (l_v49_0 + 1 <= v40) or v75) then
                        local v76 = v13[v45][l_v49_0 + 1][v47];
                        local v77 = v12[v45][l_v49_0 + 1][v47];
                        local v78 = v14[v45][l_v49_0 + 1][v47];
                        local v79 = false;
                        if v77 == l_Air_0 then
                            v79 = v78 > 0;
                        end;
                        local v80 = true;
                        if v76 ~= 0 then
                            v80 = l_ignoreWater_0 and v79;
                        end;
                        v75 = v80;
                    end;
                    local v81 = true;
                    if l_flattenMode_0 ~= l_FlattenMode_0.Erode then
                        v81 = v70 > 0;
                    end;
                    if not (not (l_v49_0 - 1 >= 1) or v81) then
                        local v82 = v13[v45][l_v49_0 - 1][v47];
                        local v83 = v12[v45][l_v49_0 - 1][v47];
                        local v84 = v14[v45][l_v49_0 - 1][v47];
                        local v85 = false;
                        if v83 == l_Air_0 then
                            v85 = v84 > 0;
                        end;
                        v81 = v82 == 1 and not v85 or not l_ignoreWater_0 and v85;
                    end;
                    if not (not v81 or not v75) then
                        if (not (l_flattenMode_0 ~= l_FlattenMode_0.Erode) or l_flattenMode_0 == l_FlattenMode_0.Both) and v50 < v70 then
                            v16[v45][l_v49_0][v47] = math.max(v70 - ((l_strength_0 * 0.25) * v73) * v74, v50);
                            if not l_ignoreWater_0 and v50 < v72 then
                                v17[v45][l_v49_0][v47] = math.max(v72 - ((l_strength_0 * 0.25) * v73) * v74, v50);
                            end;
                        end;
                        if (not (l_flattenMode_0 ~= l_FlattenMode_0.Grow) or l_flattenMode_0 == l_FlattenMode_0.Both) and v70 < v50 then
                            v16[v45][l_v49_0][v47] = math.min(v70 + ((l_strength_0 * 0.25) * v73) * v74, v50);
                            if (not l_ignoreWater_0 and v72 ~= 0) and v72 < v50 then
                                v17[v45][l_v49_0][v47] = math.min(v72 + ((l_strength_0 * 0.25) * v73) * v74, v50);
                            end;
                        end;
                    end;
                end;
            end;
        end;
    end;
end;


local l_Parent_0 = script.Parent.Parent.Parent;
local v1 = require(l_Parent_0.Src.Util.Constants);
local v2 = require(l_Parent_0.Src.Util.TerrainEnums);
local l_BrushMode_0 = v2.BrushMode;
local l_FlattenMode_0 = v2.FlattenMode;
local l_ToolId_0 = v2.ToolId;
local v6 = require(l_Parent_0.Src.Util.applyPivot);
local v7 = require(script.Parent.OperationHelper);
local v8 = require(script.Parent.SculptOperations);
local l_Air_0 = Enum.Material.Air;
local l_Water_0 = Enum.Material.Water;
local l_TerrainEditorOverhaul_0 = game:GetFastFlag("TerrainEditorOverhaul");
return function(v12, v13, v14, v15, v16, v17, v18, v19, v20)
    local l_currentTool_0 = v12.currentTool;
    local l_brushMode_0 = v12.brushMode;
    local l_brushShape_0 = v12.brushShape;
    local l_cursorSize_0 = v12.cursorSize;
    local v25 = v6(v12.pivot, v12.centerPoint, v12.cursorHeight * v1.VOXEL_RESOLUTION);
    local l_autoMaterial_0 = v12.autoMaterial;
    local l_material_0 = v12.material;
    local l_flattenMode_0 = v12.flattenMode;
    local l_ignoreWater_0 = v12.ignoreWater;
    local l_strength_0 = v12.strength;
    local l_x_0 = v25.x;
    local l_y_0 = v25.y;
    local l_z_0 = v25.z;
    local l_x_1 = v13.x;
    local l_y_1 = v13.y;
    local l_z_1 = v13.z;
    local l_x_2 = v14.x;
    local l_l_Air_0_0 = l_Air_0;
    local v39 = 0;
    if l_ignoreWater_0 then
        local v40, v41 = v7.getWaterHeightAndAirFillerMaterial(v15);
        v39 = v40;
        l_l_Air_0_0 = v41;
    end;
    local v42 = (l_x_2 - l_x_1) * 0.5;
    local v43 = #v16;
    local v44 = #v16[1];
    local v45 = #v16[1][1];
    local v46 = {};
    local v47 = {};
    local v48 = math.floor((v25.x - l_x_1) / v1.VOXEL_RESOLUTION + 0.5);
    local v49 = math.floor((v25.y - l_y_1) / v1.VOXEL_RESOLUTION + 0.5);
    local v50 = math.floor((v25.z - l_z_1) / v1.VOXEL_RESOLUTION + 0.5);
    for v51 = -1, 1 do
        for v52 = -1, 1 do
            for v53 = -1, 1 do
                local v54 = v48 + v51;
                local v55 = v49 + v52;
                local v56 = v50 + v53;
                if ((((v54 > 0 and v54 <= v43) and v55 > 0) and v55 <= v44) and v56 > 0) and v56 <= v45 then
                    v46[v54 + v43 * (v55 + v43 * v56)] = true;
                    table.insert(v47, {
                        v54,
                        v55,
                        v56
                    });
                end;
            end;
        end;
    end;
    local v57;
    if not l_TerrainEditorOverhaul_0 then
        v57 = true;
        if not (l_currentTool_0 ~= l_ToolId_0.Erode) then
            goto label0;
        end;
    end;
    if l_TerrainEditorOverhaul_0 and l_currentTool_0 == l_ToolId_0.Sculpt then
        v57 = true;
        if not (l_brushMode_0 ~= l_BrushMode_0.Subtract) then
            goto label0;
        end;
    end;
    v57 = l_currentTool_0 == l_ToolId_0.Flatten;
    ::label0::;
    local v58;
    if not l_TerrainEditorOverhaul_0 then
        v58 = true;
        if not (l_currentTool_0 ~= l_ToolId_0.Grow) then
            goto label1;
        end;
    end;
    if l_currentTool_0 == l_ToolId_0.Sculpt then
        v58 = true;
        if not (l_brushMode_0 ~= l_BrushMode_0.Add) then
            goto label1;
        end;
    end;
    v58 = l_currentTool_0 == l_ToolId_0.Flatten;
    ::label1::;
    local v59 = l_currentTool_0 == l_ToolId_0.Smooth;
    local l_planeNormal_0 = v12.planeNormal;
    local l_x_3 = l_planeNormal_0.x;
    local l_y_2 = l_planeNormal_0.y;
    local l_z_2 = l_planeNormal_0.z;
    local l_planePoint_0 = v12.planePoint;
    local l_x_4 = l_planePoint_0.x;
    local l_y_3 = l_planePoint_0.y;
    local l_z_3 = l_planePoint_0.z;
    local v68 = {
        readMaterials = v15,
        readOccupancies = v16,
        readWaterOccupancies = v17,
        writeMaterials = v18,
        writeOccupancies = v19,
        writeWaterOccupancies = v20,
        sizeX = v43,
        sizeY = v44,
        sizeZ = v45,
        strength = l_strength_0,
        ignoreWater = l_ignoreWater_0,
        desiredMaterial = l_material_0,
        autoMaterial = l_autoMaterial_0,
        filterSize = 1,
        maxOccupancy = 1
    };
    while #v47 > 0 do
        local v69 = table.remove(v47);
        local v70 = v69[1];
        local v71 = v69[2];
        local v72 = v69[3];
        local v73 = v16[v70][v71][v72];
        local v74 = v15[v70][v71][v72];
        local v75 = v17[v70][v71][v72];
        local l_l_ignoreWater_0_0 = l_ignoreWater_0;
        if l_l_ignoreWater_0_0 then
            l_l_ignoreWater_0_0 = true;
            if v74 ~= l_Water_0 then
                l_l_ignoreWater_0_0 = false;
                if v15[v70][v71][v72] == l_Air_0 then
                    l_l_ignoreWater_0_0 = v17[v70][v71][v72] ~= 0;
                end;
            end;
        end;
        local v77 = l_x_1 + (v70 - 0.5) * v1.VOXEL_RESOLUTION;
        local v78 = v77 - l_x_0;
        local v79 = (v77 - l_x_4) * l_x_3;
        local v80 = l_y_1 + (v71 - 0.5) * v1.VOXEL_RESOLUTION;
        local v81 = v80 - l_y_0;
        local v82 = v79 + (v80 - l_y_3) * l_y_2;
        local v83 = l_z_1 + (v72 - 0.5) * v1.VOXEL_RESOLUTION;
        local v84 = v83 - l_z_0;
        local v85 = v82 + (v83 - l_z_3) * l_z_2;
        local v86;
        if not l_TerrainEditorOverhaul_0 then
            v86 = true;
            if not (l_currentTool_0 ~= l_ToolId_0.Erode) then
                goto label2;
            end;
        end;
        v86 = l_TerrainEditorOverhaul_0;
        if v86 then
            v86 = false;
            if l_currentTool_0 == l_ToolId_0.Sculpt then
                v86 = l_brushMode_0 == l_BrushMode_0.Subtract;
            end;
        end;
        ::label2::;
        local v87;
        if not l_TerrainEditorOverhaul_0 then
            v87 = true;
            if not (l_currentTool_0 ~= l_ToolId_0.Grow) then
                goto label3;
            end;
        end;
        v87 = l_TerrainEditorOverhaul_0;
        if v87 then
            v87 = false;
            if l_currentTool_0 == l_ToolId_0.Sculpt then
                v87 = l_brushMode_0 == l_BrushMode_0.Add;
            end;
        end;
        ::label3::;
        local v88 = l_currentTool_0 == l_ToolId_0.Smooth;
        if l_currentTool_0 == l_ToolId_0.Flatten then
            v68.maxOccupancy = math.abs(v85);
            if v1.FLATTEN_PLANE_TOLERANCE < v85 and l_flattenMode_0 ~= l_FlattenMode_0.Grow then
                v86 = true;
            elseif v85 < -v1.FLATTEN_PLANE_TOLERANCE and l_flattenMode_0 ~= l_FlattenMode_0.Erode then
                v87 = true;
            end;
        end;
        l_l_Air_0_0 = v71 <= v39 and l_l_Air_0_0 or l_Air_0;
        v68.airFillerMaterial = l_l_Air_0_0;
        if not (not (v86 and v73 > 0) or l_l_ignoreWater_0_0) then
            local l_v73_0 = v73;
            local v90, v91 = v7.calculateBrushPowerForCell(v78, v81, v84, l_cursorSize_0, l_brushShape_0, v42, true);
            if l_ignoreWater_0 and v74 == l_Water_0 then
                l_v73_0 = 0;
            end;
            v68.x = v70;
            v68.y = v71;
            v68.z = v72;
            v68.brushOccupancy = v90;
            v68.magnitudePercent = v91;
            v68.cellOccupancy = l_v73_0;
            v68.cellMaterial = v74;
            v68.cellWaterOccupancy = v75;
            v8.erode(v68);
        end;
        if not (not v87 or v73 >= 1 and not l_l_ignoreWater_0_0) then
            local l_v73_1 = v73;
            local l_v74_0 = v74;
            local v94, v95 = v7.calculateBrushPowerForCell(v78, v81, v84, l_cursorSize_0, l_brushShape_0, v42, true);
            if l_ignoreWater_0 and l_v74_0 == l_Water_0 then
                l_v74_0 = l_Air_0;
                l_v73_1 = 0;
            end;
            v68.x = v70;
            v68.y = v71;
            v68.z = v72;
            v68.brushOccupancy = v94;
            v68.magnitudePercent = v95;
            v68.cellOccupancy = l_v73_1;
            v68.cellMaterial = l_v74_0;
            v68.cellWaterOccupancy = v75;
            v68.desiredMaterial = l_material_0;
            v8.grow(v68);
        end;
        if v88 then
            local l_v73_2 = v73;
            local v97, v98 = v7.calculateBrushPowerForCell(v78, v81, v84, l_cursorSize_0, l_brushShape_0, v42, false);
            if v97 >= 0.5 then
                if l_ignoreWater_0 and v74 == l_Water_0 then
                    l_v73_2 = 0;
                end;
                v68.x = v70;
                v68.y = v71;
                v68.z = v72;
                v68.brushOccupancy = v97;
                v68.magnitudePercent = v98;
                v68.cellOccupancy = l_v73_2;
                v68.cellMaterial = v74;
                v8.smooth(v68);
            end;
        end;
        v86 = true;
        v87 = true;
        v88 = false;
        for v99 = -1, 1 do
            for v100 = -1, 1 do
                for v101 = -1, 1 do
                    local v102 = v70 + v99;
                    local v103 = v71 + v100;
                    local v104 = v72 + v101;
                    if (((((v102 > 0 and v102 <= v43) and v103 > 0) and v103 <= v44) and v104 > 0) and v104 <= v45) and (not (v99 == 0 and v100 == 0) or v101 ~= 0) then
                        local v105 = if not (v15[v102][v103][v104] == l_Air_0) or l_ignoreWater_0 then v16[v102][v103][v104] else v17[v102][v103][v104];
                        if l_ignoreWater_0 and (not (v15[v102][v103][v104] ~= l_Water_0) or v15[v102][v103][v104] == l_Air_0) then
                            v105 = 0;
                        end;
                        if v105 > 0 then
                            v86 = false;
                        end;
                        if v105 < 1 then
                            v87 = false;
                        end;
                        if not (v86 or v87) then
                            v88 = true;
                            break;
                        end;
                    end;
                end;
                if v88 then
                    break;
                end;
            end;
            if v88 then
                break;
            end;
        end;
        v88 = true;
        if not l_TerrainEditorOverhaul_0 then
            if not (l_currentTool_0 ~= l_ToolId_0.Erode) or l_currentTool_0 == l_ToolId_0.Flatten and v1.FLATTEN_PLANE_TOLERANCE < v85 then
                local l_v86_0 = v86;
                if not l_v86_0 then
                    l_v86_0 = false;
                    if v73 == 1 then
                        l_v86_0 = not l_l_ignoreWater_0_0 and v87;
                    end;
                end;
                v88 = l_v86_0;
            elseif not (l_currentTool_0 ~= l_ToolId_0.Grow) or l_currentTool_0 == l_ToolId_0.Flatten and v85 < -v1.FLATTEN_PLANE_TOLERANCE then
                v88 = v87 or (not (v73 ~= 0) or l_l_ignoreWater_0_0) and v86;
            elseif (l_currentTool_0 == l_ToolId_0.Flatten and -v1.FLATTEN_PLANE_TOLERANCE < v85) and v85 < v1.FLATTEN_PLANE_TOLERANCE then
                v88 = false;
            elseif l_currentTool_0 == l_ToolId_0.Smooth then
                v88 = (v73 == 0 and v86) and true or v73 == 1 and (v87 and true or false);
            end;
        else
            local v107 = if not (v74 == l_Air_0) or l_ignoreWater_0 then v73 else v75;
            if l_currentTool_0 == l_ToolId_0.Sculpt then
                if not (l_brushMode_0 ~= l_BrushMode_0.Subtract) or l_currentTool_0 == l_ToolId_0.Flatten and v1.FLATTEN_PLANE_TOLERANCE < v85 then
                    local l_v86_1 = v86;
                    if not l_v86_1 then
                        l_v86_1 = false;
                        if v107 == 1 then
                            l_v86_1 = not l_l_ignoreWater_0_0 and v87;
                        end;
                    end;
                    v88 = l_v86_1;
                elseif not (l_brushMode_0 ~= l_BrushMode_0.Add) or l_currentTool_0 == l_ToolId_0.Flatten and v85 < -v1.FLATTEN_PLANE_TOLERANCE then
                    v88 = v87 or (not (v107 ~= 0) or l_l_ignoreWater_0_0) and v86;
                end;
            elseif (l_currentTool_0 == l_ToolId_0.Flatten and -v1.FLATTEN_PLANE_TOLERANCE < v85) and v85 < v1.FLATTEN_PLANE_TOLERANCE then
                v88 = false;
            elseif l_currentTool_0 == l_ToolId_0.Smooth then
                v88 = (v107 == 0 and v86) and true or v107 == 1 and (v87 and true or false);
            end;
        end;
        if not v88 then
            for v109 = -1, 1 do
                for v110 = -1, 1 do
                    for v111 = -1, 1 do
                        local v112 = v70 + v109;
                        local v113 = v71 + v110;
                        local v114 = v72 + v111;
                        if (((((v112 > 0 and v112 <= v43) and v113 > 0) and v113 <= v44) and v114 > 0) and v114 <= v45) and (not (v109 == 0 and v110 == 0) or v111 ~= 0) then
                            local v115 = if not (v15[v112][v113][v114] == l_Air_0) or l_ignoreWater_0 then v16[v112][v113][v114] else v17[v112][v113][v114];
                            local v116 = if not (v74 == l_Air_0) or l_ignoreWater_0 then v73 else v75;
                            if l_ignoreWater_0 and (not (v15[v112][v113][v114] ~= l_Water_0) or v15[v112][v113][v114] == l_Air_0 and v17[v112][v113][v114] ~= 0) then
                                v115 = 0;
                            end;
                            local v117 = false;
                            local v118 = false;
                            if v57 then
                                v117 = v115 > 0;
                                if not (not (v116 == 1) or l_l_ignoreWater_0_0) and v115 == 1 then
                                    v117 = false;
                                end;
                            end;
                            if v58 then
                                v118 = v115 < 1;
                                if not (v116 ~= 0 and not l_l_ignoreWater_0_0) and v115 == 0 then
                                    v118 = false;
                                end;
                            end;
                            if not (not (v117 or v118) and not v59 or v46[v112 + v43 * (v113 + v43 * v114)]) then
                                v46[v112 + v43 * (v113 + v43 * v114)] = true;
                                table.insert(v47, {
                                    v112,
                                    v113,
                                    v114
                                });
                            end;
                        end;
                    end;
                end;
            end;
        end;
    end;
end;


local l_CoreGui_0 = game:GetService("CoreGui");
local l_RunService_0 = game:GetService("RunService");
local l_Workspace_0 = game:GetService("Workspace");
local v3 = {};
v3.__index = v3;
v3.new = function(v4, v5, v6, v7)
    local v8 = setmetatable({
        _axis = v6,
        _mouse = v4,
        _position = v5,
        _clampingFunc = v7
    }, v3);
    assert(v4 ~= nil, "Mouse missing in for AxisLockedDragger");
    local l_Part_0 = Instance.new("Part");
    l_Part_0.Name = "AdornPart";
    l_Part_0.Transparency = 1;
    l_Part_0.TopSurface = "Smooth";
    l_Part_0.BottomSurface = "Smooth";
    l_Part_0.Anchored = true;
    l_Part_0.CanCollide = true;
    l_Part_0.CastShadow = false;
    l_Part_0.Parent = l_CoreGui_0;
    local l_SphereHandleAdornment_0 = Instance.new("SphereHandleAdornment");
    l_SphereHandleAdornment_0.Color = BrickColor.new("Toothpaste");
    l_SphereHandleAdornment_0.Radius = 10;
    l_SphereHandleAdornment_0.AlwaysOnTop = true;
    l_SphereHandleAdornment_0.Visible = false;
    l_SphereHandleAdornment_0.ZIndex = 1;
    v8._updateDrag = function()
        local v11 = v8:calcAxisPosMouseClick();
        if v11 then
            v8:setPosition(v11);
        end;
    end;
    v8._endDrag = function()
        if v8._updateDragConnection then
            v8._updateDragConnection:Disconnect();
            v8._updateDragConnection = nil;
        end;
        if v8._mouseButton1UpConnection then
            v8._mouseButton1UpConnection:Disconnect();
            v8._mouseButton1UpConnection = nil;
        end;
    end;
    v8._startDrag = function()
        if not v8._updateDragConnection then
            v8:updateCollisionPlaneNormal();
            v8._prevPosition = v8._position;
            v8._mouseButton1UpConnection = v8._mouse.Button1Up:Connect(v8._endDrag);
            v8._updateDragConnection = l_RunService_0.RenderStepped:Connect(v8._updateDrag);
            return ;
        else
            return ;
        end;
    end;
    v8._mouseButton1UpConnection = nil;
    v8._mouseButton1DownConnection = l_SphereHandleAdornment_0.MouseButton1Down:Connect(v8._startDrag);
    v8._updateDragConnection = nil;
    l_SphereHandleAdornment_0.Adornee = l_Part_0;
    l_SphereHandleAdornment_0.Parent = l_Part_0;
    v8._part = l_Part_0;
    v8._adorn = l_SphereHandleAdornment_0;
    return v8;
end;
v3.destroy = function(v12)
    v12._clampingFunc = nil;
    if v12._updateDragConnection then
        v12._updateDragConnection:Disconnect();
        v12._updateDragConnection = nil;
    end;
    if v12._mouseButton1DownConnection then
        v12._mouseButton1DownConnection:Disconnect();
        v12._mouseButton1DownConnection = nil;
    end;
    if v12._mouseButton1UpConnection then
        v12._mouseButton1UpConnection:Disconnect();
        v12._mouseButton1UpConnection = nil;
    end;
    if v12._adorn then
        v12._adorn:Destroy();
        v12._adorn = nil;
    end;
    if v12._part then
        v12._part:Destroy();
        v12._part = nil;
    end;
end;
v3.updateVisibility = function(v13, v14)
    v13._adorn.Visible = v14;
    if not v14 then
        v13._endDrag();
    end;
end;
v3.getPosition = function(v15)
    return v15._position;
end;
v3.setPosition = function(v16, v17)
    if v16._position ~= v17 then
        v16._position = v17;
        v16._part.Position = v17;
        v16._adorn.Radius = math.sqrt(((l_Workspace_0.CurrentCamera.CoordinateFrame.p + v16._position) / 2).Magnitude);
    end;
end;
v3.updateCollisionPlaneNormal = function(v18)
    local l__position_0 = v18._position;
    local l_p_0 = l_Workspace_0.CurrentCamera.CoordinateFrame.p;
    local l__axis_0 = v18._axis;
    local v22 = l_p_0 - l__position_0;
    if l__axis_0:Dot(v22) == 0 then
        v18._planeNormal = nil;
        return ;
    else
        v18._planeNormal = l__axis_0:Cross(v22):Cross(l__axis_0).Unit;
        return ;
    end;
end;
v3.calcPlaneHit = function(v23)
    local l_p_1 = l_Workspace_0.CurrentCamera.CoordinateFrame.p;
    local l_Direction_0 = v23._mouse.UnitRay.Direction;
    local v26 = l_Direction_0:Dot(v23._planeNormal);
    if v26 < 0 then
        return l_p_1 + ((v23._position - l_p_1):Dot(v23._planeNormal) / v26) * l_Direction_0;
    else
        return nil;
    end;
end;
v3.calcAxisPosMouseClick = function(v27)
    if v27._planeNormal then
        local v28 = v27:calcPlaneHit();
        if not v28 then
            return v27._position;
        else
            local v29 = v28 - v27._prevPosition;
            local l__axis_1 = v27._axis;
            local v31 = (v29:Dot(l__axis_1) / l__axis_1:Dot(l__axis_1)) * l__axis_1 + v27._prevPosition;
            if v27._clampingFunc then
                v31 = v27._clampingFunc(v31);
            end;
            return v31;
        end;
    else
        return ;
    end;
end;
return v3;


local l_Selection_0 = game:GetService("Selection");
local l_Signal_0 = require(script.Parent.Parent.Parent.Packages.Framework).Util.Signal;
local v2 = require(script.Parent.AxisLockedDragger);
local l_EnumItems_0 = Enum.NormalId:GetEnumItems();
local v4 = {};
v4.__index = v4;
v4.new = function(v5, v6)
    local v7 = setmetatable({
        _mouse = v5,
        _target = v6,
        _position = Vector3.new(),
        _size = Vector3.new(4, 4, 4),
        _onSizeChanged = l_Signal_0.new()
    }, v4);
    assert(v7._mouse, "Mouse missing in LargeVoxelRegionPreview");
    local function _(v8, v9)
        return function(v10)
            if not (not v7._adorns or not v7._adorns[v8]) and v7._adorns[v9] then
                local v11 = v7._adorns[v8]:getPosition();
                local v12 = v7._adorns[v9]:getPosition();
                local v13 = v11 - v12;
                local v14 = v13.Unit:Dot(v10 - v12);
                if v14 < 4 then
                    return v12 + v13.Unit * 4;
                elseif v14 > 16000 then
                    return v12 + v13.Unit * 16000;
                else
                    v7._position = (v10 + v12) / 2;
                    local v15 = v10 - v12;
                    local l_Magnitude_0 = v15.Magnitude;
                    v7._size = Vector3.new(v15.x ~= 0 and l_Magnitude_0 or v7._size.x, v15.y ~= 0 and l_Magnitude_0 or v7._size.y, v15.z ~= 0 and l_Magnitude_0 or v7._size.z);
                    v7._onSizeChanged:Fire(v7._size, v7._position);
                    v7:updateBlockMesh();
                    v7:updateAdorns();
                    return v10;
                end;
            else
                return v10;
            end;
        end;
    end;
    v7._adorns = {};
    local l__adorns_0 = v7._adorns;
    local l_Right_0 = Enum.NormalId.Right;
    local l_new_0 = v2.new;
    local l_v5_0 = v5;
    local v22 = Vector3.new(0, 0, 0);
    local v23 = Vector3.new(1, 0, 0);
    local l_Right_1 = Enum.NormalId.Right;
    local l_Left_0 = Enum.NormalId.Left;
    local l_l_Right_1_0 = l_Right_1 --[[ copy: 11 -> 13 ]];
    local l_l_Left_0_0 = l_Left_0 --[[ copy: 12 -> 14 ]];
    l__adorns_0[l_Right_0] = l_new_0(l_v5_0, v22, v23, function(v28)
        if not (not v7._adorns or not v7._adorns[l_l_Right_1_0]) and v7._adorns[l_l_Left_0_0] then
            local v29 = v7._adorns[l_l_Right_1_0]:getPosition();
            local v30 = v7._adorns[l_l_Left_0_0]:getPosition();
            local v31 = v29 - v30;
            local v32 = v31.Unit:Dot(v28 - v30);
            if v32 < 4 then
                return v30 + v31.Unit * 4;
            elseif v32 > 16000 then
                return v30 + v31.Unit * 16000;
            else
                v7._position = (v28 + v30) / 2;
                local v33 = v28 - v30;
                local l_Magnitude_1 = v33.Magnitude;
                v7._size = Vector3.new(v33.x ~= 0 and l_Magnitude_1 or v7._size.x, v33.y ~= 0 and l_Magnitude_1 or v7._size.y, v33.z ~= 0 and l_Magnitude_1 or v7._size.z);
                v7._onSizeChanged:Fire(v7._size, v7._position);
                v7:updateBlockMesh();
                v7:updateAdorns();
                return v28;
            end;
        else
            return v28;
        end;
    end);
    l__adorns_0 = v7._adorns;
    l_Right_0 = Enum.NormalId.Left;
    l_new_0 = v2.new;
    l_v5_0 = v5;
    v22 = Vector3.new(0, 0, 0);
    v23 = Vector3.new(-1, 0, 0);
    l_Right_1 = Enum.NormalId.Left;
    l_Left_0 = Enum.NormalId.Right;
    local l_l_Right_1_1 = l_Right_1 --[[ copy: 11 -> 15 ]];
    local l_l_Left_0_1 = l_Left_0 --[[ copy: 12 -> 16 ]];
    l__adorns_0[l_Right_0] = l_new_0(l_v5_0, v22, v23, function(v37)
        if not (not v7._adorns or not v7._adorns[l_l_Right_1_1]) and v7._adorns[l_l_Left_0_1] then
            local v38 = v7._adorns[l_l_Right_1_1]:getPosition();
            local v39 = v7._adorns[l_l_Left_0_1]:getPosition();
            local v40 = v38 - v39;
            local v41 = v40.Unit:Dot(v37 - v39);
            if v41 < 4 then
                return v39 + v40.Unit * 4;
            elseif v41 > 16000 then
                return v39 + v40.Unit * 16000;
            else
                v7._position = (v37 + v39) / 2;
                local v42 = v37 - v39;
                local l_Magnitude_2 = v42.Magnitude;
                v7._size = Vector3.new(v42.x ~= 0 and l_Magnitude_2 or v7._size.x, v42.y ~= 0 and l_Magnitude_2 or v7._size.y, v42.z ~= 0 and l_Magnitude_2 or v7._size.z);
                v7._onSizeChanged:Fire(v7._size, v7._position);
                v7:updateBlockMesh();
                v7:updateAdorns();
                return v37;
            end;
        else
            return v37;
        end;
    end);
    l__adorns_0 = v7._adorns;
    l_Right_0 = Enum.NormalId.Top;
    l_new_0 = v2.new;
    l_v5_0 = v5;
    v22 = Vector3.new(0, 0, 0);
    v23 = Vector3.new(0, 1, 0);
    l_Right_1 = Enum.NormalId.Top;
    l_Left_0 = Enum.NormalId.Bottom;
    local l_l_Right_1_2 = l_Right_1 --[[ copy: 11 -> 17 ]];
    local l_l_Left_0_2 = l_Left_0 --[[ copy: 12 -> 18 ]];
    l__adorns_0[l_Right_0] = l_new_0(l_v5_0, v22, v23, function(v46)
        if not (not v7._adorns or not v7._adorns[l_l_Right_1_2]) and v7._adorns[l_l_Left_0_2] then
            local v47 = v7._adorns[l_l_Right_1_2]:getPosition();
            local v48 = v7._adorns[l_l_Left_0_2]:getPosition();
            local v49 = v47 - v48;
            local v50 = v49.Unit:Dot(v46 - v48);
            if v50 < 4 then
                return v48 + v49.Unit * 4;
            elseif v50 > 16000 then
                return v48 + v49.Unit * 16000;
            else
                v7._position = (v46 + v48) / 2;
                local v51 = v46 - v48;
                local l_Magnitude_3 = v51.Magnitude;
                v7._size = Vector3.new(v51.x ~= 0 and l_Magnitude_3 or v7._size.x, v51.y ~= 0 and l_Magnitude_3 or v7._size.y, v51.z ~= 0 and l_Magnitude_3 or v7._size.z);
                v7._onSizeChanged:Fire(v7._size, v7._position);
                v7:updateBlockMesh();
                v7:updateAdorns();
                return v46;
            end;
        else
            return v46;
        end;
    end);
    l__adorns_0 = v7._adorns;
    l_Right_0 = Enum.NormalId.Bottom;
    l_new_0 = v2.new;
    l_v5_0 = v5;
    v22 = Vector3.new(0, 0, 0);
    v23 = Vector3.new(0, -1, 0);
    l_Right_1 = Enum.NormalId.Bottom;
    l_Left_0 = Enum.NormalId.Top;
    local l_l_Right_1_3 = l_Right_1 --[[ copy: 11 -> 19 ]];
    local l_l_Left_0_3 = l_Left_0 --[[ copy: 12 -> 20 ]];
    l__adorns_0[l_Right_0] = l_new_0(l_v5_0, v22, v23, function(v55)
        if not (not v7._adorns or not v7._adorns[l_l_Right_1_3]) and v7._adorns[l_l_Left_0_3] then
            local v56 = v7._adorns[l_l_Right_1_3]:getPosition();
            local v57 = v7._adorns[l_l_Left_0_3]:getPosition();
            local v58 = v56 - v57;
            local v59 = v58.Unit:Dot(v55 - v57);
            if v59 < 4 then
                return v57 + v58.Unit * 4;
            elseif v59 > 16000 then
                return v57 + v58.Unit * 16000;
            else
                v7._position = (v55 + v57) / 2;
                local v60 = v55 - v57;
                local l_Magnitude_4 = v60.Magnitude;
                v7._size = Vector3.new(v60.x ~= 0 and l_Magnitude_4 or v7._size.x, v60.y ~= 0 and l_Magnitude_4 or v7._size.y, v60.z ~= 0 and l_Magnitude_4 or v7._size.z);
                v7._onSizeChanged:Fire(v7._size, v7._position);
                v7:updateBlockMesh();
                v7:updateAdorns();
                return v55;
            end;
        else
            return v55;
        end;
    end);
    l__adorns_0 = v7._adorns;
    l_Right_0 = Enum.NormalId.Front;
    l_new_0 = v2.new;
    l_v5_0 = v5;
    v22 = Vector3.new(0, 0, 0);
    v23 = Vector3.new(0, 0, 1);
    l_Right_1 = Enum.NormalId.Front;
    l_Left_0 = Enum.NormalId.Back;
    local l_l_Right_1_4 = l_Right_1 --[[ copy: 11 -> 21 ]];
    local l_l_Left_0_4 = l_Left_0 --[[ copy: 12 -> 22 ]];
    l__adorns_0[l_Right_0] = l_new_0(l_v5_0, v22, v23, function(v64)
        if not (not v7._adorns or not v7._adorns[l_l_Right_1_4]) and v7._adorns[l_l_Left_0_4] then
            local v65 = v7._adorns[l_l_Right_1_4]:getPosition();
            local v66 = v7._adorns[l_l_Left_0_4]:getPosition();
            local v67 = v65 - v66;
            local v68 = v67.Unit:Dot(v64 - v66);
            if v68 < 4 then
                return v66 + v67.Unit * 4;
            elseif v68 > 16000 then
                return v66 + v67.Unit * 16000;
            else
                v7._position = (v64 + v66) / 2;
                local v69 = v64 - v66;
                local l_Magnitude_5 = v69.Magnitude;
                v7._size = Vector3.new(v69.x ~= 0 and l_Magnitude_5 or v7._size.x, v69.y ~= 0 and l_Magnitude_5 or v7._size.y, v69.z ~= 0 and l_Magnitude_5 or v7._size.z);
                v7._onSizeChanged:Fire(v7._size, v7._position);
                v7:updateBlockMesh();
                v7:updateAdorns();
                return v64;
            end;
        else
            return v64;
        end;
    end);
    l__adorns_0 = v7._adorns;
    l_Right_0 = Enum.NormalId.Back;
    l_new_0 = v2.new;
    l_v5_0 = v5;
    v22 = Vector3.new(0, 0, 0);
    v23 = Vector3.new(0, 0, -1);
    l_Right_1 = Enum.NormalId.Back;
    l_Left_0 = Enum.NormalId.Front;
    l__adorns_0[l_Right_0] = l_new_0(l_v5_0, v22, v23, function(v71)
        if not (not v7._adorns or not v7._adorns[l_Right_1]) and v7._adorns[l_Left_0] then
            local v72 = v7._adorns[l_Right_1]:getPosition();
            local v73 = v7._adorns[l_Left_0]:getPosition();
            local v74 = v72 - v73;
            local v75 = v74.Unit:Dot(v71 - v73);
            if v75 < 4 then
                return v73 + v74.Unit * 4;
            elseif v75 > 16000 then
                return v73 + v74.Unit * 16000;
            else
                v7._position = (v71 + v73) / 2;
                local v76 = v71 - v73;
                local l_Magnitude_6 = v76.Magnitude;
                v7._size = Vector3.new(v76.x ~= 0 and l_Magnitude_6 or v7._size.x, v76.y ~= 0 and l_Magnitude_6 or v7._size.y, v76.z ~= 0 and l_Magnitude_6 or v7._size.z);
                v7._onSizeChanged:Fire(v7._size, v7._position);
                v7:updateBlockMesh();
                v7:updateAdorns();
                return v71;
            end;
        else
            return v71;
        end;
    end);
    v7._borders = {};
    return v7;
end;
v4.getOnSizeChanged = function(v78)
    return v78._onSizeChanged;
end;
v4.destroy = function(v79)
    if v79._rootModel then
        v79._rootModel:Destroy();
        v79._rootModel = nil;
    end;
    if v79._centerPart then
        v79._centerPart:Destroy();
        v79._centerPart = nil;
    end;
    if v79._blockMesh then
        v79._blockMesh:Destroy();
        v79._blockMesh = nil;
    end;
    for _, v81 in pairs(v79._adorns) do
        v81:destroy();
    end;
    v79._adorns = nil;
    for _, v83 in pairs(v79._borders) do
        v83:Destroy();
    end;
    v79._borders = nil;
    l_Selection_0:ClearTerrainSelectionHack();
end;
v4.updateVisibility = function(v84, v85)
    if v84._centerPart then
        v84._centerPart.Transparency = not v85 and 1 or 0.9;
    end;
    for _, v87 in pairs(v84._borders) do
        v87.Transparency = not v85 and 1 or 0.5;
    end;
    for _, v89 in pairs(v84._adorns) do
        v89:updateVisibility(v85);
    end;
end;
v4.updateBlockMesh = function(v90, _)
    if not v90._rootModel then
        local l_Model_0 = Instance.new("Model");
        l_Model_0.Name = "RegionPreview";
        l_Model_0.Archivable = false;
        v90._rootModel = l_Model_0;
        v90._rootModel.Parent = v90._target;
    end;
    if not v90._centerPart then
        local l_Part_0 = Instance.new("Part");
        l_Part_0.Name = "RegionCenter";
        l_Part_0.Size = Vector3.new(1, 1, 1);
        l_Part_0.TopSurface = "Smooth";
        l_Part_0.BottomSurface = "Smooth";
        l_Part_0.CastShadow = false;
        l_Part_0.Locked = true;
        l_Part_0.Anchored = true;
        l_Part_0.CanCollide = false;
        l_Part_0.BrickColor = BrickColor.new("Toothpaste");
        l_Part_0.Material = Enum.Material.Neon;
        l_Part_0.Archivable = false;
        l_Part_0.Transparency = 1;
        local l_BlockMesh_0 = Instance.new("BlockMesh");
        l_BlockMesh_0.Scale = Vector3.new(1, 1, 1);
        l_BlockMesh_0.Parent = l_Part_0;
        v90._blockMesh = l_BlockMesh_0;
        v90._centerPart = l_Part_0;
    end;
    v90._centerPart.Position = v90._position;
    v90._centerPart.Parent = v90._rootModel;
    v90._blockMesh.Scale = v90._size;
end;
v4.updateAdorns = function(v95)
    local l__position_0 = v95._position;
    local v97 = v95._size / 2;
    v95._adorns[Enum.NormalId.Right]:setPosition(l__position_0 + Vector3.new(v97.x, 0, 0));
    v95._adorns[Enum.NormalId.Left]:setPosition(l__position_0 + Vector3.new(-v97.x, 0, 0));
    v95._adorns[Enum.NormalId.Top]:setPosition(l__position_0 + Vector3.new(0, v97.y, 0));
    v95._adorns[Enum.NormalId.Bottom]:setPosition(l__position_0 + Vector3.new(0, -v97.y, 0));
    v95._adorns[Enum.NormalId.Front]:setPosition(l__position_0 + Vector3.new(0, 0, v97.z));
    v95._adorns[Enum.NormalId.Back]:setPosition(l__position_0 + Vector3.new(0, 0, -v97.z));
end;
v4.updateBorder = function(v98, v99, v100)
    assert(v98._adorns[v99] and v98._adorns[v100], "accessing invalid terrain");
    local v101 = string.format("%d_%d", v99.Value, v100.Value);
    local v102 = (v98._adorns[v99]:getPosition() - v98._position) + (v98._adorns[v100]:getPosition() - v98._position);
    if v102.Magnitude < 1 then
        return ;
    else
        local v103 = Vector3.new(v102.x == 0 and v98._size.x or 8, v102.y == 0 and v98._size.y or 8, v102.z == 0 and v98._size.z or 8);
        v102 = v102 + v98._position;
        if not v98._borders[v101] then
            local l_Part_1 = Instance.new("Part");
            l_Part_1.Name = "RegionBorder";
            l_Part_1.Size = Vector3.new(1, 1, 1);
            l_Part_1.TopSurface = "Smooth";
            l_Part_1.BottomSurface = "Smooth";
            l_Part_1.Locked = true;
            l_Part_1.Anchored = true;
            l_Part_1.CanCollide = false;
            l_Part_1.BrickColor = BrickColor.new("Toothpaste");
            l_Part_1.Material = Enum.Material.Neon;
            l_Part_1.Archivable = false;
            l_Part_1.Transparency = 1;
            l_Part_1.CastShadow = false;
            l_Part_1.Parent = v98._rootModel;
            v98._borders[v101] = l_Part_1;
            local l_BlockMesh_1 = Instance.new("BlockMesh");
            l_BlockMesh_1.Name = "BorderMesh";
            l_BlockMesh_1.Parent = l_Part_1;
        end;
        v98._borders[v101].BorderMesh.Scale = v103;
        v98._borders[v101].Position = v102;
        return ;
    end;
end;
v4.updateBorders = function(v106)
    if not v106._centerPart then
        v106:updateBlockMesh();
    end;
    for v107 = 1, #l_EnumItems_0 - 1 do
        for v108 = v107 + 1, #l_EnumItems_0 do
            v106:updateBorder(l_EnumItems_0[v107], l_EnumItems_0[v108]);
        end;
    end;
end;
v4.setSizeAndPosition = function(v109, v110, v111)
    v109._position = v111;
    v109._size = v110;
    v109:updateBlockMesh();
    v109:updateAdorns();
    v109:updateBorders();
    l_Selection_0:SetTerrainSelectionHack(v111, v110);
end;
return v4;


local l_Parent_0 = script.Parent.Parent.Parent;
local l_Signal_0 = require(l_Parent_0.Packages.Framework).Util.Signal;
local v2 = require(l_Parent_0.Src.Util.quickWait);
local l_Workspace_0 = game:GetService("Workspace");
local l_UserInputService_0 = game:GetService("UserInputService");
local v5 = Vector3.new(0, 1, 0);
local v6 = {};
v6.__index = v6;
v6.new = function(v7, v8, v9, v10)
    assert(v7, "MidPlanePreview needs reference to plugin");
    local v11 = (v9 + v10) * 0.5;
    local l_Part_0 = Instance.new("Part");
    l_Part_0.Name = "MidPlanePreview";
    l_Part_0.Size = Vector3.new(1, 1, 1);
    l_Part_0.Position = v11;
    l_Part_0.TopSurface = "Smooth";
    l_Part_0.BottomSurface = "Smooth";
    l_Part_0.CastShadow = false;
    l_Part_0.Locked = true;
    l_Part_0.Anchored = true;
    l_Part_0.CanCollide = false;
    l_Part_0.BrickColor = BrickColor.new("Toothpaste");
    l_Part_0.Material = Enum.Material.Neon;
    l_Part_0.Archivable = false;
    l_Part_0.Transparency = 1;
    local l_BlockMesh_0 = Instance.new("BlockMesh");
    local v14 = v10 - v9;
    l_BlockMesh_0.Scale = Vector3.new(v14.x, 1, v14.z);
    l_BlockMesh_0.Parent = l_Part_0;
    l_Part_0.Parent = v8;
    local v15 = setmetatable({
        _plugin = v7,
        _mouse = v7:GetMouse(),
        _selectingHeight = false,
        _target = v8,
        _rootPart = l_Part_0,
        _blockMesh = l_BlockMesh_0,
        _targetRegion = Region3.new(v9, v10)
    }, v6);
    v15._heightSelectedSignal = l_Signal_0.new();
    return v15;
end;
v6.destroy = function(v16)
    if v16._blockMesh then
        v16._blockMesh:Destroy();
        v16._blockMesh = nil;
    end;
    if v16._rootPart then
        v16._rootPart:Destroy();
        v16._rootPart = nil;
    end;
    if v16._connection then
        v16._connection:Disconnect();
    end;
end;
v6.updateCollisionPlaneNormal = function(v17)
    local l_Position_0 = v17._rootPart.Position;
    local l_p_0 = l_Workspace_0.CurrentCamera.CoordinateFrame.p;
    local l_v5_0 = v5;
    local v21 = l_p_0 - l_Position_0;
    if l_v5_0:Dot(v21) == 0 then
        v17._planeNormal = nil;
        return ;
    else
        v17._planeNormal = l_v5_0:Cross(v21):Cross(l_v5_0).Unit;
        return ;
    end;
end;
v6.calcPlaneHit = function(v22)
    local l_p_1 = l_Workspace_0.CurrentCamera.CoordinateFrame.p;
    local l_Direction_0 = v22._mouse.UnitRay.Direction;
    local v25 = l_Direction_0:Dot(v22._planeNormal);
    if v25 < 0 then
        return l_p_1 + ((v22._rootPart.Position - l_p_1):Dot(v22._planeNormal) / v25) * l_Direction_0;
    else
        return nil;
    end;
end;
v6.calcAxisPosMouseClick = function(v26)
    if v26._planeNormal then
        local v27 = v26:calcPlaneHit();
        if not v27 then
            return v26._position;
        else
            return ((v27 - v26._prevPosition):Dot(v5) / v5:Dot(v5)) * v5 + v26._prevPosition;
        end;
    else
        return ;
    end;
end;
v6.startSelectHeight = function(v28, v29, v30)
    if not v28._connection then
        v28._plugin:Activate(true);
        v28:updateCollisionPlaneNormal();
        v28._prevPosition = v28._rootPart.Position;
        v28._connection = l_UserInputService_0.InputEnded:Connect(function()
            if v28._planeNormal then
                v28._planeNormal = nil;
            end;
            v29();
            v28._plugin:Deactivate();
            v28._connection:Disconnect();
            v28._connection = nil;
        end);
        spawn(function()
            while v28._connection ~= nil do
                local v31 = v28:calcAxisPosMouseClick();
                if v28._rootPart.Position ~= v31 then
                    v28._rootPart.Position = v31;
                    v30(v31.Y);
                end;
                v2();
            end;
        end);
        return ;
    else
        return ;
    end;
end;
v6.updateVisibility = function(v32, v33)
    if v32._rootPart then
        v32._rootPart.Transparency = not v33 and 1 or 0.9;
    end;
end;
v6.updatePlaneScaling = function(v34, v35, v36)
    local v37 = v36 - v35;
    local v38 = (v35 + v36) * 0.5;
    local l_Y_0 = v34._rootPart.Position.Y;
    v34._blockMesh.Scale = Vector3.new(v37.x * 1.2, 1, v37.z * 1.2);
    v34._rootPart.Position = Vector3.new(v38.X, l_Y_0, v38.Z);
end;
v6.setY = function(v40, v41)
    assert(type(v41) == "number", "");
    local l_Position_1 = v40._rootPart.Position;
    v40._rootPart.Position = Vector3.new(l_Position_1.X, v41, l_Position_1.Z);
end;
v6.setPosition = function(v43, v44)
    v43._rootPart.Position = v44;
end;
v6.getPosition = function(v45)
    return v45._rootPart.Position;
end;
return v6;


local l_Parent_0 = script.Parent.Parent.Parent;
local v1 = require(l_Parent_0.Src.Util.Constants);
local v2 = require(l_Parent_0.Src.Util.TerrainEnums);
local l_BrushShape_0 = v2.BrushShape;
local l_ToolId_0 = v2.ToolId;
local v5 = require(l_Parent_0.Src.Util.applyPivot);
local l_TerrainEditorOverhaul_0 = game:GetFastFlag("TerrainEditorOverhaul");
local l_CoreGui_0 = game:GetService("CoreGui");
local v8 = nil;
local v9 = nil;
local v10 = nil;
local v11 = nil;
if not l_TerrainEditorOverhaul_0 then
    v9 = {
        [l_BrushShape_0.Sphere] = Enum.PartType.Ball,
        [l_BrushShape_0.Cube] = Enum.PartType.Block,
        [l_BrushShape_0.Cylinder] = Enum.PartType.Cylinder
    };
    v10 = function(v12)
        return 0.9 - v12 * 0.3;
    end;
    v11 = function()
        local l_Part_0 = Instance.new("Part");
        l_Part_0.Name = "TerrainBrushCursorPart";
        l_Part_0.TopSurface = Enum.SurfaceType.Smooth;
        l_Part_0.BottomSurface = Enum.SurfaceType.Smooth;
        l_Part_0.CastShadow = false;
        l_Part_0.Locked = true;
        l_Part_0.Anchored = true;
        l_Part_0.CanCollide = false;
        l_Part_0.BrickColor = BrickColor.new("Toothpaste");
        l_Part_0.Material = Enum.Material.Neon;
        l_Part_0.Archivable = false;
        l_Part_0.Size = Vector3.new(v1.VOXEL_RESOLUTION, v1.VOXEL_RESOLUTION, v1.VOXEL_RESOLUTION);
        l_Part_0.Shape = v9[l_BrushShape_0.Sphere];
        l_Part_0.Transparency = v10(v1.INITIAL_BRUSH_STRENGTH);
        return l_Part_0;
    end;
else
    v8 = function()
        local v14 = l_CoreGui_0:FindFirstChild("TerrainCursor") or Instance.new("Folder");
        v14.Name = "TerrainCursor";
        v14.Parent = l_CoreGui_0;
        local l_SphereHandleAdornment_0 = Instance.new("SphereHandleAdornment");
        l_SphereHandleAdornment_0.Name = "SphereCursorOnTop";
        l_SphereHandleAdornment_0.Radius = v1.VOXEL_RESOLUTION / 2;
        l_SphereHandleAdornment_0.Transparency = v1.TERRAIN_BRUSH_TRANSPARENCY;
        l_SphereHandleAdornment_0.Color = BrickColor.new("White");
        l_SphereHandleAdornment_0.AlwaysOnTop = true;
        l_SphereHandleAdornment_0.ZIndex = 0;
        l_SphereHandleAdornment_0.Parent = v14;
        local l_SphereHandleAdornment_1 = Instance.new("SphereHandleAdornment");
        l_SphereHandleAdornment_1.Name = "SphereCursorOutline";
        l_SphereHandleAdornment_1.Radius = v1.VOXEL_RESOLUTION / 2;
        l_SphereHandleAdornment_1.Transparency = v1.TERRAIN_BRUSH_TRANSPARENCY;
        l_SphereHandleAdornment_1.Color = BrickColor.new("White");
        l_SphereHandleAdornment_1.Parent = v14;
        local l_BoxHandleAdornment_0 = Instance.new("BoxHandleAdornment");
        l_BoxHandleAdornment_0.Name = "BoxCursorOnTop";
        l_BoxHandleAdornment_0.Size = Vector3.new(v1.VOXEL_RESOLUTION, v1.VOXEL_RESOLUTION, v1.VOXEL_RESOLUTION);
        l_BoxHandleAdornment_0.Transparency = v1.TERRAIN_BRUSH_TRANSPARENCY;
        l_BoxHandleAdornment_0.Color = BrickColor.new("White");
        l_BoxHandleAdornment_0.AlwaysOnTop = true;
        l_BoxHandleAdornment_0.ZIndex = 0;
        l_BoxHandleAdornment_0.Parent = v14;
        local l_BoxHandleAdornment_1 = Instance.new("BoxHandleAdornment");
        l_BoxHandleAdornment_1.Name = "BoxCursorOutline";
        l_BoxHandleAdornment_1.Size = Vector3.new(v1.VOXEL_RESOLUTION, v1.VOXEL_RESOLUTION, v1.VOXEL_RESOLUTION);
        l_BoxHandleAdornment_1.Transparency = v1.TERRAIN_BRUSH_TRANSPARENCY;
        l_BoxHandleAdornment_1.Color = BrickColor.new("White");
        l_BoxHandleAdornment_1.Parent = v14;
        local l_CylinderHandleAdornment_0 = Instance.new("CylinderHandleAdornment");
        l_CylinderHandleAdornment_0.Name = "CylinderCursorOnTop";
        l_CylinderHandleAdornment_0.Height = v1.VOXEL_RESOLUTION;
        l_CylinderHandleAdornment_0.Radius = v1.VOXEL_RESOLUTION / 2;
        l_CylinderHandleAdornment_0.Transparency = v1.TERRAIN_BRUSH_TRANSPARENCY;
        l_CylinderHandleAdornment_0.Color = BrickColor.new("White");
        l_CylinderHandleAdornment_0.AlwaysOnTop = true;
        l_CylinderHandleAdornment_0.ZIndex = 0;
        l_CylinderHandleAdornment_0.Parent = v14;
        local l_CylinderHandleAdornment_1 = Instance.new("CylinderHandleAdornment");
        l_CylinderHandleAdornment_1.Name = "CylinderCursorOutline";
        l_CylinderHandleAdornment_1.Height = v1.VOXEL_RESOLUTION;
        l_CylinderHandleAdornment_1.Radius = v1.VOXEL_RESOLUTION / 2;
        l_CylinderHandleAdornment_1.Transparency = v1.TERRAIN_BRUSH_TRANSPARENCY;
        l_CylinderHandleAdornment_1.Color = BrickColor.new("White");
        l_CylinderHandleAdornment_1.Parent = v14;
        local l_SphereHandleAdornment_2 = Instance.new("SphereHandleAdornment");
        l_SphereHandleAdornment_2.Name = "Central";
        l_SphereHandleAdornment_2.Radius = 0.15;
        l_SphereHandleAdornment_2.Transparency = 0.25;
        l_SphereHandleAdornment_2.Color = BrickColor.new("White");
        l_SphereHandleAdornment_2.Parent = v14;
        return {
            CursorFolder = v14,
            Central = l_SphereHandleAdornment_2,
            Sphere = {
                OnTop = l_SphereHandleAdornment_0,
                Outline = l_SphereHandleAdornment_1
            },
            Cube = {
                OnTop = l_BoxHandleAdornment_0,
                Outline = l_BoxHandleAdornment_1
            },
            Cylinder = {
                OnTop = l_CylinderHandleAdornment_0,
                Outline = l_CylinderHandleAdornment_1
            }
        };
    end;
end;
local v22 = {};
v22.__index = v22;
v22.new = function(v23)
    return (setmetatable({
        _terrain = v23,
        _cursor = nil,
        _cursorPart = nil,
        _cursorFolder = nil,
        _brushShape = "Sphere"
    }, v22));
end;
v22.isVisibleForOperation = function(v24)
    if v24.currentTool == l_ToolId_0.None then
        return false;
    else
        return (v24.planeLockActive and not v24.heightPicker) and not v24.editPlaneMode;
    end;
end;
if not l_TerrainEditorOverhaul_0 then
    v22.getCursorPart = function(v25)
        return v25._cursorPart;
    end;
    v22.destroy = function(v26)
        if v26._cursorPart then
            v26._cursorPart:Destroy();
            v26._cursorPart = nil;
        end;
        if v26._cursorFolder then
            v26._cursorFolder:Destroy();
            v26._cursorFolder = nil;
        end;
    end;
    v22.hide = function(v27)
        if v27._cursorPart then
            v27._cursorPart.Parent = nil;
        end;
    end;
    v22.maybeCreate = function(v28)
        if not v28._cursorFolder then
            v28._cursorFolder = Instance.new("Folder");
            v28._cursorFolder.Name = "TerrainCursorPart";
        end;
        if not v28._cursorFolder.Parent then
            v28._cursorFolder.Parent = game:GetService("Workspace");
        end;
        if not v28._cursorPart then
            v28._cursorPart = v11();
        end;
        v28._cursorPart.Parent = v28._cursorFolder;
    end;
    v22.update = function(v29, v30)
        if v29._cursorPart then
            local v31 = v30.size * v1.VOXEL_RESOLUTION;
            local v32 = v30.height * v1.VOXEL_RESOLUTION;
            local l_shape_0 = v30.shape;
            v29._cursorPart.Shape = v9[v30.shape];
            if not v30.mouseDown then
                v29._cursorPart.Transparency = v10(v30.strength);
            else
                v29._cursorPart.Transparency = 0.9;
            end;
            if l_shape_0 == l_BrushShape_0.Cylinder then
                v29._cursorPart.Size = Vector3.new(v32, v31, v31);
            else
                v29._cursorPart.Size = Vector3.new(v31, v32, v31) + Vector3.new(0.1, 0.1, 0.1);
            end;
            v29._cursorPart.CFrame = CFrame.new((v5(v30.pivot, v30.location, v32)));
            if l_shape_0 == l_BrushShape_0.Cylinder then
                v29._cursorPart.Rotation = Vector3.new(0, 0, 90);
            end;
            return ;
        else
            return ;
        end;
    end;
else
    v22.destroy = function(v34)
        if v34._cursor then
            v34._cursor.CursorFolder:Destroy();
        end;
    end;
    v22.createOnce = function(v35)
        if not v35._cursor then
            v35._cursor = v8();
        end;
    end;
    v22.hide = function(v36)
        if v36._cursor then
            v36._cursor.Central.Adornee = nil;
            for _, v38 in v36._cursor, nil, nil do
                if typeof(v38) == "table" then
                    for _, v40 in v38, nil, nil do
                        v40.Adornee = nil;
                    end;
                end;
            end;
            return ;
        else
            return ;
        end;
    end;
    v22.show = function(v41, v42, v43, v44, v45, v46, v47)
        if v41._cursor then
            v41._cursor.Central.Adornee = game.Workspace.Terrain;
            v41._cursor.Central.CFrame = v45;
            v41._cursor.Central.Radius = math.abs((game.Workspace.CurrentCamera.CFrame.Position - v45.Position).Magnitude / 128);
            for _, v49 in v41._cursor[v42], nil, nil do
                v49.Adornee = game.Workspace.Terrain;
                v49.CFrame = v45;
                if v42 == "Cylinder" then
                    v49.CFrame = CFrame.Angles(1.5707963267948966, 0, 0) + v49.CFrame.Position;
                    v49.Height = v47 or v46;
                    v49.Radius = v46 / 2;
                elseif v42 == "Cube" then
                    v49.Size = Vector3.new(v46, v47 or v46, v46);
                elseif v42 == "Sphere" then
                    v49.Radius = v46 / 2;
                end;
                if not v43 or v44 then
                    v49.Transparency = v1.TERRAIN_BRUSH_TRANSPARENCY;
                else
                    v49.Transparency = v1.TERRAIN_BRUSH_TRANSPARENCY_MOUSE_DOWN;
                end;
            end;
            return ;
        else
            return ;
        end;
    end;
    v22.update = function(v50, v51)
        if v50._cursor then
            local v52 = v51.size * v1.VOXEL_RESOLUTION;
            local v53 = v51.height * v1.VOXEL_RESOLUTION;
            local l_shape_1 = v51.shape;
            local l_mouseDown_0 = v51.mouseDown;
            local l_adjusting_0 = v51.adjusting;
            local v57 = v5(v51.pivot, v51.location, v53);
            if v50._brushShape ~= l_shape_1 then
                v50:hide();
                v50._brushShape = l_shape_1;
            end;
            v50:show(l_shape_1, l_mouseDown_0, l_adjusting_0, CFrame.new(v57), v52, v53);
            return ;
        else
            return ;
        end;
    end;
end;
return v22;


local l_Parent_0 = script.Parent.Parent.Parent;
local v1 = require(l_Parent_0.Src.Util.Constants);
local v2 = require(l_Parent_0.Src.Util.TerrainEnums);
local l_ToolId_0 = v2.ToolId;
local l_PlaneLockType_0 = v2.PlaneLockType;
local l_CoreGui_0 = game:GetService("CoreGui");
local function _()
    local l_Part_0 = Instance.new("Part");
    l_Part_0.Name = "LinePart";
    l_Part_0.Transparency = 1;
    l_Part_0.TopSurface = Enum.SurfaceType.Smooth;
    l_Part_0.BottomSurface = Enum.SurfaceType.Smooth;
    l_Part_0.Anchored = true;
    l_Part_0.CanCollide = false;
    l_Part_0.Locked = true;
    l_Part_0.CastShadow = false;
    l_Part_0.Archivable = false;
    local l_SelectionBox_0 = Instance.new("SelectionBox");
    l_SelectionBox_0.Name = "SelectionBox";
    l_SelectionBox_0.Adornee = l_Part_0;
    l_SelectionBox_0.Archivable = false;
    l_SelectionBox_0.Parent = l_Part_0;
    return l_Part_0;
end;
local function _(v9, v10, v11, v12)
    if v10 then
        v11 = 0.5 + 0.5 * v11;
    end;
    local l_BoxHandleAdornment_0 = Instance.new("BoxHandleAdornment");
    l_BoxHandleAdornment_0.Name = "BoxHandle";
    l_BoxHandleAdornment_0.Adornee = v9;
    l_BoxHandleAdornment_0.Archivable = false;
    l_BoxHandleAdornment_0.Parent = v9;
    l_BoxHandleAdornment_0.AlwaysOnTop = v10;
    l_BoxHandleAdornment_0.ZIndex = not v10 and -1 or 0;
    l_BoxHandleAdornment_0.Transparency = v11;
    l_BoxHandleAdornment_0.Color = v12;
    return l_BoxHandleAdornment_0;
end;
local function _()
    local l_ScreenGui_0 = Instance.new("ScreenGui");
    l_ScreenGui_0.Name = "TerrainBrushGui";
    l_ScreenGui_0.Archivable = false;
    return l_ScreenGui_0;
end;
local function _()
    local l_Part_1 = Instance.new("Part");
    l_Part_1.Name = "LinePart";
    l_Part_1.Transparency = 1;
    l_Part_1.TopSurface = Enum.SurfaceType.Smooth;
    l_Part_1.BottomSurface = Enum.SurfaceType.Smooth;
    l_Part_1.Anchored = true;
    l_Part_1.CanCollide = false;
    l_Part_1.Locked = true;
    l_Part_1.CastShadow = false;
    l_Part_1.Archivable = false;
    return l_Part_1;
end;
local v19 = {};
v19.__index = v19;
v19.new = function()
    return (setmetatable({
        _cursorGui = nil,
        _cursorGridPart = nil,
        _cursorGridParts = {},
        _cursorGridPartsOnTop = {}
    }, v19));
end;
v19.isVisibleForOperation = function(v20)
    if v20.currentTool == l_ToolId_0.None then
        return false;
    else
        local v21 = v20.planeLockActive and v20.planeLock ~= l_PlaneLockType_0.Off;
        local v22 = true;
        if v20.currentTool ~= l_ToolId_0.Flatten then
            v22 = v21 or v20.heightPicker;
        end;
        return v22;
    end;
end;
v19.destroy = function(v23)
    if v23._cursorGridParts and type(v23._cursorGridParts) == "table" then
        for _, v25 in ipairs(v23._cursorGridParts) do
            if v25 then
                v25:Destroy();
            end;
        end;
    end;
    v23._cursorGridParts = {};
    if v23._cursorGui then
        v23._cursorGui:Destroy();
    end;
    if v23._cursorGridPart then
        v23._cursorGridPart:Destroy();
        v23._cursorGridPart = nil;
    end;
end;
v19.hide = function(v26)
    if v26._cursorGui then
        v26._cursorGui.Parent = nil;
    end;
end;
v19.maybeCreate = function(v27)
    if v27._cursorGui then
        if not v27._cursorGui.Parent then
            v27:destroy();
            local l_ScreenGui_1 = Instance.new("ScreenGui");
            l_ScreenGui_1.Name = "TerrainBrushGui";
            l_ScreenGui_1.Archivable = false;
            v27._cursorGui = l_ScreenGui_1;
        end;
    else
        local l_ScreenGui_2 = Instance.new("ScreenGui");
        l_ScreenGui_2.Name = "TerrainBrushGui";
        l_ScreenGui_2.Archivable = false;
        v27._cursorGui = l_ScreenGui_2;
    end;
    v27._cursorGui.Parent = l_CoreGui_0;
end;
v19.update = function(v30, v31)
    v30:_updateInternal(v31.planePoint, v31.planeNormal, v31.cursorSize, not v31.mouseDown and 0.3 or 0.8, nil, v31.planeLock, v31.planeCFrame, v31.editPlaneMode);
end;
v19._updateInternal = function(v32, v33, v34, v35, v36, v37, v38, v39, v40)
    v36 = v36 or 0.95;
    v37 = BrickColor.new(v37 or "Institutional white");
    local v41 = v35 * v1.VOXEL_RESOLUTION;
    local v42 = CFrame.new(v33, v33 + v34);
    local v43 = CFrame.new(Vector3.new(0, 0, 0), v34);
    local v44 = nil;
    v44 = if v38 == l_PlaneLockType_0.Manual and v39 then v39:PointToObjectSpace(v33) else v43:PointToObjectSpace(v33);
    local _ = (Vector3.new((v44.x / v41) % 1, (v44.y / v41) % 1, 0) - Vector3.new(0.5, 0.5, 0)) * -v41;
    if not v32._cursorGridParts or type(v32._cursorGridParts) ~= "table" then
        v32._cursorGridParts = {};
    end;
    if not v32._cursorGui then
        local l_ScreenGui_3 = Instance.new("ScreenGui");
        l_ScreenGui_3.Name = "TerrainBrushGui";
        l_ScreenGui_3.Archivable = false;
        v32._cursorGui = l_ScreenGui_3;
    end;
    if not v32._cursorGridPart then
        local l_Part_2 = Instance.new("Part");
        l_Part_2.Name = "LinePart";
        l_Part_2.Transparency = 1;
        l_Part_2.TopSurface = Enum.SurfaceType.Smooth;
        l_Part_2.BottomSurface = Enum.SurfaceType.Smooth;
        l_Part_2.Anchored = true;
        l_Part_2.CanCollide = false;
        l_Part_2.Locked = true;
        l_Part_2.CastShadow = false;
        l_Part_2.Archivable = false;
        v32._cursorGridPart = l_Part_2;
    end;
    v32._cursorGridPart.Parent = v32._cursorGui;
    if not (v38 == l_PlaneLockType_0.Manual) or not v39 then
        v32._cursorGridPart.CFrame = v42;
    else
        v32._cursorGridPart.CFrame = (v39 - v39.Position) + v33;
    end;
    for v48 = 1, 10 do
        local v49 = (((v48 - ((v44.Y / v41) % 1 or 0)) - 1.5) / 9) % 1;
        local v50 = (v41 * 9) * math.sin((math.acos(v49 * 1.99 - 0.995)));
        local v51 = ((v49 - 0.5) * 9) * v41;
        local v52 = (((v48 - ((v44.X / v41) % 1 or 0)) - 1.5) / 9) % 1;
        local v53 = (v41 * 9) * math.sin((math.acos(v52 * 1.99 - 0.995)));
        local v54 = ((v52 - 0.5) * 9) * v41;
        local v55 = v32._cursorGridParts[v48];
        local v56 = v32._cursorGridPartsOnTop[v48];
        local v57 = v32._cursorGridParts[10 + v48];
        local v58 = v32._cursorGridPartsOnTop[10 + v48];
        if not v55 then
            local l__cursorGridPart_0 = v32._cursorGridPart;
            local l_v36_0 = v36;
            local l_v37_0 = v37;
            local l_BoxHandleAdornment_1 = Instance.new("BoxHandleAdornment");
            l_BoxHandleAdornment_1.Name = "BoxHandle";
            l_BoxHandleAdornment_1.Adornee = l__cursorGridPart_0;
            l_BoxHandleAdornment_1.Archivable = false;
            l_BoxHandleAdornment_1.Parent = l__cursorGridPart_0;
            l_BoxHandleAdornment_1.AlwaysOnTop = false;
            l_BoxHandleAdornment_1.ZIndex = -1;
            l_BoxHandleAdornment_1.Transparency = l_v36_0;
            l_BoxHandleAdornment_1.Color = l_v37_0;
            v55 = l_BoxHandleAdornment_1;
            v32._cursorGridParts[v48] = v55;
        end;
        if not v56 then
            local l__cursorGridPart_1 = v32._cursorGridPart;
            local l_v36_1 = v36;
            local l_v37_1 = v37;
            l_v36_1 = 0.5 + 0.5 * l_v36_1;
            local l_BoxHandleAdornment_2 = Instance.new("BoxHandleAdornment");
            l_BoxHandleAdornment_2.Name = "BoxHandle";
            l_BoxHandleAdornment_2.Adornee = l__cursorGridPart_1;
            l_BoxHandleAdornment_2.Archivable = false;
            l_BoxHandleAdornment_2.Parent = l__cursorGridPart_1;
            l_BoxHandleAdornment_2.AlwaysOnTop = true;
            l_BoxHandleAdornment_2.ZIndex = 0;
            l_BoxHandleAdornment_2.Transparency = l_v36_1;
            l_BoxHandleAdornment_2.Color = l_v37_1;
            v56 = l_BoxHandleAdornment_2;
            v32._cursorGridPartsOnTop[v48] = v56;
        end;
        if not v57 then
            local l__cursorGridPart_2 = v32._cursorGridPart;
            local l_v36_2 = v36;
            local l_v37_2 = v37;
            local l_BoxHandleAdornment_3 = Instance.new("BoxHandleAdornment");
            l_BoxHandleAdornment_3.Name = "BoxHandle";
            l_BoxHandleAdornment_3.Adornee = l__cursorGridPart_2;
            l_BoxHandleAdornment_3.Archivable = false;
            l_BoxHandleAdornment_3.Parent = l__cursorGridPart_2;
            l_BoxHandleAdornment_3.AlwaysOnTop = false;
            l_BoxHandleAdornment_3.ZIndex = -1;
            l_BoxHandleAdornment_3.Transparency = l_v36_2;
            l_BoxHandleAdornment_3.Color = l_v37_2;
            v57 = l_BoxHandleAdornment_3;
            v32._cursorGridParts[10 + v48] = v57;
        end;
        if not v58 then
            local l__cursorGridPart_3 = v32._cursorGridPart;
            local l_v36_3 = v36;
            local l_v37_3 = v37;
            l_v36_3 = 0.5 + 0.5 * l_v36_3;
            local l_BoxHandleAdornment_4 = Instance.new("BoxHandleAdornment");
            l_BoxHandleAdornment_4.Name = "BoxHandle";
            l_BoxHandleAdornment_4.Adornee = l__cursorGridPart_3;
            l_BoxHandleAdornment_4.Archivable = false;
            l_BoxHandleAdornment_4.Parent = l__cursorGridPart_3;
            l_BoxHandleAdornment_4.AlwaysOnTop = true;
            l_BoxHandleAdornment_4.ZIndex = 0;
            l_BoxHandleAdornment_4.Transparency = l_v36_3;
            l_BoxHandleAdornment_4.Color = l_v37_3;
            v58 = l_BoxHandleAdornment_4;
            v32._cursorGridPartsOnTop[10 + v48] = v58;
        end;
        local v75 = math.pow((game:GetService("Workspace").CurrentCamera.CFrame.Position - v33).Magnitude, 0.5) / v1.GRID_LINE_WIDTH;
        local v76 = Vector3.new(v50, v75, v75);
        local v77 = CFrame.new(0, v51, 0);
        local v78 = Vector3.new(v75, v53, v75);
        local v79 = CFrame.new(v54, 0, 0);
        v55.Size = v76;
        v55.CFrame = v77;
        v56.Size = v76;
        v56.CFrame = v77;
        v56.Visible = v40;
        v57.Size = v78;
        v57.CFrame = v79;
        v58.Size = v78;
        v58.CFrame = v79;
        v58.Visible = v40;
    end;
end;
return v19;


local l_Signal_0 = require(script.Parent.Parent.Parent.Packages.Framework).Util.Signal;
local v1 = {};
v1.__index = v1;
v1.new = function()
    return (setmetatable({
        ProgressUpdate = l_Signal_0.new(),
        ColormapHasUnknownPixels = l_Signal_0.new()
    }, v1));
end;
v1.IsA = function(_, v3)
    return v3 == "HeightmapImporterService";
end;
v1.ImportHeightmap = function(_, _, _, _, _)
end;
v1.SetImportHeightmapPaused = function(_, _)
end;
v1.CancelImportHeightmap = function(_)
end;
v1.IsValidHeightmap = function(_, _)
    return true, "Ok", 1024, 1024, 3, 1;
end;
v1.IsValidColormap = function(_, _)
    return true, "Ok", 1024, 1024, 3;
end;
return v1;