Vectrosity - Fast and Easy Line Drawing

Version 5.4.2 available now! (link not available)

Vectrosity is a complete line-drawing solution, which uses Unity’s canvas system for GUI lines, and meshes for 3D lines drawn inside the scene. You can easily make lines, curves, end caps, textures and more, with a simple yet deep API. Drawing lines can be as easy as this:

VectorLine.SetLine (Color.yellow, Vector2(0, 0), Vector2(100, 200));

Or you can get fancier and make all kinds of graphs, grids, selection boxes, and anything else to do with lines, including entire games made with vector graphics if you want.

• Works on most platforms including mobile; doesn’t need Unity Pro. Written in C# but works with any language.
• “Free” anti-aliasing when used with textures, which means you don’t need FSAA to have anti-aliased lines.
• Can also use textures for making things like glowing lines without full-screen glow effects, dotted or dashed lines, etc.
• 3D, 2D, and point drawing. Lines can be any number of pixels thick.
• Can have continuous or discontinuous lines with arbitrary colors and widths for each segment. This way, with discrete lines, many “separate” lines can be drawn in a single line object.
• Lines can have end caps, for making arrows, rounded ends, etc.
• Many functions for easily making boxes, circles, splines, etc.
• Fast — lines only have to update when they change, so static lines take no extra CPU time, and don’t need to constantly redraw every frame like GL lines.
• Includes a utility for quickly making customized 3D vector shapes from existing meshes, or automatically make wireframes in code with one function call.
• Helper scripts for making 3D vector objects behave like standard game objects.
• Complete documentation, plus a reference guide covering all functions.
• Dozens of example scripts and demos, plus the complete “Tank Zone” game project is included free.
• Low price, so most anyone can afford it.
• Source code included.

This topic should be used for Vectrosity 4 and 5 discussion; the original topic for Vectrosity 3 and earlier can be found here.

–Eric

4 Likes

Awesome Eric just what I needed to add a finishing touch to a client’s travel app!

Cheers.

Is there a way to have a ScrollUV script attached to the vector lines automatically? (Or some other way to add a pulsing effect to the vectrosity lines?)

You can scroll the material’s offset using VectorLine.textureOffset, or Material.mainTextureOffset (normally preferred since it doesn’t need to compute UVs every frame). I imagine that expanding/contracting the line width in a sine wave pattern would be useful for a pulsing effect.

–Eric

What’s the easier way to make a curve of more than 4 points? I’m having troubles to achieve a curve like this:

EDIT: I already read about MakeSpline, but i need beziers for my project

You can use multiple bezier curves in a single line, as shown in the DrawCurve demo script.

–Eric

Hi, i’m using vectrosity for unity 4.6 now and my code is used to show me the distance between two points.
In unity 4.6 with vectrosity 3.1 used to work fine.
What i done wrong when i changed to vectrosity 4?
The line not changing when raycast look to other point of terrain. The line stay in same place.
Sorry for my english.

using UnityEngine;
using System.Collections;
using Vectrosity;

public class VectrosityRadial : MonoBehaviour
{
        private Vector3[] _radial;
        public static VectorLine _radialLine;
        public Material _lineMaterial;
        // Use this for initialization
        void Start ()
        {
                _radial = new Vector3[2] {Vector3.zero,Vector3.zero};
              
        }
  
        // Update is called once per frame
        void Update ()
        {
                if (_radialLine == null) {
                        InstanceRadial ();
                }
                RaycastHit hit;
                if (Physics.Raycast (CameraSelect.Camera_Ativa.ScreenPointToRay (new Vector2 (Input.mousePosition.x, Input.mousePosition.y)), out hit, Mathf.Infinity)) {
                        _radial [0] = ADM._SetaReloc.transform.position;
                        _radial [1] = hit.point;
                        Distancia ();
                } else {
                        _radial [0] = ADM._SetaReloc.transform.position;
                        _radial [1] = ADM._SetaReloc.transform.position;
                        ADM._CanvasMenu.GetComponent<ADMCanvas> ()._distanciaText.text = "0 m";
                }
        }
        public void Distancia ()
        {
                float _dist = (_radial [1] - _radial [0]).magnitude;
                ADM._CanvasMenu.GetComponent<ADMCanvas> ()._distanciaText.text = (_dist).ToString ("#####.##") + " m";
          
        }
        void InstanceRadial ()
        {
                VectorManager.useDraw3D = true;
                _radialLine = new VectorLine ("Radial", _radial, _lineMaterial, 3);
                _radialLine.Draw3DAuto (Mathf.Infinity);
                _radialLine.AddNormals ();
                _radialLine.AddTangents ();
        }
        public static void DestroyRadial ()
        {

                VectorLine.Destroy (ref _radialLine);
        }
}

What is the code supposed to do, and what is it not doing now? I can’t run it because it depends on other scripts.

–Eric

By the way, version 4.0 (also includes 3.1.2) is on the Unity asset store now, which is…faster than I was expecting. Not complaining though…

–Eric

I would like to see the one point of line follow the hit of raytracer.
The line not changing when raycast look to other point of terrain. The line stay in same place.

Oh, I see…you probably want to read the Vectrosity 4 upgrade guide, particularly this part: “Since the array of points used to create a VectorLine is no longer referenced after the line is created, use VectorLine.points2 (for Vector2 lines) or VectorLine.points3 (for Vector3 lines) instead.” There’s a code example of the old way compared to the new way.

–Eric

Thank you so much, it’s worked!

using UnityEngine;
using System.Collections;
using Vectrosity;

public class VectrosityRadial : MonoBehaviour
{
        public static VectorLine _radialLine;
        public Material _lineMaterial;

        // Update is called once per frame
        void Update ()
        {
                if (_radialLine == null) {
                        InstanceRadial ();
                }
                RaycastHit hit;
                if (Physics.Raycast (CameraSelect.Camera_Ativa.ScreenPointToRay (new Vector2 (Input.mousePosition.x, Input.mousePosition.y)), out hit, Mathf.Infinity)) {
                        _radialLine.points3 [0] = ADM._SetaReloc.transform.position;
                        _radialLine.points3 [1] = hit.point;
                        Distancia ();
                } else {
                        _radialLine.points3 [0] = ADM._SetaReloc.transform.position;
                        _radialLine.points3 [1] = ADM._SetaReloc.transform.position;
                        ADM._CanvasMenu.GetComponent<ADMCanvas> ()._distanciaText.text = "0 m";
                }
        }
        public void Distancia ()
        {
                float _dist = (_radialLine.points3 [1] - _radialLine.points3 [0]).magnitude;        //_radialLine.GetLength ();
                ADM._CanvasMenu.GetComponent<ADMCanvas> ()._distanciaText.text = (_dist).ToString ("#####.##") + " m";
           
        }
        void InstanceRadial ()
        {
                _radialLine = new VectorLine ("Radial", new Vector3[2], _lineMaterial, 3);
                _radialLine.Draw3DAuto ();
                _radialLine.AddNormals ();
                _radialLine.AddTangents ();
        }
        public static void DestroyRadial ()
        {

                VectorLine.Destroy (ref _radialLine);
        }
}

Hi Eric,
A question for you. I’m having some trouble with the new Vectrosity 4, but I suspect it’s an understanding issue. I’m making a 2D game using Unity 4.6. I have two cameras, one for UI and one for gameplay. Both are set to be Orthographic. The UI camera stays at a fixed location on the screen (so the buttons are always in the same place), and the main camera stays centered on the player.

In terms of drawing order, I have a few sortingLayers, with UI on top and enemies,players, obstacles on lower sorting layers.

I am using 2D lines and not 3d lines, and draw them using the mainCamera. Do I need to use the mainCamera to convert the points using Camera.main.WorldToScreenPoint() every time the object moves? Is there an easier way to do this?

Also… using Vectrosity4, setting line.active=false doesn’t seem to hide the line as per the docs (and it used to work in Vectrosity 3). Am I missing something?

Thanks for any help you might be able to offer.

Hmmm… one more thing I noticed is that upgrading to the latest Vectrosity made my Unity start crashing a lot as well… not sure why. Fortunately I was able to use Git to downgrade :frowning: I’m using Unity 4.60b18 so it’s the beta and thus likely some bug or other.

I spent quite a lot of time developing Vectrosity with 4.6b18 and it never crashed, so I’m pretty sure any crashing isn’t related to Vectrosity. Anyway b20 is out now so you can try that. See the notes in the changelog about line.active.

I’d recommend just using one camera; you don’t need two. The UI won’t move when you move the main camera anyway. I doubt you need to use WorldToScreenPoint for anything, but without knowing what you’re doing, it’s hard to offer any advice.

–Eric

Hey Eric,

I’m trying to switch my DLL to the Vectrosity 4 version, and each time I overwrite the last version I was using (the most recent version before 4 was released) I get this error:

It goes away as soon as I swap out the new DLL for the old one. Intellisense is working as expected, allowing me to insert VectorLines without any issue. If I remove the one reference to my line, the error goes away, of course. I’ve gone through the upgrade guide and reduced my code down to one line call which seems to adhere to the upgrade recommendations. Here’s my line:

lineVec = new VectorLine("main", new Vector3[segmentNum], null, 40.0f);

Would you have any ideas?

Many thanks, and as always, awesome work,
TheAryeh

I tried importing the Vectrosity 4 DLL into a Vectrosity 3 project, and it worked without errors (well, aside from the scripts no longer working of course). So unfortunately I’m not really sure. Unless you’re not using Unity 4.6b19 or later?

–Eric

Hi Eric, thanks for the quick reply.

I don’t know why it was crashing… but as soon as I went back to Vectrosity 3 the stability was fine again under 4.6b18. It’s weird… might be that Unity is less stable for some reason related to my particular project or machine configuration.

Good point about only needing the one camera… I’ll take out the second one.

The DLL was built with 4.6b19, so I’d recommend using b19 or later.

–Eric

Ah, well that would definitely explain potential stability issues. Thanks Eric.