Search Unity

  1. New Unity Live Help updates. Check them out here!

    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,225
    I haven't seen it, and there isn't any code in Vectrosity that can move a line's position. However in most cases you should not move the GameObject anyway, but instead move the points in the line.

    --Eric
     
  2. robinspots

    robinspots

    Joined:
    May 10, 2018
    Posts:
    10
    Since my last message I've done a bit more testing and I think that this will recreate what I'm seeing:
    1. Create a new scene
    2. Create a new Vectorline
    3. Set the vectorcanvas to 'scale with screen size'
    4. change the line's recttransform x or y position values a little bit
    5. The line will shoot off the screen never to return :)
    Does anyone know how I can avoid this?
     
  3. robinspots

    robinspots

    Joined:
    May 10, 2018
    Posts:
    10
    OK thanks for getting back to me. I was hoping to avoid having to reposition all my lines but I should be able to reposition everything using the line points instead.
     
  4. hurleybird

    hurleybird

    Joined:
    Mar 4, 2013
    Posts:
    81
    Hey there... so setting the VectorLine.active property is extremely expensive. Which is fine, except that it looks like a field. This is why the proper convention is to capitalise properties, and for sufficiently expensive operations you often want to err on the side of using a method just so you can make the point that "I might be expensive, tread carefully" even more clear.

    Besides that, the property should absolutely check to see if the backing field changes before doing any heavy lifting. That will at least protect from the case where someone is setting it to true every frame.
     
    Last edited: May 11, 2019
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,225
    I don't know about that. Aside from an early out in the drawing function, for a 3D line, it just enable/disables the mesh renderer, which should be nothing. For a 2D line, it uses Unity's RawImage.enabled property, so it does whatever that does. Which seems to be MaskableGraphic.OnDisable(). If I toggle that every frame, I get .01ms in the profiler. If I set it to true every frame, there's nothing. So as far as I can tell it's not expensive. Anyway the conventions were made to be like Unity's; you may notice that GameObject.active is also not capitalized.

    --Eric
     
  6. hurleybird

    hurleybird

    Joined:
    Mar 4, 2013
    Posts:
    81
    That's odd then, since my case is getting something like 1ms per (Only thing I can can think of is that I'm setting the texture offset right before then). UT is wrong about lower case properties (I believe that back in the day they wanted to look more like JS), but I understand the thought about mirroring their convention in the event that there isn't supposed to be a noticeable performance hit.
     
    Last edited: May 11, 2019
  7. jaydee_programming

    jaydee_programming

    Joined:
    Feb 19, 2019
    Posts:
    9
    Is the documentation available online? I only see it listed in the package preview. Would be helpful for people trying to decide on a purchase.
     
  8. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,225
  9. jaydee_programming

    jaydee_programming

    Joined:
    Feb 19, 2019
    Posts:
    9
    Great thanks!
     
  10. hurleybird

    hurleybird

    Joined:
    Mar 4, 2013
    Posts:
    81
    Is there a reason why smoothcolor only starts blending after the end of the first line segment? If you have two line segments, one red and one blue, you end up with 75% of your line red and 25% blue. This is very unintuitive.
     
    Last edited: May 24, 2019
  11. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,225
    Yes, it's due to the way line colors are per-segment rather than per-point.

    --Eric
     
  12. hurleybird

    hurleybird

    Joined:
    Mar 4, 2013
    Posts:
    81
    What's the benefit?
     
  13. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,225
    It supports the "multiple lines within a single VectorLine" approach if you can easily color line segments individually. Obviously this isn't ideal for 100% of all use cases as your example shows, but everything's a tradeoff.

    --Eric
     
  14. hurleybird

    hurleybird

    Joined:
    Mar 4, 2013
    Posts:
    81
    I'm not sure I get the mutual exclusivity here. Proper blending of segments feels orthogonal to keeping those segments distinct when there is no blending. You just need to do a transformation. Off the top of my head, start out with each color positioned in the centre of its segment, which we can call a color-point, and then scale the collection of color-points so that the position of its first element conforms to the first vertex of the line, and its last element conforms to the last vertex of the line.
     
    Last edited: May 24, 2019
  15. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,225
    |----|----|

    That's a vertex, a segment, a vertex, another segment, and the last vertex. If the colors are per-vertex instead of per-segment, it's impossible for the two segments to have individual, non-blended colors.

    Anyway, the work-around to get what you want for this is fairly trivial: instead of two segments, you have three, where the first segment is a "nothing" segment where the two points are the same, so it just gets skipped over.

    --Eric
     
  16. hurleybird

    hurleybird

    Joined:
    Mar 4, 2013
    Posts:
    81
    The solution is to keep the colors per-segment, but do the transformation I talked about for color positions when using smoothcolor.

    This is incorrect. With segment points (0, 0, 0.5, 1) and colors (green, red, blue), you end up with a line that looks to be 1/3 each color. An empty segment blends into the segment that comes after it.

    To satisfy the example of a straight blend between two colors, you use (0, 1/3, 2/3, 1) and (red, blue, blue), which will yield a line that is 50% red and 50% blue.

    None of this is intuitive in the slightest.
     
  17. zoltanBorbas

    zoltanBorbas

    Joined:
    Nov 12, 2016
    Posts:
    79
    Hi Eric5h5

    I am looking for some help regarding correctly drawing line at the mouse pointer. As you can see below, the line is drawn at the pointer but due to its width it seems like it is offset (The line width is considerably increased for the sake of presentation), i would like to center the line at the pointer or at least figure out how to offset the crosshair.

    Any suggestion would be greatly appreciated!

    Thanks is advance!

    upload_2019-5-24_21-21-17.png
     
  18. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,225
    A line's width extends outward from a given point equally on both sides of the point, so there isn't any inherent offset. If I draw a line with Input.mousePosition as one point, you can see that it's centered around the mouse cursor tip, where the hotspot is:

    linepointer.png

    Is your cursor hotspot in the center of the crosshair?

    --Eric
     
  19. zoltanBorbas

    zoltanBorbas

    Joined:
    Nov 12, 2016
    Posts:
    79

    Hi Eric

    Thanks for the response, turned out alignOddWidthToPixels was causing the issue! It is great now!

    Thanks again!
     
  20. VectorWorlds

    VectorWorlds

    Joined:
    Feb 24, 2019
    Posts:
    2
    Hello,

    When using the Linemaker editor, is there a way to define what color individual lines should be? At the moment, I seem to be only able to make the whole mesh one color, but I would like to be able to pick render certain lines within the mesh different colors.

    Thanks.
     
  21. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,225
    Not directly in Linemaker itself, however, to quote the docs:

    This way you can use SetColors to color individual segments as indicated by the appropriate numbers.

    --Eric
     
  22. VectorWorlds

    VectorWorlds

    Joined:
    Feb 24, 2019
    Posts:
    2
    Thanks that's great. I saw I could do it in code, but I was hoping to define the colors directly in the editor. Not an issue. I will just need to think about how I can weave that into my modeling pipeline.
     
  23. Crayz

    Crayz

    Joined:
    Mar 17, 2014
    Posts:
    118
    Vectrosity 5.6 fails to load in 2019.3a, failure to reference UnityEngine.UI I believe.
     
  24. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,225
    Yes, UnityEngine.UI seems to be a package now. The source still works, however.

    --Eric
     
  25. zoltanBorbas

    zoltanBorbas

    Joined:
    Nov 12, 2016
    Posts:
    79
    Hi guys,

    Could anyone help me with calculating a rectangle's bottom left and top right corners' 3d coordinates from a center point, width and height? I have a line starting from a point and ending where the mouse is pointing to and i am trying to draw rectangles in 3D space along the line every so often as if the line piercing the middle of each rectangle.

    Did anyone ever come across with something like that? Any suggestion would be greatly appreciated!
     
  26. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,225
    Isn't the bottom-left just (x - width/2, y - height/2), and the top right (x + width/2, y + height/2)?

    --Eric
     
  27. zoltanBorbas

    zoltanBorbas

    Joined:
    Nov 12, 2016
    Posts:
    79
    Hi Eric,

    I thought the same, but i am not great at Vector3 math so i just used parented transforms for the corners, and although it seemed to work i am getting some weird behaviour, to demonstrate here is a short clip:
    https://1drv.ms/u/s!AqDKYfErvs5phNphYdDHwoOaV6xuSg

    I look rotate the root transform visualized by the rectangle toward the mouse pointer and the corners with spheres follow along. I assumed providing the corners in 3D position would do the trick, but i believe i am missing the understanding how these lines should act in 3D space. For your information i am using a discrete line and i hoped that these rects would lineup kind of like a tunnel an indication which way the ship will jump.
     
    Last edited: Jun 6, 2019
  28. zoltanBorbas

    zoltanBorbas

    Joined:
    Nov 12, 2016
    Posts:
    79
    UPDATE:

    Turned out doing the corners manually done the trick, the make rect function somehow did not got the same result, the thing is that it works now! Cheers!
     
  29. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,225
    Use Draw3D every frame, or Draw3DAuto.

    --Eric
     
  30. danielesuppo

    danielesuppo

    Joined:
    Oct 20, 2015
    Posts:
    168
    Many thanks for your reply, I've deleted my post because I've just figured out that I can call
    myLine.Draw3D();
    on each Update! Thank-you!
     
  31. danielesuppo

    danielesuppo

    Joined:
    Oct 20, 2015
    Posts:
    168
    Hello,
    sorry for my newbie question, is it possible to update the line with an array instead of a list?
    Many thanks
     
  32. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,225
    No, but you can make lists using the array data.

    --Eric
     
  33. AndreasO

    AndreasO

    Joined:
    Sep 25, 2012
    Posts:
    90
    Hi, is it possible to change the default layer to another layer without having to change the layer on each newly instantiated vector line?

    My code looks like this:

    Code (csharp):
    1. VectorLine.SetRay3D(.....).lineWidth = 3;
    Now that I found out that the vector lines must not be on the UI layer in my project I'm forced to either write a wrapper method/class or store the instantiated vector in an extra variable ... at every single location in my code ...

    Code (csharp):
    1. VectorLine line = VectorLine.SetRay3D(.....);
    2. line.layer = LayerMask.NameToLayer("Debug");
    3. line.lineWidth = 3;
    I'm looking for something like this:
    Code (csharp):
    1. VectorLine.DefaultLayer = LayerMask.NameToLayer("Debug");
     
  34. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,225
    There isn't built-in way (unless you want to make one yourself using the source code), but writing a small wrapper function is trivial and a common way to do custom things like this. To create a line after writing the function, you'd call:

    Code (csharp):
    1. MyLineFunction(....., 3);
    Which would make creating a line even simpler than what you're doing now.

    --Eric
     
  35. AndreasO

    AndreasO

    Joined:
    Sep 25, 2012
    Posts:
    90
    Yep, decided to write a utility class just for that now.

    Here's the code in case anyone else needs this:
    Code (csharp):
    1.  
    2. public static class VectrosityUtils {
    3.  
    4.     private static readonly int LAYER_DEBUG = LayerMask.NameToLayer("Debug");
    5.  
    6.     public static VectorLine SetRay3D(Color color, float time, Vector3 origin, Vector3 direction, float lineWidth = 1.0f) {
    7.         return SetRay3DonLayer(LAYER_DEBUG, color, time, origin, direction, lineWidth);
    8.     }
    9.  
    10.     public static VectorLine SetRay3DonLayer(int layer, Color color, float time, Vector3 origin, Vector3 direction, float lineWidth) {
    11.         VectorLine vectorLine = VectorLine.SetRay3D(color, time, origin, direction);
    12.         vectorLine.layer = layer;
    13.         vectorLine.lineWidth = lineWidth;
    14.         return vectorLine;
    15.     }
    16.  
    17. }
     
  36. Chun-Yuan

    Chun-Yuan

    Joined:
    Oct 16, 2018
    Posts:
    3
    Hi @Eric5h5 , Is it posiable to show stereoscopic effect with drawing 3D lines?I want to get the shadow effect to determine the relative line point position.Sorry for my English and thanks a lot.
     
    Last edited: Jun 18, 2019
  37. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,225
    Hi, unfortunately I'm not sure what you mean. Perhaps posting a picture would help.

    --Eric
     
  38. Chun-Yuan

    Chun-Yuan

    Joined:
    Oct 16, 2018
    Posts:
    3
    I want to a draw a water pipe with point3 and set the line radius by SetWidth function.
     

    Attached Files:

    • pipe.png
      pipe.png
      File size:
      11.3 KB
      Views:
      255
  39. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,225
    I see, thank you. Vectrosity lines can't be extruded to 3D shapes, sorry.

    --Eric
     
  40. Chun-Yuan

    Chun-Yuan

    Joined:
    Oct 16, 2018
    Posts:
    3
    OK:(,thanks for your reply.
     
  41. bdominguezvw

    bdominguezvw

    Joined:
    Dec 4, 2013
    Posts:
    95
    I'm developing a feature like Windows Snipping Tool editor where you can draw above an image with a pen and be able to erase lines with an eraser.

    I want to be able to interact with lines using Unity's EventSystem (IPointerDownHandler, IPointerClickHandler, ...) using a Physics2DRaycaster. My problem is that it only works if VectorLine is set to Discrete (Polygon Collider 2D) and not Continuous (Edge Collider 2D).

    You can see the behaviour easily on EventSystem inspector.

    Do you know how to fix it @Eric5h5 ?? Thanks.
     
  42. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,225
    No, but you could always just not use Continuous and draw all lines as Discrete.

    --Eric
     
  43. bdominguezvw

    bdominguezvw

    Joined:
    Dec 4, 2013
    Posts:
    95
    But if I draw it as discret it is not going to be a continuous line but cut by each point and it is not what I want so your solution is not valid.

    There is no way to achieve this and be able to use Unity's EventSystem as I said?

     
  44. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,225
    You can make discrete lines look like continuous lines without any problems, it just requires duplication of points. If Unity's event system doesn't work with edge colliders, then there's nothing I can do about that.

    --Eric
     
  45. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    735
    It works but only if radius it's not zero and in your case it is.
     
  46. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,225
    The colliders wouldn't be accurate if the radius was non-zero. Like I said, it's very easy to use discrete lines instead of continuous lines if you need to. A continuous line of (Vector2(0, 0), Vector2(100, 0), Vector2(100, 100)) would be a discrete line of (Vector2(0, 0), Vector2(100, 0), Vector2(100, 0), Vector2(100, 100)).

    --Eric
     
  47. danielesuppo

    danielesuppo

    Joined:
    Oct 20, 2015
    Posts:
    168
    Hello, I've a quite hard to explain issue: I'm reading longitude/latitude positions from a .gpx file.
    Next, thanks to OnlineMaps for Unity I convert them to world positions.
    So I can create a Vectrosity Line for all my points, to show the track on a map.
    But, since the recorded .gpx track is often a bit confused, if you look at it from a long distance, I create 3 different List<Vector2>, "fromNearDistance", "fromMediumDistance", "fromFarDistance" when loading the .gpx positions (just like the "Simplify" option in the the Unity LineRenderer).
    Each of them take in consideration only a minimum required distance from each recorded position, so when you look at it from a far distance the Vectrosity Line will use the List<Vector2> "fromFarDistance", for example.
    I'm actually using a 64x64 pixels sprite with a line in the middle (just as you suggested in your coding help).
    Everything is working perfectly, except that when I look from a far distance the Vectrosity Line is strange: the segments of the line are too long.
    I made a test with the same List<Vector2> "fromFarDistance" and the built-in LineRenderer, and the line is just what expected, so it's not a problem of my List.
    Maybe Vectrosity cannot draw segments shorter than some value or something like that?
    In the picture in attachment I try to show better my issue
    Many thanks
     
  48. danielesuppo

    danielesuppo

    Joined:
    Oct 20, 2015
    Posts:
    168
    I've made a close-up to show better the problem

     
  49. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,225
    That's pretty weird...any chance you're using Joins.Weld?

    --Eric
     
  50. danielesuppo

    danielesuppo

    Joined:
    Oct 20, 2015
    Posts:
    168
    Yes, I'm using Joins.Weld
     
unityunity