Search Unity

Vectrosity - Fast and Easy Line Drawing

Discussion in 'Assets and Asset Store' started by Eric5h5, Sep 26, 2014.

  1. cvoigt

    cvoigt

    Joined:
    Dec 29, 2013
    Posts:
    1
    Hi, I would like to use Vectrosity's collider feature in my 2d game for adding some obstacles (similar to the RandomHills example). But I don't want to create the "landscape" procedurally. Instead I want to build my level manually and draw the lines in edit mode. I learned from this thread that I should use Draw3D and Vector3 points to get lines in world space, but that the line editor currently only supports 2d lines in Screen Space Overlay mode. So I thought I could write my own simple editor that uses a list of transforms to get splinePoints and calls MakeSpline whenever a position of these transforms changes.

    But so far my experiments with getting 3d lines to work in edit mode have failed. I see my VectorLine in play mode, but in edit mode it remains invisible, even though a GameObject with the right components has been added (VectorObject3D, MeshRenderer and so on). Are there any special considerations in edit mode? Is this possible at all?
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
    Only 2D lines are supported in edit mode, sorry.

    --Eric
     
  3. jrhee

    jrhee

    Joined:
    Dec 5, 2013
    Posts:
    72
    I upgraded to v5.1 and am no longer using canvases. I'm trying to nest my vectorline rect transforms to help stay organized, but I noticed Vectorline.SetupCanvasState forces the parent transform to null when off canvas. Is this required, or is it safe to comment that line out?
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
    It's there for switching between 2D and 3D lines (since 3D lines shouldn't be on a canvas). A better solution might be to check for a canvas instead of just setting null.

    --Eric
     
  5. Matze123

    Matze123

    Joined:
    Jan 7, 2016
    Posts:
    1
    Hey Eric,

    i am developing a light beam based Puzzle Game so the generated line is in general my light beam.

    My questions:
    1. i know you can add collider to the lines. Are OnTriggerEnter(), OnColliderEnter(), OnCollisionEnter() etc. available (e.g. to detect objects like Collectable Game Objects)?
    2. Can i set the direction and size (line and collider) based on Raycasthit?
    3. Can i resize the lines in a running game?
    4. Can i animate the lines? (so my light beam looks like a living thing :) )
    5. If i use Vector3.Reflect() and reflect the line on a mirror, does it look good or like the twisted surface like in-build Line Renderer from Unity?
    6. Can i split lines? (like one light beam shines on water. One Part of beam will be reflected and another part will be refracted --> 1 line will be 2 or more lines)

    Sry for my english
    Greetz

    Matze
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
    1. Not quite; you'd use OnTriggerEnter2D etc., since the lines use 2D physics.
    2. I'm not sure what you mean by this.
    3. Yes.
    4. Yes.
    5. It doesn't behave like the LineRenderer; lines are 2D even in 3D space.
    6. You can use multiple lines.

    --Eric
     
  7. MythicalCity

    MythicalCity

    Joined:
    Feb 10, 2011
    Posts:
    391
    Hi there, I'm using set widths to create a v-shape vectrosity line but the line's thickness seems to change when I move the camera in relation to it (zooming), it gets thinner when I move the camera closer to it. The camera is drawn with Draw3DAuto.
    Here it is zoomed out:


    and here it is zoomed in to those 2 squares in the middle:


    The line has 4 points (0 = origin point, 1,2,3 = end point).
     
  8. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
    The line isn't actually changing thickness; that's the idea of Vectrosity, that lines are vector lines and maintain a constant width regardless of camera position.

    --Eric
     
  9. MythicalCity

    MythicalCity

    Joined:
    Feb 10, 2011
    Posts:
    391
    Hmm, okay but why would it look like that? if I move the camera really close to the line shouldn't it look thicker from the closer perspective? It seems to do the opposite right now. The closer the camera gets to it the thinner the line looks.
     
  10. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
    No, as mentioned, Vectrosity is designed to maintain a constant line thickness.

    --Eric
     
  11. MythicalCity

    MythicalCity

    Joined:
    Feb 10, 2011
    Posts:
    391
    I understand, but do you know why it doesn't seem to work in practice? anything that I could be doing wrong that would create this effect? or is there any way to inspect the line and the coordinates of the vertices?
     
  12. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
    It is working though; the line looks "thinner" when you move the camera closer because you expect it to get thicker, but it's the same thickness. Line width is in pixels, so if you have the line at say 10 pixels thick, it will always be 10 pixels thick regardless of where the camera is.

    --Eric
     
  13. MythicalCity

    MythicalCity

    Joined:
    Feb 10, 2011
    Posts:
    391
    Ok, I think that was the confusion. I thought that it would stay the same size in world space, but you're saying that it is relative to the screen. In that case, is there a way to have the line be a fixed size in world space so that the thickness is in Unity units not pixels? The reason I ask is because in my game the line's thickness represents a area that can be attacked, so it actually impacts the gameplay (or the visualization of it).
     
  14. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
    There isn't really a way, though you could draw the line once and not update it (though that would also prevent the camera-facing functionality from working).

    --Eric
     
  15. Nine_Tails

    Nine_Tails

    Joined:
    Sep 16, 2013
    Posts:
    31
    Hey there

    I'm using an older version of Vectrosity to draw a line between my 3D gameobject and a UI element. However, I'm struggling to convert the RectTransform position data of the UI component so I can pass it to the drawline function.

    This is my code I've placed in the start method


    Code (CSharp):
    1.     void Start ()
    2.     {
    3.         cam = Camera.main;
    4.  
    5.       //  points[0] = image.rectTransform.transform.position;
    6.       //  points[1] = image2.rectTransform.transform.position;
    7.  
    8.         points[0] = obj1.transform.position;
    9.         points[1] = obj2.transform.position
    10.  
    11.         line = new VectorLine("Line", points, mat, 2.0f, LineType.Continuous);
    12.         VectorLine.canvas.sortingOrder = 1;
    13.         VectorLine.SetCanvasCamera(Camera.main);
    14.  
    15.     }

    Both game objects are public and I just drop in what I want. Is someone able to point out what I'm doing wrong?
     
    Last edited: Mar 11, 2016
  16. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
    Probably use ScreenToWorldPoint.

    --Eric
     
  17. boolean01

    boolean01

    Joined:
    Nov 16, 2013
    Posts:
    68
    Hi

    Small question: I read that you can use colliders on the lines being draw by Vectrosity - does this also work if the path overlaps itself? For example, a figure 8 shape?
     
  18. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
    It's standard Unity colliders, so if that works normally (which I assume) then it will work with Vectrosity.

    --Eric
     
  19. boolean01

    boolean01

    Joined:
    Nov 16, 2013
    Posts:
    68
    Hmm ok I'll give it a shot then. The reason I ask was because I was having troubles with some other scripts when overlapping paths because the 2D Polygon Colldier (used in others) tries to intersect itself and it seems to break the collider shape.
     
  20. wxxhrt

    wxxhrt

    Joined:
    Mar 18, 2014
    Posts:
    140
    Hi,

    Updating my Vectrosity4 scripts to Vectrosity5, can't seem to get the to work, any ideas?
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using Vectrosity;
    5.  
    6. public class scriptVectros : MonoBehaviour {
    7.  
    8.     public TextAsset lineData;
    9.     public float lineThickness;
    10.     public bool onlyWireframe;
    11.     List<Vector3> linePoints;
    12.  
    13.     void Start () {
    14.         linePoints =  VectorLine.BytesToVector3List(lineData.bytes);
    15.         VectorLine line = new VectorLine("Shape", linePoints, 50.0f);
    16.         line.joins = Joins.None;
    17.         line.Draw3DAuto ();
    18.         VectorManager.useDraw3D = true;
    19.         VectorManager.ObjectSetup(this.transform.gameObject, line, Visibility.Dynamic, Brightness.None, onlyWireframe);
    20.  
    21.     }
    22.  
    23.  
    24.     void Update () {
    25.    
    26.     }
    27. }
    28.  
    Thanks
     
  21. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
    You can't use Draw3DAuto and VectorManager.ObjectSetup at the same time; they are conflicting things. Either let Vectrosity manage it (ObjectSetup) or manage it yourself (Draw3DAuto), but not both.

    --Eric
     
  22. wxxhrt

    wxxhrt

    Joined:
    Mar 18, 2014
    Posts:
    140
    Thanks Eric!
     
  23. holtex

    holtex

    Joined:
    Dec 13, 2015
    Posts:
    1
    Hi, I'm looking to create a Rectangle and a RoundedRectangle with the Up Vector of (0, 1, 0) (so that it lies flat on the Z axis on the Unity editor and if you were looking down on it. X and Z would be the x and y co-ordinates).

    I've got the rectangle working fine with the following code but the rounded rectangle gives me a very strange error.

    The same code, shown below, is being used to generate each of them.

    As a quick side note as well, what is the best way to edit a shape at runtime? Right now I destroy the shape then rebuild it but this obviously isn't ideal. Is there any way to switch a point list of a shape at runtime? I ask primarily because of shapes which utilise segments as I can't find a reference to this in the documentation (though I am sure I'm overlooking something).

    Code (CSharp):
    1.         LPoints = new List<Vector3>();
    2.         VLine = new VectorLine("RoundedRect", LPoints, ShapeFactory.Instance.LineTexture, 3.0f, LineType.Continuous);
    3.  
    4.         Vector3 topRight = Vector3.zero;
    5.         topRight.x = StartPoint.x + Width;
    6.         topRight.y = StartPoint.y;
    7.         topRight.z = StartPoint.z;
    8.         Vector3 bottomLeft = Vector3.zero;
    9.         bottomLeft.x = StartPoint.x;
    10.         bottomLeft.y = StartPoint.y;
    11.         bottomLeft.z = StartPoint.z - Height;
    12.  
    13.         VLine.MakeRoundedRect(bottomLeft, topRight, CornerRadius, CornerSegments);
    14.         VLine.Draw3DAuto();
     

    Attached Files:

  24. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
    Yes, sorry, MakeRoundedRect only works on the X/Y plane. I've updated the docs to make this clear. There's no good way to make this work in a general case for arbitrary 3D orientation, though if you need a version that works on the X/Z plane, I can send you that.

    There's no need to destroy anything; just call the function again. See the SelectionBox example, which repeatedly calls MakeRect as the box changes size.

    --Eric
     
    holtex likes this.
  25. memetic-arts

    memetic-arts

    Joined:
    Feb 27, 2011
    Posts:
    82
    Hi all, it's been a while!

    Was wondering if Vectrosity is supporting any type of SVG import yet ... seems that there are a few plugins out there, so wasn't sure if the feature had been integrated yet or not.

    Thx!
     
  26. MythicalCity

    MythicalCity

    Joined:
    Feb 10, 2011
    Posts:
    391
    Hi, I've noticed another issue after I updated to the latest version. I can't seem to get a rectangle vectorLine drawn. It doesn't get completed using the LineType continuous, and the left and right side of the rectangle don't look the same as the top line (which looks great).


    I used the following code:

    List<Vector3>borderPoints=newList<Vector3>();
    borderPoints.Add(newVector3(-CameraControlManager.Instance.gameMapXLimit,10f,-CameraControlManager.Instance.gameMapZLimit));
    borderPoints.Add(newVector3(-CameraControlManager.Instance.gameMapXLimit,10f,CameraControlManager.Instance.gameMapZLimit));
    borderPoints.Add(newVector3(CameraControlManager.Instance.gameMapXLimit,10f,CameraControlManager.Instance.gameMapZLimit));
    borderPoints.Add(newVector3(CameraControlManager.Instance.gameMapXLimit,10f,-CameraControlManager.Instance.gameMapZLimit));
    borderPoints.Add(newVector3(-CameraControlManager.Instance.gameMapXLimit,10f,-CameraControlManager.Instance.gameMapZLimit));

    VectorLinenewLine=newVectorLine("Border",borderPoints,borderMaterial.mainTexture,20f,LineType.Continuous);
    newLine.textureScale=1f;
    newLine.layer=Globals.Instance.layerVectrosity;
    newLine.material=borderMaterial;
    newLine.Draw3D();
     
  27. boolean01

    boolean01

    Joined:
    Nov 16, 2013
    Posts:
    68
    Hi there

    I picked up a copy of Vectrosity and even though it has fantastic documentation I've still run into an strange issue:

    I seem to be having troubles getting IsSelected to work consistently. I can recreate the problem in the 'Draw Lines Touch' example - if you run the example and then use IsSelected in the update loop to switch between to colours, you will notice it flickers a lot like as if there are gaps (even though visually there are none). I then found that if I switch to 3D, it still doesn't work but it does seem to show where all the gaps are:


    (This can be recreated by opening the 'Draw Lines Touch' example, clicking the 3D checkbox and then drawing with the mouse).

    I then found that if I comment out 'Line.endPointsUpdate = 1', I get a solid line visually (no gaps), BUT, the IsSelected still hits the gaps in between. I'm not sure if this is a bug or just a setting I'm missing.

    Cheers
     
  28. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
    No, sorry.

    I can't run your code because it has a lot of external dependencies, but I'd recommend looking at the included examples to see how it's done. One thing is you can just use MakeRect instead of adding all the points individually.

    In the interest of speed, Selected doesn't take into account gaps that would be filled by Joins.Weld/Fill. Therefore it's not entirely appropriate for super-thick lines that are curved or angled. Not really a bug, just the way it's designed. You could probably use the collider function to do selections instead.

    --Eric
     
  29. MythicalCity

    MythicalCity

    Joined:
    Feb 10, 2011
    Posts:
    391
    Ok, well here's the code without external dependencies.. it's just some values.

    List<Vector3>borderPoints=newList<Vector3>();
    borderPoints.Add(newVector3(-5000,10f,-4500));
    borderPoints.Add(newVector3(-5000,10f,4500));
    borderPoints.Add(newVector3(5000,10f,4500));
    borderPoints.Add(newVector3(5000,10f,-4500));
    borderPoints.Add(newVector3(-5000,10f,-4500));

    VectorLinenewLine=newVectorLine("Border",borderPoints,any texture,20f,LineType.Continuous);
    newLine.textureScale=1f;
    newLine.material=any material;
    newLine.Draw3D();
     
  30. MythicalCity

    MythicalCity

    Joined:
    Feb 10, 2011
    Posts:
    391
    And I've tried the MakeRect using the bottom left and top right, it does the same thing.
     
  31. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
    Seems fine. I assume you're doing something funky with your camera.

    Screen Shot 2016-03-15 at 12.10.13 AM.png

    --Eric
     
  32. MythicalCity

    MythicalCity

    Joined:
    Feb 10, 2011
    Posts:
    391
    Can you suggest any "funky" things I could be doing with my camera and your plugin? that are new to this version of Vectrosity? I haven't changed anything with the camera or added any funkiness since it was all working fine with an older version of vectrosity. So, is there any slight tiny possibility that there has been a change to the vectrosity system that alters the way it now works?

    Maybe Draw3D doesn't do the same thing it used to do? maybe now it only creates the line that is visible by the camera at the time it is called?
     
  33. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
    Are you saying you're drawing the line where it's not visible by the camera, and then moving the camera later? If so, you need to update the line when you move the camera, which is the same as always. If it ever worked without updating the line before, then it was by accident.

    --Eric
     
  34. MythicalCity

    MythicalCity

    Joined:
    Feb 10, 2011
    Posts:
    391
    Yes, that is it. Last year's version always did that, when you did a Draw3D then the line would be created no matter where the camera was or where it was facing. Each of the segments of the line were nicely renderer. Why would it not draw the line outside of the camera? it's a 3d line so it should just exist in 3d space, right?

    Also, even if the parts of the line that are not visible are not being rendered then why would the sides of the line look so strange now as opposed to looking the same as the top of the line?
     
  35. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
    Well, no, Vectrosity has culled line segments that are outside the camera view for quite a long time, though the exact method has changed a few times so it's possible some line segments might render in one version and not in another. One for speed reasons, and two because otherwise there can be rendering artifacts in certain cases. Standard Unity GameObjects are not drawn if they're outside the camera view either. The difference is they are evaluated every frame, whereas in Vectrosity you can choose not to, which can be useful sometimes, though the docs have always emphasized that you should redraw the line if you move the camera. If you don't, the behavior is undefined.

    --Eric
     
  36. camel82106

    camel82106

    Joined:
    Jul 2, 2013
    Posts:
    303
    Hello,
    I'm drawing movement tail on player's map.

    I'm using 3D VectorLine.

    I'm calling this script in Start:

    // create and initialize movement tail
    var linePoints = newList<Vector3>();
    this.movementTail = newVectorLine("SnakeTrail", linePoints, 70.0f);
    this.movementTail.layer = LayerMask.NameToLayer("Map");
    this.movementTail.color = Color.red;
    this.movementTail.joins = Joins.Weld;
    VectorLine.SetCamera3D(GameManagerScript.Instance.MapRenderTextureCamera);
    this.movementTail.Draw3DAuto();

    Than in Update method I'm clearing vectorline points:
    this.movementTail.points3.Clear();
    And I'm filling them with new values
    for (int i = minIndex; i < log.Count; i++)
    {


    this.movementTail.points3.Add(snakeTrail[i - 1]);
    this.movementTail.points3.Add(snakeTrail);
    }

    Problem is that after every update of vectorline points it will flicker. When updating points in every frame it's flickering.
    I have tried to update points only on some keypress. Than it will flicker on key pressed. When points are not changed it's not flickering.

    Am I doing something wrong? I have seen similar case in documentation as Updating lines.
    Thanks
    Peter
     
  37. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
    It's unlikely you want to update points every frame; instead update the points only when needed. Also I doubt you need to use Clear; just change/add the point that's actually changing.

    --Eric
     
  38. kelloh

    kelloh

    Joined:
    Mar 2, 2015
    Posts:
    29
    Is there a simple way to have my line's width always correspond to world units? I'm trying to draw lasers that look thicker up close than from far away.
     
  39. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
    No, sorry.

    --Eric
     
  40. camel82106

    camel82106

    Joined:
    Jul 2, 2013
    Posts:
    303
    Thanks. Addiing only new points has helped with flickering.
     
  41. camel82106

    camel82106

    Joined:
    Jul 2, 2013
    Posts:
    303
    Hello,
    I'm drawing movement tail on player's map.

    I have problem with some artifacts when using joins.

    When using Joins.Weld I have problem that when I'm creating player movement tail which actual position is near it's start position. Simply I'm nearly joining end to start. Then line is joining/jumping to start point. And that's not behaviour that I want.

    When I use Joins.Fill (I'm using continuous lines) it's working properly. But than I get artifacts when I'm staying on place. (I'm drawing line with points on same position)

    Is there something to fight with this behaviour? I can imagine that I can filter out points that are too near.
    Thanks
    Peter
     
  42. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
    Yes, for example the DrawLinesMouse demo script doesn't allow points that are too close.

    --Eric
     
  43. Questioning

    Questioning

    Joined:
    May 17, 2015
    Posts:
    17
    Hi,

    Does the "IsSelected" function take into account culling? Or is it purely a test for each line?

    Example in case I'm wording this poorly here is an example scenario. I have a scene with a few hundred lines, I want to check for collision against them to see which is selected. I run a brute force loop through all lines to check for IsSelected().

    Thanks!
     
  44. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
    VectorLine.Selected doesn't do any culling.

    --Eric
     
  45. TerrortecK

    TerrortecK

    Joined:
    Nov 14, 2014
    Posts:
    8
    Hi I am interested in purchasing Vectrosity I just have some general questions that I hope you can answer. I am wanting to use this to create a wireframe for objects similar to what you have your VR looking tank game. From looking at the documentation I can use the Linemaker script but I have some objects that are going to be animated using DoTween would I be able use this on moving objects also can I changed how the lines appear? This is a mobile game how many line should i get able to render at the same time? Thanks for your help!
     
  46. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
    You can see in the tank game that the objects are moving, so yes. (They are using Vectrosity as a "renderer" component more or less.) You can change how the lines appear. How many lines depends on the target hardware; "mobile" covers a large range so it can't really be answered usefully. Thank you for your interest!

    --Eric
     
  47. Zoser

    Zoser

    Joined:
    Oct 2, 2015
    Posts:
    1
    Hi, there is a way to draw 3d line between unity sprite objects.?. something like SortingLayers

    And, there is a way to don't distort the texture when Joins.Weld is on?

    Thanks!
     
  48. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
    Distorting the texture is unavoidable. You can set the sorting layer of lines if you want.

    --Eric
     
  49. Mike-Le-Watt

    Mike-Le-Watt

    Joined:
    Mar 28, 2016
    Posts:
    6
    I know I'm doing something silly, but I haven't been able to figure this one out for a couple of days, it's driving me crazy.

    I'm making a simple puzzle game where the user draws lines by clicking on a square grid of tiles. I need the vector lines to have a collider, which I set (collider=true). Unfortunately the lines do not interact with my box coliders attached to other game object in the scene. I have looked at the scene view and it appears that the edge collider for the vector line, appear really tiny, away from the actual scene. I have played around with different canvases/camera settings, and I still can't get it to work. Please help.

     
  50. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
    The edge collider matches the line in the camera view; it won't match in the scene view. UI elements aren't in world space, and the collider needs to be in world space, or else it wouldn't be able to collide with anything properly. See the RandomHills demo scene for an example of an object interacting with a line collider.

    --Eric