Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Created by chocken123
- local Toolbar = plugin:CreateToolbar("Model to part")
- local MainButton = Toolbar:CreateButton("Create part", "Creates a new part which is the size of the model's boundaries and located at the centre of its mass ", "rbxasset://textures/TerrainTools/icon_shape_cube.png")
- local SettingsButton = Toolbar:CreateButton("Part settings", "Choose type of part, material, color and name (in development)", "rbxasset://textures/GameSettings/ToolbarIcon.png")
- local ChangeHistoryService = game:GetService("ChangeHistoryService")
- local PartType = "Block"
- local PartMaterial = Enum.Material.Plastic
- local PartName = "Part"
- local FitBall = false
- local PartColor3
- local PartBrickColor
- local UsingColor3
- local PartTypeStrings = "Block\nWedge\nWedgePart\nBall\nMeshPart\nCylinder\nSpawnLocation"
- local HelpMessage = "-----\nPart type - type of part to fill model e.g. Ball, Cylinder or Wedge\nFit ball - Makes sure ball part type size fits into the model\nSize increment - increases the part size by set Vector3\nSize decrease - decreases the part size by set Vector3\n-----"
- local SizeIncrement = Vector3.new(0,0,0)
- local SizeDecrease = Vector3.new(0,0,0)
- local Order = 0
- local widgetInfo = DockWidgetPluginGuiInfo.new(
- Enum.InitialDockState.Float, -- Widget will be initialized in floating panel
- false, -- Widget will be initially enabled
- true, -- Don't override the previous enabled state
- 200, -- Default width of the floating window
- 200, -- Default height of the floating window
- 50, -- Minimum width of the floating window (optional)
- 50 -- Minimum height of the floating window (optional)
- )
- -- Create new widget GUI
- local SettingsWidget = plugin:CreateDockWidgetPluginGui("Part settings", widgetInfo)
- SettingsWidget.Title = "Part Settings"
- SettingsWidget.Enabled = false
- -- Ui object environment creation
- local LeftSide = {}
- local RightSide = {}
- local MainFrame = Instance.new("Frame")
- MainFrame.Size = UDim2.new(1,0,0.9,0)
- MainFrame.BackgroundColor3 = Color3.new(1,1,1)
- MainFrame.BorderSizePixel = 0
- --local Layout = Instance.new('UIListLayout')
- --Layout.Parent = MainFrame
- local UILayout = Instance.new("UIGridLayout")
- UILayout.Parent = MainFrame
- UILayout.CellPadding = UDim2.new(0,0,0,0)
- UILayout.CellSize = UDim2.new(0.5,0,0.1,0)
- UILayout.SortOrder = Enum.SortOrder.LayoutOrder
- local PartTypeBtn = Instance.new("TextButton")
- PartTypeBtn.Text = "Set part type as:"
- PartTypeBtn.BorderSizePixel = 0
- PartTypeBtn.TextSize = 13
- table.insert(LeftSide,PartTypeBtn)
- PartTypeBtn.LayoutOrder = Order
- Order = Order + 1
- local PartTypeBox = Instance.new("TextBox")
- PartTypeBox.Text = "Block"
- PartTypeBox.ClearTextOnFocus = false
- PartTypeBox.BorderSizePixel = 0
- PartTypeBox.TextSize = 13
- table.insert(RightSide,PartTypeBox)
- PartTypeBox.LayoutOrder = Order
- Order = Order + 1
- local FitBall = Instance.new("TextButton")
- FitBall.Text = "Fit ball"
- FitBall.BorderSizePixel = 0
- PartTypeBtn.TextSize = 13
- table.insert(LeftSide, FitBall)
- FitBall.LayoutOrder = Order
- Order = Order + 1
- local PrintSupportedTypes = Instance.new("TextButton")
- PrintSupportedTypes.Text = "Print supported part types"
- PrintSupportedTypes.BorderSizePixel = 0
- PartTypeBtn.TextSize = 13
- table.insert(RightSide, PrintSupportedTypes)
- PrintSupportedTypes.LayoutOrder = Order
- Order = Order + 1
- local IncrementSize = PartTypeBtn:Clone()
- IncrementSize.Text = "Set increment of:"
- table.insert(LeftSide, IncrementSize)
- IncrementSize.LayoutOrder = Order
- Order = Order + 1
- local IncrementSizeFrame = Instance.new("Frame")
- IncrementSizeFrame.BorderSizePixel = 0
- table.insert(RightSide, IncrementSizeFrame)
- IncrementSizeFrame.LayoutOrder = Order
- Order = Order + 1
- local IncrementSizeBox1 = Instance.new("TextBox")
- IncrementSizeBox1.Size = UDim2.new((1/3),0,1,0)
- IncrementSizeBox1.Text = "0"
- IncrementSizeBox1.TextSize = 13
- IncrementSizeBox1.BackgroundTransparency = 1
- IncrementSizeBox1.ClearTextOnFocus = false
- IncrementSizeBox1.Parent = IncrementSizeFrame
- local IncrementSizeBox2 = Instance.new("TextBox")
- IncrementSizeBox2.Size = UDim2.new((1/3),0,1,0)
- IncrementSizeBox2.Text = "0"
- IncrementSizeBox2.Position = UDim2.new((1/3),0,0,0)
- IncrementSizeBox2.TextSize = 13
- IncrementSizeBox2.BackgroundTransparency = 1
- IncrementSizeBox2.ClearTextOnFocus = false
- IncrementSizeBox2.Parent = IncrementSizeFrame
- local IncrementSizeBox3 = Instance.new("TextBox")
- IncrementSizeBox3.Size = UDim2.new((1/3),0,1,0)
- IncrementSizeBox3.Text = "0"
- IncrementSizeBox3.Position = UDim2.new((2/3),0,0,0)
- IncrementSizeBox3.TextSize = 13
- IncrementSizeBox3.ClearTextOnFocus = false
- IncrementSizeBox3.BackgroundTransparency = 1
- IncrementSizeBox3.Parent = IncrementSizeFrame
- local DecreaseSize = PartTypeBtn:Clone()
- DecreaseSize.Text = "Set decrease of:"
- table.insert(LeftSide, DecreaseSize)
- DecreaseSize.LayoutOrder = Order
- Order = Order + 1
- local DecreaseSizeFrame = Instance.new("Frame")
- DecreaseSizeFrame.BorderSizePixel = 0
- table.insert(RightSide, DecreaseSizeFrame)
- DecreaseSizeFrame.LayoutOrder = Order
- Order = Order + 1
- local DecreaseSizeBox1 = Instance.new("TextBox")
- DecreaseSizeBox1.Size = UDim2.new((1/3),0,1,0)
- DecreaseSizeBox1.Text = "0"
- DecreaseSizeBox1.TextSize = 13
- DecreaseSizeBox1.BackgroundTransparency = 1
- DecreaseSizeBox1.ClearTextOnFocus = false
- DecreaseSizeBox1.Parent = DecreaseSizeFrame
- local DecreaseSizeBox2 = Instance.new("TextBox")
- DecreaseSizeBox2.Size = UDim2.new((1/3),0,1,0)
- DecreaseSizeBox2.Text = "0"
- DecreaseSizeBox2.Position = UDim2.new((1/3),0,0,0)
- DecreaseSizeBox2.TextSize = 13
- DecreaseSizeBox2.BackgroundTransparency = 1
- DecreaseSizeBox2.ClearTextOnFocus = false
- DecreaseSizeBox2.Parent = DecreaseSizeFrame
- local DecreaseSizeBox3 = Instance.new("TextBox")
- DecreaseSizeBox3.Size = UDim2.new((1/3),0,1,0)
- DecreaseSizeBox3.Text = "0"
- DecreaseSizeBox3.Position = UDim2.new((2/3),0,0,0)
- DecreaseSizeBox3.TextSize = 13
- DecreaseSizeBox3.ClearTextOnFocus = false
- DecreaseSizeBox3.BackgroundTransparency = 1
- DecreaseSizeBox3.Parent = DecreaseSizeFrame
- local MiniOutput = Instance.new("TextLabel")
- MiniOutput.Text = ""
- MiniOutput.Size = UDim2.new(1,0,0.1,0)
- MiniOutput.Position = UDim2.new(0,0,0.9,0)
- MiniOutput.BorderSizePixel = 0
- MiniOutput.TextScaled = true
- table.insert(LeftSide, MiniOutput)
- local MaterialBtn = Instance.new("TextButton")
- MaterialBtn.Text = "Set material"
- MaterialBtn.BorderSizePixel = 0
- MaterialBtn.TextSize = 13
- table.insert(LeftSide,MaterialBtn)
- MaterialBtn.LayoutOrder = Order
- Order = Order + 1
- local MaterialBox = Instance.new("TextBox")
- MaterialBox.Text = "Plastic"
- MaterialBox.BorderSizePixel = 0
- MaterialBox.ClearTextOnFocus = false
- MaterialBox.TextSize = 13
- table.insert(RightSide,MaterialBox)
- MaterialBox.LayoutOrder = Order
- Order = Order + 1
- local NameBtn = Instance.new("TextButton")
- NameBtn.Text = "Set name"
- NameBtn.BorderSizePixel = 0
- NameBtn.TextSize = 13
- table.insert(LeftSide,NameBtn)
- NameBtn.LayoutOrder = Order
- Order = Order + 1
- local NameBtnBox = Instance.new("TextBox")
- NameBtnBox.Text = "Part"
- NameBtnBox.BorderSizePixel = 0
- NameBtnBox.TextSize = 13
- NameBtnBox.ClearTextOnFocus = false
- table.insert(RightSide,NameBtnBox)
- NameBtnBox.LayoutOrder = Order
- Order = Order + 1
- local DefaultBtn = Instance.new("TextButton")
- DefaultBtn.Text = "Reset default settings"
- DefaultBtn.BorderSizePixel = 0
- DefaultBtn.TextSize = 13
- table.insert(LeftSide,DefaultBtn)
- DefaultBtn.LayoutOrder = Order
- Order = Order + 1
- local Help = Instance.new("TextButton")
- Help.Text = "Help"
- Help.BorderSizePixel = 0
- Help.TextSize = 13
- table.insert(RightSide,Help)
- Help.LayoutOrder = Order
- Order = Order + 1
- MainFrame.Parent = SettingsWidget
- PartTypeBtn.Parent = MainFrame
- PartTypeBox.Parent = MainFrame
- PrintSupportedTypes.Parent = MainFrame
- FitBall.Parent = MainFrame
- IncrementSize.Parent = MainFrame
- IncrementSizeFrame.Parent = MainFrame
- DecreaseSize.Parent = MainFrame
- DecreaseSizeFrame.Parent = MainFrame
- MiniOutput.Parent = SettingsWidget
- DefaultBtn.Parent = MainFrame
- Help.Parent = MainFrame
- NameBtn.Parent = MainFrame
- NameBtnBox.Parent = MainFrame
- MaterialBox.Parent = MainFrame
- MaterialBtn.Parent = MainFrame
- -- Ui object environment colours management
- for i, v in ipairs(LeftSide) do
- if v:IsA("TextButton") or v:IsA("TextLabel") or v:IsA("TextBox") or v:IsA("Frame") then
- v.BackgroundTransparency = 0.75
- v.BackgroundColor3 = Color3.fromRGB(157, 157, 157)
- if v:IsA("TextButton") or v:IsA("TextLabel") or v:IsA("TextBox") and v~= MiniOutput then
- v.TextScaled = false
- v.TextSize = 13
- v.TextTruncate = Enum.TextTruncate.AtEnd
- end
- end
- end
- for i, v in pairs(RightSide) do
- if v:IsA("TextButton") or v:IsA("TextLabel") or v:IsA("TextBox") or v:IsA("Frame") then
- v.BackgroundTransparency = 0.75
- v.BackgroundColor3 = Color3.fromRGB(208, 208, 208)
- if v:IsA("TextButton") or v:IsA("TextLabel") or v:IsA("TextBox") and v ~= MiniOutput then
- v.TextScaled = false
- v.TextSize = 13
- v.TextTruncate = Enum.TextTruncate.AtEnd
- end
- end
- end
- MainFrame.BackgroundColor3 = settings().Studio.Theme:GetColor(Enum.StudioStyleGuideColor.MainBackground)
- MainFrame.BackgroundTransparency = 0
- -- Events/functions
- MainButton.Click:Connect(function()
- local Selection = game:GetService("Selection") -- Service required for getting selected objetcs
- -- if player selected at least one thing
- if #Selection:Get() >= 1 then
- -- Loop through selection
- for i,v in pairs(Selection:Get()) do
- if v:IsA("Model") == true then
- local NewPart = Instance.new("Part")
- -- Get model CFrame and size
- local cframe, size = v:GetBoundingBox()
- -- Checks if part can be party type enum
- local Succes, Response = pcall(function()
- local Temp = Enum.PartType[PartType]
- end)
- --
- if Succes == false then
- if PartType == "MeshPart" then
- NewPart = Instance.new("MeshPart")
- elseif PartType == "Wedge" then
- NewPart = Instance.new("WedgePart")
- elseif PartType == "WedgePart" then
- NewPart = Instance.new("WedgePart")
- elseif PartType == "SpawnLocation" then
- NewPart = Instance.new("SpawnLocation")
- else
- warn("---------\nList of part types\n"..(PartTypeStrings))
- end
- else
- NewPart = Instance.new("Part")
- NewPart.Shape = Enum.PartType[PartType]
- end
- -- Create new part
- NewPart.CFrame = cframe
- if PartType == "Ball" and FitBall == true then
- local FinalVec = size
- local low = math.huge
- local index
- local Vec = {
- x = size.x,
- y = size.y,
- z = size.z
- }
- for i, v in pairs(Vec) do
- if v < low then
- low = v
- end
- end
- NewPart.Size = Vector3.new(low,low,low)
- else
- NewPart.Size = size
- end
- NewPart.Material = PartMaterial
- NewPart.Size = NewPart.Size + SizeIncrement
- NewPart.Size = NewPart.Size - SizeDecrease
- NewPart.Name = PartName
- NewPart.FrontSurface = Enum.SurfaceType.Smooth
- NewPart.BackSurface = Enum.SurfaceType.Smooth
- NewPart.BottomSurface = Enum.SurfaceType.Smooth
- NewPart.LeftSurface = Enum.SurfaceType.Smooth
- NewPart.RightSurface = Enum.SurfaceType.Smooth
- NewPart.TopSurface = Enum.SurfaceType.Smooth
- NewPart.Parent = v
- Selection:Set({NewPart})
- -- Allow undoing
- ChangeHistoryService:SetWaypoint("Create part")
- end
- end
- end
- end)
- SettingsButton.Click:Connect(function()
- if SettingsWidget.Enabled == true then
- SettingsWidget.Enabled = false
- else
- SettingsWidget.Enabled = true
- end
- end)
- PartTypeBtn.MouseButton1Click:Connect(function()
- local Text = PartTypeBox.Text
- local Succes, Response = pcall(function()
- local Temp = Enum.PartType[Text]
- end)
- if Succes == false then
- if Text == "MeshPart" then
- PartType = "MeshPart"
- MiniOutput.Text = "Set part type to MeshPart"
- elseif Text == "Wedge" then
- PartType = "Wedge"
- MiniOutput.Text = "Set part type to Wedge"
- elseif Text == "WedgePart" then
- PartType = "WedgePart"
- MiniOutput.Text = "Set part type to Wedge"
- elseif Text == "SpawnLocation" then
- PartType = "SpawnLocation"
- MiniOutput.Text = "Set part type to Spawn location"
- else
- warn("---------\nList of part types\n"..(PartTypeStrings))
- PartTypeBox.Text = "Block"
- MiniOutput.Text = "See output for supported types"
- end
- else
- PartType = Text
- MiniOutput.Text = "Set part type to "..Text
- end
- end)
- PrintSupportedTypes.MouseButton1Click:Connect(function()
- warn("---------\nList of part types\n"..(PartTypeStrings))
- MiniOutput.Text = "See output for supported types"
- end)
- FitBall.MouseButton1Click:Connect(function()
- if FitBall == true then
- FitBall = false
- MiniOutput.Text = "Set fit ball to false"
- else
- FitBall = true
- MiniOutput.Text = "Set fit ball to true"
- end
- end)
- local IncrementDebounce = false
- IncrementSize.MouseButton1Click:Connect(function()
- if IncrementDebounce == false then
- IncrementDebounce = true
- local X
- local Y
- local Z
- if tonumber(IncrementSizeBox1.Text) ~= nil then
- X = math.abs(tonumber(IncrementSizeBox1.Text))
- if X > 1000 then
- X = 1000
- end
- else
- X = 0
- end
- if tonumber(IncrementSizeBox2.Text) ~= nil then
- Y = math.abs(tonumber(IncrementSizeBox2.Text))
- if Y > 1000 then
- Y = 1000
- end
- else
- Y = 0
- end
- if tonumber(IncrementSizeBox3.Text) ~= nil then
- Z = math.abs(tonumber(IncrementSizeBox3.Text))
- if Z > 1000 then
- Z = 1000
- end
- else
- Z = 0
- end
- SizeIncrement = Vector3.new(X,Y,Z)
- MiniOutput.Text = "Set increment of: "..(tostring(SizeIncrement))
- IncrementDebounce = false
- end
- end)
- local DecreaseDebounce = false
- DecreaseSize.MouseButton1Click:Connect(function()
- if DecreaseDebounce == false then
- DecreaseDebounce = true
- local X
- local Y
- local Z
- if tonumber(DecreaseSizeBox1.Text) ~= nil then
- X = math.abs(tonumber(DecreaseSizeBox1.Text))
- if X > 1000 then
- X = 1000
- end
- else
- X = 0
- end
- if tonumber(DecreaseSizeBox2.Text) ~= nil then
- Y = math.abs(tonumber(DecreaseSizeBox2.Text))
- if Y > 1000 then
- Y = 1000
- end
- else
- Y = 0
- end
- if tonumber(DecreaseSizeBox3.Text) ~= nil then
- Z = math.abs(tonumber(DecreaseSizeBox3.Text))
- if Z > 1000 then
- Z = 1000
- end
- else
- Z = 0
- end
- SizeDecrease = Vector3.new(X,Y,Z)
- MiniOutput.Text = "Set decrease of: "..(tostring(SizeDecrease))
- DecreaseDebounce = false
- end
- end)
- DefaultBtn.MouseButton1Click:Connect(function()
- PartType = "Block"
- FitBall = false
- SizeIncrement = Vector3.new(0,0,0)
- SizeDecrease = Vector3.new(0,0,0)
- NameBtnBox.Text = "Part"
- MaterialBox.Text = "Plastic"
- PartTypeBox.Text = "Block"
- IncrementSizeBox1.Text = "0"
- IncrementSizeBox2.Text = "0"
- IncrementSizeBox3.Text = "0"
- DecreaseSizeBox1.Text = "0"
- DecreaseSizeBox2.Text = "0"
- DecreaseSizeBox3.Text = "0"
- PartMaterial = Enum.Material.Plastic
- PartName = "Part"
- MiniOutput.Text = "Set default settings"
- end)
- Help.MouseButton1Click:Connect(function()
- warn(HelpMessage)
- MiniOutput.Text = "See output for details"
- end)
- MaterialBtn.MouseButton1Click:Connect(function()
- local Succes, Message = pcall(function()
- local Temp = Enum.Material[MaterialBox.Text]
- end)
- if Succes then
- PartMaterial = Enum.Material[MaterialBox.Text]
- MiniOutput.Text = "Set material to "..MaterialBox.Text
- else
- MaterialBox.Text = "Plastic"
- PartMaterial = Enum.Material.Plastic
- MiniOutput.Text = "Set material to Plastic"
- end
- end)
- NameBtn.MouseButton1Click:Connect(function()
- PartName = NameBtnBox.Text
- MiniOutput.Text = ("Set name to "..PartName)
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement