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

    GXMark

    Joined:
    Oct 13, 2012
    Posts:
    514
    I noticed that its batching. Why is it that 2 draw calls get created then its batching on 3rd 4th etc..
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Batching VectorLines follows the rules of standard Unity dynamic batching, since they are just mesh renderers. The DLLs are compiled from the source; note that there are two, one for Unity 3 and one for Unity 4, since as I mentioned just above, conditional compilation doesn't work in DLLs.

    --Eric
     
  3. Maxii

    Maxii

    Joined:
    May 28, 2012
    Posts:
    45
    Just bought 2.3 off the asset store. Impressive! Initial question - I've imported and noticed that the .dll is imported into the main assets folder. It is only labeled as Vectrosity, but I assume that is the 3.x version you refer to in the docs? Anyhow, when I import the 4.x .dll, it is automatically installed in the Plugins folder, I assume because it is in UnityScript... Is the initial Vectrosity.dll in c#? I assume it can be deleted?
     
    Last edited: Sep 13, 2013
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Thanks!

    Yes.

    No, it's a DLL; it doesn't have a language at that point since it's compiled.

    The source code is C#. You must only have one copy of Vectrosity in a project (including source and DLLs), or else you'll get errors.

    --Eric
     
  5. Maxii

    Maxii

    Joined:
    May 28, 2012
    Posts:
    45
    Duh, it's an assembly of course so in CIL. :roll: I assume the 4.x .dll doesn't have to be in the plugins folder then?
     
  6. pateras

    pateras

    Joined:
    Jan 12, 2013
    Posts:
    50
    Is there a way to get Vectrosity to use the main camera, and not its own camera? The documentation says:

    A few things on that:

    1. By default, the main camera is tagged as "MainCamera", not "Main Camera". Is that space supposed to be there?
    2. By "don't need to do anything", does that mean that the object is going to use a Vectrosity camera configured like the main camera? Or will the Vectrosity camera not be used at all? I'd really like to just use the main camera, if possible.
    3. If the Vectrosity camera is required, is there a way to get its coordinates to match the main camera's? Zeroing out its transform does appear to move the camera in the editor, but the lines still seem to have their own origin?

    One last, seemingly unrelated issue. I'm drawing a cube like so:

    Code (csharp):
    1.  
    2. indicatorCube = new VectorLine("Cube", new Vector3[24], null, 1.0f);
    3. indicatorCube.MakeCube(new Vector3(0.0f, 0.0f, 0.0f), 1.0f, 0.25f, 1.0f);
    4. indicatorCube.Draw(transform);
    It draws fine, until I set the localScale on the transform beyond a certain point, which results in some clipping. If I continue to scale the cube up, more lines are clipped. I've tried increasing the camera's clipping planes and viewport, but that doesn't seem to help.

    Thank you for your time, assistance, and for this great tool.
     
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It doesn't have to be, no; DLLs can be moved anywhere and they should work.

    You can pass in a camera to SetCamera. If you're using only DrawLine3D(), then no VectorCamera is created. For "normal" 2D lines using Draw(), it's required that the VectorCamera is created.

    Nope, sorry...I've fixed it in the docs now.

    See above.

    No, the VectorCamera should not be touched, or else Vectrosity won't work right.

    How much are you scaling it up? Might be hitting floating point precision issues if it's a lot.

    --Eric
     
  8. Maxii

    Maxii

    Joined:
    May 28, 2012
    Posts:
    45
    I'm confused about what passing in transform into line.Draw3D does (and does not) do for you.

    I've got a moving 3D object (a physics powered rigidbody) and a moving camera and I'm trying to create a velocity vector emanating from the moving object. I've been successful by manually updating the start and end point of the line each update without passing in transform, but I'd like to use any benefits that are builtin from using the transform in the Draw3D method.

    I've noticed that when using the transform, line.point3[0] doesn't change value, yet the line's starting point continues to track the moving object. Also, I assume as the speed of the object is increasing with time, I need to update line.point3[1] with that new value which I am doing. I can see the value of line.point3[1] increasing as I make the change each update, but it appears to me that the length of the line is not increasing.

    Clearly I don't understand what is going on when passing in transform. Normally I'd just read the code, but I'm not familiar enough with matrix4x4 math to make sense of it. Any explanations you can provide would be helpful. The documentation really only refers to getting the benefits of the transform's matrix...
     
  9. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Passing in a transform makes a line be "controlled" by that transform, so moving/rotating/scaling the transform makes the line be drawn likewise. It doesn't change the values in the points array. For example, if you attach this script to a cube (or some other object):

    Code (csharp):
    1. function Start () {
    2.     var vLine = new VectorLine("VLine", [Vector3.zero, Vector3.forward*10], null, 2.0);
    3.     vLine.Draw3DAuto (transform);
    4. }
    Then there will be a 10-unit line drawn in the forward direction of the cube that follows it around as it moves and rotates.

    --Eric
     
  10. Maxii

    Maxii

    Joined:
    May 28, 2012
    Posts:
    45
    Thanks for the explanation. On the second part of my question, re: lengthening the line via increasing the value of line.point3[1], will this change the length or does it ignore point3[1] like it does point3[0]? If so, how do I dynamically change the length of the line while using transform, or can I?
     
  11. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Nothing is ignored. Changing either of the points in the array will change the line; passing in a transform is "on top of" the data that already exists. As I mentioned, passing in a transform does not affect the points array.

    --Eric
     
  12. wbl1

    wbl1

    Joined:
    Apr 22, 2009
    Posts:
    159
    getting the following error:

    "Ambiguous reference 'VectorLine': Vectrosity.VectorLine, Vectrosity.VectorLine"

    Using Unity version 3.4.2f3 (long story) and have VectrocitySource loaded. Any thoughts?
     
    Last edited: Sep 19, 2013
  13. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can only have the source or the DLL in your project, not both.

    --Eric
     
  14. jchow

    jchow

    Joined:
    Jun 20, 2013
    Posts:
    28
    Hi Gang, I want to use Vectrosity to draw a line around an irregular region. I'm hoping to make this a thick line with a gradient material. Unfortunately it looks like the mesh is being pivoted and the line strips aren't perfectly vertical. here's an example:

    http://screencast.com/t/r80wkOtuL

    Does anyone know how I can solve this and make each line segment a vertical plane? It looks like the world->screen mapping isn't working quite right?

    Thanks in advance,
    Jeff
     
    Last edited: Sep 26, 2013
  15. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I can't really see what's going on in that screenshot; do you have a better one?

    --Eric
     
  16. jchow

    jchow

    Joined:
    Jun 20, 2013
    Posts:
    28
    Hi Eric,

    Never mind, I understand the problem now. The planes are pivoted every frame to maintain the same screen thickness. If I want my lines to do the same thing (but at the same time rendering the strips so they are propped up perfectly vertically I'll have to do something similar manually.
    Sorry for your time!
     
  17. mstath1s

    mstath1s

    Joined:
    Dec 31, 2012
    Posts:
    5
    Hi all,

    Eric thanks a lot for your great tool!
    I am working at a project where I am using vectrosity to make a radar/ tactical map.

    I have used your LineMaker tool to make lines for each tile that we are using to make a level (worked like a charm).

    Then when the level is set up the vector lines are put to certain layer.
    Then VectorLines.SetCamera(orthoCam) and it renders only this certain layer.
    The problem comes when I am setting the Visibilty.Static or Visibility.Dynamic. Vector lines are updating in relation to the 3rd person camera and not to my orthoCam as I would expect. Do I miss anything?

    I'd like to use Visibilty.Static or Dynamic because rendering the lines all the time put LineManager.LateUpdate to the top of my profiler, spending 3ms per frame.

    Below you can see the pictures that illustrates my problem:



    First picture with Visiblity.Always renders the tactical map correctly.
    Second picture with Visibility.Dynamic and player's 3rd person camera looking up.
    Third picture with Visibility.Static and player's 3rd person camera looking down.

    Thanks in advance!
     

    Attached Files:

    Last edited: Sep 30, 2013
  18. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    That makes use of OnBecameVisible, so you'd have to make use of layers to make sure that only the orthocam can see the Vectrosity lines.

    --Eric
     
  19. mstath1s

    mstath1s

    Joined:
    Dec 31, 2012
    Posts:
    5
    This is what I was doing. Only the ortho camera can see the vectrosity lines.
    There is also a VectorCam in the hierarchy where the culling mask is set to an UnnamedLayer 31.
    Should I set it up this camera with code to see only my tactical map layer?
     
  20. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Sorry, I meant that only the orthocam should be able to see the meshes that control the Vectrosity lines. I'm not sure that using ObjectSetup is really appropriate in this case though. It might be better to use Draw() manually.

    --Eric
     
  21. mstath1s

    mstath1s

    Joined:
    Dec 31, 2012
    Posts:
    5
    Thanks for your input!
    I used both of your recommendations and the performance is way much better now.
     
  22. Maxii

    Maxii

    Joined:
    May 28, 2012
    Posts:
    45
    Eric,

    What a great tool! I'm finding more and more uses for it and I've implemented it in a number of different ways. I'm now trying to consolidate into just a couple of approaches (1 for 2D Ortho drawing and 1 or 2 for 3D perspective drawing). Wrt 3D perspective drawing associated with scene objects, do you have some guidelines as to when (and when not) to use VectorManager.ObjectSetup vs Draw3D vs Draw3DAuto? You mention that Draw3DAuto is slightly less efficient than Draw3D in the manual, but I expect you have a lot more insight to share about conditions and directions to take that would be helpful.
     
  23. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    ObjectSetup is generally best when you want a VectorLine to behave "like a GameObject" (such as the objects in the TankZone demo). If you want precise control over when a VectorLine updates for maximum efficiency, then use Draw3D rather than Draw3DAuto.

    --Eric
     
  24. Maxii

    Maxii

    Joined:
    May 28, 2012
    Posts:
    45
    Thanks. You also mentioned those in the manual. A couple of more specific questions then:

    Does Draw3D/Draw3DAuto stop drawing when the line is not visible too, or is that only incorporated into ObjectSetup via OnBecameVisible/Invisible?

    Is ObjectSetup heavier, ie. suck up more resources, effect performance than the others?
     
  25. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,764
    Before I purchase.

    Is it possible to have 2D objects collide with the lines generated from this tool?
     
  26. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Draw3DAuto always draws every frame.

    Not necessarily; depending on whether you use Visibility.Static etc. then it can be cheaper than Draw3DAuto.

    Not currently, sorry, or at least there's nothing built-in.

    --Eric
     
  27. Daniel-Talis

    Daniel-Talis

    Joined:
    Dec 10, 2011
    Posts:
    425
    Hi, I bought Vectrosity some time ago and am just beginning to explore it and have come across a couple of things that need clarifying..

    If I create lines in 3D space..

    Is there some way to treat them like objects and click on them to create states or use a mouseover event to create a state, like..

    I have read through the manual and there seem to be a number of approaches to things, not sure which to try.
    Thanks.
     
    Last edited: Oct 18, 2013
  28. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I'd recommend using VectorLine.Selected; see the SelectLine demo for an example.

    --Eric
     
  29. Doompanther

    Doompanther

    Joined:
    Aug 11, 2012
    Posts:
    24
    Is their website down for everyone or just me?

    Also, are there any good tutorials?
     
    Last edited: Oct 30, 2013
  30. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
  31. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I replied to your PM...you don't need to both post in this topic and send a PM for the same thing; either one or the other is fine.

    --Eric
     
  32. Doompanther

    Doompanther

    Joined:
    Aug 11, 2012
    Posts:
    24
    Ok, I've gone through the documentation and I still can't figure out how to do some basic things.

    What I'm trying to do is draw a line between Object A and Object B. Done. That problem is that as object B moves around the line is not being updated with it.

    The docs say to use Draw3DAuto() but that doesn't work.
    Code (csharp):
    1.  
    2. void Start ()
    3. {
    4.     Line = VectorLine.SetLine3D(Color.green, StartPosition.transform.position, Endposition.transform.position);
    5.         Line.Draw3DAuto();
    6. }  
    7.  
    8. void Update ()
    9. {
    10.     //Line.Draw3DAuto();
    11. }
    12.  
    13.  
    14.  
     
  33. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    What that's doing is setting the points in the line array to the objects' initial positions, so there's no way they can change unless you update the points in the array yourself. It's probably easier if you create the VectorLine object manually rather than using SetLine3D. That way you can make the points array yourself, and update the appropriate points in the array as needed.

    --Eric
     
  34. Doompanther

    Doompanther

    Joined:
    Aug 11, 2012
    Posts:
    24
    Can you describe how to do this (or point to a chapter in the manual)? Is this through the VectorManager.ObjectSetup or the linemaker system?


    EDIT:

    Ok, this works:

    Code (csharp):
    1.  
    2. void Start ()
    3. {
    4.     HLine = VectorLine.SetLine3D(Color.green, transform.position, HEnd.transform.position);
    5. }
    6. void Update ()
    7. {
    8.     HLine.points3[0] = HEnd.transform.position;
    9.     HLine.points3[1] = transform.position;
    10. }
    11.  
    This works, is there a reason why I wouldn't want to use this/whats a better way?
     
    Last edited: Oct 31, 2013
  35. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    See page 5 in the docs.

    --Eric
     
  36. NoXQS

    NoXQS

    Joined:
    Jan 26, 2013
    Posts:
    5
    Hi Eric,

    I need to calculate the OOBB. Unity bounds is AABB.
    Can Vectrosity create OOBB ?

    $aabb.PNG
    -- Morgan
     
  37. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It can draw the OOBB, if you give it data to do that. There isn't a built-in function, but you can create one.

    --Eric
     
  38. Doompanther

    Doompanther

    Joined:
    Aug 11, 2012
    Posts:
    24
    Hey Eric, new question:

    I'm working with the selection system and I can't figure out how to get information on items inside the selection area. The biggest problem is that the selection area is not actually formed over the main camera but over the Vectorcam. So trying to find objects between the mouseDown original position and the mouseUp Input.mousePosition position does not work.

    So how do you collect information (like gameObjects) that exist inside a vectrosity selection box?
     
  39. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    2D VectorLines use screen space coordinates, so you could use ScreenToWorldPoint probably.

    --Eric
     
  40. Doompanther

    Doompanther

    Joined:
    Aug 11, 2012
    Posts:
    24
    There is no way to just get a VectorLine to use world space like a linerenderer?

    Also, the ScreenToWorldPoint is for vector3s. I guess I can just convert the 2D vectorline, but that seems like an unnecessary step.
     
    Last edited: Nov 5, 2013
  41. hitmax87

    hitmax87

    Joined:
    May 27, 2013
    Posts:
    12
    Eric hi! I dont need camera dependence, I mean when the camera go back - line is growing. I want constant size of line. Help please.
     
  42. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    If you use Vector3 points in a line, then they are in world space. If you use Vector2 points, then they are in screen space.

    Yes, that's the idea. Convert screen points (Vector2) to world points (Vector3).

    Vectrosity is specifically designed to render vector lines that use pixels as the measurement for lines, so that they maintain a constant width at all times.

    --Eric
     
  43. Doompanther

    Doompanther

    Joined:
    Aug 11, 2012
    Posts:
    24


    Yes, the issue is with the Z portion of the vector3. The X and Y work, but only if the Z is manually setup correctly determining the distance of the


    Current setup:

    Code (csharp):
    1.  
    2. update()
    3. {
    4.  
    5.     if (Input.GetMouseButtonUp(0))
    6.     {
    7.         ScreenToWorldPointx = new Vector3(selectionLine.points2[0].x, selectionLine.points2[0].y, ZFloat);
    8.          ScreenToWorldPointy = new Vector3(selectionLine.points2[2].x, selectionLine.points2[2].y, ZFloat);
    9.  
    10.         ScreenToWorldPointx = camera.ScreenToWorldPoint(ScreenToWorldPointx);
    11.         ScreenToWorldPointy = camera.ScreenToWorldPoint(ScreenToWorldPointy);
    12.        
    13.         WhatsInsideThisThing(ScreenToWorldPointx, ScreenToWorldPointy);
    14.     }
    15. }
    16.  
    17. WhatsInsideThisThing(Vector2 StantPoint, Vector2 EndPoint)
    18. {
    19.     foreach (GameObject thing in EverythingInScene)
    20.     {
    21.         ThingPos = thing.transform.position;
    22.  
    23.         if (ThingPos .x > StantPoint.x  ThingPos .x < EndPoint.x  ThingPos .y < StantPoint.y  ThingPos .y > EndPoint.y)
    24.         {
    25.             ThingsInside.Add(thing);
    26.  
    27.             if (Debug.isDebugBuild)
    28.                 Debug.Log("What's inside: " + thing.name);
    29.         }
    30.     }
    31. }
    32.  
    33.  
    Yes, it only works so far if the box is drawn left-right top-bottom BUT I'll add flip box code in later after the basics work.
    So the current issue is with the Z position. Most of what I've been able to search basically says you have to estimate the objects distance.

    Iterating Z 0 through ~100 turns out to be horribly inefficient and ends up adding multiple copies of the same thing to ThingsInside.
     
  44. Doompanther

    Doompanther

    Joined:
    Aug 11, 2012
    Posts:
    24
    Never mind Eric, I built a completely different system that uses textures instead of Vectrosity and got it to work.
     
  45. Jimmy_H

    Jimmy_H

    Joined:
    Nov 9, 2013
    Posts:
    3
    Hello Eric! I meet a problem when using Curve in Demo...
    Im trying to make several bezier curves at once, so I simply duplicate the object with DrawCurve script. But the problem is: only the first one can use the anchor and controller. How to modified the script to make all curves can follow their own anchor and controller?

    Thank you so much!:D
     
  46. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You'd want to get rid of the static "use" variable, and have a variable in the CurvePointControl script that references the DrawCurve script instead. e.g., "var drawCurveScript : DrawCurve;", and whenever the CurvePointControl script is instantiated, set drawCurveScript to the DrawCurve script that instantiated it. So instead of DrawCurve.use.UpdateLine it would be drawCurveScript.UpdateLine.

    --Eric
     
  47. Jimmy_H

    Jimmy_H

    Joined:
    Nov 9, 2013
    Posts:
    3
    Hello Eric, thanks for your fast reply! I tried the steps you gave me :

    1. get rid of "static var use",
    2. put "var drawCurveScript : DrawCurve" in CurvePointControl to access DrawCurve
    3. then change "DrawCurve.use.UpdateLine" to "drawCurveScript.UpdateLine"

    and now the curves are not following updating, and get
    " NullReferenceException: Object reference not set to an instance of an object " error
    I think I miss some parts to connect two scripts...

    please give me some clue, Im a starter to script...Thank you ~ !
     
    Last edited: Nov 9, 2013
  48. catchthefloaty

    catchthefloaty

    Joined:
    Feb 11, 2013
    Posts:
    15
  49. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Looks neat, but unfortunately all I get with the webplayer here is a white screen.

    @JimmyH: as I mentioned, you need to set drawCurveScript to the DrawCurve script that instantiated it...look up GetComponent in the docs.

    --Eric
     
  50. Jimmy_H

    Jimmy_H

    Joined:
    Nov 9, 2013
    Posts:
    3
    Thanks a lot Eric, fixed it with GetComponent:D
     
Thread Status:
Not open for further replies.