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, Sep 26, 2014.

  1. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Multi-threading isn't really a possibility at this time since it doesn't work on WebGL. Breaking the lines into smaller pieces is probably the way to go.

    --Eric
     
  2. Arkade

    Arkade

    Joined:
    Oct 11, 2012
    Posts:
    654
    Hello again
    I split the lines and it's improved things sufficiently for now. I'm now having a little difficulty figuring the best way to achieve something and would appreciate some advice.

    I have some Vectrosity lines that I wish to appear stationary and far-off in 3D space -- they're the constellations viewed in space. As mentioned above, I'm not drawing them each frame to avoid performance load. However that leads to a bit of a problem -- how to keep them synchronized with the player?

    A couple of complexities: The player is 'in space' = Y:5000. The player is scaled uniformly by 50 so they can 'walk around space' while still having scale to be scaled down for going close to the planets without running into numerical issues.

    Things I've tried:
    1. creating a GameObject with player-position-matching component that I then use as the `drawTransform`.
    2. parenting the `VectorLine.rectTransform` to that GO either with `localPosition` set to zero or allowed to stay at zero with offset on all points.
    3. parenting `rectTransform` to player with a component per line that forces the global rotation back to its original.
    4. (probably some other stuff I've forgotten?)
    Problems I encounter (some or several of these depending on the setup):
    1. Looking down = big, up = invisible (I guess due to line transform origin being at 0,0,0 while player is at 0,5000,0).
    2. Walking in a direction causes lines in that direction to get smaller and those opposite to get bigger.
    3. Different lines (stars and lines) get out of sync due to not being re-drawn in the same frame.
    4. Too high = double the offset from 0,0,0 = lines are at 0,10000,0.
    5. Too low = still at 0,0,0.
    6. Don't move with the player.
    I'm hoping I've just missed the obvious answer and there's some combination that I just haven't seen. Any thoughts appreciated.
    Btw I'm using the o/s GoogleVR controller for viewing in case that's relevant.

    Thanks in advance!
    (he lingers over the send button in the hopes that what usually occurs right after posting occurs slightly before for once... ...nope!)
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Unfortunately I'm not really able to understand what you're doing. At a wild guess, maybe have a separate camera for drawing Vectrosity lines, but again I don't follow so that's probably wrong.

    --Eric
     
  4. Arkade

    Arkade

    Joined:
    Oct 11, 2012
    Posts:
    654
    Sure, I understand. If I were to work on a minimal test case, would you be able to take a look?
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I can take a look, although one thing I can say after re-reading is that if the camera is moving, lines have to be redrawn every frame.

    --Eric
     
  6. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    298
    Hi Eric,

    I've just tested my game on a 4K screen (having previous been playing at 1440p) and noticed that everything is much smaller. I can calculate the line width according to a world value easily enough, but I wondered if you have any tips for calculating a consistent textureScale?

    Thanks!
     
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can use Screen.dpi as a factor to calculate line width, since that's measured in pixels.

    --Eric
     
  8. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    298
    I don't suppose you have a snippet for that? Also is there a way to make the textureScale consistent? I have some marching ant effects on lines, and on that screen they were tiny.
     
  9. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    No, but it's just basic math. :) e.g., if you say 72 dpi = 10 pixels, then 144 dpi = 20 pixels. If the line is scaled up like that, then textureScale would be too.

    --Eric
     
  10. DrJedd

    DrJedd

    Joined:
    Dec 13, 2013
    Posts:
    2
    Hello,

    I am considering purchasing this asset for a very specific use: I'm trying to render a musical staff (5 horizontal lines), and at any zoom level (orthographic camera) they must all be exactly the same size (height), and a minimum of 1px (they must never be invisible even when zoomed far out. Is it possible to achieve this with this solution?

    Thanks a lot,

    jedd
     
  11. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes, the main idea with Vectrosity is that lines are a constant pixel width, so if you specify 1 for the width, it will always be that width. Thank you for your interest!

    --Eric
     
  12. steve248

    steve248

    Joined:
    Feb 24, 2016
    Posts:
    2
    I really hope someone can help me out. I have tried for ages but cannot figure out how to get my "Asteroid" to rotate on it's centre axis. This is my code:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using Vectrosity;
    public class VectorScript : MonoBehaviour {
    private VectorLine myLine1;
    public List<Vector2> linePoints;

    void Start ()
    {
    linePoints = new List<Vector2>() { new Vector2(35, 0), new Vector2(85, 0), new Vector2(85, 0),
    new Vector2(110, 25), new Vector2(110, 25), new Vector2(110, 75), new Vector2(110, 75),
    new Vector2(75, 125), new Vector2(75, 125), new Vector2(35, 125), new Vector2(35, 125),
    new Vector2(50, 100), new Vector2(50, 100), new Vector2(35, 100), new Vector2(35, 100),
    new Vector2(0, 60), new Vector2(0, 60), new Vector2(50, 60), new Vector2(50, 60),
    new Vector2(0, 35), new Vector2(0, 35), new Vector2(35, 0) };
    myLine1 = new VectorLine("Line", linePoints, 1.0f);
    myLine1.drawTransform = transform;
    myLine1.color = Color.green;
    }

    void Update ()
    {
    myLine1.Draw();
    transform.Rotate (new Vector3 (0, 0, 40 * Time.deltaTime));

    }
    }

    This is attached to an empty object but it rotates in the bottom left corner or 0,0.

    Help would be greatly appreciated!
     
  13. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The points in the asteroid should be centered around (0, 0).

    --Eric
     
  14. steve248

    steve248

    Joined:
    Feb 24, 2016
    Posts:
    2
    You mean do the line points again?
     
  15. yamlCase

    yamlCase

    Joined:
    Apr 13, 2017
    Posts:
    34
    How do I keep a circle from rotating about the axis pointed at the main camera? I'm trying to create a HUD marker and figured out how to point the circle at the camera, but I can't make it not rotate around what I presume is the Y axis.

    Code (CSharp):
    1. circle.MakeCircle(objectiveGO.transform.position, cameraDir, circleRadius, 6);
    Here's an example video:
     
  16. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes. (Sorry for the late answer; I stopped getting notifications for this topic.)

    Are you updating the line when the camera moves? You can use Draw3DAuto to automatically redraw every frame.

    --Eric
     
  17. yamlCase

    yamlCase

    Joined:
    Apr 13, 2017
    Posts:
    34
    That didn't seem to make any change. Perhaps some more info. Should circle.MakeCircle be in Update()?

    Code (CSharp):
    1. List<Vector3> circlePoints = new List<Vector3>(7);
    2.  
    3.  
    4. void Start ()
    5. {
    6.     objectiveGO = transform.Find("Objective").gameObject;
    7.     circle = new VectorLine("Target", circlePoints, lineWidth, LineType.Continuous, Joins.Weld);
    8. }
    9.  
    10.  
    11. void Update ()
    12. {
    13.     Vector3 cameraDir = Camera.main.transform.position - transform.position;
    14.     circle.MakeCircle(objectiveGO.transform.position, cameraDir, circleRadius, 6);
    15. }
    16.  
    17.  
    18. private void LateUpdate()
    19. {
    20.     circle.Draw3DAuto();
    21. }
     
  18. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    No, you should only make the circle once. Also Draw3DAuto should only be called once (the whole point is to be, well, auto).

    --Eric
     
  19. yamlCase

    yamlCase

    Joined:
    Apr 13, 2017
    Posts:
    34
    awesome, I tried that (along with a circle.drawTransform = objectiveGO.transform) and it works beautifully. Now I can have it point wherever I want. Thanks!
     
  20. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    New version:

    Vectrosity 5.6

    Changes:
    • Changing a VectorLine from Draw to Draw3D leaves the CanvasRenderer component on the line GameObject. This is due to removing it causing a crash in Unity 2017.4 and later. Leaving it doesn't seem to cause any adverse effects.
    • Cleaned up some unused components in demo scenes to remove deprecation warnings in later Unity versions.

    Fixes:
    • The back end cap is colored correctly when using line colors and smoothColor = true.

    --Eric
     
  21. Robutmike

    Robutmike

    Joined:
    Nov 25, 2013
    Posts:
    4
    I am working on a project where I need to create a line in the direction of a vector.magnitude. So imagine a golf ball from above, you click on the golf ball, then pull back away from the ball with a line drawing out from the ball to the mouse position. The line gets longer as you get farther from the ball, and perhaps changes color based on length (indicating that a greater distance means a stronger swing). The line would have to rotate during runtime, with one end stuck to the ball, and the other end stuck to the mouse position. Upon releasing the mouse, the ball would launch, line disappears, etc.

    Would Vectrosity be a good solution to this problem?
     
  22. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes, it would work very well for that.

    --Eric
     
  23. emorling

    emorling

    Joined:
    Jul 6, 2015
    Posts:
    24
    I am curious if VectorLine or 3D vector performs the best with ~30 000 lines and 10-20 nodes in each? thanks
     
  24. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Nothing's really going to perform well with so many separate lines. I'd suggest combining into as few lines as possible.

    --Eric
     
  25. zoltanBorbas

    zoltanBorbas

    Joined:
    Nov 12, 2016
    Posts:
    83
    Hello guys, i am new here as well as using Vecrosity.

    I have built a nice solar system generator for my 4X game and as you can image using this line tool i had a great time ordering my space object about in the scene. All was great, good performance nice orbit lines easy way to access separate sections of the orbits programmatically. Then i moved on to terrain for planet surfaces, when i learned that

    Linear Color Space is best to use for rendering terrain so i have changed the project to it from Gamma. To my mayhem when i loaded up the solar system view the previously gorges lines got blurry jittery.
    FYI i am using the LineGlow material with the BigGlow texture which looked great giving a nice line and glow around it when i used Gamma color space, but now the previously glowy edge of the line seam to have lost its transparency.

    Please could somebody help me with this issue? I would very much like to stay in Linear Color space and have the lines back to as they were.
     

    Attached Files:

  26. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Unfortunately I don't really know much about the technical details of gamma vs. linear so I can't really advise much. That's a general graphics question, not specific to Vectrosity, since it's just using regular shaders, nothing special. The LineGlow material uses the Particles/Additive (Soft) shader, so anything about that shader in linear color space would apply in this case. You could try increasing the transparency of the texture (in Photoshop or whatever).

    --Eric
     
  27. ifnoLee

    ifnoLee

    Joined:
    Feb 27, 2017
    Posts:
    7
    Hi,

    I Use Vectrosity create some line(2D) from a list of Point, it is fine,but I try create Line3D form same points ,it is broken。what is the Requirement for the Points when I create 3d Line ?
    -ifnoLee
     
  28. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I'm not sure what you mean by "broken", but the only requirement for points in a 3D line is that they are Vector3 coordinates, just like you use Vector2 coordinates for 2D lines. Have a look at the various included demos that use 3D lines.

    --Eric
     
  29. look001

    look001

    Joined:
    Mar 23, 2017
    Posts:
    111
    Very cool asset and the docs are amazing. However i ran into a problem with the 3d vector object. After calling VectorManager.ObjectSetup() i need to Destroy the whole GameObject in order to destroy the lines. According to the docs i shouldn't use VectorLine.Destroy(). However i don't want to destroy the whole GameObject. I only want to destroy the lines. I looked in the docs and there are no more informations about that. So what can i do here?
    Also is it possible to have a 3d vector object on an GameObject with a deformable Mesh? I noticed that the Lines of a Wireframe don't move with the vertices if they are moved.
    Thank you for the amazing asset!
     
  30. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You could use VectorLine.active to turn off the VectorLine. But if you want more precise control, it's best to create VectorLines manually instead of using ObjectSetup. For a deformable mesh, you could call MakeWireframe using that mesh whenever it changes.

    --Eric
     
  31. aBrokenDonut

    aBrokenDonut

    Joined:
    Feb 14, 2015
    Posts:
    2
    I had a bug with drawing a 3d Spline. It overshot the target and returned to it, this is visible when the target it small (In my case 0.01f).
    (Have updated to the newest version, it was also on the older version)
    upload_2018-6-5_14-41-14.png

    I made sure that it was not in the vector points supplied to the MakeSpline function.
    Also removing the last segments did not work, by removing 2 it still overshot and with 3 it fell short.

    My fix is the following:
    VectorUtilities.cs, line 597:
    var numberOfPoints = loop? pointsLength : pointsLength-1;
    to
    var numberOfPoints = loop? pointsLength : pointsLength-2;
     
  32. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Do you have code which demonstrates the problem?

    --Eric
     
  33. aBrokenDonut

    aBrokenDonut

    Joined:
    Feb 14, 2015
    Posts:
    2
    I tried to recreate the issue in another project but i was not able to.
    Still some things are happening that shoudnt, i found out its duo the Mixed reality toolkit (https://github.com/Microsoft/MixedRealityToolkit-Unity)

    Create a new project
    Add Vectrosity
    Place a cubes, name "From" at 0,0,0 scale 0.01
    Add a cube, name "To" at 0.5,0,0
    Add a script, code like this:

    Code (CSharp):
    1.     void Start () {
    2.         var from = GameObject.Find("From");
    3.         var to = GameObject.Find("To");
    4.         var path = new List<Vector3>()
    5.         {
    6.             from.transform.position,
    7.             to.transform.position,
    8.         };
    9.         var segments = 7;
    10.         var spline = new VectorLine("Spline", new List<Vector3>(path.Count * segments + 1), 2.0f, LineType.Continuous, Joins.None);
    11.         spline.MakeSpline(path.ToArray(), path.Count * segments, false);
    12.         spline.SetColor(Color.green);
    13.         spline.Draw3D();
    14.     }
    Start the project
    Look at the line and take a screenshot, so you can inspect it later.

    Add the Mixed reality toolkit.

    After a minute you get a menu item called "Mixed reality toolkit"
    In that menu: Configure -> Apply mixed reality project settings
    Then press apply
    Then again in that menu: Configure -> Apply Mixed reality scene settings
    Then press apply

    Start the project

    The line is not being drawn.... Its in the hiearchy though.

    Move To And From infront of the camera.

    Start the project
    Now there is a line but less thick than it used to be.

    Now Adjust this line:

    Code (CSharp):
    1. var spline = new VectorLine("Spline", new List<Vector3>(path.Count * segments + 1), 2.0f, LineType.Continuous, Joins.None);
    to:
    Code (CSharp):
    1. var spline = new VectorLine("Spline", new List<Vector3>(path.Count * segments + 2), 2.0f, LineType.Continuous, Joins.None);
    Now it starts drawing a random line, it seems to point always to the camera.

    If i find a way to recreate my issue i will post it.
     
  34. GuruRamen

    GuruRamen

    Joined:
    Jan 15, 2014
    Posts:
    13
    Hey Eric (or anyone else wanting to take a crack at this),

    I'm mostly done with a game built using Vectrosity, and it's time to start adding a bit of visual polish. I'd like to see if I can add some of the artifacts seen on the old vector monitors, in particular, the brighter areas that show up near the ends of lines, as the electron beam "dwells" changing direction.

    You can see that a bit in the vectrex game in the first image below, and in a grab from a video short that simulated this effect somehow at bottom.

    Wondering if you have any suggestions on how to achieve this effect?

    Also, are there any examples on how to control the glow/bloom around the lines?. Is that just in the choice of line texture?

    Thanks,
    Dan


    vectrex-game-v-hockey-homebrew-2.jpg


    Capture.PNG
     
  35. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You could use another line with LineType.Points using the same data as the regular line. Here's a cube VectorLine with a glow texture, and the same cube as points with a dot texture:

    Screen Shot 2018-06-07 at 12.13.49 AM.png

    The glow is just a texture, though I imagine you could get a better effect with some kind of full-screen image effect.

    --Eric
     
  36. MperiumGoods

    MperiumGoods

    Joined:
    May 25, 2018
    Posts:
    2
    Great Asset! One thing I'm totally unable to figure out though is:

    How do I get my gameObjects to display above the rendered Vectorlines?
    I tried manipulating: Sorting Layer, Layer (Mask), Z-Axis for the GameObjects, VectorLine and (VectorLine-)Canvas.

    My game is 2D and I'm creating a Runtime Mesh LevelEditor with it right now.


    Thanks for any help!

    Best Regards
    Gerrit
     
  37. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Probably the easiest way is to use a 3D line instead of a canvas; that way you can do sorting in the usual ways. You can just use the same z coords for all points, so they are 2D-like, but in 3D space.

    --Eric
     
  38. GuruRamen

    GuruRamen

    Joined:
    Jan 15, 2014
    Posts:
    13
    Ok, great.

    That's more or less what I imagined.

    Thanks for the help Eric.

    Dan

     
  39. tbg10101_

    tbg10101_

    Joined:
    Mar 13, 2011
    Posts:
    192
    Are you looking at updating Vectrosity to use ECS+Jobs at some point in the future?
     
  40. Brian-Washechek

    Brian-Washechek

    Joined:
    Aug 5, 2015
    Posts:
    846
    I don’t know what you mean by ECS + jobs. Please explain.
     
  41. tbg10101_

    tbg10101_

    Joined:
    Mar 13, 2011
    Posts:
    192
  42. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Unfortunately, that has the same problem as regular threaded code: no worky on WebGL.

    --Eric
     
  43. Brian-Washechek

    Brian-Washechek

    Joined:
    Aug 5, 2015
    Posts:
    846
    I’m not trying to get my game to be played online at all. Will the absence of WebGL affect me at all?
     
  44. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I'm not really sure what you mean. There isn't any absence of WebGL.

    --Eric
     
  45. Brian-Washechek

    Brian-Washechek

    Joined:
    Aug 5, 2015
    Posts:
    846
    Doesn’t “no worky on WebGL” kind of mean that? I take it that I’m misinterpreting your joke.
     
  46. ArtyBoomshaka

    ArtyBoomshaka

    Joined:
    Mar 5, 2013
    Posts:
    226
    Hey there,

    I'm having an issue with the edge colliders on the lines I'm drawing (Unity 2018.1.2, latest version of Vectrosity).

    Every other frame the colliders seem to be padded with a bunch of 0-ed elements, leading to false positives with my triggers. See the screenshots and details here : https://imgur.com/a/5Sx0xcp

    I might be doing something wrong with my lines' update (I update the first point at every frame in Update) but this does look like a bug.
    Is this a known issue? Is there a workaround?
    I can provide a lightweight repro scene if necessary.

    Cheers,
     
  47. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It would mean that if I used it, hence why I won't be implementing that at this time. There wasn't really any joke involved. Hopefully WebGL will have threading support at some point. I don't know if there would be any advantage to the job system as opposed to normal threaded code though.

    I tried some things and wasn't able to reproduce it, so if you could PM me the repro scene, that would be helpful.

    --Eric
     
  48. ArtyBoomshaka

    ArtyBoomshaka

    Joined:
    Mar 5, 2013
    Posts:
    226
    I sent you an email with the archive and the details. Thanks!
     
  49. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You had points being added that were identical to the previous point; this isn't advised and can result in unwanted behavior (for LineType.Continuous anyway). If I change the code to get rid of that, the problem goes away.

    --Eric
     
  50. ArtyBoomshaka

    ArtyBoomshaka

    Joined:
    Mar 5, 2013
    Posts:
    226
    Ah yes, that was it. Thank you!