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, May 26, 2010.

Thread Status:
Not open for further replies.
  1. wightwhale

    wightwhale

    Joined:
    Jul 28, 2011
    Posts:
    397
    Any idea why the following code is crashing on iOS? I'm getting a bad access on line 13

    Code (csharp):
    1.  
    2.  lineToWeld = new VectorLine("lineToWeld", lineToWeldList.ToArray(), Color.white, lineMatPink, lineWidthGash, LineType.Continuous, Joins.None) {layer = LayerMask.NameToLayer("MinigameLayer")};
    3.  
    4. lineToWeld.vectorObject.renderer.sortingOrder = -1;
    5.  
    6. Texture2D[] texArry = new Texture2D[2];
    7. texArry[0] = lineMatPinkEndCapFront.GetTexture(0) as Texture2D;
    8.  texArry[1] = lineMatPinkEndCapBack.GetTexture(0) as Texture2D;
    9.  
    10.  
    11. if (string.IsNullOrEmpty(lineToWeld.endCap))
    12. {
    13.       VectorLine.SetEndCap("lineToWeldEndCapFront", EndCap.Both, lineMatPinkEndCapFront, texArry);
    14. }
    15.  
    16. lineToWeld.endCap = "lineToWeldEndCapFront";
    17.  
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Null reference exception, I assume. Make sure all variables involved are not null.

    --Eric
     
  3. ruetaitbout

    ruetaitbout

    Joined:
    Aug 29, 2014
    Posts:
    2
    How can I get a line rendered with Draw3D() to maintain its size when the field of view of the main camera changes? Thanks!
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Not sure what you mean by "maintain its size"...if you mean width, it already does that, since width is measured in pixels, so if it's 2 pixels wide it will always be 2 pixels wide regardless of field of view settings.

    --Eric
     
  5. pretender

    pretender

    Joined:
    Mar 6, 2010
    Posts:
    862
    Hi eric...I was looking through your scripts Simple3DObject and wanted to make a cube with standard shader and all edges with vectrosity drawn. and it works good but when i wanted to use line.textureOffset += 0.1f and animate it in the update loop it gives me null reference exception.

    i am initializing line in Start()

    and in Update() i have null check like this

    Code (CSharp):
    1. if(line != null)
    2. line.textureOffset += 0.1f;
    what seems to be the problem with this, error puts me in the line where textureOffset it attempted to be increaed but the message says something about unable to set texture scale (which is done in the Start() after line is created with line.textureScale = 1.0f

    thanks!
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Hi, I can't reproduce that, so I'd need more info. FYI, adding 0.1 in Update won't work right because it will be framerate-dependent; you need to use Time.deltaTime.

    --Eric
     
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Vectrosity 4 considerations

    Some time ago I made a preliminary effort at using the new GUI capabilities in Unity 4.6 for Vectrosity. There were a number of clear advantages, but it does naturally require Unity 4.6. It is of course possible to use conditional compilation, which I already do for Unity 4.3 features. Aside from the code, however, I was concerned about the documentation and general usability, since while it would mostly still work the same, there are some fundamental changes, and I wasn't too keen on having a bunch of "if you're using Unity 4.0-4.5, then this, otherwise that" scattered around. It's just kinda confusing.

    After not really being able to decide what to do, it finally occurred to me that maybe I should just ask people. ;) I've been playing around with 4.6 some more recently, and it became clear that ideally I'd like to just drop support for anything less than 4.6 for future versions of Vectrosity.

    The pros:

    • No more VectorCamera. I was never 100% happy with the VectorCamera from the beginning, but there wasn't really any good alternative (there's immediate mode, but that's slower). Now I can just use a canvas instead, which instantly makes things cleaner in general. No worries about GameObject layers and so on.
    • No more meshes. Since CanvasRenderer.SetVertices can take a List as well as an array, that would make it much easier to have dynamically-sized lines without all the indexing hacks currently required. (There's still a 65K vertex limit though.)
    • Can easily layer lines with other canvases, and put 3D objects in front of/behind 2D lines (or you can use it as an overlay, similar to the VectorCamera).
    • All VectorLine objects are grouped under a canvas, which makes the hierarchy cleaner at runtime.
    • Lines don't distort when changing screen resolution at runtime, so you don't necessarily need to redraw them.
    • Seems to be about 10% faster judging from initial tests.

    The cons:
    • Joins.Fill was basically free with meshes, but would now be somewhat slower since it requires additional quads.
    • No hardware 1-pixel lines or points; all line segments must be made of quads, so these would be slower too, if you had been using VectorLine.useMeshLines.

    So...should Vectrosity 4.0 be Unity 4.6+ only? Or not?

    --Eric
     
  8. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    3,037
    Ditch the old engines like a bad habit, but keep the most recent pre-4.6 in a package. So basically the usual thing people do on the UAS. The slight drawbacks may have solutions in the future anyway.


    All line segments being quads - how much more work is the system doing because of that? 50-80%? Will it matter for anything less than a BattleZone-like full scene on average modern hardware?
     
  9. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Unless you specifically use 1-pixel lines and VectorLine.useMeshLines, Vectrosity always uses quads anyway. I think using hardware 1-pixel lines is about twice as fast or so. It doesn't matter on modern hardware unless you have a huge number of lines. (Personally, I never actually used that for my own stuff, since I always prefer lines to be at least 2 pixels.)

    --Eric
     
  10. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    3,037
    No problem, then! In with the new :)
     
  11. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I do use Joins.Fill a lot though. ;)

    --Eric
     
  12. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,042
    I would like all the 4.6 stuff you are thinking about and a package with the latest version pre 4.6 for the people that cant or dont want to use 4.6+

    NGUI used to do that
     
  13. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,773
    I'll put it this way.... if Vectrosity uses uGUI, I will buy it in a heartbeat for our next game. If it doesn't, I'll have to write my own line solution that does.
     
  14. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Well, we certainly can't have you doing that, now, can we. ;) I've ditched all the mesh stuff and have been systematically replacing it with UIVertex stuff...as usual there's a bunch of details I hadn't really considered before embarking on this idea, but nothing major, so it's getting there.

    --Eric
     
  15. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    Eric,

    Unity 4.6 is still beta software and I think of as something not stable enough to build on top of. If you do plan to be Unity 4.6+ only I think you should keep the older 4.x - 4.5.x versions (even if they are not changing) in the package for a while. At keep least the older versions around at least until Unity 4.6 is officially released. Your package is not that large so keeping them around should not impact downloading time for updates that much.
     
    Last edited: Sep 7, 2014
  16. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    3,037
    I'm pretty sure that's his plan. You aren't allowed to release a package that requires a beta version of Unity; you must target the latest stable release.
     
  17. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Don't think so, since Unity themselves have published at least one Unity 4.6 package and I've seen others. But yes, it would make sense to include the Vectrosity 4.0 stuff as a separate package and keep 3.1.1 around for now.

    --Eric
     
  18. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    3,037
  19. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Hmm, yeah, they're sometimes inconsistent with rejections. I wouldn't want to make 4.6 the required minimum for quite some time anyway, so I would continue to upload to the store with 4.0, and have Vectrosity 4 be an optional package.

    --Eric
     
  20. MarcoMeter

    MarcoMeter

    Joined:
    Jun 14, 2013
    Posts:
    69
    I would love to see an update concerning the possible benefits of 4.6 .
     
  21. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I wrote a list of the benefits above. Although I can think of one more: easier to deal with lines in the scene view.

    --Eric
     
  22. kenshin

    kenshin

    Joined:
    Apr 21, 2010
    Posts:
    940
    Hi Eric,

    Unity3D new gui is absolutely without a decent line system, so we need an updated version of Vectrosity at least from when 4.6 will become stable... this is mandatory! ;)
    I hope Unity3D guys will add some good features to help you to improve your library performances in the 5.x cycle.

    At the same time I think will be a good idea to keep 3.1.1 version inside a separate package.

    Keep up the good work!
     
  23. polytropoi

    polytropoi

    Joined:
    Aug 16, 2006
    Posts:
    681
    +1 for 4.6-friendly vectrosity!
     
  24. SantosR

    SantosR

    Joined:
    Dec 18, 2013
    Posts:
    27
    Whenever I draw a spline that is thick I get some artifacts, like in the attached image.


    How can I fix this?
     

    Attached Files:

  25. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Use Joins.Fill or Joins.Weld. Also it looks like it has a LOT of points; it would be better to use fewer.

    --Eric
     
    SantosR likes this.
  26. SantosR

    SantosR

    Joined:
    Dec 18, 2013
    Posts:
    27
    Thanks for the lightspeed support. This plugin rocks.

    I am now trying to make draw Spline progressively, I know there are the min/maxDrawIndex properties for drawing the points, however I would like to have this control at segment level. Is it possible?
     
  27. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Do you mean having the segment itself drawn progressively? In that case no, sorry. If that's what you're doing, then having lots of points isn't such a bad idea after all. ;)

    --Eric
     
  28. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I'm about done with the initial version of Vectrosity 4.0. It seems to work for what I've tested so far, but I'm sure some beta testing would help. So if you've bought a previous version and want to participate, send me a PM with your email address (should be the same as the one you used when buying from my site; if you bought from the asset store, include the invoice number). I haven't updated the docs or written an upgrade guide yet, but the preliminary changelog has notes about the changes that should be sufficient for updating your code, I hope. Also I converted all the demo scripts. The focus should be on bugs, but suggestions for improvements are welcome.

    --Eric
     
  29. iamsam

    iamsam

    Joined:
    Dec 22, 2013
    Posts:
    233
    Excellent Work! Looking forward for 4.0

    Had a quick question. I have been using this plugin since a long time and all this time I just had one camera in my game. However in my new game I am using two cameras (a first person perspective and an orthographic one) and I am finding it difficult to figure out how to make the line render to only one of the cameras. Is this possible and if it is can you please let me know how to do it using code.

    Thanks,
    Sam
     
  30. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Is that for lines made with Draw, or Draw3D?

    --Eric
     
  31. iamsam

    iamsam

    Joined:
    Dec 22, 2013
    Posts:
    233
    Hi Eric,

    Thanks for getting back so quickly. I am using the spline Draw3D.
     
  32. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    In that case, first use VectorLine.vectorLayer3D to set the layer the lines are drawn on. This should be a layer you're not using for anything else. Then, for the camera that you don't want to draw lines, change the culling mask to exclude the vector layer.

    --Eric
     
  33. iamsam

    iamsam

    Joined:
    Dec 22, 2013
    Posts:
    233
    Wow... that worked!!... Thank you very much Eric. Outstanding support! :)
     
  34. Armageddon104

    Armageddon104

    Joined:
    Sep 14, 2014
    Posts:
    22
    Quick question before I buy this, I haven't seen a definitive answer to it. Can Vectrosity do perfect 1px lines like Kentucky Route Zero/GL.lines? And in 3D space and they won't change thickness like this:



    Thanks!
     
  35. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yep, that's what I made it for originally, in fact. :) (Although for more than 1px, but that works too.)

    --Eric
     
  36. Armageddon104

    Armageddon104

    Joined:
    Sep 14, 2014
    Posts:
    22
    That's great, follow up question I forgot to ask: Can you fade between colors/textures between line points? I've only seen pictures with solid colors/textures.
     
  37. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Line segments can fade between colors (as seen in this demo). There can only be one texture per line though.

    --Eric
     
  38. Jonathan-Bro

    Jonathan-Bro

    Joined:
    Apr 11, 2013
    Posts:
    35
    I'm trying to use your demo scene "Curve" to see if I can have the lines Join.Fill (on line 62) of DrawCurve.js (see picture). The lines are not joining though. Is this supposed to happen?
     

    Attached Files:

  39. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Actually yes, since the way the curves are made in that script, the last point in one is identical to the first point in the next, which makes Vectrosity skip a quad so there's no fill possible at that spot. You could fiddle with the index values of MakeCurve in that script to prevent that from happening.

    --Eric
     
  40. Ajes

    Ajes

    Joined:
    Sep 13, 2013
    Posts:
    26
    I hope that it is just me that is derping.. but:

    When I draw a line to screen coords:
    VectorLine dasdsadsa = VectorLine.SetLine(Color.green, new Vector2(0, 0), new Vector2(200, 200));
    dasdsadsa.Draw();

    It shows correctly from downleft corner towards middle on screen.

    when I resize my game window and use dasdsadsa.Draw(); again. the line has moved wrongly?! and when I try other stuff, I cannot get it to draw the line again even if I use:


    VectorLine.Destroy(ref dasdsadsa);
    dasdsadsa = VectorLine.SetLine(Color.green, new Vector2(0, 0), new Vector2(200, 200));
    dasdsadsa.Draw();

    after a window resize..

    any suggestions? - have looked thrue google and the documentation for some hours now..
     
  41. Ajes

    Ajes

    Joined:
    Sep 13, 2013
    Posts:
    26
    I fixed my "problem" when I saw that there was a VectorCam object in the hierachy..

    I used:

    Destroy(GameObject.Find("VectorCam"));

    to destroy it to reset the weird wrong positions the line would have after a screen resize..

    so now my lines works correctly again after a resize :)
     
  42. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    There's no need to destroy the VectorCam; you can call Vector.SetCamera and re-draw the line after the resolution changes. Also you don't have to recreate the line, just re-draw it. Most of the demos have code which does this. (No longer an issue in Vectrosity 4 anyway....)

    --Eric
     
    Ajes likes this.
  43. Assault

    Assault

    Joined:
    Aug 21, 2012
    Posts:
    60
    Hi. Is there a way to get the length of a line created with MakeCurve? VectorLine.GetLength() seems to always return a constant value, which seems to be the length of the line when it was created. Why isnt it returning the current length? I am calling MakeCurve() in Update() because the line is constantly changing shape and length.
     
  44. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Make sure you call SetDistances on a line after updating it, if you're going to use GetLength.

    --Eric
     
  45. Jonathan-Bro

    Jonathan-Bro

    Joined:
    Apr 11, 2013
    Posts:
    35
    Sorry, could you go in a little bit more depth when you mean fiddling with the index values of MakeCurve? What will I need to do to fill in the connection?
     
  46. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Probably the simplest would be to change all cases of MakeCurve where it's currently "segments+1" to "segments", and vice versa ("segments" to "segments+1"). That would cause the curves to overlap by 1 point, so there would no longer be two points in a row with the same value. Also you'd need to adjust the length of the linePoints array to compensate.

    --Eric
     
    Jonathan-Bro likes this.
  47. TheAryeh

    TheAryeh

    Joined:
    Jan 18, 2014
    Posts:
    4
    Hey Eric,

    Awesome product-- it's enabled me to try out making a game idea I've had. I've hit a snag though. In your documentation it explains that in order to get smooth color transitions you just set "myLine.smoothColor = true;". It keeps giving me an error, however, and Intellisense isn't indicating there is a smoothColor available as a property. Thanks for your help.

    TheAryeh
     
  48. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Hi, you'd need to be sure that the version of Vectrosity in your project is 3.1 or later.

    --Eric
     
  49. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It looks like I'm about done with the code for Vectrosity 4, unless the beta testers find any bugs. I'm starting on the docs next, so if anyone else wants to do some testing, now's the time. I did a benchmark of drawing a Vector2 line with 1000 points 1000 times, and it seems Vectrosity 4 is 30% faster than Vectrosity 3.1. Drawing a Vector3 line with Draw was 32% faster in Vectrosity 4, and drawing a Vector3 line with with Draw3D was 18% faster. So that's nice. ;)

    --Eric
     
    orb likes this.
  50. dualite2

    dualite2

    Joined:
    Feb 21, 2012
    Posts:
    23
    Hi, i need the possibility of specify line width in unity world space unit (3d line).
    Can you had a boolean like "worldSpaceForWidth" to VectorLine object or other tricks?

    And is you can do this, i need to know when because i'm need this really fast ;)

    FYI i want use this for create dynamic HUD like Animated Holo Interface.

    I hope my english is correct.
     
    Last edited: Sep 17, 2014
Thread Status:
Not open for further replies.