Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ChangeHistoryService = game:GetService("ChangeHistoryService")
- local toolbar = plugin:CreateToolbar("RoCurves")
- local newScriptButton = toolbar:CreateButton("RoCurves", "Generate Smooth Curves.", "rbxassetid://6840838833")
- local Opened = false
- local RoCurvesInfo = DockWidgetPluginGuiInfo.new(
- Enum.InitialDockState.Left,
- false, -- Widget will be initially enabled
- false, -- Don't override the previous enabled state
- 300, -- Default width of the floating window
- 300, -- Default height of the floating window
- 300, -- Minimum width of the floating window (optional)
- 400 -- Minimum height of the floating window (optional)
- )
- local PluginWidget = plugin:CreateDockWidgetPluginGui("RoCurves", RoCurvesInfo)
- PluginWidget.Title = "Curve Settings"
- local RoCurveGui = script.Parent.RoCurveGui
- RoCurveGui.Parent = PluginWidget
- local SelectOne = RoCurveGui.SelectOne
- local SelectTwo = RoCurveGui.SelectTwo
- local SelectThree = RoCurveGui.SelectThree
- local PartNumber = RoCurveGui.PartNumber
- local Generate = RoCurveGui.Generate
- local Preview = RoCurveGui.Preview
- --Variables
- local CurvePart1 = nil
- local CurvePart2 = nil
- local CurvePart3 = nil
- local Button1Active = false
- local Button2Active = false
- local Button3Active = false
- local function MouseSelector(Target)
- --if Opened then
- if Button1Active == true then
- Button1Active = false
- Button2Active = false
- Button3Active = false
- CurvePart1 = Target
- elseif Button2Active == true then
- Button1Active = false
- Button2Active = false
- Button3Active = false
- CurvePart2 = Target
- elseif Button3Active == true then
- Button1Active = false
- Button2Active = false
- Button3Active = false
- CurvePart3 = Target
- end
- end
- --Handle Opening/Closing the Plugin.
- newScriptButton.Click:Connect(function()
- if Opened then
- PluginWidget.Enabled = false
- Opened = false
- else
- --Handle the Mouse.
- plugin:Activate(false) -- gain non exclusive access to the mouse
- local mouse = plugin:GetMouse() -- get the PluginMouse
- mouse.Button1Down:Connect(function()
- MouseSelector(mouse.Target)
- end)
- PluginWidget.Enabled = true
- Opened = true
- end
- end)
- --Handle the ButtonPlugins
- SelectOne.MouseButton1Click:Connect(function()
- Button1Active = true
- Button2Active = false
- Button3Active = false
- plugin:Activate(false) -- gain non exclusive access to the mouse
- local mouse = plugin:GetMouse() -- get the PluginMouse
- mouse.Button1Down:Connect(function()
- MouseSelector(mouse.Target)
- end)
- end)
- SelectTwo.MouseButton1Click:Connect(function()
- Button1Active = false
- Button2Active = true
- Button3Active = false
- plugin:Activate(false) -- gain non exclusive access to the mouse
- local mouse = plugin:GetMouse() -- get the PluginMouse
- mouse.Button1Down:Connect(function()
- MouseSelector(mouse.Target)
- end)
- end)
- SelectThree.MouseButton1Click:Connect(function()
- print("Middle Part Selected!")
- Button1Active = false
- Button2Active = false
- Button3Active = true
- plugin:Activate(false) -- gain non exclusive access to the mouse
- local mouse = plugin:GetMouse() -- get the PluginMouse
- mouse.Button1Down:Connect(function()
- MouseSelector(mouse.Target)
- end)
- end)
- --
- PartNumber:GetPropertyChangedSignal("Text"):Connect(function()
- PartNumber.Text = PartNumber.Text:gsub('%D+', '');
- end)
- local function RunCode(ActionName)
- if ActionName == "EndPreview" then
- if game.Workspace:FindFirstChild("PreviewCurve") then
- game.Workspace:FindFirstChild("PreviewCurve"):Destroy()
- end
- Preview.BackgroundColor3 = Color3.fromRGB(253, 245, 9)
- Preview.Text = "PREVIEW"
- else
- local PartMinimum = 3 --Default
- local PartNum = PartNumber.Text
- local PartCount = 0
- if CurvePart1 and CurvePart2 and CurvePart3 then
- local Button1Active = false
- local Button2Active = false
- local Button3Active = false
- if PartNumber.Text ~= " " and PartNumber.Text ~= "" then
- if tonumber(PartNumber.Text) > PartMinimum then
- PartCount = tonumber(PartNum)
- else
- PartCount = PartMinimum
- end
- else
- PartCount = PartMinimum
- end
- ChangeHistoryService:SetWaypoint("Waypoint Before")
- local NewFolder = Instance.new("Folder")
- local FinalFolder = Instance.new("Folder")
- if ActionName == "Generate" then
- NewFolder.Name = "PartHolder"
- FinalFolder.Name = "Curve"
- else
- NewFolder.Name = "PreviewPartHolder"
- FinalFolder.Name = "PreviewCurve"
- end
- NewFolder.Parent = game.Workspace
- FinalFolder.Parent = game.Workspace
- local function QuadraticBezier(t,p0,p1,p2)
- return (1-t)^2*p0+2*(1-t)*t*p1+t^2*p2;
- end;
- local Part0 = CurvePart1 --<Start point
- local Part1 = CurvePart3 --<'Curve' Point
- local Part2 = CurvePart2 --<End Point
- local Start1Orientation = CurvePart1.Orientation
- local FinishOrientation = CurvePart2.Orientation
- local Increment = 1/PartCount
- for t = 0,1,Increment do
- local TargetPosition = QuadraticBezier(t , Part0.Position, Part1.Position, Part2.Position);
- local Part = Instance.new("Part")
- Part.Name = t
- Part.Size = Vector3.new(.05,.05,.05)
- if ActionName == "Generate" then
- Part.Material = Part0.Material
- Part.Color = Part0.Color
- else
- Part.Material = Enum.Material.SmoothPlastic
- Part.Color = Color3.new(0.164706, 0.65098, 0.027451)
- Part.Transparency = .2
- end
- Part.Anchored = true
- Part.CFrame = CFrame.new(TargetPosition, QuadraticBezier(t + 0.01 , Part0.Position, Part1.Position, Part2.Position))
- Part.Parent = NewFolder
- end
- local Start = Increment
- local JustCreated = nil
- local function StretchPart()
- local pos1 = nil
- local pos2 = nil
- if JustCreated == nil then
- pos1 = NewFolder:FindFirstChild(tostring(0)).Position
- Start = 0 + Increment
- else
- pos1 = NewFolder:FindFirstChild(tostring(Start)).Position
- --pos1 = JustCreated.Position
- Start = Start + Increment
- end
- if Start < 1 then
- pos2 = NewFolder:FindFirstChild(tostring(Start)).Position
- local newpart = Instance.new("Part")
- --Part front at pos1 and back and pos2
- local v = (pos1 - pos2)
- newpart.Anchored = true
- newpart.CanCollide = false
- newpart.Name = NewFolder:FindFirstChild(tostring(Start)).Name
- newpart.Size = Vector3.new(1,CurvePart1.Size.Y,v.Magnitude)
- newpart.CFrame = CFrame.new(pos2 + .5*v, pos1) * CFrame.new(-.5,0,0)
- if ActionName == "Generate" then
- newpart.Material = NewFolder:FindFirstChild(tostring(Start)).Material
- newpart.Color = NewFolder:FindFirstChild(tostring(Start)).Color
- else
- newpart.Material = Enum.Material.SmoothPlastic
- newpart.Color = Color3.new(0.164706, 0.65098, 0.027451)
- newpart.Transparency = .2
- end
- newpart.Parent = FinalFolder
- JustCreated = newpart
- wait()
- StretchPart()
- end
- end
- StretchPart()
- Start = Start - Increment
- local pos1 = nil
- --Now for the final part
- local Mark = 0
- for i, v in pairs(FinalFolder:GetChildren()) do
- if tonumber(v.Name) > Mark then
- Mark = tonumber(v.Name)
- pos1 = NewFolder:FindFirstChild(tostring(Mark)).Position
- end
- end
- local pos2 = CurvePart2.Position
- local newpart = Instance.new("Part")
- local v = (pos1 - pos2)
- newpart.Anchored = true
- newpart.CanCollide = false
- newpart.Size = Vector3.new(1 ,CurvePart1.Size.Y,v.Magnitude)
- newpart.CFrame = CFrame.new(pos2 + .5*v, pos1) * CFrame.new(-.5,0,0)
- if ActionName == "Generate" then
- newpart.Material = NewFolder:FindFirstChild(tostring(Start)).Material
- newpart.Color = NewFolder:FindFirstChild(tostring(Start)).Color
- else
- newpart.Material = Enum.Material.SmoothPlastic
- newpart.Color = Color3.new(0.164706, 0.65098, 0.027451)
- newpart.Transparency = .2
- end
- newpart.Parent = FinalFolder
- JustCreated = newpart
- --
- NewFolder:Destroy()
- --for i, v in pairs(FinalFolder:GetChildren()) do
- --local lookVector = v.CFrame.lookVector.X
- --end
- ChangeHistoryService:SetWaypoint("Waypoint After")
- if ActionName == "Generate" then
- CurvePart1 = nil
- CurvePart2 = nil
- CurvePart3 = nil
- end
- end
- end
- end
- local ActivePreview = false
- Generate.MouseButton1Click:Connect(function()
- if ActivePreview == true then
- ActivePreview = false
- RunCode("EndPreview")
- end
- wait()
- RunCode("Generate")
- end)
- Preview.MouseButton1Click:Connect(function()
- if ActivePreview == false then
- ActivePreview = true
- Preview.BackgroundColor3 = Color3.fromRGB(255, 1, 1)
- Preview.Text = "STOP PREVIEW"
- RunCode("Preview")
- else
- ActivePreview = false
- RunCode("EndPreview")
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement