Skip to content

Repository files navigation

ReGizmo

ReGizmo is a gizmo drawing library aiming to give access to gizmos from anywhere.

Features:

  • Legacy/URP/HDRP Support
  • Call from anywhere and it will render to both Scene View and Game View
  • Sample-Space AA and Filtering, enjoy smooth lines in the Scene View
    Only applies to 2D Shapes and Lines
  • Draw from using scopes and avoid doing manual translations
  • Font rendering, both in glyph and SDF form
    Comes with tool to generate MSDF/SDF from your own font (see third party section)
  • Visualize Raycast, Boxcast, etc.

Installation

This package is configured as a Unity UPM Package so you can install it through the Package Manager with this URL:
https://github.com/Refsa/ReGizmo.git#v1.0.0

Notes

Requires that depth texture is enabled. This is handled slight different depending on the active render pipeline.

  • Built-In: ReGizmo will automatically set the depth mode flag on any active cameras
  • URP: The "Depth Texture" has to be enabled in the Universal Render Pipeline Asset

General Usage

Since ReGizmo is available from anywhere it can be called from Update, OnDrawGizmos, an Editor Window or anywhere else. Just make sure it is called every frame/repaint event since your draw calls dont persist.

usingReGizmo.Drawing;publicclassSomeClass:MonoBehaviour{[SerializeField]Texture2DiconTexture;voidUpdate(){// Position A, Position B, Color, WidthReDraw.Line(Vector3.zero,Vector3.one,Color.green,1f);// Position, Direction, Color, WidthReDraw.Arrow(Vector3.zero,Vector3.up,Color.green,1f);// Position, Size, ColorReDraw.Sphere(Vector3.zero,Vector3.one,Color.red);// Texture, Position, SizeReDraw.Icon(iconTexture,Vector3.zero,Size.Pixels(32f));// Position, Normal, DrawMode, SizeReDraw.Circle(Vector3.zero,Vector3.right,DrawMode.AxisAligned,Size.Units(2f));using(newTransformScope(transform)){ReDraw.Cube(Color.red);}}}

Available Draw Calls

Most, if not all, drawing methods have overrides to fit any situation. Dont want to specify color or position? It can do that.

// 3D PrimitivesReDraw.Quad(Vector3position,Quaternionrotation,Vector3scale,Colorcolor);ReDraw.Sphere(Vector3position,Quaternionrotation,Vector3scale,Colorcolor);ReDraw.Cube(Vector3position,Quaternionrotation,Vector3scale,Colorcolor);ReDraw.Capsule(Vector3position,Quaternionrotation,Vector3scale,Colorcolor);ReDraw.Pyramid(Vector3position,Quaternionrotation,Vector3scale,Colorcolor);ReDraw.Octahedron(Vector3position,Quaternionrotation,Vector3scale,Colorcolor);ReDraw.Icosahedron(Vector3position,Quaternionrotation,Vector3scale,Colorcolor);ReDraw.Cylinder(Vector3position,Quaternionrotation,Vector3scale,Colorcolor);// 3D Wire PrimitivesReDraw.WireSphere(...);ReDraw.WireCube(...);ReDraw.WireCapsule(...);// Custom MeshesReDraw.Mesh(Meshmesh,Vector3position,Quaternionrotation,Vector3scale,Colorcolor);ReDraw.WireframeMesh(Meshmesh,Vector3position,Quaternionrotation,Vector3scale,Colorcolor);// Font/TextReDraw.TextSDF("someText", ...);ReDraw.Text("someText", ...);// LinesReDraw.Line(Vector3p1,Vector3p2,Colorcolor1,Colorcolor2,floatwidth1,floatwidth2);ReDraw.Line(Vector3p1,Vector3p2,Colorcolor,floatwidth);ReDraw.Ray(Vector3origin,Vector3direction,Colorcolor,floatwidth);ReDraw.Arrow(Vector3position,Vector3direction,ArrowCaparrowCap,floatlength,ReGizmo.Drawing.SizearrowSize,floatlineWidthPixels,Colorcolor);ReDraw.PolyLine(PolyLinepolyLine);// More on this below// 2D ShapesReDraw.Circle(Vector3position,Vector3normal,DrawModedrawMode,Sizeradius,FillModefillMode,Colorcolor);ReDraw.Triangle(Vector3position,Vector3normal,DrawModedrawMode,Sizeradius,FillModefillMode,Colorcolor);ReDraw.Rect(Rectrect,Colorcolor,floatdepth=0f);// 3D PhysicsReDraw.Raycast(Vector3origin,Vector3direction,floatdistance=float.MaxValue,intlayerMask=~0);// These are also available as extension methods to BoxCollider, SphereCollider and CapsuleCollider under ReGizmo.Drawing.ExtReDraw.BoxCast(Vector3center,Vector3direction,Vector3halfExtents,Quaternionorientation,floatdistance=float.MaxValue,intlayerMask=~0);ReDraw.SphereCast(Vector3origin,Vector3direction,floatradius,floatdistance=float.MaxValue,intlayerMask=~0);ReDraw.CapsuleCast(Vector3point1,Vector3point2,floatradius,Vector3direction,floatdistance=float.MaxValue,intlayerMask=~0);// These will also display text with the number of hitsReDraw.OverlapBox(Vector3center,Vector3halfExtents,Quaternionorientation,intlayerMask=~0);ReDraw.OverlapSphere(Vector3origin,floatradius,intlayerMask=~0);ReDraw.OverlapCapsule(Vector3point1,Vector3point2,floatradius,intlayerMask=~0);// 2D PhysicsReDraw.Raycast2D(Vector2origin,Vector2direction,floatdistance=float.MaxValue,intlayerMask=~0);// These are also available as extension methods to BoxCollider2D, SphereCollider2D and CapsuleCollider2D under ReGizmo.Drawing.ExtReDraw.BoxCast2D(Vector2origin,Vector2size,floatangle,Vector2direction,floatdistance=float.MaxValue,intlayerMask=~0);ReDraw.CircleCast2D(Vector2origin,floatradius,Vector2direction,floatdistance=float.MaxValue,intlayerMask=~0);ReDraw.CapsuleCast2D(Vector2origin,Vector2size,CapsuleDirection2DcapsuleDirection,floatangle,Vector2direction,floatdistance=float.MaxValue,intlayerMask=~0);// These will also display text with the number of hitsReDraw.OverlapBox2D(Vector2origin,Vector2size,floatangle,intlayerMask=~0);ReDraw.OverlapCircle2D(Vector2origin,floatradius,intlayerMask=~0);ReDraw.OverlapCapsule2D(Vector2origin,Vector2size,CapsuleDirection2DcapsuleDirection,floatangle,intlayerMask=~0);

Poly Lines

Poly Lines works by first pushing points into the PolyLine struct. This is done with the help of the Builder Pattern to also configure other settings for the PolyLine drawing.

varpolyLine=newPolyLine().Point(Vector3.zero).Point(Vector3.one).Point(Vector3.right).ClosedLoop()// If you want the start and end point to connect.Draw();

You can turn off disposing of the struct if you want to store it as a member variable to avoid recreating it everytime you want to render it.

PolyLinepolyLine=newPolyLine().Point(Vector3.zero).Point(Vector3.one).Point(Vector3.right).DontDispose();
...polyLine.Draw();
...// Just make sure to dispose of it when you're done using itpolyLine.Dispose();

You can also use it with a using scope that makes sure it automatically calls Draw and disposes itself.

using(varpolyLine=PolyLine.Scope()){polyLine.Point(Vector3.zero).Point(Vector3.one);}

Scopes

Scopes exists to share data between different draw calls and restoring the original values afterwards.

ColorScopePositionScope
ScaleScope
RotationScope
TransformScope
using(newColorScope(Color.red)){ReDraw.Sphere(...);
...}

Size

Some draw calls takes the Size struct to control the scale of the drawing. You can pick between Pixels, Units or Percent by using the static methods of the same name on the Size struct.

// Size will be in pixelsSize.Pixels(32f);// Size will be in world unitsSize.Units(2f);// Size will be a percent of the overall screen resolutionSize.Percent(0.25f);

Fill Mode

Some draw calls takes a FillMode enum, this controls if the shape should be filled or just an outline.

FillMode.OutlineFillMode.Fill

Draw Mode

Some draw calls takes a DrawMode enum, this controls the alignment/billboarding of the drawing.

// Shape is aligned with the given normal axis in world spaceDrawMode.AxisAligned// Shape is billboarding but fixed around the given normal axisDrawMode.BillboardAligned
// Shape is fully billboarded and will always face the cameraDrawMode.BillboardFree

Arrow Cap

Arrows can have different types of caps

Triangle,
Cone,
Cube,
Sphere

Third Party Licenses

msdfgen / msdf-atlas-gen

msdfgen license
msdf-atlas-gen license

This library makes use of this library to generate MSDF/SDF font atlases.

About

Immediate-Mode Gizmos for unity

Topics

Resources

Stars

9 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages