Search Unity

Vectrosity - fast and easy line drawing

Discussion in 'Assets and Asset Store' started by Eric5h5, May 26, 2010.

Thread Status:
Not open for further replies.
  1. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You'd use Draw3DAuto if you want the line to be updated every frame, for example if the camera is moving or the line itself is being changed. If you manually call Draw3D every frame then it's no different than using Draw3DAuto.

    --Eric
     
  2. Timbola

    Timbola

    Joined:
    Jun 7, 2010
    Posts:
    4
    He Eric,

    Thanks for the great work on Vectrosity. We are making a line drawing (and path following) game. Currently the user can draw a line. We are using the makeSpline function to curve the line. Working great. But can you give us some more details what the makeSpline function does?

    You have to pass all the points of the line, but does it calculate every the the whole line? Or just the last part?

    Thanks,
    Tim.
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It calculates the entire line if you want, but you can use the index value with a subset of spline points to only update part of a line. Such as the DrawCurves example does; using MakeCurve in that case rather than MakeSpline, but the idea is the same.

    --Eric
     
  4. Kamadake

    Kamadake

    Joined:
    Oct 12, 2013
    Posts:
    12
    Hey, first of all thanks a lot for an amazing plugin. Using it a lot for the drawing of lines.

    I wish to ask, I'm trying to draw a line with a repeated pattern (footsteps texture), and a quad should occupy a grid of a 1x1 square. What I've tried are two methods:
    • Discrete lines stretching from one edge to another. The problem is that the texture goes beyond a 1x1 quad when I draw with the line, even though texturescale has been set to 1. And also the quad is drawing based off the perspective the camera, I don't want that if possible since I'd like the material to be flat on the floor.
    • I then tried with points and the footsteps started to show well, the problem is now that the texture doesn't rotate like when drawing the line. Maybe there's a way to rotate a point?
    I've been looking at the documentation to maybe find a way to disable the perspective drawing but didn't find what I need, maybe you know of a way to do so? Or maybe rotate the points being drawn?

    Thanks!
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    A textureScale of 1 means that the texture width will be drawn in direct proportion to the height, so a square texture will be drawn exactly square and not stretched. So if the line is wider than it is tall, then it will be repeated. It's not possible to draw without being based on the perspective of the camera, but a hack is to use a secondary camera pointing in the direction you want and use that with SetCamera.

    --Eric
     
  6. ViCoX

    ViCoX

    Joined:
    Nov 22, 2013
    Posts:
    37
    Hi Eric,

    Works well so far however I cannot get my selection index working. (line selection works well)

    Code (CSharp):
    1.         if (pCloud.collections.Length > 0) {
    2.             for (int i = 0; i<pCloud.collections.Length; i++) {
    3.                 if (pCloud.collections[i].line.Selected(EndPoint2), out index) {
    4.                     Debug.Log("line index: " + index);
    5.                 }
    6.             }
    7.         }
    Console says:
    C:\Users\JUHANI\Documents\Verlet02\Assets\pInput.cs(91,86) error:CS1525 Unexpected symbol `out'

    It has something to do with the "out" statement. What it actually does?
    Thanks,
    - J
     
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The "out index" has to be inside the Selected call; you have it inside the if statement.

    --Eric
     
  8. ViCoX

    ViCoX

    Joined:
    Nov 22, 2013
    Posts:
    37
    Thanks Eric got it working! Looking good : ) I got confused somehow when reading the documentation.
     
  9. qtownMWD

    qtownMWD

    Joined:
    Feb 5, 2014
    Posts:
    1
    Great job with Vectrosity!!!
    I am using the SetLine3D functions in a situation where i do not know beforehand how many points will be in the line. what is the best way to handle this?
    i have been declaring a Vector3 array that is longer than the max number of points then copying the last line point into the remaining unused slots in the array so that the line doesn't go to origin. Using C#. thank you
     
  10. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The usual way is to declare an array that's the maximum size you think you would use, then only use some of the points.

    --Eric
     
  11. pretender

    pretender

    Joined:
    Mar 6, 2010
    Posts:
    865
    Hi! I was wondering if you could help me with the situation I ended up in.
    I have a spline, which is changed by dragging fingers across it. While drag is not finished there is a "ghost" line that shows what the final edit will look like. So when it is done, points are animated in a coroutine from ghost to original line, and that works good.

    Now, there is a lot of intermediary point arrays, and some problem arise when I want, for example, to remember the previous shapes. I would make a stack of Vector2[] and push current array before it's edited. If I do it like this:

    Code (CSharp):
    1.  
    2. Stack<Vector2[]> history = new Stack<Vector2>();
    3. histroy.Push(line.points2);
    4.  
    It seems that array is stored by reference
    so I need to do something like this:

    Code (CSharp):
    1.  
    2. List<Vector2>h=newList<Vector2>();
    3. foreach(Vector2 v in line.points2)
    4. {
    5. Vector2 hv=v;
    6. h.Add(hv);
    7. }
    8.  
    9. history.Push(h.ToArray());
    10.  
    Am I missing something here, about how Vector2 data is passed here? By value or reference?

    Also as a helper I have map of point values for easier editing of the splines like this (its stored by reference):
    Code (CSharp):
    1.  
    2. Dictionary<int,Vector2> Line = new <int,Vector2>();
    3.  
    at the beginning I store all indeces and Vector2 values to this map so I can easily edit certain points.
    Is there a easier way to do this? I think I am overlooking something!

    Thanks for great package and great support!
     
  12. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Arrays are always by reference, yes. If you want to copy an array you can just use System.Array.Copy. Even if you did it by hand, the correct way would be:

    Code (csharp):
    1. var h = new Vector2[line.points2.Length];
    2. for (int i = 0; i < h.Length; i++) {
    3.     h[i] = line.points2[i];
    4. }
    --Eric
     
  13. timothyjoelwrigh

    timothyjoelwrigh

    Joined:
    Feb 16, 2013
    Posts:
    3
    I'm seeing odd behavior when applying Depth of Field to my main camera. 3D lines appear arbitrarily blurred regardless of how close or far they are from the camera along the Z axis:
    Screen Shot 2014-07-28 at 7.50.22 PM.png

    Oddly, if a line is visually in front of another object (between the object and the camera) it appears perfectly sharp regardless of Z axis positioning:
    Screen Shot 2014-07-28 at 7.51.13 PM.png Screen Shot 2014-07-28 at 7.52.02 PM.png

    I'm using Vectrosity's default material. Am I missing some way of making the lines render properly?
     
  14. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I'm guessing it's shader-related, probably the z-buffer; try a different shader. Although the default shader does have zwrite on...maybe it's alpha/transparency that's the issue? I haven't really used the DOF effect.

    --Eric
     
  15. Kamadake

    Kamadake

    Joined:
    Oct 12, 2013
    Posts:
    12
    Hey Eric5h5, thanks for your previous post. Took your tip for the secondary camera as a hack and that worked well. I have two new questions now if I may please?
    • Is there a way to use SetCamera maybe with separate VectorLine variables instead of using the static method? At the moment I'm switching between two cameras because of perspectives I want to maintain.
    • I'm using endcap to outptut an arrow. Inside the Unity Editor, the image shows perfectly but on Android tablets, that arrow is not showing. Do you have an idea maybe of why this is happening please?
    Thanks for your help and again good job on Vectrosity ^_^
     
  16. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

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

    Maybe the material isn't included? Try putting the material in the Resources folder, which makes it be included regardless of whether Unity knows it's being used or not.

    --Eric
     
  17. timothyjoelwrigh

    timothyjoelwrigh

    Joined:
    Feb 16, 2013
    Posts:
    3
    Thanks for pointing me in the right direction. Apparently this is a common shader issue with partially transparent objects and DOF. I was able to modify a simple shader to work properly in case anyone else has the same problem:

    http://forum.unity3d.com/threads/depth-of-field-bug-with-alpha-channels.79209/

     
  18. ViCoX

    ViCoX

    Joined:
    Nov 22, 2013
    Posts:
    37
    Hi Eric (again)

    Vectrosity works very well now.
    It seems that each VectorLine takes one drawcall and I have few hundred lines in the scene. The dynamic batching is taking care of it pretty well and I have good fps, but would it be generally faster to render everything in one VectorLine or is the dynamic batching enough fast?

    Thanks,
    - J
     
  19. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The idea with dynamic batching is that the time taken for batching should be less than the time it would have taken if it was using separate draw calls, but batching is still taking CPU time. So ideally you would have 1 draw call in the first place, rather than using dynamic batching to achieve 1 draw call.

    --Eric
     
  20. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    A small update out now (on the asset store soon I expect):

    Vectrosity 3.1.1

    Fixes:
    • Using .drawStart and .drawEnd with 1-pixel lines made with LineType.Continuous and VectorLine.useMeshLines = true works correctly.
    • Colliders created for Continuous lines with .drawStart and .drawEnd are correct.

    --Eric
     
  21. Jonathan-Bro

    Jonathan-Bro

    Joined:
    Apr 11, 2013
    Posts:
    35
    I'm drawing a "continuous" line with Joins set to Weld, but just as the screenshot shows, it looks like it's not being joined at all.

    Code (CSharp):
    1.  VectorLine previewLine = new VectorLine("Gesture Preview", points, mat, 4.0f, LineType.Continuous, Joins.Weld);
    I'm joining multiple "MakeCurve" lines together. The material is additive soft, if it's important.

    Can I not use weld in this case?
     

    Attached Files:

    • weld.png
      weld.png
      File size:
      113.9 KB
      Views:
      819
  22. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Looks like you want to change VectorLine.maxWeldDistance.

    --Eric
     
  23. Jonathan-Bro

    Jonathan-Bro

    Joined:
    Apr 11, 2013
    Posts:
    35
    I made it ridiculously huge, but it didn't change anything.

    Diving into your code at Line2D() where WeldJoins() is being called, it looks like WeldJoins() it can only be called when the vector line is connected as a loop as determined by your approximately2 method.

    What can I do to have my curve lines welded together without having to connect the line vector into a loop (first point = last point)?
     
  24. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Are you using separate VectorLines? Those can't be welded; the points must all be in a single VectorLine.

    --Eric
     
  25. Jonathan-Bro

    Jonathan-Bro

    Joined:
    Apr 11, 2013
    Posts:
    35
    All points are on a single vector line using multiple "MakeCurves."

    More info: I have a for-loop which assigns 4 Vector2 variables into a MarkCurve method from a VectorLine. I run through the loop a few times so that I can draw a bunch of curves.
     
  26. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    For Continuous lines, all joins are welded as long as maxWeldDistance permits it. The thing about being connected as a loop only applies to the first and last points.

    --Eric
     
  27. Jonathan-Bro

    Jonathan-Bro

    Joined:
    Apr 11, 2013
    Posts:
    35
    Yep, that's what I feared. Ok, thanks for the help!
     
  28. Curious

    Curious

    Joined:
    Nov 19, 2009
    Posts:
    334
    Is there any way to make a circle partially? Like the PartialLine demo? (With the same material perhaps?)
     
  29. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes, you could make a circle and erase the part you don't want with .drawStart/.drawEnd. Or make a circle in a line and copy the points of the array into another line.

    --Eric
     
  30. Curious

    Curious

    Joined:
    Nov 19, 2009
    Posts:
    334
    Thanks Eric, did it :D
    I have one more question for you:
    Is it possible to create a flat 3d shape say a flat circle facing up, so that the triangles are not facing the camera? If yes, how?
     
  31. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Not currently, but as a hack you can make another camera that faces the way you want, and use that in SetCamera.

    --Eric
     
  32. helios

    helios

    Joined:
    Oct 5, 2009
    Posts:
    308
    Hi Eric, is it possible to fill shapes with a solid color? Such as a simple circle or triangle. Thanks.
     
  33. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

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

    --Eric
     
  34. chrisleathers

    chrisleathers

    Joined:
    Jul 6, 2012
    Posts:
    4
    This is a huge thread. Seems like maybe vectorocity needs its own forum, so we can get specific answers seperated out.

    I just bought Vectorocity, hoping it would solve my line problems, And I am sure it can. But for the life of me, I can not get it to do this simple thing:

    I want to draw a line between two objects in the 3D view. As the camera moves, the line should stay attached to both objects if they are moved or if the camera moves. That's it..

    This is the JS code I assembled but it is not working. Any help greatly appreciated:
    ------------
    #pragma strict
    import Vectrosity;

    var startobj : Transform;
    var endobj : Transform;

    function LateUpdate () {
    // Make Vector2 array; in this case we just use 2 elements...
    var linePoints = Vector2(startobj.transform.x, startobj.transform.y),(endobj.transform.x, endobj.transform.y);

    // Make a VectorLine object using the above points and the default material, with a width of 2 pixels
    var myline = new VectorLine("Line", linePoints, null, 2.0);

    // Draw the line
    myline.Draw3Dauto();
    }
    --------------
     
  35. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The main problem is that you're creating a new VectorLine object every frame. Also that's not the syntax for how arrays are declared, and you would need to use the complete transform.position including z, not just x and y. You should create the line (and the array) once, and update the points in the array as needed. I'd strongly recommend at least reading pages 6-7 in the docs, which cover how VectorLine objects are created and used. So you'd create the line and the array (which would need to be a global variable) in Start, and every frame you'd put the transform.position of startobj into one element in the array and the transform.position of endobj into the other element in the array. Let me know if you're still having problems with the code after trying this.

    --Eric
     
  36. gpaulin

    gpaulin

    Joined:
    Mar 19, 2007
    Posts:
    40
    Hi Eric,

    Thanks for Vectrosity! I'm looking for a way to figure out which (overlapping) line segments are at certain point. For example, the following code has two segments crossing at (50,50). I'm getting segment 1, which is OK, but I need segment 3 also returned.

    Code (JavaScript):
    1. import Vectrosity;
    2. var index : int;
    3. private var line : VectorLine;
    4. private var linePoints = [
    5.     Vector2(0, 50),
    6.     Vector2(0, 0),
    7.     Vector2(100, 100),
    8.     Vector2(100, 0),
    9.     Vector2(0, 100)
    10. ];
    11.  
    12. function Start () {
    13.     var line = VectorLine("TestLine", linePoints, null, 4.0, LineType.Continuous);
    14.     line.Draw();
    15.     line.Selected(Vector2(50,50), index);
    16. }
    Is there a (simple) way to get it? I'm thinking of altering Selected method, testing all segments and returning an array of ints - but before I do that and give myself updating headaches :) - is there any chance that you add this feature in some future update?
     
  37. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    There isn't a simple way, sorry. I think this is too specific to have as a standard feature...the API is already very big so I have to be careful about adding stuff. But that's why the source is included. :)

    --Eric
     
  38. gpaulin

    gpaulin

    Joined:
    Mar 19, 2007
    Posts:
    40
    Fair enough. :)
     
  39. pretender

    pretender

    Joined:
    Mar 6, 2010
    Posts:
    865
    Hi guys!

    Currently I am drawing lines as splines and that works well, so if i have just a few points that make a rect, using MakeSpline gives me nice shape with number of segments that I want. Now I am trying to draw a line with just a few points but to have many segments but still to keep rectangular shape. is this possible, take a look at the pic (line should be defined with just four points and other points are automatically added).

    thanks!
     

    Attached Files:

  40. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    There isn't a built-in function for that, but you can make your own by supplying the appropriate points in the array.

    --Eric
     
  41. krayzie762

    krayzie762

    Joined:
    Aug 21, 2014
    Posts:
    3
    Hey Eric, love the asset, however i keep getting the error that the shader wants normals, but the mesh actionline doesnt have them. I tried using the .AddNormals() method, heck i even tried the .AddTangents() method, and ive tried placing them all over the place with no luck. What am i doing wrong?

    Thanks in advance!
     
  42. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Did you draw the line again after using AddNormals? (Sorry, the documentation doesn't really make this clear.)

    --Eric
     
  43. krayzie762

    krayzie762

    Joined:
    Aug 21, 2014
    Posts:
    3
    Code (CSharp):
    1. void Awake()
    2. {
    3. actionLine = new VectorLine ("ActionLine", linePoints, lineMaterial, lineWidth, LineType.Continuous, Joins.None);
    4. actionLine.AddNormals();
    5. actionLine.vectorObject.renderer.receiveShadows = false;
    6. actionLine.vectorObject.renderer.castShadows = false;
    7. actionLine.layer = 0;
    8. actionLine.textureScale = 1.0;
    9. }
    10.  
    11. void Update()
    12. {
    13.  
    14. if(!actionComplete)
    15. {
    16. actionLine.active = true;
    17. actionLine.AddNormals();
    18. actionLine.Draw3D();
    19. }
    20. else actionLine.active = false;
    21. }

    So i pretty much have it in awake function and in update, and i also tried putting it in all different orders and no luck

    Also i should mention, it still draws the line out with the correct normals and everything, the only downfall i experience is a lag spike, but its a pretty bad one


    **Edit:

    Okay so i fixed it and what i actually had to do was create and assign a second material without normals at first then switch the materials out after i call the addnormals.
     
    Last edited: Aug 21, 2014
  44. niraj

    niraj

    Joined:
    Feb 14, 2013
    Posts:
    56
    Eric,

    fantastic tool for Line drawing in unity. Just need a little help though from your side:

    Say i want to Draw a capped Straight line with rounded angle that should be drawn between two specific screen positions and using Orthographic main camera. For example:


    ---------------------------------------------------------
    function OnMouseDown()
    {
    startPosition = Current Vector2 position of Mouse on screen when mouse pressed;
    }

    function OnMouseUp()
    {
    endPosition = Current Vector2 position of Mouse on screen when mouse released;

    DrawLine between startPosition and endPosition <---------------------How to achieve this?
    }

    ---------------------------------------------------------------

    PLease help, actually i want to create application like Free flow game and thus want to start like this.



    Waiting for your kind reply.

    Thanks and Regards
    Niraj Vishwakarma
     
  45. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Vectrosity doesn't really support rounded corners, although it would probably work if you made a very short curve at the correct location.

    --Eric
     
    niraj likes this.
  46. pretender

    pretender

    Joined:
    Mar 6, 2010
    Posts:
    865
    forum.png Hi Eric!

    Is it somehow possible to have a spline (with line.MakeSpline) just like in the attached image, so that one point have
    different interpolation or something like that? View attachment 110542
     

    Attached Files:

    Last edited: Aug 26, 2014
  47. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The image doesn't seem to work.

    --Eric
     
  48. pretender

    pretender

    Joined:
    Mar 6, 2010
    Posts:
    865
    it should work now i hope
     
  49. niraj

    niraj

    Joined:
    Feb 14, 2013
    Posts:
    56
    Hello Eric,

    I have got how to create rounded ended lines. Just help me draw line between two Screen positions in the form of Vector2 as i described below where i need help:

    ----------------------------------------------------

    function OnMouseDown()
    {
    startPosition = Current Vector2 position of Mouse on screen when mouse pressed;
    }

    function OnMouseUp()
    {
    endPosition = Current Vector2 position of Mouse on screen when mouse released;

    DrawLine between startPosition and endPosition <---------------------How to achieve this?
    }

    ---------------------------------------------------

    Thanks and Regards
    Niraj Vishwakarma
     
  50. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    @niraj: lines just use an array of points, so you use the array when creating a VectorLine, and then update the points in the array as needed.

    Code (javascript):
    1. linePoints = new Vector2[numberOfPoints];
    So you use linePoints (which should be a global variable) to create the VectorLine, and then change the entries in linePoints to accomplish what you want.

    @pretender: if I understand what you're asking, you can use two splines. MakeSpline has an option to use an index for the segments, so if e.g. you have a line with 100 segments, then you could use MakeSpline with one spline for 50 segments, and then MakeSpline with another spline for another 50 segments, starting at 50.

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