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

    tbg10101_

    Joined:
    Mar 13, 2011
    Posts:
    192
    Bug report:

    Setting a VectorLine's material to null throws an exception. The issue is on VectorObject3D.cs:54 because the sharedMaterial is set to null so the texture cannot be set.
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I'm not sure what you mean by "turning it into a GameObject", but that doesn't sound like something that can/should be done regardless of VR. Glad you found the solution though!

    Ah yes...putting "if (mat != null)" in front of line 54 fixes that.

    --Eric
     
  3. GameSolutionsLab

    GameSolutionsLab

    Joined:
    Mar 24, 2017
    Posts:
    2
    Hey Eric,

    The Plugin is great! We bought it yesterday and it works miracles :)

    I do have a feature request (if I may post that here)

    I would like to be able to add whitespace between the texture input. Basically being able to create a dotted line without needing to add whitespace in the original 'Circle image texture'.

    Kind Regards,

    -GameSolutionsLab
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Hi, thank you! You can add whitespace without adding it to the texture by using VectorPoints instead of VectorLine. Other than that it's not really feasible.

    --Eric
     
  5. GameSolutionsLab

    GameSolutionsLab

    Joined:
    Mar 24, 2017
    Posts:
    2
    Hey Eric,

    Where in the documentation can I read about these VectorPoints?

    Kind Regards,

    -GameSolutionsLab
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Actually it's LineType.Points now (used to be VectorPoints). Page 31 in the coding docs, "Drawing Points".

    --Eric
     
  7. ratking

    ratking

    Joined:
    Feb 24, 2010
    Posts:
    349
    Hi, I found a bug I think.

    I have some kind of wireframe preview for an editing tool in my Unity app, I use Vectrosity for that. I dynamically add and remove wireframe cubes (i.e. 12 lines / 24 points each) to this preview. The maximum is 729 cubes (=9x9x9). When I add 729 cubes at once (from 0), I get an error that the mesh generated by Vectrosity has too much vertices, even though it should only be 9x9x9x12x4 = 34,992 (while the error claims it's over 64,000). BUT when I start with 512 cubes at first, and then increase it to 729, there is no error and everything is displayed correctly.

    It seems Vectrosity allocates too much vertices in advance when the number set via Resize() is over a certain value.
     
  8. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yep, not sure what was going on there...the code in the MaxPoints function in the VectorLine.cs script should be:

    Code (csharp):
    1.         if (m_capType != EndCap.None) {
    2.             return 16381;
    3.         }
    4.         return 16383;
    --Eric
     
  9. gumboots

    gumboots

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

    I'm wondering about how SetCamera3D works. I have a split screen game and it doesn't seem possible to have multiple players drawing Vector3 lines, is that right? I tried having a separate camera that is full screen and remains static, but as the other players are moving all about the level, this solution unfortunately doesn't seem to work.

    What I'm trying to do is draw reticles for each player based on where they are looking/where the keyboard/mouse player's mouse is. It works perfectly fine if I make my first player's camera Camera.main, but subsequent players all fail because SetCamera3D is a static function as opposed to per line.

    Don't suppose you've got any pointers? Or that I'm doing it incorrectly?
     
  10. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    298
    Also, please forgive the very basic question. But I'm attempting to get the free anti-aliasing you talk about in the 'Coding' documentation, however using Unlit/Transparent stops the line getting coloured. Particles/Additive makes it blurry and semi-transparent. Is there an option to colour it but receive the anti-aliasing effect?
     
  11. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can make two lines, one for each camera, and set the line layers, and the cameras' culling masks, so they draw the lines appropriately. That is, each camera sees only one line. Say, line 1 is on layer 20 and line 2 is on layer 21, with camera 1 seeing layer 20 and not 21, and camera 2 seeing layer 21 but not 20. Then every update, do SetCamera3D(camera1) and line1.Draw3D, plus SetCamera3D(camera2) and line2.Draw3D. I realize that's a little convoluted, sorry! But it does work.

    The default 3D line material works. (It's using Particles/Alpha Blended.)

    --Eric
     
  12. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    298
    Thanks for the response! Unfortunately Particles/Alpha Blended seems to make the result a single, solid colour, where I have a series of greys that I want tinted.

    Thanks for the SetCamera suggestion, settings SetCamera3D before each line draw has fixed the issue. Though the line's layers don't appear to actually affect anything?
     
    Last edited: Jun 30, 2017
  13. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Particles/Alpha Blended definitely works, and is what the default line material uses. If it didn't work, then none of the demo scenes that use textured lines would work either. As far as performance, basically you're doubling the amount of line drawing. But just drawing a reticle isn't much at all, so doubling that is still not much.

    --Eric
     
  14. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    298
    Hmm you're right, it had to do with the 'Tint Color' I had set, it seems. I had assumed it was like a sprite, so I set it white and it removed the multiple tones I had.

    I'm trying to set each line's canvas to a Screen Overlay - Camera canvas in order to restrict each player's reticle to their camera. However the end result seems to be that the drawing coordinates get thrown off. Does setting the camera become redundant in a Screen Overlay - Camera perhaps?
     
  15. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I'd suggest just using Draw3D rather than using a canvas.

    --Eric
     
  16. Arrovs

    Arrovs

    Joined:
    Sep 23, 2014
    Posts:
    24
    Hello.

    Does anyone else have experienced line "clipping" with long lines - multiple screens long lines.
    At one end it draws nicely, but at other end it disapears.
    This is on PC, if that makes any difference.
     
  17. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Do you have a code example? I tried making a line that was 2000 units long and it worked as expected when moving the camera around.

    --Eric
     
  18. TrisJ

    TrisJ

    Joined:
    Mar 24, 2016
    Posts:
    2
    Hi Eric,

    I just purchased Vectrosity, because the game I'm making is using a lot of trajectory lines to predict where your ship and projectiles are going to end up based on gravity.
    One of the main reasons I made the purchase was because so many people have said it's a huge performance improvement over using the Unity LineRenderer, however in my use-case it appears that Vectrosity has a lower performance than lineRenderer.

    Essentially every frame I predict the next 5000 frames of where my ship will end up based on it's current velocity, and the strength of gravity (it's in space near a planet, so gravity varies with position). With LineRenderer I can just put those 5000 positions into one LineRenderer object every frame and it runs fairly smoothly, albeit with some graphical quirks. However doing the same with Vectrosity and the Draw3D function, there is quite a bit of lag when the number of positions gets that high, and I can't figure out why it would be worse than the unity LineRenderer.

    Do you have any recommended do's or don't for this type of large array/list updating every frame? I need to use Draw3D unfortunately, I want the trajectories rendered in world space.

    Lastly, I want to thank you for creating such a wonderful tool that has been so useful to so many people and making up for the lack of adequate tools Unity comes with as standard. :) Keep it up!!
     
  19. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    5000 isn't that much; are you just updating the List of points and drawing the line? Or creating new a list or line? If you're creating anything new, that would explain it, and should not be done.

    --Eric
     
  20. TrisJ

    TrisJ

    Joined:
    Mar 24, 2016
    Posts:
    2
    Thanks, I messed around with the Lists a bit and it runs much better now. LineRenderer performs better if you set all the positions in one go, so I was creating a list each frame and assigning it at the end of my 5000 frame simulation.

    Vectrosity seems to run much better if I just update each point individually and then draw at the end of the frame.

    EDIT: Is there a way to have different 3D lines face different cameras? The setcamera3d is a static function so it seems to apply to all lines.
     
    Last edited: Jul 2, 2017
  21. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    See my post about that above.

    --Eric
     
  22. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    298
    Hey Eric, thanks for the response. So to clarify, the documentation says that Vector3 points lists can be used for world space coordinates. Can these then be used to draw a 2D line? Or does this restrict the line to Draw3D? I can't seem to get coordinates working properly when using split screen, and I'm wondering if it's a glitch in my code (though the line's drawTransform is being positioned correctly), or if I'm misunderstanding how Vector3 points can actually be used.
     
  23. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can use Vector3 points with Draw, in addition to Draw3D. Vector2 points can only use Draw.

    --Eric
     
  24. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    298
    Hmm, I don't suppose you have any idea why when using a split screen (two cameras vertically, both half the screen's width), the drawTransforms are in the correct position, but the lines are drawn with substantial offset?
     
  25. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    No, sorry. I did a quick test with a 2-camera setup as described, and there's no offset. Well, except maybe you're not accounting for the transform position when using drawTransform? That is, points in that case should be local coords, not world coords, since the transform.positions are added when using drawTransform.

    --Eric
     
  26. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    298
    So currently I have a drawTransform that I am moving around the world to the position I want the line to start from. Then my line is drawn as though that position is Vector3.zero, with zero rotation. So the first point might be (-1, 0, 0) the next (0, 0, 0) and the final (1, 0, 0). This makes a horizontal line, so if I rotate the drawTransform clockwise by 90 degrees the line should not be vertical, with the top most point being points[0]. And the center point of the line will always be at the position of the drawTransform. So if I moved the drawTransform to (500, 500, 0), the line points would be (visually, in real world coordinates, but I'm drawing them as 2D so they should actually be in screen coordinates) (-499, 500, 0), (500, 500, 0), (501, 500, 0).

    Is that correct? Or should I not be moving the drawTransform around the actual world? But rather in the world relative to the screen?

    Edit: The above works perfectly when I then use Draw3D. But if I instead set a Canvas for the line, that's when the ratio between the drawTransform's position and where the reticle is drawn on screen start to vary wildly. The scale of the reticle is suddenly far bigger than it should be, and it is moving around at a far greater ratio than the drawTransform is being moved.

    Edit 2: One strange thing seems to be that when the Canvas is set, the line's scale is being set to ~5 on all axes. This accounts for its size, and also seems to fix the relative movement speed when I set it back to 1. But the positions still don't match up when I manually set the scale back to 1.

    Edit 3: I've managed to recreate the 'issue' in a blank project, without involving a DrawTransform. You can download the package here:

    https://www.dropbox.com/s/jql6vr6oro0dmek/VectrosityTest.unitypackage?dl=1

    Of course it's highly possible that I'm just misinterpreting how this should function. But if you play the demo, you can only see one of the dots if you move your mouse to the bottom left of the screen. Where my expectation would be that each camera should always be able to see a dot. It also has the same 'issue' of scaling the lines. If you look in the Scene view, you can see the two dots, spaced apart from each other and moving relative to your mouse movements. But the scale and position obviously don't match up to the line's Canvas.
     
    Last edited: Jul 4, 2017
  27. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Use false for WorldPositionStays when using SetCanvas.

    --Eric
     
  28. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    298
    Excellent, that fixed the relationship between mouse movement and the dot position! (What does 'WorldPositionStays' actually mean/do?)

    However now you can see the offset issue that I was talking about. I uploaded a new package to show it:

    https://www.dropbox.com/s/jql6vr6oro0dmek/VectrosityTest.unitypackage?dl=1

    The light blue dot should show on the blue background, the red dot show on the orange background. But you can see there seems to be a half screen offset. Look in the scene view to see what I mean: Move your mouse far to the left, off the actual Game view, and you'll see the light blue dot appear. But what I would expect is that the appropriate coloured dot should appear under the mouse when you are over that camera, the other camera not showing anything.

    Edit: Ok that seems fixable by not using VectorLine.SetCamera3D. However in my actual game I'm still getting an offset, it just doesn't seem related to the split screen camera. I'll try and get a replication setup for you. How do you use VectorLine.SetCamera3D when you also have a different line's canvas set? As that seems to ruin the coordinates of lines.
     
    Last edited: Jul 4, 2017
  29. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    WorldPositionStays as in Transform.SetParent. I think the offset issue is the result of having two cameras with different screen positions, so you'd have to compensate for that.

    --Eric
     
  30. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    298
    Hmm could you point me in the right direction of compensating for that? Right now I'm just relying on the drawTransform, and I can't seem to find out how to provide some sort of rendering offset? (VectorLine.SetCamera3D only seems to create a larger discrepancy. I've uploaded a package showing the exact issue:

    https://www.dropbox.com/s/jql6vr6oro0dmek/VectrosityTest.unitypackage?dl=1

    The cameras aren't in the same position anymore (X: -30 and X: 30), the coloured dot should be being drawn over the black circle on each camera, but it is offset on the second camera. And the further you move Camera 2, the larger the error in line position becomes.

    Thanks for all your help so far!
     
  31. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You could add/subtract a value from the x coordinates in the lines as needed to compensate. How you derive the value I'm not entirely sure since it's a rather unusual setup. Instead of canvases, I'd suggest using Draw3D instead, since you wouldn't have to worry about it in that case.

    --Eric
     
  32. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    298
    Oh, that's a shame. It'd be nice to be able to use the UI for automatically overlaying things like that on specific player cameras, but I'll use Draw3D instead. Thanks for your help. Is there a way to change a 3D line's sortingOrder and sortingLayer? DrawDepth doesn't appear to affect how it's rendered around sprites.
     
  33. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    VectorLine.rectTransform.GetComponent(Renderer).sortingOrder, though you need to use a material for the line that has a shader that uses things like sortingOrder (e.g. Sprites/Default).

    --Eric
     
  34. Nedgoom

    Nedgoom

    Joined:
    Jan 16, 2013
    Posts:
    9
    This asset looks really great, but is there an easy way to import a mesh from 3ds Max and convert it to Vector lines?
     
  35. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    There's a LineMaker utility for making lines from meshes; see page 18 in the docs.

    --Eric
     
  36. Nedgoom

    Nedgoom

    Joined:
    Jan 16, 2013
    Posts:
    9
    Perfect, that's exactly what I was looking for, thanks!
     
  37. bkachmar

    bkachmar

    Joined:
    Mar 15, 2013
    Posts:
    43
    Hello,

    I just bought Vectrosity to be able to draw a few nice lines in my application.
    I use "Screen Space - Camera" mode of my Canvas and I want to draw a line with a set of points as a child object of one of RectTransforms there.
    When I use Vector Object 2D it states "Only canvases using Screen Space Overlay are supported".

    Does this mean that I will not be able to do that?

    In my case I have a Hierarchy of object that include a scroll view. And inside that scroll view I want to show some custom drawings in local coordinates.
     
  38. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    That's an info box in the scene view that's referring to the scene view VectorLine inspector; it's not an error that prevents you from using Screen Space Camera for lines in code. However it's usually best if you don't parent VectorLines, but use VectorLine.drawTransform instead.

    --Eric
     
  39. ozergul

    ozergul

    Joined:
    May 3, 2016
    Posts:
    11
    Hello Eric,
    How can i add Rigidbody2D component to draw lines. I didnt do it for days.
    line.addComponent or line.gameobject etc... Really stuck...

    Regards.
     
  40. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    line.rectTransform.AddComponent, however that won't work as you want, so don't do it. ;) Directly manipulating line transforms generally causes Vectrosity to fail. Instead use a rigidbody on some other object, and line.drawTransform with that object.

    --Eric
     
    ozergul likes this.
  41. frederic-moulis

    frederic-moulis

    Joined:
    Jul 6, 2017
    Posts:
    17
    Hi, I updated my Unity from 5.5 to 5.6.2f1 recently.
    Now, I get errors on Vectrosity objects :

    Enabling or adding a Renderer during rendering; this is not allowed. Renderer '<NAME>' will not be added.
    This error happens on line " GetComponent<MeshRenderer>().enabled = enable;" in VectorObject3D.Enable(bool)
    called by VectorLine.set_active(bool)
    called by VisibilityControlStatic.OnBecameVisible()

    Is there an existing fix to this bug that I missed ?

    Thank you,
    Fred
     
  42. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes, Vectrosity 5.4.2 fixed that.

    --Eric
     
  43. frederic-moulis

    frederic-moulis

    Joined:
    Jul 6, 2017
    Posts:
    17
    Thanks for the answer,
    I used to work with sources, so I tried to import Vectrosity5-Unity5.6.unitypackage
    The exact same error is still raised unfortunately

    Best regards,
    Fred
     
  44. frederic-moulis

    frederic-moulis

    Joined:
    Jul 6, 2017
    Posts:
    17
    May I precise that I meant "I'm already using Vectrosity 5.4.2"
    Thanks
    Fred
     
  45. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Did you make sure to delete old Vectrosity scripts/DLLs before importing the new version?

    --Eric
     
  46. frederic-moulis

    frederic-moulis

    Joined:
    Jul 6, 2017
    Posts:
    17
    I retries :
    1- remove Assets/Vectrosity folder
    2- check that no folder or file does contain the name vectrosity in my project folder
    3- go to asset store/Vectrosity
    4- click on import
    5- once imported, double click on Vectrosity5-Unity5.6.unitypackage
    6- once project has compiled, run

    And I still get the error :-( sorry
    Fred
     
  47. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Do you have any example code that results in the error?

    --Eric
     
  48. frederic-moulis

    frederic-moulis

    Joined:
    Jul 6, 2017
    Posts:
    17
    Here's a function that generates objects that raise this error :

    Code (CSharp):
    1. private GameObject MyCreateVectorLine(List<Vector3> linePoints, string lineName, Material lineMaterial, bool closed, float width)
    2. {
    3.     vectorLine = new VectorLine(lineName, linePoints, 3.0f, LineType.Continuous, Joins.Fill);
    4.     vectorLine.SetWidth(width*2);
    5.     vectorLine.smoothWidth = false;
    6.     if (closed) {
    7.         vectorLine.SetColor(color);
    8.     } else {
    9.         List<Color32> lineColors = new List<Color32>();
    10.         for(int i=0;i< linePoints.Count-2;i++)
    11.         {
    12.             lineColors.Add(color);
    13.         }
    14.         //last segment must be transparent
    15.         lineColors.Add(new Color32(255, 255, 255, 0));
    16.         vectorLine.SetColors(lineColors);
    17.     }
    18.  
    19.     linkedGameObject = new GameObject(lineName + "_ObjectSetup");
    20.     linkedGameObject.isStatic = true;
    21.     VectorManager.useDraw3D = true;
    22.    
    23.     VectorManager.ObjectSetup(linkedGameObject, vectorLine, Visibility.Static, Brightness.None);
    24.  
    25.     linkedGameObject.GetComponent<Renderer>().sharedMaterial = lineMaterial;
    26.    
    27.     GameObject baseVectorLineGameObject = GameObject.Find(lineName);
    28.     baseVectorLineGameObject.GetComponent<Renderer>().sharedMaterial = lineMaterial;
    29.    
    30.     return linkedGameObject;
    31. }
    Thanks for your support,
    Fred
     
  49. HugeElephant

    HugeElephant

    Joined:
    Jul 5, 2017
    Posts:
    2
    I'm creating an "orbit-like" experience with 3D vectors created via code. Reading about VectorManager, I see that it has a way to incorporate brightness fading with a fog-like effect. I tried setting the parent gameObject via VectorManager, but it doesn't seem to be affected.

    Is VectorManager supposed to only be used for converting object to vector rendering? What's the best way to achieve fading with just a VectorLine? I didn't see that in the documentation.

    Thanks!
     
  50. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Sorry, looks like I didn't catch all cases where the error could occur. If you use the source, in the VisibilityControlStatic script, in the WaitCheck function, the line "yield return null" should be followed by another "yield return null" line.

    Yes, it's for having regular GameObjects basically use Vectrosity as a renderer.

    It depends on what you mean by fading, but probably the SetColor function would be relevant; that's what the brightness function for VectorManager uses.

    --Eric