Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    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. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    That seems kind of application-specific, so I'd say go ahead with the lerpy loops. You could write your own function to do that (using myLine.points2/points3).

    --Eric
     
  2. memetic-arts

    memetic-arts

    Joined:
    Feb 27, 2011
    Posts:
    82
    yup, on it.

    you wouldn't happen to know the equation for scaling-up along a given angle,would you? i know you can add/multiply vectors, but i can't find the equations . . . if not, no worries, i'll figure it out sooner or later, just thought I'd ask.

    thanks!
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Alas not, sorry!

    --Eric
     
  4. d12frosted

    d12frosted

    Joined:
    Feb 3, 2014
    Posts:
    43
    Hello!
    I like this asset, but faced one little problem.
    I am making 2d game (orthoraphic camera, sprites + sortingLayerID and sortingLayerOrder for configuring draw orders). And I can't figure out, how to make Vectrosity draw line on specific sortingLayer. I am trying this ones:

    Code (csharp):
    1. line.vectorObject.renderer.sortingLayerID = mySortingLayerID; // doesn't work at all
    2. line.vectorObject.renderer.sortingLayerName = mySortingLaterName; // the same - it doesn't work
    I even tried in Update (lol, I'm so desperate), but it doesn't work even there (lol again).

    Have anyone achieved working state of sortingLayerID for lines?
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Hi, use VectorLine.sortingLayerID.

    --Eric
     
  6. Burglecut_0001

    Burglecut_0001

    Joined:
    Nov 26, 2012
    Posts:
    8
    hi Eric,

    I have a problem I can't figure out about screen resizing. Using VectorLine.SetCamera() after a screen resize that includes any horizontal change to the window dimensions works just fine. But if the screen resize is only in the vertical direction, my VectorLines disappear. But they re-appear again once I do a horizontal screen resize.

    It seems like it has something to do with the VectorLines being outside the clipping planes of VectorCam after a vertical-only resize. Things I've observed:

    1. If I do a vertical-only resize (calling SetCamera or not), my VectorLines become invisible. Then if I make VectorCam's clipping planes wide enough in the inspector by hand, the VectorLines show up again.

    2. Calling SetCamera after a vertical window resize changes the clipping planes on VectorCam. But after a horizontal resize, SetCamera does not change the clipping planes.

    3. I think the values of the clipping planes set after a vertical resize are probably okay. Because I can do a small horizontal resize and call SetCamera to make the VectorLines re-appear, and the clipping planes have the same value as before when the VectorLines were invisible, only now they are visible.

    So, my guess is that SetCamera() re-positions the z value of the VectorLine mesh after a horizontal resize, but it doesn't do that after a vertical screen resize, it just changes VectorCam's clipping planes. And so after a vertical resize, the mesh ends up outside the clipping planes. And I verified that this is happening by printing out the vectorLine object's mesh bounds after a resize. (Compare mesh z value to the clipping plane range.)

    Initial state, VectorLines are visible:
    vectorline mesh bounds Center: (399.0, 377.0, 377.0)
    VectorCam clipping plane, near: 376.9999
    VectorCam clipping plane, far: 377.0101

    After a small vertical resize and SetCamera(), VectorLines are invisible:
    vectorline mesh bounds Center: (399.0, 377.0, 377.0)
    VectorCam clipping plane, near: 371.9999
    VectorCam clipping plane, far: 372.0101

    After a small horizontal resize and SetCamera(), VectorLines are visible again:
    vectorline mesh bounds Center: (400.0, 372.0, 372.0)
    VectorCam clipping plane, near: 371.9999
    VectorCam clipping plane, far: 372.0101

    So for the vertical resize, SetCamera adjusted the clipping planes, but not the mesh z value. It took a horizontal resize and calling SetCamera to re-position the mesh inside the clipping planes again.

    I can't figure out why this is happening. I've tried tricking it by simulating a horizontal resize, by tweaking my camera's pixelRect width, or using Screen.SetResolution() to nudge the horizontal value a little. But this hasn't had any effect. I've tried waiting a few frames before calling SetCamera(), or calling SetCamera multiple times, or even hooking it to a button, so I can call it manually whenever I want. But no dice.

    I think it's possible that this behavior might somehow be related to how Unity handles resizing slightly differently for vertical and horizontal directions. Resizing horizontally continuously updates Screen.width during the whole drag. Resizing vertically looks like it scales everything according to aspect ratio till the mouse is released at the end of the drag, then it figures out the final geometry, and updates Screen.height only once at the end. The VectorLines are visible during the vertical drag, but disappear at the end, when Screen.height is updated, whether or not I call SetCamera.

    Here are some of my setup details: I have a coroutine that tests for Screen.width or Screen.height changes. When a change is detected, I adjust the pixelRect of the scene camera (it only uses a certain portion of the screen), and then fire an event for the resize. A method that subscribes to that event, calls VectorLine.SetCamera() on the recently modified scene camera. And then sets the cullingmask and depth to the correct values on the returned camera from the SetCamera method (aka VectorCam). And then I call Draw again on all my VectorLines to refresh them. My VectorLines use an array of points3 to describe their lines.

    Any thoughts or suggestions would be appreciated.
    thanks,
    Jon

    P.S. Vectrosity is awesome!
     
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Indeed that seems to be the case; I'll investigate. In the meantime, if you pass in true with SetCamera so that the VectorCam is orthographic, that works with vertical-only resizing.

    --Eric
     
  8. Burglecut_0001

    Burglecut_0001

    Joined:
    Nov 26, 2012
    Posts:
    8
    hi Eric,
    Thanks, ortho does work on vertical resize!

    I haven't used ortho before because it says in the docs,
    "The optional useOrtho is false by default. Passing true will cause the vector camera to use orthographic
    mode, which may render lines slightly more accurately, but can potentially cause anomalies in 3D lines under
    certain circumstances."

    Are there any circumstances that I should avoid with ortho so I don't trigger the anomolies?
    thanks,
    Jon
     
  9. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    OK, the z position was fine, but the issue was that the mesh bounds weren't updated unless the horizontal screen size was changed, so that's fixed for the next version.

    The circumstances to avoid with ortho seem to be objects passing behind the camera, which you can see if you try to use ortho with the Tank Zone demo.

    --Eric
     
  10. Burglecut_0001

    Burglecut_0001

    Joined:
    Nov 26, 2012
    Posts:
    8
  11. d12frosted

    d12frosted

    Joined:
    Feb 3, 2014
    Posts:
    43
    Hello. Sorry for late reply. I know about VectorLine.sortingLayerID from documentation. But it doesn't work as well :( That's why i tried this voodoo magic.

    BTW, even if I use VectorLine.sortingLayerID = 0, the line is on top.]

    Update

    Oh sorry, I found a solution. I am using VectorLine.Draw() instead of VectorLine.Draw3D().
     
    Last edited: May 15, 2014
  12. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Are you using Draw()? That creates a separate camera where lines are drawn as an overlay. If you want lines to interact with other objects you need to use Draw3D().

    --Eric
     
  13. d12frosted

    d12frosted

    Joined:
    Feb 3, 2014
    Posts:
    43
    Thank you for your help :)
     
  14. Jimmythesaint82

    Jimmythesaint82

    Joined:
    Sep 20, 2012
    Posts:
    21
  15. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You could use splines if the drawing speed is too fast.

    --Eric
     
  16. Jimmythesaint82

    Jimmythesaint82

    Joined:
    Sep 20, 2012
    Posts:
    21

    Attached Files:

    Last edited: May 16, 2014
  17. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Increasing the number of points would fix that.

    --Eric
     
  18. MythicalCity

    MythicalCity

    Joined:
    Feb 10, 2011
    Posts:
    420
    Hi,
    I'm trying to set the color of a line that is created, but SetColor doesn't seem to do anything. My shader is the UnlitAlpha shader which seems to support changing colors. Here is the code I am using:

    VectorLine circleLine = new VectorLine("circle", new Vector3[128], Color.cyan, distanceCircleMaterial, 10f);
    circleLine.MakeCircle(center, Vector3.up, radius);
    VectorLine.vectorLayer3D = Globals.Instance.layerObject;
    circleLine.SetColor(Color.cyan);
    circleLine.Draw3DAuto();
     
  19. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    If you mean Unlit/Transparent, that doesn't support vertex colors. A quick test is to replace the material with null, and if the colors work, that means the shader in the material is the problem.

    --Eric
     
  20. wbl1

    wbl1

    Joined:
    Apr 22, 2009
    Posts:
    159
    Is it possible to have more than one vectrocity camera in your scene?

    In one part of my scene, we have a series of simple lines (representing a path that a rover is going to move along), and in another part of the scene I have some graphs that I have developed using vectrocity.

    The problem is that we need to allow the user to zoom in on the path (to do this we just change the orthographic size of the vectrocity camera). But, when we do this, I expect the graphs will move to a different place or get larger/smaller etc ...

    So, I would think two different cameras would be the easiest way to go. If this is not possible, do you have any other suggestions for how to solve this issue?

    Thanks!
     
  21. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It's not possible to have more than one Vectrosity camera. You could do zooming by altering the scale of the path, which can be easily accomplished by using .drawTransform and changing the scale of that transform. I'd recommend that over altering the VectorCam anyway.

    --Eric
     
  22. Jlpeebles

    Jlpeebles

    Joined:
    Oct 21, 2012
    Posts:
    54
    Has anyone had any luck with using some sort of mesh exploder/breaker with Vectrosity?

    I've tried using Mesh Explosion but the normal and tangent arrays give array out of index errors. (This is with using AddNormals and AddTangents)
     
  23. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I doubt altering the VectorLine mesh would work well since Vectrosity isn't expecting that, but what are you attempting? Since LineType.Discrete can have every line segment appear separate, you could "explode" a line by moving the line segments in the points array.

    --Eric
     
  24. wbl1

    wbl1

    Joined:
    Apr 22, 2009
    Posts:
    159
    We've had some success with this, but still running into problems. I take it if we make the "path" 3D lines that this wont solve the problem? In other words, are 3d lines rendered via a "normal" camera meaning that the vectrocity camera could be dedicated to the 2D graphs - or is the vectrocity camera going to be displaying both the 2D and 3D elements?
     
  25. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The Vectrosity camera only shows the 2D elements. (By default; you can change the layer stuff to make it work differently if you wanted to.)

    --Eric
     
  26. arkon

    arkon

    Joined:
    Jun 27, 2011
    Posts:
    1,122
    Hi, I've just upgraded project that uses Vectrosity to Unity 4.5 and my animated dashed lines no longer work.
    The dashed texture seems to be stretched the entire length of the line and the dots don't repeat. I'm trying a blank project no just with the vectrosity demos.

    *Edit, fixed it, I had to move the textureOffset setting to after drawing it in 4.5
     
    Last edited: May 28, 2014
  27. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I'm not aware of any differences with 4.3 and 4.5 as far as Vectrosity is concerned...the selection box demo, for example, works the same.

    --Eric
     
  28. arkon

    arkon

    Joined:
    Jun 27, 2011
    Posts:
    1,122
    yes it does all work the same, but not in the way I'd implemented it in a game. I was animating the material by moving the offset on the material directly whereas in your demo you use the line.textureOffset thingy. in 4.3 my way worked in 4.5 it doesn't. It's not a vectosity problem after all but one of those subtle fundamental things that change in the engine for no apparent reason.

    If you want to replicate the problem just to see whats up, change your selection box demo to:

    Code (csharp):
    1.      public Material lineMaterial;
    2.        lineMaterial.SetTextureOffset("_MainTex",-Time.time*2.0f % 1);
    3.        line.Draw3D();
    4.  
    whereas yours does this and works fine:

    Code (csharp):
    1.     line.Draw3D();
    2.         line.textureOffset = -Time.time*2.0f % 1;
    3.  
    Except on yours if you try and do the texture offset before the draw3d you get an exception.
     
  29. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Hmm, still works the same here if I use SetTextureOffset before Draw3D in both 4.3 and 4.5.

    --Eric
     
  30. arkon

    arkon

    Joined:
    Jun 27, 2011
    Posts:
    1,122
    No matter I've fixed it now using your way. Meanwhile there is another oddity I've discovered.
    I was using your unlitAlpha shader on some flames created using the legacy particle system because they looked really good, better than any other shader.
    The particles a behind a Unity 2d sprite. In V4.3 all worked well, flames behind the sprite. In V4.5 the sprite is not visible when the particles go behind the sprite. I've had to change to the unlit/transparent shader to get it working again.

    I know this is nothing really to do with your plugin but I thought you should know as they may be something in your shader causing problems with sprites.
     
  31. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I tried that, and again I get the same behavior in 4.3 and 4.5. Make sure you're not relying on undefined behavior (for example, using the same sorting layer and the same order in layer for both particles and sprite), since that frequently results in "works one way in this version/build, works another way in another version/build".

    --Eric
     
  32. Edge-Lee

    Edge-Lee

    Joined:
    Jul 13, 2012
    Posts:
    4
    Hey Eric,
    I've noticed that VectorLine.SetEndCap("End", EndCap.Back ....) is not working for 3d lines. It works for the other EndCap modes except EndCap.Back

    Is there some attributes I must initialize before using it ? I've tried modifying the demo package "End Cap" with 3d lines and the end cap doesn't seem show up as well.

    - Lee
     
  33. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    That was a stupid mistake on my part; I've fixed it for 3.1, but if you want to fix it now, use the source and on line 1815 of VectorLine.cs, change "m_lineWidths[widthIndex] * 2.0f * capDictionary[m_endCap].ratio1" to "m_lineWidths[widthIndex] * 2.0f * capDictionary[m_endCap].ratio2".

    --Eric
     
  34. Edge-Lee

    Edge-Lee

    Joined:
    Jul 13, 2012
    Posts:
    4
    Alright Eric,
    thanks for the fix and solution~ :)

    - Lee
     
  35. doombob

    doombob

    Joined:
    Jan 25, 2014
    Posts:
    23
    Hi there,

    I bought Vectrosity a couple weeks ago, excellent plugin, can't thank you enough for it :)

    I'm having a little issue, to set the scene briefly: I'm projecting a vector image of the earth and all its countries onto a 3D globe. The camera can orbit around this globe google earth style.

    The problem I'm having is when I draw the 350+ lines using Draw3DAuto() they don't face the camera or adjust their size in regards to the camera's movement and rotation. I've tried using SetCamera3D() in several places (though I only have 1 camera "Main Camera" in the scene) to no avail.

    I created a very simple test scene with just a single line and the same orbiting camea and that works as I would expect, the line re-orientates itself and scales appropriately.

    I've only been using Vectrosity for a couple weeks so I may be missing something obvious. I've included a video if it helps. you can see the lines are billboarded correctly when they are created, but if I orbit over to the over side of the world you can see the orientation doesn't change.

    http://youtu.be/DT2bhN3P1Uw

    Thanks for any help!

    - Cash

    EDIT:

    I guess a little code would help:

    Code (csharp):
    1. var line = new VectorLine("globe", vertices, Color.green, Global.instance.borderLineMaterial, 1f, LineType.Continuous)
    2. {
    3.     joins = Joins.Fill
    4. };
    5. line.Draw3DAuto();
     
    Last edited: Jun 2, 2014
  36. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I don't know if it would make any difference, but the standard way of creating a line would be

    Code (csharp):
    1. var line = new VectorLine("globe", vertices, Color.green, Global.instance.borderLineMaterial, 1f, LineType.Continuous, Joins.Fill);
    Other than that I'm afraid I'm not really sure. I made a test where 350 VectorLines are created with Draw3DAuto, and they behave as expected regardless of camera movement. What typically causes Vectrosity to not work is if the camera is destroyed without setting a new one, or the VectorLines' transforms are altered directly.

    --Eric
     
  37. doombob

    doombob

    Joined:
    Jan 25, 2014
    Posts:
    23
    Damn, well I'll keep poking at it, I must be doing something weird in that scene, since the camera never gets created or destroyed dynamically and I don't touch the line transforms either.

    If I can find any more information I'll be back.

    Cheers
     
  38. doombob

    doombob

    Joined:
    Jan 25, 2014
    Posts:
    23
    Ok I've fixed it, looks like I was adding one line with no vertices due to bad parsing, thus tripping the static error boolean you've got in there and preventing all updates.

    I have another problem now however, and it maybe or may not be solvable:

    I have 387 lines in my scene (with between 10 and 200 vertices each) that make up my globe, and now the updating is actually happening, my framerate has plummeted to 10fps :S

    Is there anything at all I can do to bring this back up? Or is 387 lines with Draw3DAuto simply too much?

    Thanks!
     
    Last edited: Jun 3, 2014
  39. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    What hardware are you running on? That doesn't sound like it should be too much.

    --Eric
     
  40. doombob

    doombob

    Joined:
    Jan 25, 2014
    Posts:
    23
    I'm developing on a Microsoft Surface Pro, but I've also run the scene on my work machine, which is a 4 core i7 with 24gb ram.

    The surface pro gets approximately 8fps
    My beast of a work machine gets about 15fps

    In total there is approximately 16.5k tris making up the lines.

    The code I'm using for each line is:

    Code (CSharp):
    1. var line = new VectorLine("globe", vertices, Color.green, Global.instance.borderLineMaterial, 3f, LineType.Continuous, Joins.Fill);
    2. line.Draw3DAuto();
     
  41. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Out of curiosity, what happens if you change it to Draw (and update them every frame) instead of Draw3DAuto?

    --Eric
     
  42. doombob

    doombob

    Joined:
    Jan 25, 2014
    Posts:
    23
    If I use Draw3D() after creating the line, and Draw3D() once per frame that framerate is uneffected.
    If I use Draw() after creating the line, and Draw() once per frame the framerate settles at around 55fps, but obviously I lose the occlusion I need.
     
  43. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Hmm, I'll see if there's some way I can speed up Draw3D.

    --Eric
     
  44. doombob

    doombob

    Joined:
    Jan 25, 2014
    Posts:
    23
    You legend, I hope you manage it, cause my project sorta depends on this vector globe :S

    Thanks!
     
  45. doombob

    doombob

    Joined:
    Jan 25, 2014
    Posts:
    23
    I can send you the scene if you like, to make it easy for you to test?
     
  46. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I don't think that's necessary, since I can profile Draw3D here easily enough.

    --Eric
     
  47. ichini

    ichini

    Joined:
    Oct 13, 2012
    Posts:
    23
    Just wondering: Is there a way to weld the joins of a vector text created with MakeText?

    Example:

    Code (csharp):
    1. var labelPoints = new Vector3[10];
    2. label = new VectorLine(collectibleName + " " + labelString, labelPoints, objColor, lineMaterial, lineWidth, LineType.Discrete, Joins.Weld);
    3. label.MakeText(labelString, Vector2(labelOffsetX, labelOffsetY), labelSize);
    4. label.drawTransform = transform;
    5. label.Draw3DAuto();
     
  48. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Not effectively, I'm afraid, since text is made with discrete lines, which have the ability to use Joins.Weld but it's somewhat limited. It could be improved but the cost is too high, in terms of slowing things down.

    --Eric
     
  49. paraself

    paraself

    Joined:
    Jun 30, 2012
    Posts:
    139
    Hi thanks for making this great plugin. Is it possible to draw filled shapes with solid color? Like the ones in processing?
     
  50. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    No, sorry; Vectrosity is only for line drawing.

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