Search Unity

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. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Not yet, sorry, I need to get Vectrosity 4 out first, since it's a pretty big rewrite that doesn't really have added features. Those can come later when I'm sure that the rest is working well.

    However, since lines are drawn on a canvas in Vectrosity 4, the canvas can be made world-space and then rotated, which should result in an effect similar to that asset:

    3dvec.png

    --Eric
     
  2. dualite2

    dualite2

    Joined:
    Feb 21, 2012
    Posts:
    23
    Alright i understand.

    Well, i hope in near future is possible, because i really think it's good solution for my game.
    However, i make animate texture for the Alpha...

    Thank you.
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It looks like I'm about done with the update, depending on feedback from beta testers. There will actually be two updates, one for Vectrosity 3 to fix a couple of issues:

    Vectrosity 3.1.2

    Changes:
    • VectorLine.SetWidth has the same options as SetColor now. Namely, SetWidth(width) sets the entire line to the specified width, SetWidth(width, index) sets only the line segment indicated by the index to the specified width, and SetWidth(width, startIndex, endIndex) sets all the line segments from the start to the end indices to the specified width.

    Fixes:
    • The last point in a VectorPoints object is colored correctly when using VectorLine.SetColors.

    And then there's Vectrosity 4:

    Vectrosity 4.0

    Changes:
    • Lots of stuff! Vectrosity now uses Unity 4.6 UI functions. See the Vectrosity 4 upgrade guide for details about upgrading existing code from Vectrosity 3.
    • Removed VectorLine.SetCamera and VectorLine.GetCamera.
    • Added VectorLine.canvas and VectorLine.canvas3D static variables.
    • VectorLine constructors can use List<Vector2> and List<Vector3> in addition to Vector2[] and Vector3[] arrays.
    • The array supplied in the VectorLine constructor is no longer used after the VectorLine is created; use VectorLine.points2 or VectorLine.points3 instead.
    • VectorLine.points2 is now List<Vector2> instead of a Vector2[] array, so lines can be dynamically resized by using List functions such as Add, RemoveAt, etc.
    • VectorLine.points3 is now List<Vector3> instead of a Vector3[] array, and can be resized as described above.
    • VectorLine constructors no longer use colors or color arrays. Instead colors are set after creating the line.
    • VectorLine.color can be used to set the color for all segments in the line. Also, it no longer returns the first line segment color; VectorLine.color is always the "true" color of the line, even if all the line segments have been set to different values when using SetColor or SetColors.
    • VectorLine.SetColors can use List<Color> in addition to a Color[] array.
    • VectorLine.SetWidths can use List<float> or List<int> in addition to float[] and int[] arrays.
    • Removed VectorLine.vectorLayer and VectorLine.vectorLayer3D.
    • Removed VectorLine.useMeshLines and VectorLine.useMeshPoints.
    • Added VectorLine.SetCanvasCamera, which is shortcut for setting the canvas.renderMode to RenderMode.OverlayCamera and setting the canvas.worldCamera to a specified camera.
    • Removed VectorLine.SetCameraRenderTexture. Instead the camera rendering to a texture can be set with VectorLine.SetCanvasCamera.
    • Removed VectorLine.SetDepth.
    • Removed VectorLine.SetVectorCamDepth.
    • Removed VectorLine.vectorObject.
    • Added VectorLine.rectTransform.
    • Removed VectorLine.SetLineParameters and VectorLine.MakeLine.
    • Removed VectorLine.sortingOrder and VectorLine.sortingLayerID.
    • Removed VectorLine.depth.
    • Added VectorLine.drawDepth, where lines with higher numbers are drawn on top of lines with lower numbers.
    • VectorLine.Resize only accepts an integer now, which non-destructively resizes the points list to the specified value (existing points in the list are untouched).
    • Removed VectorLine.ZeroPoints. Instead you can use List.Clear() with VectorLine.points2/points3.
    • Removed VectorLine.ResetTextureScale. Instead you can set line.textureScale to 0 and re-draw the line
    • Removed VectorLine.minDrawIndex and VectorLine.maxDrawIndex.
    • Added VectorLine.endPointsUpdate, which is the number of points from the end of the line that's updated when drawn, and the rest is left untouched. This is an optimization used primarily when dynamically extending a line, where most of it remains the same and doesn't need to be re-computed, such as drawing a line with the mouse.
    • VectorLine.MakeRect, when passing in a Rect, draws from the bottom-up, making it consistent with screen space coordinates.
    • Removed VectorLine.mesh.
    • Screen resolution changes no longer affect existing lines.
    • The default material for VectorLines (if no material is supplied) now uses the UI/Default shader.
    • In addition to the 65K vertex limit per line, there is a 65K total vertex limit for all lines. So e.g. using two continuous lines with 10000 points each (40K vertices) will fail.
    • Typically 18% - 30% faster, depending on the type of line being drawn.

    Known issues:
    • VectorLine.active does nothing, due to a Unity bug in 4.6b19, which has been verified and should be fixed in a future version. Once it's fixed, VectorLine.active should work without needing an update to Vectrosity. In the meantime, a possible workaround is to disable/enable VectorLine.canvas, though that will affect all VectorLines (but that may indeed be what you actually want). For individual lines, another possibility is to set VectorLine.drawEnd to 0 and re-draw the line to "deactivate" it, then set drawEnd back to points.Count-1 and re-draw to "reactivate" it.
    However, this issue with VectorLine.active prevents VectorManager.ObjectSetup from working properly with Visibility.Dynamic and Visibility.Static. The TankZone demo has been updated for Vectrosity 4 but is currently not included because it relies heavily on VectorLine.active and therefore doesn't really work correctly.
    • Setting VectorLine.canvas.sortingOrder has no apparent effect, due to a Unity bug in 4.6b19. It can be worked around by first changing the canvas sorting order, then using VectorLine.canvas.gameObject.SetActive(false) followed immediately by VectorLine.canvas.gameObject.SetActive(true), which forces the correct sorting order.

    Also the documentation is reduced by 4 pages, and the reference guide reduced by 7 pages, without losing any info, because of the streamlining. This is pretty much what I really wanted Vectrosity to be from the beginning, thanks to the UI stuff in Unity 4.6. (Now if they can just fix those bugs. ;) )

    --Eric
     
  4. TheAryeh

    TheAryeh

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

    I managed to get .SetColor() working based on your advice-- thanks! I have another question I was hoping you might answer. Is there any way to have a line switch from a spline line to a straight line from segment to segment? Or would I need to have two separate lines end to end to achieve that effect? Thanks again for your help!

    TheAryeh
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can have a spline be part of a line by specifying the segment number and the index. So if a line has 100 segments and you said to use 50 for the spline, then it would take up half the line.

    --Eric
     
  6. sn0w4pne

    sn0w4pne

    Joined:
    Jan 27, 2014
    Posts:
    2
    Hi guys,

    Apologies if this issue has already been addressed but this is a pretty big thread so I didn't have time to read everything.

    I've been writing some simple shaders and I'm having a bit of trouble getting them to perform correctly with my Vectrosity lines. I've noticed that when I run my game, the lines are drawn in the scene view way closer to the view than they are in the actual game window. This isn't a major problem seeing as the lines are in the correct place in the game window, I presume it's something to do with the VectorCam object that Vectrosity creates.

    However, my shader is not being applied to lines in my game window properly. The massive lines in my scene view are blending their colours with other objects but no such luck in the game window. Hopefully this is a common problem and there's a simple fix or setting I can change, if not I can provide more information.

    Thanks in advance,
    Chris.
     
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Sadly not a common problem. Vectrosity meshes, when created with Draw(), are made in a similar way as the new Unity 4.6 canvas stuff works in overlay mode, namely 1 unit = 1 pixel. Not sure if that helps or not.

    --Eric
     
  8. sn0w4pne

    sn0w4pne

    Joined:
    Jan 27, 2014
    Posts:
    2
    Wow, thanks for the quick reply. Ok, so you're saying that the size/position of the line is always going to be different in the scene view? That's not a problem as long as they're in the correct position in the game view ;)

    In regards to the shader though, is it possible to have it blending correctly with other objects in my scene? Basically I have a background grid drawn with Vectrosity and I'm attempting to have areas of the grid "glow" based on the position of a faded png. So I'm masking the grid apart from where the png is. It's working when I use my grid's shader on other objects such as a sphere but not on the grid itself (except in the scene view).

    Cheers,
    Chris.
     
  9. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Maybe it's not working because of the separate cameras? You could try using Draw3D instead.

    --Eric
     
  10. TheAryeh

    TheAryeh

    Joined:
    Jan 18, 2014
    Posts:
    4
    Thanks for the fast reply Eric. Prior to posting I had tried submitting a sub-array to .spline(), and it did indeed make a spline out of the range of points specified. Unfortunately, however, it doesn't draw the rest of the line at all. I currently have this generating the line:

    Code (CSharp):
    1. void LateUpdate()
    2.     {
    3.         lineVec.MakeSpline(buffer.SubArray(0,23));
    4.  
    5.         lineVec.Draw3D();
    6.     }
    Do I need to call something different to draw the rest of the line instead of only the spline portion? Thanks again for your help.

    TheAryeh
     
  11. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes, you need to indicate the number of segments to use, and the index. See the first overload for MakeSpline in the docs.

    --Eric
     
  12. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    Will this show as Vectrosity 4.0 in the asset store which also includes 3.1.2 (internal to the same package)?
     
  13. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes.

    --Eric
     
  14. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    Is there a way to make a line taper? What I mean by that is, well, I'm trying to draw tree branches simply using lines. But I want the branch to be wider where it meets the trunk and narrow to a point at the tip. Is that do-able?
     
  15. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes, you can use SetWidths with appropriate line segment widths, along with smoothWidth = true.

    --Eric
     
  16. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    Thanks! One other question: I don't suppose there is a built-in way to have screen-space based UVs? That is, when a line renders, its UVs would be based on each point's screen position? So for example if I had a texture and wanted the left edge of the screen to be u=0 and the right u=1, then when a line traveled from left to right on the screen, it would "reveal" that respective portion of the texture. If not, then is there a recommended way to manually manipulate the UVs of a spline? I looked in the reference and couldn't find much about UVs. Thanks again.
     
  17. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    No built-in way, sorry. VectorLine.mesh references the line's mesh, so you can get the UVs from that, then calculate them and assign them back. If it helps, the vertex indices for the first quad, starting from the upper-left corner and going clockwise, are 0, 2, 3, 1. So the next quad would be 4, 6, 7, 5, and so on.

    --Eric
     
  18. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Vectrosity 4 is out now! (On my site; not yet available on the asset store.) I started a new topic for Vectrosity 4 here. This one has become rather large, and a lot of the earlier pages aren't entirely relevant since Vectrosity has changed quite a bit since it was introduced. You can still post about Vectrosity 3 in this topic though.

    --Eric
     
    Last edited: Sep 26, 2014
  19. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    That is great news Eric. Thanks!
     
  20. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    I was wondering if there was a way to avoid some glitchy artifacts I'm getting in a 3D spline I'm building. Here is a video of the glitch:


    What I'm doing is I have a transform with child transforms which serve as points along the spline. Each frame I manually transform these points into the root transform's local space and assign them to the VectorLine using .MakeSpline(). I've also assigned the root transform to the VectorLine's .drawTransform member so that the whole thing can be rotated by rotating the root transform. I call line.Draw3DAuto() when it is created. Then I'm rotating that transform manually at runtime and, as you can see, as it rotates, I get various bits sharply and suddenly protruding from the path I've defined.

    Specifically, each frame I do the following:
    Code (csharp):
    1.  
    2. line.Resize(segmentCount + 1);
    3. line.MakeSpline(points, segmentCount, false);
    4. line.SetDistances();
    5.  
    Is there something I'm doing wrong, or something I can try that might eliminate these artifacts? Thanks!

    P.S.: I create the line with LineType.Continuous and Joins.Weld and set .smoothWidth to true.
     
    Last edited: Sep 30, 2014
  21. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Do the artifacts go away if you use Joins.None?

    --Eric
     
  22. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    Yes, pretty much. I tried playing with maxWeldDistance but wound up either with a line with lots of gaps in tight turns, or if I increased the value to get rid of the gaps, I got the artifacts once again.
     
  23. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Try using fewer points in the spline, so the points are farther apart and the segments are longer. I think the weld routine gets mathematically confused when the points are too close together. When I did the most recent update I tried changing the calculations to use doubles instead of floats, but the extra precision didn't help.

    --Eric
     
  24. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    Hmmm... unfortunately, using fewer segments isn't an option for my purposes, unless I had a way to have an un-rendered spline that I use to generate points for the VectorLine. You see, I'm trying to have tree branches that grow at runtime. If you have another recommendation as to how I could accomplish that effect, that'd be great.
     
  25. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I mean use fewer points for the VectorLine, so they aren't so close together. You can probably have a lot fewer and it will still look pretty smooth. At least try it to see if it fixes the problem.

    --Eric
     
  26. Ian76

    Ian76

    Joined:
    Sep 20, 2014
    Posts:
    3
    Hi Eric,

    I'm having a problem with Vectrosity.

    I have a %50 Transparent sphere and a 3D circle (using MakeCircle with material VectorLineGlow) sharing the same origin and diameter. The circle is in a vertical orientation. They are both rotating around their origins in the same direction and speed. When the circle appears to go behind the sphere, the occluded part of the circle may flicker, disappear or oscilate between correct transparency.

    The placement of the camera changes the way the problem behaves.

    If I use a Fresnel sphere or more complicated materials, the flickering and disappearing gets worse.

    I feel like I've tried everything but I can't get it too work properly.

    Please help.

    Ian.
     
  27. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
  28. Ian76

    Ian76

    Joined:
    Sep 20, 2014
    Posts:
    3
    I'll check it out. Thanks for your quick reply!
     
  29. Assault

    Assault

    Joined:
    Aug 21, 2012
    Posts:
    60
    Hi. I am using Vectrosity to mimic a rope hanging from an object in a multicamera setup. I call Draw3D in LateUpdate to update the rope. The problem is, when I rotate one camera, the "rope" appear thicked and thinner and also totally invisible from a certain angles. I think this is because the Draw3D aligns the line with a main camera. Is there a way to define which camera is the one where the line is aligned to?
     
  30. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can call SetCamera3D (followed by Draw3D) with the appropriate cameras each frame.

    --Eric
     
  31. arkon

    arkon

    Joined:
    Jun 27, 2011
    Posts:
    1,122
    I am trying to draw a 3D thick glowing circle using the MakeCircle command and line.Draw3D but it is being drawn with strange gaps in the line. what am I doing wrong? Here is a picture of the output:
    Screen Shot 2014-11-11 at 10.51.50 am.png
     
  32. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Use Joins.Weld.

    --Eric
     
  33. arkon

    arkon

    Joined:
    Jun 27, 2011
    Posts:
    1,122
    ta.
     
  34. ortin

    ortin

    Joined:
    Jan 13, 2013
    Posts:
    221
    Is it somehow possible to mask image using Vectrosity lines to get something like this
    4.jpg
    ?
     
  35. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can use Vectrosity to draw the lines, but the gradient fill would have to be done another way.

    --Eric
     
  36. ortin

    ortin

    Joined:
    Jan 13, 2013
    Posts:
    221
    Well, I know that I can draw lines :) Problem is how to use those lines to make gradient fill connected with them without recreating "line drawing logic" (to cut gradient). I thought about somehow using new UI's Mask to cut big prefilled gradient image, but seems it was stupid idea.
     
  37. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Maybe this would help? You could pass in the same points used for the lines (plus a few extra for the sides and bottom) in order to make a mesh.

    --Eric
     
  38. ortin

    ortin

    Joined:
    Jan 13, 2013
    Posts:
    221
    I'll take a look, thanks for your help!
     
  39. kvander

    kvander

    Joined:
    Oct 27, 2013
    Posts:
    3
    I'm fading my lines, but having trouble with the endcaps. Is there an efficient way to fade the endcaps?

    Thanks
     
  40. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    VectorLine.SetColor should work.

    --Eric
     
  41. kvander

    kvander

    Joined:
    Oct 27, 2013
    Posts:
    3
    SetColor works for fading the lines, but it's leaving all the endcaps behind. Here's my code

    IEnumerator FadeAllLines(float duration) {
    float elapsed = 0;
    Color gridColor = gridLine.color;
    Color solvedColor = Color.yellow;

    while(elapsed <= duration) {
    gridColor.a = Mathf.Lerp(1, 0, elapsed/duration);
    gridLine.SetColor(gridColor);
    gridOutline.SetColor(gridColor);

    solvedColor.a = Mathf.Lerp(1, 0, elapsed/duration);
    foreach(VectorLine line in solved)
    line.SetColor(solvedColor);

    elapsed += Time.deltaTime;
    yield return null;
    }
     
  42. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Make sure you're using an updated version of Vectrosity.

    --Eric
     
  43. kvander

    kvander

    Joined:
    Oct 27, 2013
    Posts:
    3
    What version is required? I'm running Unity 4.5.5f1, do I need to upgrade so I can use Vectrosity 4?

    Thanks
     
  44. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    At least 3.1.2.

    --Eric
     
  45. kadirfu

    kadirfu

    Joined:
    Oct 3, 2013
    Posts:
    6
    I have the very same problem. I just imported all of the assets from the folder Vectrosity 4.03 and nothing else. Could you solve this problem?
     
  46. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    That means you have the same thing imported twice.

    --Eric
     
  47. hugohil

    hugohil

    Joined:
    Nov 20, 2014
    Posts:
    1
    Hi there !

    Indeed, great work Eric, Vectrosity is really cool and nice to use.
    I just have a small issue with deleting VectorLines. When I type in my loop:

    VectorLine lineToDestroy = lines[ i];
    Vector.DestroyLinae(lineToDestroy);

    Unity console throws me an error saying the Vector class does not exist in the current context.

    Do you have any idea about what can I be doing wrong ?

    Thanks !
     
    Last edited: Nov 20, 2014
  48. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    There's no Vector; it's VectorLine. Also you need to use ref in C#.

    --Eric
     
  49. redmotion_games

    redmotion_games

    Joined:
    May 6, 2013
    Posts:
    84
    I'm passing a vector3[] to a vectorline and redrawing the line using resize and draw (every couple of seconds a new random point is added onto the line - so it gets longer and longer over time) and for the most part it works but randomly points are being draw out of place causing certain segments to vanish.
    Each vector in the vector array is always (x,0,z) (as in every y co-ordinate in every vector supplied is set to zero), but it seems that sometimes the vectorline is not drawing it at zero. I've checked the array at runtime and the y is always zero in every array element.
    Is there a way to make sure it stays "flat"?
     
  50. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Do you have any example code that causes this?

    --Eric
     
Thread Status:
Not open for further replies.