Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
DrawsDev committed Jul 4, 2024
0 parents commit 44905e9
Show file tree
Hide file tree
Showing 11 changed files with 224 additions and 0 deletions.
Binary file added Assets/Icons/icon_circular_beam.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Icons/icon_circular_beam_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Icons/icon_circular_beam_ok_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Icons/icon_circular_beam_resize.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Media/media1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Media/media2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Textures/beam1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Textures/beam2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
117 changes: 117 additions & 0 deletions CircularBeam.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
-- Types
export type BeamParams = {
Color : Color3,
LightEmission : number,
LightInfluence : number,
TextureId : number,
TextureLength : number,
TextureSpeed : number,
Transparency : number,
Segments : number,
Width0 : number,
Width1 : number
}

-- Variables
local DEFAULT_PARAMS : BeamParams = {
Color = Color3.new(255, 255, 255),
LightEmission = 1,
LightInfluence = 0,
TextureId = 18302051506,
TextureLength = 1,
TextureSpeed = 0,
Transparency = 0.5,
Segments = 10,
Width0 = 2,
Width1 = 2
}

-- Functions
local function CalculateCurveSize(radius : number)
return (radius * 4) / 3
end

local function CreateBeam(radius, beamParams, attachment0, attachment1, inverse, name, parent)
local curveSize = CalculateCurveSize(radius)

local beam = Instance.new("Beam")
beam.Color = ColorSequence.new(beamParams.Color or DEFAULT_PARAMS.Color)
beam.LightEmission = beamParams.LightEmission or DEFAULT_PARAMS.LightEmission
beam.LightInfluence = beamParams.LightInfluence or DEFAULT_PARAMS.LightInfluence
beam.Texture = "rbxassetid://" .. (beamParams.TextureId or DEFAULT_PARAMS.TextureId)
beam.TextureLength = beamParams.TextureLength or DEFAULT_PARAMS.TextureLength
beam.TextureSpeed = beamParams.TextureSpeed or DEFAULT_PARAMS.TextureSpeed
beam.Transparency = NumberSequence.new(beamParams.Transparency or DEFAULT_PARAMS.Transparency)
beam.Segments = beamParams.Segments or DEFAULT_PARAMS.Segments
beam.Width0 = beamParams.Width0 or DEFAULT_PARAMS.Width0
beam.Width1 = beamParams.Width1 or DEFAULT_PARAMS.Width1
beam.Name = name
beam.Parent = parent

if inverse then
beam.Attachment0, beam.Attachment1 = attachment1, attachment0
beam.CurveSize0, beam.CurveSize1 = curveSize, -curveSize
else
beam.Attachment0, beam.Attachment1 = attachment0, attachment1
beam.CurveSize0, beam.CurveSize1 = -curveSize, curveSize
end

return beam
end

local function CreateAttachment(position, name, parent)
local attachment = Instance.new("Attachment")
attachment.Position = position
attachment.Orientation = Vector3.new(0, 90, 180)
attachment.Name = name
attachment.Parent = parent
return attachment
end

local function CreateRoot()
local root = Instance.new("Part")
root.CastShadow = false
root.Transparency = 1
root.Size = Vector3.one
root.Anchored = true
root.CanCollide = false
root.CanTouch = false
root.Name = "CircularBeam"
return root
end

local function CreateCircularBeam(radius, beamParams)
local root = CreateRoot()
local attachment0 = CreateAttachment(Vector3.new( radius, root.Size.Y / 2, 0), "Attachment0", root)
local attachment1 = CreateAttachment(Vector3.new(-radius, root.Size.Y / 2, 0), "Attachment1", root)
local beam0 = CreateBeam(radius, beamParams, attachment0, attachment1, false, "Beam0", root)
local beam1 = CreateBeam(radius, beamParams, attachment0, attachment1, true, "Beam1", root)
return root
end

-- Class
local CircularBeam = {}
CircularBeam.__index = CircularBeam

-- Methods
function CircularBeam.Create(radius : number, beamParams : BeamParams?)
return CreateCircularBeam(radius, if not beamParams then DEFAULT_PARAMS else beamParams)
end

function CircularBeam.Resize(circularBeam : BasePart, radius : number)
local curveSize = CalculateCurveSize(radius)

local attachment0 = circularBeam:FindFirstChild("Attachment0")
local attachment1 = circularBeam:FindFirstChild("Attachment1")
local beam0 = circularBeam:FindFirstChild("Beam0")
local beam1 = circularBeam:FindFirstChild("Beam1")

if attachment0 and attachment1 and beam0 and beam1 then
attachment0.Position = Vector3.new(radius, circularBeam.Size.Y / 2, 0)
attachment1.Position = Vector3.new(-radius, circularBeam.Size.Y / 2, 0)
beam0.CurveSize0, beam0.CurveSize1 = -curveSize, curveSize
beam1.CurveSize0, beam1.CurveSize1 = curveSize, -curveSize
end
end

return CircularBeam
Binary file added ResizeGui.rbxm
Binary file not shown.
107 changes: 107 additions & 0 deletions Script.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
local Selection = game:GetService("Selection")
local Workspace = game:GetService("Workspace")

local Camera = Workspace.Camera

local folder = script.Parent
local circularBeamModule = require(folder.CircularBeam)
local toolbar = plugin:CreateToolbar("Circular Beam")
local createButton = toolbar:CreateButton(
"New Circular Beam",
"Create a new circular beam.",
"rbxassetid://18329485600"
)
local resizeButton = toolbar:CreateButton(
"Resize Circular Beam",
"Resize the selected circular beam.",
"rbxassetid://18329700935"
)
local resizeWidget = plugin:CreateDockWidgetPluginGui(
"resizeCircularBeam",
DockWidgetPluginGuiInfo.new(
Enum.InitialDockState.Float,
false,
true,
250,
60,
250,
60
)
)
local resizeGui = folder.ResizeGui
local resizeGuiSet = resizeGui.Main.Set
local resizeGuiValue = resizeGui.Main.Value
local resizeGuiInfo = resizeGui.Info

resizeWidget.Title = "Resize Circular Beam"
resizeGui.Parent = resizeWidget

local function SetCursor(cursorAsset)
plugin:GetMouse().Icon = cursorAsset
end

local function GetPosition()
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {}
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
raycastParams.IgnoreWater = false

local raycastResult = Workspace:Raycast(Camera.CFrame.Position, Camera.CFrame.LookVector * 1000, raycastParams)
if raycastResult then
return raycastResult.Position
else
return Camera.CFrame.Position + Camera.CFrame.LookVector * 100
end
end

resizeGuiSet.MouseEnter:Connect(function()
resizeGuiSet.BackgroundColor3 = Color3.fromHex("35B5FF")
SetCursor("rbxasset://SystemCursors/PointingHand")
end)

resizeGuiSet.MouseLeave:Connect(function()
resizeGuiSet.BackgroundColor3 = Color3.fromHex("00A2FF")
SetCursor("")
end)

resizeGuiSet.MouseButton1Down:Connect(function()
resizeGuiSet.BackgroundColor3 = Color3.fromHex("006DCC")
end)

resizeGuiSet.MouseButton1Up:Connect(function()
resizeGuiSet.BackgroundColor3 = Color3.fromHex("00A2FF")
end)

resizeGui.Main.Set.MouseButton1Click:Connect(function()
local size = tonumber(resizeGui.Main.Value.Text)
if size then
for _, child in Selection:Get() do
circularBeamModule.Resize(child, size)
end
end
end)

createButton.Click:Connect(function()
local new = circularBeamModule.Create(5)
new.Position = GetPosition()
new.Parent = Workspace

Selection:Set({new})
end)

resizeButton.Click:Connect(function()
resizeWidget.Enabled = not resizeWidget.Enabled
end)

while true do
task.wait(1)

local circularBeams = 0
for _, child in Selection:Get() do
if child.Name == "CircularBeam" and child:FindFirstChild("Beam0") then
circularBeams += 1
end
end

resizeGuiInfo.Text = `Apply to {circularBeams} selected circular beams.`
end

0 comments on commit 44905e9

Please sign in to comment.