Skip to content

rendering

World-to-screen projection, viewport control, and convex hull helpers for drawing overlays.

rendering.WorldToScreen(worldPos: Vector3, viewport: Vector2?) -> (screenPos: Vector2, onScreen: boolean, depth: number)

Projects a world space point to screen space using the active camera, optionally overriding the viewport size for this call.

local pos, onScreen, depth = rendering.WorldToScreen(Vector3.new(0, 5, 0))
if onScreen then print(pos.X, pos.Y, depth) end

rendering.IsOnScreen(worldPos: Vector3) -> boolean

Returns true if the given world space point projects inside the current viewport bounds and is in front of the camera.

if rendering.IsOnScreen(part.Position) then
-- draw something
end

rendering.MassProject(points: {Vector3}) -> {[integer]: {Position: Vector2, OnScreen: boolean, Depth: number}}

Projects a batch of world space points in one call, returning a table of screen results in the same order, entries with invalid Vector3 values are skipped.

local results = rendering.MassProject({Vector3.new(0,0,0), Vector3.new(10,0,0)})
for i, r in results do print(i, r.Position, r.OnScreen, r.Depth) end

rendering.SetViewport(width: number, height: number)

Sets the fallback viewport size used when the Camera’s ViewportSize property cannot be read, values less than or equal to zero are ignored.

rendering.SetViewport(2560, 1440)

rendering.GetViewport() -> Vector2

Returns the currently configured fallback viewport size as a Vector2.

local vp = rendering.GetViewport()
print(vp.X, vp.Y)

rendering.ConvexHull2D(points: {Vector2}) -> {[integer]: Vector2}

Computes the 2D convex hull of a set of screen space points using Andrew’s monotone chain algorithm, returning the hull vertices in counter-clockwise order.

local hull = rendering.ConvexHull2D({Vector2.new(0,0), Vector2.new(10,0), Vector2.new(5,10)})
for i, v in hull do print(v.X, v.Y) end

rendering.ConvexHull3D(points: {Vector3}) -> {[integer]: {Vector3, Vector3, Vector3}}

Computes the 3D convex hull of a set of world space points using an incremental algorithm, returning an array of triangular faces, each a 3-element array of Vector3 corners, degenerate input returns an empty table.

local faces = rendering.ConvexHull3D(pointCloud)
for i, tri in faces do print(tri[1], tri[2], tri[3]) end