Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Vectrosity - Fast and Easy Line Drawing

Discussion in 'Assets and Asset Store' started by Eric5h5, Sep 26, 2014.

  1. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You created a local line variable in the Shape constructor, so it doesn't exist anywhere else.

    --Eric
     
  2. Lautaro-Arino

    Lautaro-Arino

    Joined:
    Sep 18, 2013
    Posts:
    93
    This is so embaressing. Thanks!
     
  3. Lautaro-Arino

    Lautaro-Arino

    Joined:
    Sep 18, 2013
    Posts:
    93
    Another question. In my Shape class i keep track of the points. I add points and i modify their positions. But calling the Draw() on the VectorLine does not show these new or modifed points. do i need to destroy the VectorLine and create a new one with the modified List<Vector2> ?
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    No, you should modify the points in line.points2 or line.points3, depending on whether it was made with Vector2 or Vector3 points.

    --Eric
     
  5. Lautaro-Arino

    Lautaro-Arino

    Joined:
    Sep 18, 2013
    Posts:
    93
    Is it possible to create a shape of lines and fill it?
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    No, sorry.

    --Eric
     
  7. Slev

    Slev

    Joined:
    Sep 8, 2012
    Posts:
    148
    When using MakeText is there a way to center the text to the screen? (Or center it to some position?)
     
  8. Redtail87

    Redtail87

    Joined:
    Jul 17, 2013
    Posts:
    125
    Hey Eric,

    I am using 3D lines in Vectrosity and am getting some glitchy results where the line is jumping away from the camera causing it to clip through an object.

    Here are video examples:
    Game View
    Scene View

    Is there something I could be doing wrong?

    Thanks.
     
  9. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    There isn't a built-in option, but since the text is fixed width, it shouldn't be hard to calculate where it should be placed to get that effect.

    Does that happen if you turn off Joins.Weld?

    --Eric
     
  10. Redtail87

    Redtail87

    Joined:
    Jul 17, 2013
    Posts:
    125
    Bam, that was it, changed it to filled

    Thanks!
     
  11. Slev

    Slev

    Joined:
    Sep 8, 2012
    Posts:
    148
    Alright... what about scaling. I know MakeText does a certain size font, but it seems like the whole setup doesn't scale very well to resolutions. I tried making something on the PC, then putting it on a tablet and it didn't scale well. Is there a way to design it for one size and then use the canvas to autoscale things? I've currently got it set to Camera for the rendering mode.
     
  12. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Use Vector3 (world space) instead of Vector2 (screen space) points.

    --Eric
     
  13. Slev

    Slev

    Joined:
    Sep 8, 2012
    Posts:
    148
    Well... I was using Draw3D and a Vector3 array, does it also need to be rendered in world space to ensure proper scaling?
     
  14. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can use Draw with a Vector3 array. Draw3D renders it in the scene instead of as an overlay.

    --Eric
     
  15. Slev

    Slev

    Joined:
    Sep 8, 2012
    Posts:
    148
    Ah I got it. Thanks Eric, top service as always.
     
  16. Slev

    Slev

    Joined:
    Sep 8, 2012
    Posts:
    148
    Because I'm a pest. I've noticed when I use Application.LoadLevel() it seems to not remove the things I've drawn in my scene. Shouldn't all the lines be destroyed when the scene changes?
     
  17. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    That would be more expected, yes, so it will be changed in the next version.

    --Eric
     
  18. ErikJohnson

    ErikJohnson

    Joined:
    Jan 4, 2013
    Posts:
    4
    Eric,
    I'm trying to sort out rendering the same lines in two different Cameras (one perspective, the other ortho) that are side-by-side in the window. I can't seem to get the right combination of SetCamera3D() and Draw3D() to have each camera render the geometry separately.

    Currently I have a GameObject with the rendering script on it. It has reference to both Cameras. Every Update() it calls SetCamera3D() and Draw3D(), for each camera and each piece of geometry.

    However the camera position in one view still seems to affect the geometry in the other view.

    Any suggestions?
    Thanks!
     
  19. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    That sounds right, and worked OK here. You are calling them in that order? (That is, SetCamera3D and Draw3D with one camera, then SetCamera3D and Draw3D with the other.)

    --Eric
     
  20. Slev

    Slev

    Joined:
    Sep 8, 2012
    Posts:
    148
    In the meantime, is there an easy way to wipe out the Vectrosity lines or do I have to call destroy on all of them? (I assume there's an internal list tracking them all, can that be accessed?)
     
  21. ErikJohnson

    ErikJohnson

    Joined:
    Jan 4, 2013
    Posts:
    4
    Yes, looks a little like this:

    Code (CSharp):
    1. Render(VectorLine line){
    2.   foreach (Camera cam in myCameras){
    3.      VectorLine.SetCamera3D(cam);
    4.      line.Draw3D();
    5.   }
    6. }
    7. Update() {
    8.   cube.MakeCube(...)
    9.   Render(cube)
    10.   marker.MakeCircle(...)
    11.   Render(marker)
    12. }

    The last camera that renders looks correct. I.e., zooming in with the second camera screws up the rendering of the first camera. And by screws up, I mean the line width changes. You can see that the left view's geometry is being affected by the right camera's location.
    unzoomed.jpg zoomed.jpg
     
    Last edited: Feb 10, 2015
  22. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    There's no internal list (except for Draw3DAuto); you can put the VectorLines in a List or array and destroy that.

    Sorry, I should have said that the lines need to update for each camera, namely in OnPreRender, not literally the Update function.

    However...it doesn't look like that actually works anymore with Vectrosity 4. It would seem that canvases are somehow rendered independently from cameras, even when in world space. I tried playing with Canvas.ForceUpdateCanvases but that didn't do anything. The only thing I can think of right now is to have two sets of lines, one for each camera.

    --Eric
     
  23. shayan_315

    shayan_315

    Joined:
    Sep 24, 2013
    Posts:
    28
    Thanks,I have done it completely and it works great but my problem is when for first time I erase first line, I continuously receiving :
    "ArgumentOutOfRangeException: Argument is out of range.Parameter name: index" Error

    I draw my line with :
    Code (CSharp):
    1.     if(Input.touchCount > 0 )
    2.       {
    3.        touch = Input.GetTouch(0);
    4.     if(!EraserButton)
    5.         {
    6.          if (touch.phase == TouchPhase.Began&&!canDraw)
    7.             {
    8.             _FirstPoint=touch.position;
    9.             }
    10.             else if (touch.phase == TouchPhase.Moved && (touch.position - _FirstPoint).sqrMagnitude > sqrMinPixelMove&&!canDraw )
    11.             {
    12.                 canDraw = true;
    13.             }
    14.             else if(touch.phase == TouchPhase.Ended&& canDraw)
    15.             {
    16.                 points = new Vector2[]{touch.position,_FirstPoint};
    17.                     RightCapedLine[RightCpCounter]= new VectorLine("RightCapLine"+RightCpCounter, points, lineMaterialLine, 8f);
    18.  
    19.                 ListOfLines.Add(RightCapedLine[RightCpCounter]);
    20.                 ListOfLines[RightCpCounter].endCap = "ArrowRight";
    21.                 ListOfLines[RightCpCounter].Draw();
    22.  
    23.                 RightCpCounter++;
    24.                 canDraw = false;
    25.             }
    26.         }
    27.       }
    I erase them with:

    Code (CSharp):
    1.         if(EraserButton && RightCpCounter>-1)
    2.         {
    3.             for (int i = 0; i < RightCpCounter; i++)
    4.             {
    5.                 if (ListOfLines[i].Selected (touch.position, extraThickness,out index))
    6.                 {
    7.                     VectorLine tempLine=RightCapedLine[i];
    8.                     RightCapedLine[i]=RightCapedLine[RightCpCounter];
    9.                     RightCapedLine[RightCpCounter]=tempLine;
    10.  
    11.                     VectorLine.Destroy(ref RightCapedLine[RightCpCounter]);
    12.                     ListOfLines.RemoveAt(RightCapedLine.Length);
    13.                     RightCpCounter--;
    14.                 }
    15.             }
    16.         }
     
  24. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    An out of range exception means you're attempting to refer to items outside the array or list. I would be suspicious of "ListOfLines.RemoveAt(RightCapedLine.Length);"

    --Eric
     
  25. shayan_315

    shayan_315

    Joined:
    Sep 24, 2013
    Posts:
    28
    I have change it to ListOfLines.RemoveAt(RightCpCounter); but I still have the same problem :(
     
  26. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You'd need to figure out the correct numbers to use. I'd recommend starting a new topic about this, since I would really prefer to keep this topic about Vectrosity specifically rather than general programming questions. It makes it easier for people to find information.

    --Eric
     
  27. ErikJohnson

    ErikJohnson

    Joined:
    Jan 4, 2013
    Posts:
    4
    I think I can render geometry with two independent cameras, if I have:
    -two Cameras
    -two VectorCanvas3D's each assigned to a separate Layer
    -two renderings of the lines, using SetCamera3D() and Draw3D(), parented under separate Canvases

    Then I can use the Camera cull mask to render only the appropriate geometry under the appropriate VectorCanvas.

    However Vectrosity has one static VectorCanvas3D object and I don't see a way to override that, without hacking up the code.

    Any suggestions? :)
     
  28. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can create a new canvas, then use VectorLine.rectTransform.SetParent() to attach the lines to the desired canvas.

    --Eric
     
  29. dttngan91

    dttngan91

    Joined:
    Nov 21, 2013
    Posts:
    80
    How to render VectorLine in specific camera in Unity using layers?
     
  30. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Set the Vectrosity canvas to a particular layer, and have the specific camera render that layer.

    --Eric
     
  31. dttngan91

    dttngan91

    Joined:
    Nov 21, 2013
    Posts:
    80
    Thanks, another question, is there anyway to create 3 or more distinct canvas rather than canvas and canvas3D? I see the VectorLine.canvas only.
     
  32. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
  33. TBruce

    TBruce

    Joined:
    Jan 18, 2015
    Posts:
    86
    Hi Eric,

    I have noticed that if I cannot keep create lines made while in the editor. If I start a game with lines previously created within the editor I get errors when the game starts. Both m_points3 and m_UIVertices are both null. And if I destroy any previous VectorLine data when the game starts, then all data that was created before the game started is invalid when the game ends.

    Is there a way around this without having to manually delete VectorCanvas and VectorCanvas3D before the start of a game?

    Brian
     
  34. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    As far as I know it shouldn't be possible to create lines in the editor; it's definitely not designed for it. The intention is that you write code which creates lines at runtime.

    --Eric
     
  35. TBruce

    TBruce

    Joined:
    Jan 18, 2015
    Posts:
    86
    That is what I thought. This was just something that would have been nice for debugging puproses.
     
  36. EddieCam

    EddieCam

    Joined:
    Oct 28, 2009
    Posts:
    26
    Hi, I'm wondering if there's any way to make Vectrosity lines respond to the new event system? If I understand the event system properly, only objects that the raycasters see will ever have events called on them, but I could be mistaken. I'm also guessing this means that vectrosity lines won't be supported since they don't (?) use UI.Image.

    The use case is for draggable lines. I know I can use line.Selected(), but it'd be nice if I could also get all the Unity-tracked event data at the same time.

    Cheers!
     
  37. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Correct, they use CanvasRenderer.SetVertices.

    --Eric
     
    EddieCam likes this.
  38. wrenagade

    wrenagade

    Joined:
    Feb 14, 2015
    Posts:
    23
    Hi,

    Can you tell me if Vectrosity can create lines like in the image below? If so, could you post an example image? In this example the outer color is the main color (Red) and the inner is a lighter shade giving a neon effect. Also there are rounded ends. Thank you.

    upload_2015-2-14_13-48-39.png
     
    Last edited: Feb 15, 2015
  39. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes, you'd need a texture for the middle and another texture for the ends.

    --Eric
     
  40. wrenagade

    wrenagade

    Joined:
    Feb 14, 2015
    Posts:
    23
    Thanks for the reply. I can now get this Asset.
     
  41. Nsomnia

    Nsomnia

    Joined:
    Sep 26, 2014
    Posts:
    27
    Im trying to create visual displays of equations say this one (speed of sound in the ocean) " speed = 4388 + (11.25 × temperature ) + (0.0182 × depth ) + salinity"

    Any references or tips to creating a graph say y is depth and x is temperature (salinity is static and doesnt change) and being able to use this equation that involves x and y and a Time.deltatime function to create a graph that updates a UI Text component 'speed' every second based on depth and temperature (bonus points to have a line drawing salinity). I can create the canvas with a UI texture grid no problem obviously and I can use a LineRenderer to draw a straight line between two points at a certain float speed.

    I'm thinking vectrosity would be the easiest way to do these kinds of things, I bought it ages ago but I've never used it.

    Any tips would be greatly appreciated.

    Currently trying to use catlikecodings tutorial on using a particle system and them something like this
    Code (csharp):
    1.  
    2.  
    3.   double graphTemp;
    4.   double graphDepth;
    5.  
    6.   public double Temp(double x)
    7.   {
    8.   float currentTemp = 30.0f;
    9.   float targetTemp = 60.0f;
    10.   float velocity = 1.0f;
    11.   float smoothTime = Time.deltaTime;
    12.   return x = Mathf.SmoothDamp(currentTemp, targetTemp, ref velocity, smoothTime);
    13.   }
    14.  
    15.   public double Depth(double y)
    16.   {
    17.   float currentDepth = 1.0f;
    18.   float targetDepth = 500.0f;
    19.   float velocity = 1.0f;
    20.   float smoothTime = Time.deltaTime;
    21.   return y = Mathf.SmoothDamp(currentDepth, targetDepth, ref velocity, smoothTime);
    22.   }
    23.  
    24.   public double Speed(double z)
    25.   {
    26.   return z = (4388 + (11.25 * Temp(graphTemp)) + (0.0182 * Depth(graphDepth)) + 0.01);
    27.   }
    28.  
    TL,DR: Trying to use Vectrosity for the first time to graph speed overtop of a UI Texture based on this equation "(speed of sound in the ocean) " speed = 4388 + (11.25 × temperature ) + (0.0182 × depth ) + salinity""
     
    Last edited: Feb 15, 2015
  42. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I'd recommend reading the docs and looking at the demo scenes. The basic idea is that you create points in a list and then Vectrosity renders those points. So I'd start by creating a function that makes a list of the points you want to show. If you have any specific questions, let me know.

    --Eric
     
  43. rsanchezsaez

    rsanchezsaez

    Joined:
    Sep 17, 2012
    Posts:
    3
    Hi,

    I'm considering buying Vectrosity and have some questions:

    Would Vectrosity be performant for complex 2D games? Could something like Geometry Wars be implemented and have a decent framerate?



    Thanks!
     
    Last edited: Feb 26, 2015
  44. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    If you were drawing 100% of that with Vectrosity, probably not, although it depends on the CPU. On a desktop computer that work probably work, but not so much on mobile.

    --Eric
     
  45. rsanchezsaez

    rsanchezsaez

    Joined:
    Sep 17, 2012
    Posts:
    3
    Thanks for the reply!

    Also, I saw the demos and they look great. A few more questions: Regarding Demo 3, how does this glow effects work within Vectrosity? Are there more effects like that? Can this kind of effect be animated in any way (I'm thinking of pulsating or something similar)? Can it be applied to circles?

    Thanks.
     
  46. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It's just a texture; any line can use any texture. You could animate the texture, or the line width.

    --Eric
     
  47. shayan_315

    shayan_315

    Joined:
    Sep 24, 2013
    Posts:
    28
    Hi,
    I want to take screen shot when I use
    Code (CSharp):
    1. Application.CaptureScreenshot(filename);
    code every things works great and Vectrosity line are exist in my line but its drawback is that you cannot gave your
    address I prefer to use
    Code (CSharp):
    1.                   RenderTexture rt = new RenderTexture(resWidth, resHeight, 24);
    2.                     camera.targetTexture = rt;
    3.                     Texture2D screenShot = new Texture2D(resWidth, resHeight, TextureFormat.RGB24, false);
    4.                     camera.Render();
    5.                     RenderTexture.active = rt;
    6.                     screenShot.ReadPixels(new Rect(0, 0, resWidth, resHeight), 0, 0);
    7.                     camera.targetTexture = null;
    8.                     RenderTexture.active = null;
    9.                     Destroy(rt);
    10.                    byte[] bytes = screenShot.EncodeToPNG();
    11.                     string filename = ScreenShotName(resWidth, resHeight);
    12.                   System.IO.File.WriteAllBytes(filename, bytes);
    it works great but vectorsity lines is not exists in my picture.
    I knowthat this is because vectorsity use its camera and I give my code in my main camera so
    my question is: how I can use later code to capture vectrosity lines?
     
  48. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can use VectorLine.SetCanvasCamera to set the camera for the canvas, and use that for the rendertexture. Basically this changes the canvas mode to RenderMode.OverlayCamera; if the canvas is using RenderMode.Overlay, the canvas (and therefore VectorLines) won't show up in the rendertexture.

    --Eric
     
  49. shayan_315

    shayan_315

    Joined:
    Sep 24, 2013
    Posts:
    28
    I use Vectrosity 3 Ithink I should use something like
    Code (CSharp):
    1. void Start () {
    2. ! var cam = VectorLine.SetCameraRenderTexture (renderTex, Color.blue);
    3. ! var line = new VectorLine("Line", [Vector2(0, 0), Vector2(255, 255)], null, 1.0);
    4. ! line.Draw();
    5. ! cam.Render();
    6. ! VectorLine.SetCameraRenderTexture (null);
    7. ! line.Draw();
    8. }
    but I draw different type of lines and circles in different C# scrptswhich are attached to my main camera
    and I have a c# script for taking screen shots. so, should I use this code after each draw in my all c# scripts?
    (My screenshot c# script makes my picture)
     
  50. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can read the entire screen into a texture, instead of using rendertextures, and resize the texture to the screenshot dimensions with this.

    --Eric