Improved Roblox Gizmos - Refactored with More Features and Optimizations

Get on the Marketplace


Improved Roblox Gizmos is a Refactored and more Advanced version of Gizmos by @sg3cko.


Why Improved Gizmos?

  • Refactored Code for reusability, readability, edits, and general optimization of code.
  • Supports 7+ more Shapes including Frustum, Cone, Cylinders, Arrow, Cones, etc..
  • Attempts of better quality of visibility and quality while attempting to keeping performance low via Rendering Optimization.

Features

Settings & Configuration

Inside Consts, You will access Constants and Configurations that you can change to alter the behavior of Gizmos.

  • Supports LODs with Configuration and Basic Culling.
  • Dynamic Edge Rendering with the SimplifyComplexEdges
  • Defaults Configuration (e.g. ArrowHeadSize)
  • Easily add more colors

--!strict
--!native

export type AvailableColors = ("red" | "green" | "blue" | "yellow" | "cyan" | "magenta" | "orange" | "purple" | "white" | "grey" | "gray" | "black") | Color3

local Constants = {
	GizmosName = "__gizmos__",
	
	GizmosTag = "__GIZMOS",
	GizmosLabelTag = "__GIZMOSLABEL",
	GizmosGuiTag = "__GIZMOSGUI",

	Settings = {
		EnableCulling = true,
		ShowCullingBounds = false, -- draws a debug box around each gizmo's cull bounds (for dev debugging)
		CullPadding = 0, -- extra world-space padding added to every cull bounding box

		SimplifyComplexEdges = true, -- uses the camera's direction to create a seamless illusion of an edge

		EnableLevelOfDetail = true,
		LODStepDistance = 12,

		AlwaysOnTop = true,

		CircleSegments = 12,
		PointSize = 0.1,

		ArrowHeadSize = 0.07,
		ArrowHeadHeight = 0.1,
	},
	
	LODSteps = {
		"24",
		"16",
		"12",
		"8"
	},

	Colors = {
		["red"] = Color3.new(1, 0, 0),
		["green"] = Color3.new(0, 1, 0),
		["blue"] = Color3.new(0, 0, 1),
		["yellow"] = Color3.new(1, 1, 0),
		["cyan"] = Color3.new(0, 1, 1),
		["magenta"] = Color3.new(1, 0, 1),
		["orange"] = Color3.new(1, 0.5, 0),
		["purple"] = Color3.new(0.5, 0, 1),
		["white"] = Color3.new(1, 1, 1),
		["gray"] = Color3.new(0.5, 0.5, 0.5),
		["grey"] = Color3.new(0.5, 0.5, 0.5),
		["black"] = Color3.new(0, 0, 0)
	}
}
return Constants
Examples / Showcase

In this example we'll make Gizmos which all spin.

SimplifyComplexEdges = true

SimplifyComplexEdges = false


Code
local RunService = game:GetService("RunService")

local Gizmos = require(game.ReplicatedStorage.Modules.Util.Gizmos)

local Origin = CFrame.new(0, 8, 0)
local SpinCF = CFrame.identity
local SpinSpeed = 1

local Colors = {
	"red","green","blue","yellow",
	"cyan","magenta","orange","purple",
	"white","black"
}

local GridWidth = 5
local Spacing = 8

local function Cell(index)
	index -= 1

	local x = index % GridWidth
	local z = math.floor(index / GridWidth)

	return CFrame.new(
		(x - (GridWidth - 1) / 2) * Spacing,
		0,
		z * Spacing
	)
end

local OrderedGizmos = {

	{
		name = "Line",
		draw = function(cf)
			local p = cf.Position
			Gizmos:DrawLine(
				p + Vector3.new(-2,0,0),
				p + Vector3.new(2,0,0)
			)
		end
	},

	{
		name = "Ray",
		draw = function(cf)
			Gizmos:DrawRay(
				cf.Position,
				cf.LookVector * 4
			)
		end
	},

	{
		name = "Path",
		draw = function(cf)
			local p = cf.Position

			Gizmos:DrawPath({
				p + Vector3.new(-2,0,-2),
				p + Vector3.new(0,2,0),
				p + Vector3.new(2,0,-2),
				p + Vector3.new(2,0,2),
			}, true, .15)
		end
	},

	{
		name = "Point",
		draw = function(cf)
			Gizmos:DrawPoint(cf.Position,1)
		end
	},

	{
		name = "Cube",
		draw = function(cf)
			Gizmos:DrawCube(cf, Vector3.one * 3)
		end
	},

	{
		name = "Circle",
		draw = function(cf)
			Gizmos:DrawCircle(cf.Position,2,cf.UpVector)
		end
	},

	{
		name = "Sphere",
		draw = function(cf)
			Gizmos:DrawSphere(cf,2)
		end
	},

	{
		name = "Pyramid",
		draw = function(cf)
			Gizmos:DrawPyramid(cf,3,4)
		end
	},

	{
		name = "CFrame",
		draw = function(cf)
			Gizmos:DrawCFrame(cf,3)
		end
	},

	{
		name = "Arrow",
		draw = function(cf)
			Gizmos:DrawArrow(
				cf.Position,
				cf.LookVector * 4
			)
		end
	},

	{
		name = "Cylinder",
		draw = function(cf)
			Gizmos:DrawCylinder(cf,4,1.25)
		end
	},

	{
		name = "Frustum",
		draw = function(cf)
			Gizmos:DrawFrustum(
				cf,
				Vector2.new(2,2),
				Vector2.new(5,5),
				2,
				6
			)
		end
	},

	{
		name = "Cone",
		draw = function(cf)
			Gizmos:DrawCone(cf,2,4)
		end
	},

	{
		name = "Capsule",
		draw = function(cf)
			Gizmos:DrawCapsule(cf,1.2,4)
		end
	},

	{
		name = "Torus",
		draw = function(cf)
			Gizmos:DrawTorus(cf,2.5,.6)
		end
	},

	{
		name = "Tetrahedron",
		draw = function(cf)
			Gizmos:DrawTetrahedron(cf,3)
		end
	},
}

RunService.Heartbeat:Connect(function(dt)

	local angle = dt * SpinSpeed

	SpinCF *= CFrame.Angles(
		angle * 0.7,
		angle,
		angle * 0.5
	)

	for i, gizmo in ipairs(OrderedGizmos) do

		Gizmos:SetColor(Colors[((i - 1) % #Colors) + 1])

		local cf = Origin * Cell(i) * SpinCF

		gizmo.draw(cf)

		Gizmos:SetColor("white")
		Gizmos:DrawText(
			cf.Position + Vector3.new(0,-3,0),
			gizmo.name,
			8
		)
	end

	Gizmos:SetColor("white") -- just to make sure nothing else is affected
end)

Performance

No exact details/records have been done to meet a formal benchmark between Gizmos, and Improved Gizmos.

A thesis would be that because Improved Gizmos supports Culling, and LOD Rendering it should generally be more preformant In terms of Culling and Simplification of Gizmos of high detail from a farther distance.


Alternatives


Download via Roblox

1 Like