Clean up terrain plugin scripts

This commit is contained in:
Lewin Kelly 2024-03-22 20:50:20 +00:00
parent 759056c0da
commit b01af4131b
9 changed files with 102 additions and 79 deletions

View File

@ -249,7 +249,7 @@ end
-- Show the highlighter. -- Show the highlighter.
function Highlighter:EnablePreview() function Highlighter:EnablePreview()
self.selectionBox.Parent = game:GetService "CoreGui" -- This will make it not show up in workspace. self.selectionBox.Parent = CoreGui -- This will make it not show up in workspace.
end end
-- Update where the highlighter is displayed. -- Update where the highlighter is displayed.
@ -971,7 +971,7 @@ function GenerateTerrain()
-- Clean up the progress bar. -- Clean up the progress bar.
UnloadProgressBar() UnloadProgressBar()
--Generate Terrain End --Generate Terrain End
game:GetService("ChangeHistoryService"):SetWaypoint "Generate" ChangeHistoryService:SetWaypoint "Generate"
end end
local ConfirmationPopup local ConfirmationPopup
@ -1018,7 +1018,7 @@ function ClearTerrain()
--Erase Terrain End --Erase Terrain End
UnloadProgressBar() UnloadProgressBar()
game:GetService("ChangeHistoryService"):SetWaypoint "Reset" ChangeHistoryService:SetWaypoint "Reset"
end end
-- Function used by the clear button. Prompts the user first. -- Function used by the clear button. Prompts the user first.

View File

@ -2,6 +2,9 @@ while game == nil do
wait(1 / 30) wait(1 / 30)
end end
local ChangeHistoryService = game:GetService "ChangeHistoryService"
local CoreGui = game:GetService "CoreGui"
--------------- ---------------
--PLUGIN SETUP- --PLUGIN SETUP-
--------------- ---------------
@ -153,7 +156,7 @@ function MouseHighlighter.Create(mouseUse)
-- NOTE: -- NOTE:
-- Change this gui to be the one you want to use. -- Change this gui to be the one you want to use.
highlighter.selectionBox.Parent = game:GetService "CoreGui" highlighter.selectionBox.Parent = CoreGui
local vectorPos = Vector3.new(position.x, position.y, position.z) local vectorPos = Vector3.new(position.x, position.y, position.z)
local cellPos = WorldToCellPreferEmpty(c, vectorPos) local cellPos = WorldToCellPreferEmpty(c, vectorPos)
@ -206,7 +209,7 @@ end
-- Show the highlighter. -- Show the highlighter.
function MouseHighlighter:EnablePreview() function MouseHighlighter:EnablePreview()
self.selectionBox.Parent = game:GetService "CoreGui" -- This will make it not show up in workspace. self.selectionBox.Parent = CoreGui -- This will make it not show up in workspace.
end end
-- Create the mouse movement highlighter. -- Create the mouse movement highlighter.
@ -243,7 +246,7 @@ end
--screengui --screengui
local g = Instance.new "ScreenGui" local g = Instance.new "ScreenGui"
g.Name = "BuilderGui" g.Name = "BuilderGui"
g.Parent = game:GetService "CoreGui" g.Parent = CoreGui
-- UI gui load. Required for sliders. -- UI gui load. Required for sliders.
local RbxGui = LoadLibrary "RbxGui" local RbxGui = LoadLibrary "RbxGui"
@ -359,7 +362,7 @@ function onClicked(mouseC)
end end
-- Mark undo point. -- Mark undo point.
game:GetService("ChangeHistoryService"):SetWaypoint "Builder" ChangeHistoryService:SetWaypoint "Builder"
UpdatePosition(mouseC.Hit) UpdatePosition(mouseC.Hit)
end end

View File

@ -2,6 +2,9 @@ while game == nil do
wait(1 / 30) wait(1 / 30)
end end
local ChangeHistoryService = game:GetService "ChangeHistoryService"
local CoreGui = game:GetService "CoreGui"
----------------- -----------------
--DEFAULT VALUES- --DEFAULT VALUES-
----------------- -----------------
@ -163,7 +166,7 @@ end
-- Show the highlighter. -- Show the highlighter.
function MouseHighlighter:EnablePreview() function MouseHighlighter:EnablePreview()
self.selectionBox.Parent = game:GetService "CoreGui" -- This will make it not show up in workspace. self.selectionBox.Parent = CoreGui -- This will make it not show up in workspace.
end end
-- Create the mouse movement highlighter. -- Create the mouse movement highlighter.
@ -261,7 +264,7 @@ function onClicked(mouse2)
SetCell(c, x, y, z, 0, 0, 0) SetCell(c, x, y, z, 0, 0, 0)
-- Mark undo point. -- Mark undo point.
game:GetService("ChangeHistoryService"):SetWaypoint "Remover" ChangeHistoryService:SetWaypoint "Remover"
UpdatePosition(mouse2.Hit) UpdatePosition(mouse2.Hit)

View File

@ -2,6 +2,9 @@ while game == nil do
wait(1 / 30) wait(1 / 30)
end end
local ChangeHistoryService = game:GetService "ChangeHistoryService"
local CoreGui = game:GetService "CoreGui"
--------------- ---------------
--PLUGIN SETUP- --PLUGIN SETUP-
--------------- ---------------
@ -62,6 +65,39 @@ local elevationOptions = {
-- What color to use for the mouse highlighter. -- What color to use for the mouse highlighter.
local mouseHighlightColor = BrickColor.new "Lime green" local mouseHighlightColor = BrickColor.new "Lime green"
-- Do a line/plane intersection. The line starts at the camera. The plane is at y == 0, normal(0, 1, 0)
--
-- vectorPos - End point of the line.
--
-- Return:
-- success - Value is true if there was a plane intersection, false if not.
-- cellPos - Value is the terrain cell intersection point if there is one, vectorPos if there isn't.
local function PlaneIntersection(vectorPos)
local currCamera = game.Workspace.CurrentCamera
local startPos = Vector3.new(
currCamera.CoordinateFrame.p.X,
currCamera.CoordinateFrame.p.Y,
currCamera.CoordinateFrame.p.Z
)
local endPos = Vector3.new(vectorPos.X, vectorPos.Y, vectorPos.Z)
local normal = Vector3.new(0, 1, 0)
local p3 = Vector3.new(0, 0, 0)
local startEndDot = normal:Dot(endPos - startPos)
local cellPos = vectorPos
local success = false
if startEndDot ~= 0 then
local t = normal:Dot(p3 - startPos) / startEndDot
if t >= 0 and t <= 1 then
local intersection = ((endPos - startPos) * t) + startPos
cellPos = c:WorldToCell(intersection)
success = true
end
end
return success, cellPos
end
-- Used to create a highlighter that follows the mouse. -- Used to create a highlighter that follows the mouse.
-- It is a class mouse highlighter. To use, call MouseHighlighter.Create(mouse) where mouse is the mouse to track. -- It is a class mouse highlighter. To use, call MouseHighlighter.Create(mouse) where mouse is the mouse to track.
local MouseHighlighter = {} local MouseHighlighter = {}
@ -118,39 +154,6 @@ function MouseHighlighter.Create(mouseUse)
mouseH.TargetFilter = highlighter.selectionPart mouseH.TargetFilter = highlighter.selectionPart
setmetatable(highlighter, MouseHighlighter) setmetatable(highlighter, MouseHighlighter)
-- Do a line/plane intersection. The line starts at the camera. The plane is at y == 0, normal(0, 1, 0)
--
-- vectorPos - End point of the line.
--
-- Return:
-- success - Value is true if there was a plane intersection, false if not.
-- cellPos - Value is the terrain cell intersection point if there is one, vectorPos if there isn't.
local function PlaneIntersection(vectorPos)
local currCamera = game.Workspace.CurrentCamera
local startPos = Vector3.new(
currCamera.CoordinateFrame.p.X,
currCamera.CoordinateFrame.p.Y,
currCamera.CoordinateFrame.p.Z
)
local endPos = Vector3.new(vectorPos.X, vectorPos.Y, vectorPos.Z)
local normal = Vector3.new(0, 1, 0)
local p3 = Vector3.new(0, 0, 0)
local startEndDot = normal:Dot(endPos - startPos)
local cellPos = vectorPos
local success = false
if startEndDot ~= 0 then
local t = normal:Dot(p3 - startPos) / startEndDot
if t >= 0 and t <= 1 then
local intersection = ((endPos - startPos) * t) + startPos
cellPos = c:WorldToCell(intersection)
success = true
end
end
return success, cellPos
end
-- Update where the highlighter is displayed. -- Update where the highlighter is displayed.
-- position - Where to display the highlighter, in world space. -- position - Where to display the highlighter, in world space.
function UpdatePosition(position) function UpdatePosition(position)
@ -160,7 +163,7 @@ function MouseHighlighter.Create(mouseUse)
-- NOTE: -- NOTE:
-- Change this gui to be the one you want to use. -- Change this gui to be the one you want to use.
highlighter.selectionBox.Parent = game:GetService "CoreGui" highlighter.selectionBox.Parent = CoreGui
local vectorPos = Vector3.new(position.x, position.y, position.z) local vectorPos = Vector3.new(position.x, position.y, position.z)
local cellPos = WorldToCellPreferEmpty(c, vectorPos) local cellPos = WorldToCellPreferEmpty(c, vectorPos)
@ -213,7 +216,7 @@ end
-- Show the highlighter. -- Show the highlighter.
function MouseHighlighter:EnablePreview() function MouseHighlighter:EnablePreview()
self.selectionBox.Parent = game:GetService "CoreGui" -- This will make it not show up in workspace. self.selectionBox.Parent = CoreGui-- This will make it not show up in workspace.
end end
-- Create the mouse movement highlighter. -- Create the mouse movement highlighter.
@ -225,7 +228,7 @@ local mouseHighlighter = MouseHighlighter.Create(mouse)
--screengui --screengui
local g = Instance.new "ScreenGui" local g = Instance.new "ScreenGui"
g.Name = "ElevationGui" g.Name = "ElevationGui"
g.Parent = game:GetService "CoreGui" g.Parent = CoreGui
-- UI gui load. Required for sliders. -- UI gui load. Required for sliders.
local RbxGui = LoadLibrary "RbxGui" local RbxGui = LoadLibrary "RbxGui"
@ -364,7 +367,8 @@ local slopeLabel = CreateStandardLabel(
"", "",
elevationFrame elevationFrame
) )
local _, slopeSliderPosition = CreateStandardSlider( local _, slopeSliderPosition
_, slopeSliderPosition = CreateStandardSlider(
"slopeSliderGui", "slopeSliderGui",
UDim2.new(0, 1, 0, 67), UDim2.new(0, 1, 0, 67),
UDim2.new(0, 10, 0.5, -2), UDim2.new(0, 10, 0.5, -2),
@ -435,6 +439,9 @@ end
local height local height
local oldheightmap = {}
local heightmap = {}
--elevates terrain at point (x, y, z) in cluster c --elevates terrain at point (x, y, z) in cluster c
--within radius r1 from x, z the elevation should become y + d --within radius r1 from x, z the elevation should become y + d
--from radius r1 to r2 the elevation should be a gradient --from radius r1 to r2 the elevation should be a gradient
@ -547,6 +554,8 @@ end
-- return math.sqrt(math.pow(dist(x1, z1, x2, z2), 2) + math.pow(math.abs(y2 - y1) * 100 / d, 2)) -- return math.sqrt(math.pow(dist(x1, z1, x2, z2), 2) + math.pow(math.abs(y2 - y1) * 100 / d, 2))
-- end -- end
local mousedown = false
-- Run when the mouse gets clicked. If the click is on terrain, then it will be used as the starting point of the elevation area. -- Run when the mouse gets clicked. If the click is on terrain, then it will be used as the starting point of the elevation area.
function onClicked(mouse2) function onClicked(mouse2)
if on then if on then
@ -594,7 +603,7 @@ function onClicked(mouse2)
-- Hide the selection area while dragging. -- Hide the selection area while dragging.
mouseHighlighter:DisablePreview() mouseHighlighter:DisablePreview()
local mousedown = true mousedown = true
local originalY = mouse2.Y local originalY = mouse2.Y
local prevY = originalY local prevY = originalY
local d = 0 local d = 0
@ -618,7 +627,7 @@ function onClicked(mouse2)
end end
wait(0) wait(0)
end end
game:GetService("ChangeHistoryService"):SetWaypoint "Elevation" ChangeHistoryService:SetWaypoint "Elevation"
end end
end end

View File

@ -2,6 +2,9 @@ while game == nil do
wait(1 / 30) wait(1 / 30)
end end
local ChangeHistoryService = game:GetService "ChangeHistoryService"
local CoreGui = game:GetService "CoreGui"
--------------- ---------------
--PLUGIN SETUP- --PLUGIN SETUP-
--------------- ---------------
@ -65,7 +68,7 @@ mouse.Button1Up:connect(function()
brushheight = nil brushheight = nil
enablePreview() enablePreview()
updatePreviewSelection(mouse.Hit) updatePreviewSelection(mouse.Hit)
game:GetService("ChangeHistoryService"):SetWaypoint "Brush" ChangeHistoryService:SetWaypoint "Brush"
end) end)
mouse.Move:connect(function() mouse.Move:connect(function()
mouseMoved() mouseMoved()
@ -541,7 +544,7 @@ end
--screengui --screengui
local g = Instance.new "ScreenGui" local g = Instance.new "ScreenGui"
g.Name = "TerrainBrushGui" g.Name = "TerrainBrushGui"
g.Parent = game:GetService "CoreGui" g.Parent = CoreGui
brushDragBar, elevationFrame, elevationHelpFrame, elevationCloseEvent = brushDragBar, elevationFrame, elevationHelpFrame, elevationCloseEvent =
RbxGui.CreatePluginFrame( RbxGui.CreatePluginFrame(

View File

@ -2,6 +2,9 @@ while game == nil do
wait(1 / 30) wait(1 / 30)
end end
local ChangeHistoryService = game:GetService "ChangeHistoryService"
local CoreGui = game:GetService "CoreGui"
--------------- ---------------
--PLUGIN SETUP- --PLUGIN SETUP-
--------------- ---------------
@ -131,7 +134,7 @@ function onClicked(mouseC)
makeCrater(x, y, z, r, d) makeCrater(x, y, z, r, d)
debounce = false debounce = false
game:GetService("ChangeHistoryService"):SetWaypoint "Crater" ChangeHistoryService:SetWaypoint "Crater"
end end
end end
@ -171,7 +174,7 @@ local RbxGui = LoadLibrary "RbxGui"
--screengui --screengui
local g = Instance.new "ScreenGui" local g = Instance.new "ScreenGui"
g.Name = "CraterGui" g.Name = "CraterGui"
g.Parent = game:GetService "CoreGui" g.Parent = CoreGui
craterDragBar, craterFrame, craterHelpFrame, craterCloseEvent = craterDragBar, craterFrame, craterHelpFrame, craterCloseEvent =
RbxGui.CreatePluginFrame( RbxGui.CreatePluginFrame(

View File

@ -2,6 +2,8 @@ while game == nil do
wait(1 / 30) wait(1 / 30)
end end
local ChangeHistoryService = game:GetService "ChangeHistoryService"
--------------- ---------------
--PLUGIN SETUP- --PLUGIN SETUP-
--------------- ---------------
@ -184,7 +186,7 @@ function makePath(px1, pz1, px2, pz2, ph, pp)
end end
end end
game:GetService("ChangeHistoryService"):SetWaypoint "Roads" ChangeHistoryService:SetWaypoint "Roads"
end end
-- Do a line/plane intersection. The line starts at the camera. The plane is at y == 0, normal(0, 1, 0) -- Do a line/plane intersection. The line starts at the camera. The plane is at y == 0, normal(0, 1, 0)

View File

@ -2,6 +2,9 @@ while game == nil do
wait(1 / 30) wait(1 / 30)
end end
local ChangeHistoryService = game:GetService "ChangeHistoryService"
local CoreGui = game:GetService "CoreGui"
--------------- ---------------
--PLUGIN SETUP- --PLUGIN SETUP-
--------------- ---------------
@ -282,16 +285,13 @@ function getSquare(cellPos, setCells)
-- local tempCellPos = Vector3.new(x, y, z) -- local tempCellPos = Vector3.new(x, y, z)
local oldMaterial, oldType, oldOrientation = GetCell(c, x, y, z) local oldMaterial, oldType, oldOrientation = GetCell(c, x, y, z)
if oldMaterial.Value > 0 then if oldMaterial.Value > 0 then
table.insert( table.insert(setCells, {
setCells, xPos = x,
{ yPos = y,
xPos = x, zPos = z,
yPos = y, theType = oldType,
zPos = z, orientation = oldOrientation,
theType = oldType, })
orientation = oldOrientation,
}
)
end end
end end
end end
@ -315,16 +315,13 @@ function getCircular(cellPos, setCells)
local oldMaterial, oldType, oldOrientation = local oldMaterial, oldType, oldOrientation =
GetCell(c, x, y, z) GetCell(c, x, y, z)
if oldMaterial.Value > 0 then if oldMaterial.Value > 0 then
table.insert( table.insert(setCells, {
setCells, xPos = x,
{ yPos = y,
xPos = x, zPos = z,
yPos = y, theType = oldType,
zPos = z, orientation = oldOrientation,
theType = oldType, })
orientation = oldOrientation,
}
)
end end
end end
end end
@ -543,7 +540,7 @@ function mouseUp(_)
setPositionDirectionality() setPositionDirectionality()
end end
game:GetService("ChangeHistoryService"):SetWaypoint "MaterialPaint" ChangeHistoryService:SetWaypoint "MaterialPaint"
lastLastCell = nil lastLastCell = nil
lastCell = nil lastCell = nil
@ -725,7 +722,7 @@ end
--screengui --screengui
local g = Instance.new "ScreenGui" local g = Instance.new "ScreenGui"
g.Name = "MaterialPainterGui" g.Name = "MaterialPainterGui"
g.Parent = game:GetService "CoreGui" g.Parent = CoreGui
dragBar, containerFrame, helpFrame, closeEvent = RbxGui.CreatePluginFrame( dragBar, containerFrame, helpFrame, closeEvent = RbxGui.CreatePluginFrame(
"Material Brush", "Material Brush",

View File

@ -2,6 +2,10 @@ while game == nil do
wait(1 / 30) wait(1 / 30)
end end
local ChangeHistoryService = game:GetService "ChangeHistoryService"
local ContentProvider = game:GetService "ContentProvider"
local CoreGui = game:GetService "CoreGui"
--------------- ---------------
--PLUGIN SETUP- --PLUGIN SETUP-
--------------- ---------------
@ -67,8 +71,7 @@ local currentMaterial = 1
-- load our libraries -- load our libraries
local RbxGui = LoadLibrary "RbxGui" local RbxGui = LoadLibrary "RbxGui"
-- local RbxUtil = LoadLibrary "RbxUtility" -- local RbxUtil = LoadLibrary "RbxUtility"
game:GetService("ContentProvider") ContentProvider:Preload "http://banland.xyz/asset/?id=82741829"
:Preload "http://banland.xyz/asset/?id=82741829"
------------------------- OBJECT DEFINITIONS --------------------- ------------------------- OBJECT DEFINITIONS ---------------------
@ -510,7 +513,7 @@ local floodFill = function(x, y, z)
LoadProgressBar "Processing" LoadProgressBar "Processing"
breadthFill(x, y, z) breadthFill(x, y, z)
UnloadProgressBar() UnloadProgressBar()
game:GetService("ChangeHistoryService"):SetWaypoint "FloodFill" ChangeHistoryService:SetWaypoint "FloodFill"
end end
-- Function used when we try and flood fill. Prompts the user first. -- Function used when we try and flood fill. Prompts the user first.
@ -843,7 +846,7 @@ mouseHighlighter.OnClicked = mouseUp
------ ------
screenGui = Instance.new "ScreenGui" screenGui = Instance.new "ScreenGui"
screenGui.Name = "FloodFillGui" screenGui.Name = "FloodFillGui"
screenGui.Parent = game:GetService "CoreGui" screenGui.Parent = CoreGui
local containerFrame local containerFrame
dragBar, containerFrame, helpFrame, closeEvent = RbxGui.CreatePluginFrame( dragBar, containerFrame, helpFrame, closeEvent = RbxGui.CreatePluginFrame(