Search Unity

Vectrosity - Fast and Easy Line Drawing

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

  1. Epictickle

    Epictickle

    Joined:
    Aug 12, 2012
    Posts:
    431
    If I read the docs correctly, I believe it has to be a 2D vector line if you want it to have a collider.
     
  2. failman

    failman

    Joined:
    Sep 11, 2014
    Posts:
    23
    I apologise for not being so clear with my question...The collisions actually work. The question is how can I attach a script to my line so it will receive trigger events? Still thanks for you effort :)
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    3D lines are fine. The colliders are always 2D though. You can add a component to VectorLine.rectTransform.gameObject.

    --Eric
     
  4. failman

    failman

    Joined:
    Sep 11, 2014
    Posts:
    23
    Wow. It worked! Thanks Eric
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Vectrosity is on sale for a limited time!

    --Eric
     
  6. craabie

    craabie

    Joined:
    Dec 27, 2014
    Posts:
    5
    does onmouseover not work with the colliders generated with collider = true and trigger = true? I'm not seeing an example of this, and I haven't been able to get it working correctly yet.
     
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I'd recommend using VectorLine.Selected. But you can add a script to the generated GameObject at runtime with OnMouseOver and it should work, keeping in mind that the colliders are 2D only. VectorLine.Selected works for all lines in all cases.

    --Eric
     
  8. craabie

    craabie

    Joined:
    Dec 27, 2014
    Posts:
    5
    This is exactly what I'm trying to do and it doesn't seem to work. Here's the line generation code:
    Code (csharp):
    1. //main3.js
    2. import System.IO;
    3. import System.String;
    4. import Vectrosity;
    5.  
    6. private var curveLine : VectorLine;
    7.  
    8.  
    9. function Start () {
    10.     makeCurve();
    11. }
    12.  
    13. function Update () {
    14.     curveLine.Draw();
    15. }
    16.  
    17. function makeCurve() {
    18.  
    19.     var lineMaterial : Material = Resources.Load("curveMat") as Material;
    20.     var linePoints = [ Vector2(20, 30), Vector2(100, 50), Vector2(200, 80), Vector2(300, 20), Vector2(400, 50), Vector2(500, 60), Vector2(600, 10)];
    21.  
    22.     curveLine = VectorLine("curve", linePoints, lineMaterial, 6.0, LineType.Continuous, Joins.Fill);
    23.     curveLine.collider = true;
    24.     curveLine.trigger = true;
    25.  
    26.     var curveLineObject : GameObject = GameObject.Find("curve");
    27.     curveLineObject.AddComponent("tooltip");
    28. }
    29.  
    tooltip is a script which is added to the generated VectorLine GameObject and looks like this:

    Code (csharp):
    1. //tooltip.js
    2. function OnMouseOver () {
    3.  
    4.     Debug.Log("RollingOver...")
    5.  
    6. }
    7.  
    ...the mouseover event never fires... or rather, I get nothing in the Debug.Log and so assume it's not firing.

    screenshots of the object directly after creation:

     
  9. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    OnMouseOver doesn't seem to work with edge colliders. You can use a discrete line, which generates a polygon collider, or you can use VectorLine.Selected instead.

    --Eric
     
  10. craabie

    craabie

    Joined:
    Dec 27, 2014
    Posts:
    5
    Ok. Then if I wanted to be able to continue to add a script to the generated GameObject at runtime and use VectorLine.Selected, how would I go about referencing the VectorLine that the script is attached to? I'm a little lost (no surprise there!!) on how to reference a specific vectorline that was not created within that script. i.e.
    Code (JavaScript):
    1. //tooltip.js
    2. import Vectrosity;
    3.  
    4. var extraThickness = 2;
    5. private var line : VectorLine;
    6. private var wasSelected = false;
    7. private var index = 0;
    8.  
    9. //SOMEWHERE IN HERE ASSIGN THE VECTORLINE THAT THE
    10. //SCRIPT IS ATTACHED TO to THE var line FROM ABOVE
    11.  
    12. function Update () {
    13.     if (line.Selected (Input.mousePosition, extraThickness, index)) {
    14.            Debug.Log("Event Firing...")
    15.     }
    16. }
    17.  
     
  11. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Make the line variable public (or use properties), and do GetComponent (Tooltip).line = new VectorLine...

    --Eric
     
  12. gregroberts

    gregroberts

    Joined:
    Nov 21, 2014
    Posts:
    25
    Hi, loving Vectrosity 4. Is there any way to make the VectorLines cast shadows? I saw some ooold posts on Unity Answers citing the following, but it doesn't work, and I find no reference in the current documentation.

    1. myLine.vectorObject.renderer.castShadows = true;

    I have a directional light in the scene with "hard shadows" and the quality settings are such that shadows from normal GameObjects ARE rendering.
     
  13. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Hi, Vectrosity 4 lines can't cast shadows, since they use the Unity 4.6 UI canvas system, which doesn't have shadows. You can use Vectrosity 3 (which uses meshes) if you need shadows.

    --Eric
     
    gregroberts likes this.
  14. gregroberts

    gregroberts

    Joined:
    Nov 21, 2014
    Posts:
    25
    Thanks for the fast response, Eric.
    What are the performance trade-offs between 3 and 4?

    And just out of curiosity, in v4, does each line segment occupy its own individual canvas container? I've noticed with "thick" multi-segment lines moving through 3d space, that the segments seem to be on planes that "rotate" on a per-segment basis... actually a beautiful effect.
     
  15. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    4 is generally somewhat faster; typically 10-30% depending on what you're doing. Although since it doesn't use the Mesh class, there's no MeshTopology.Lines, so 1-pixel-thick lines are slower. All VectorLines use one canvas normally; I imagine a separate object for every line segment would not perform well.

    --Eric
     
    gregroberts likes this.
  16. craabie

    craabie

    Joined:
    Dec 27, 2014
    Posts:
    5
    I've been using VectorLine.Selected as the trigger to show/hide some pertinent info about a line, and I've come across an annoying anomaly. The text activated by the trigger flashes on/off as the mouseposition moves.
     
  17. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    VectorLine.Selected itself always just returns true or false if the point is within the line area, so I'd have to guess there's something in your code logic which is causing that.

    --Eric
     
  18. craabie

    craabie

    Joined:
    Dec 27, 2014
    Posts:
    5
    Further investigation reveals that VectorLine.Selected index is returning -1 when the text disappears, even though the point is within the line area. I must admit that the points which make up each line are some 6000 in number (in this example). Trying to show many points across a display which has significantly less number of pixels (1600 in this case - that would be 6000 points in 1600 pixels) would cause many of the segments to "stack" up on each other, I would think... but they should still return a valid yes/no. How does the interior logic of vectrosity deal with this?
     
  19. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can look at the source code for Selected in the VectorLine.cs script, but index can only be -1 if Selected returns false. If you have a reproducible case of Selected returning false when it shouldn't, I can take a look at it.

    --Eric
     
  20. Idodi1337

    Idodi1337

    Joined:
    Jul 7, 2014
    Posts:
    11
    Hey,

    I want Vectrosity to make a 'dotted' line for me. I looked at the documentation, specifically in the uniform-scaled textures part of it. I've followed all the instructions, but my line is still being drawn as a whole line, and not a segment with dots. I'm not sure if this is a problem with Vectrosity, or the way that I am handling material and texture.

    Is there any way I can accomplish this?
     

    Attached Files:

  21. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Looks like you'd need to use a material with a transparent shader, as shown in the demo scenes that have dotted lines (such as Path, etc.).

    --Eric
     
  22. Idodi1337

    Idodi1337

    Joined:
    Jul 7, 2014
    Posts:
    11
    Hey Eric,

    Whenever I take one of my textures and apply it to a material, and then use a transparent shader I lose the texture and it becomes transparent. Why does this happen? (I understand this is not a Vectrosity question). I'm clearly missing something here (sorry I'm a beginner).

    A solution that seemed to work for me now is simply to take the material from the demo project of Path, and change it to the color I wanted to use (this looks good enough for me).

    Thank you for your responsiveness and help.
     
    Last edited: Jan 7, 2015
  23. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Maybe it's to do with the alpha channel of your texture? Or the color you're using has the alpha set to 0?

    --Eric
     
  24. nburlock

    nburlock

    Joined:
    Apr 11, 2013
    Posts:
    65
    I'm using the latest Vectrosity and I cannot figure out how to stop Vectrosity drawing over the top of the app UI. I need it to render above the 3D scene but below the UI. What do I have to do?
     
  25. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Change the sorting order of the Vectrosity canvas to be below the others, or change the others to be on top of the Vectrosity canvas.

    --Eric
     
  26. nburlock

    nburlock

    Joined:
    Apr 11, 2013
    Posts:
    65
    I can't get the latest Vectrosity to render to any other layer besides UI. This is a problem because the lines are being drawn over the top of the UI which looks awful. I want the vectors to be drawn over the 3D objects and underneath the UI.

    I've tried the following. Attempting to render anywhere besides the UI results in nothing being drawn unless render mode is "screen space overlay" which is not what I want.
    Code (csharp):
    1. VectorLine.SetCanvasCamera(camVector);
    2. VectorLine.canvas.gameObject.layer = LayerMask.NameToLayer("Vector");
    The camera mask is set to the Vector layer. Anything else I put on the vector layer is visible when the camera is active.

    What else is needed to force Vectrosity to render on a layer other than UI?
     
  27. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Don't use layers, just set the sorting order for the canvas. You can't sort anything with layers unless you're using multiple cameras and appropriate layermasks.

    --Eric
     
  28. nburlock

    nburlock

    Joined:
    Apr 11, 2013
    Posts:
    65
    I'm using NGUI. It hasn't got a canvas. I setup multiple cameras with layer masks but it doesn't work.

    Edit:
    Wow. I spent all day on this.

    The problem is the plane distance value. The default value resulted in Vectrosity not working if there was a value in the camera field of the Vectrosity canvas. It worked fine when the camera was null.

    Documentation would have helped. While I did find documents, they contain nothing about plane distance. I tried searching and the only information I came up with was from the upgrade guide, but it doesn't mention plane distance.
     
    Last edited: Jan 8, 2015
  29. ichini

    ichini

    Joined:
    Oct 13, 2012
    Posts:
    23
    Hi Eric,

    I'm just updating my project to Vectrosity 4 (thank you for the new version), and was wondering about the persistence of canvases when changing scenes.

    All lines I'm drawing using VectorManager behave as with Vectrosity 3, but the ones I'm drawing with Draw3DAuto() aren't destroyed when the scene changes. Is there an easy way to clear the canvas3D on scene change? I'd rather not have to find and destroy every VectorLine manually.

    I've tried this:

    functionAwake() {
    Destroy(VectorLine.canvas3D);
    }

    but if I do this, the VectorCanvas3D object doesn't have a Canvas component if I draw the lines later and the lines remain invisible until I add one.

    Sorry if I'm missing this information somewhere.

    Thanks, georg.
     
    Last edited: Jan 8, 2015
  30. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Well, plane distance is a Unity thing, not specific to Vectrosity. The Unity docs for UI also apply to Vectrosity; the idea of Vectrosity 4 is that it uses the standard UI now and therefore the same info applies to both. http://docs.unity3d.com/Manual/class-Canvas.html

    I'd recommend adding the lines to a List, then using Destroy with that List. I'm thinking it might be better to change the behavior for Draw3DAuto in the future.

    --Eric
     
  31. helios

    helios

    Joined:
    Oct 5, 2009
    Posts:
    308
    Great tool, but I'm completely failing on one thing: How on earth do I prevent it from persisting between scenes? My lines are all permanently drawn to the camera and if the scene is re-loaded it creates a new instance of it.

    Many thanks.
     
  32. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Right now you'd have to destroy the lines before loading a new scene. Sorry about that; it's a holdover from Vectrosity 3 for reasons that no doubt made sense at the time.

    --Eric
     
  33. helios

    helios

    Joined:
    Oct 5, 2009
    Posts:
    308
    Thanks - I got it working, but I also had to do a Destroy() on the VectorCanvas gameObject as that persists as well. Is there another method you have for destroying the canvas? I couldn't find anything in the docs.

    Also, one more question. Is there support for scaling at different screen resolutions? Right now I'm using iPhone 5/5S as the native resolution, but if I view my dotted curve on say a 6 or 6 Plus, the "dots" don't scale up with the rest of the objects rendered by the camera (I'm using an orthographic camera with 2D Toolkit that has auto-scaling depending on device resolution).

    Thanks again.
     
  34. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    No, the canvas is just a normal canvas.

    Since Vectrosity uses pixel widths, I'd recommend using the screen size to calculate the line width. e.g., if you had a screen with a width of 1000 pixels and you used that as the baseline, and the app was running on a screen with a width of 2000 pixels, the ratio would be 2.0, which you'd use to multiply the line width.

    --Eric
     
  35. helios

    helios

    Joined:
    Oct 5, 2009
    Posts:
    308
    Got it sorted out now, thanks for the quick reply!
     
  36. XaeroDegreaz

    XaeroDegreaz

    Joined:
    Feb 6, 2010
    Posts:
    15
    @Eric5h5

    Thanks for the tool. After watching this project for quite some time, I finally purchased it, and I'm happy to see that it works with the new GUI system.

    I don't know if this is on your radar or not, but the lines don't seem to obey the new masking system.

    Any chance that will be implemented at some point?

     
    Last edited: Jan 12, 2015
  37. ichini

    ichini

    Joined:
    Oct 13, 2012
    Posts:
    23
    I was afraid you would say that : ) Thanks anyway!
    g.
     
  38. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    That looks like the old Atari coin-op game Lunar Lander. :)
     
  39. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I'd like it to be implemented, but that depends on Unity making that work with CanvasRenderer.SetVertices. (Which is somewhat buggy; there are some other things that don't work such as SetActive.) Unfortunately there's nothing I can do on my end.

    --Eric
     
  40. Dev Chorus

    Dev Chorus

    Joined:
    Nov 1, 2013
    Posts:
    5
    Hi. I'm trying to draw a 2D-ish curve, using code identical to the MakeSpline script from the Vectrosity4 Demos. I managed to get the curve to appear on the Scene View, but it doesn't show up in the Game View. Am using the Unity 4.6 UI.

    Any help would be greatly appreciated. Thanks!
     
  41. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The MakeSpline demo and code appears fine in the game view, so if it's actually identical, it would work. If you made some changes, it would be useful to know what they are.

    --Eric
     
  42. Dev Chorus

    Dev Chorus

    Joined:
    Nov 1, 2013
    Posts:
    5
    Hi Eric,

    Basically i'm trying to draw a graph on an interface that's made up purely from the Unity UI system, without any cameras. Currently, using the MakeSpline script, i am only able to see the spline in the Game view when i use a camera. So i'll like to ask, whether it's possible to just view the spline through a Unity UI canvas(2D) instead of through a camera(3D). And if so, how do i do it?

    Thanks
     
  43. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You need a camera to provide the background; otherwise it's undefined (might be black on some systems, might be filled with random garbage, etc.). Regardless, Vectrosity uses the canvas system and doesn't rely on a camera being present when using Draw. Draw3D requires a camera to orient the lines to.

    --Eric
     
  44. David Wagg

    David Wagg

    Joined:
    Aug 5, 2013
    Posts:
    8
    Hi Eric - I'm getting ugly mesh artifacts with smoothWidth (Vectrosity 4.0.4, Unity 4.6.1f1).

    I've attached the following script to an empty GameObject in a new scene:
    Code (CSharp):
    1. public class LineTest : MonoBehaviour
    2. {
    3.     public Material lineMaterial;
    4.  
    5.     public void Start()
    6.     {
    7.         Vector2[] linePoints = { new Vector2(400, 300), new Vector2(600, 300), new Vector2(800, 300), new Vector2(1000, 300) };
    8.         VectorLine line = new VectorLine("Test", linePoints, lineMaterial, 0f, LineType.Continuous);
    9.  
    10.         float[] lineWidths = { 4f, 16f, 32f };
    11.         line.SetWidths(lineWidths);
    12.         line.smoothWidth = true;
    13.  
    14.         line.Draw();
    15.     }
    16. }
    The result looks like this:


    If I remove 'line.smoothWidth = true' then the line renders correctly (albeit step-wise):

    Any idea what's going wrong?
     
  45. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Sorry, that's a bug. So I released 4.0.5:

    Fixes:
    • SetCamera3D works properly even if the canvas hasn't been set up yet.
    • VectorLine.smoothWidth works properly.

    Also I think I forgot to mention 4.0.4 here, which has:

    Changes:
    • VectorLine.Selected can use an additional extraLength parameter, which is similar to extraWidth except it adds the specified distance to the beginning and end of each line segment for the purposes of checking the line.

    Fixes:
    • Lines that use a drawTransform where some of the axes are scaled to 0 no longer cause a "Screen position out of view frustum" error when the scene view is active.

    --Eric
     
  46. David Wagg

    David Wagg

    Joined:
    Aug 5, 2013
    Posts:
    8
    Thanks for the swift response! I'll check it out when it hits the asset store.
     
  47. fieldrequired

    fieldrequired

    Joined:
    Feb 26, 2014
    Posts:
    108
    Hi Eric,

    In a game I am making there are two main 'views' the first view is a planetarium of sorts, Vectrosity draws the lines set to 1px in this view fine:



    The game can then switch to a second mode in which the lines shown below are also set to 1px, yet you can see they appear thicker and distorted. I'm using Vectrosity with the 4.6 UGUI integration, but the same occurs if I switch to a previous version of Vectrosity. I can switch between the two modes and the issue is consistent.

    Do you have any ideas?

    Note that the grid is not created with Vectrosity.



    Thanks in advance!
     
  48. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Sounds like you're using two different cameras? If so, use SetCamera3D with the appropriate camera and re-draw the lines, so they will be oriented correctly.

    --Eric
     
  49. fieldrequired

    fieldrequired

    Joined:
    Feb 26, 2014
    Posts:
    108
    Tut, yep that was it - sorry for being stupid and thanks for coming back to me on the weekend.

    Cheers dude, peace.
     
  50. betovena

    betovena

    Joined:
    Dec 4, 2012
    Posts:
    82
    Hello Eric5h5, how are you doing?

    I want to buy your asset, but I need to know if it is possible, for example, create a triangle using 3 lines and change the color inside the triangle, not only the color of the lines. Do you get it?

    Thank you.