Search Unity

  1. New Unity Live Help updates. Check them out here!

    Dismiss Notice

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,225
    What if you use SetCamera(true)?

    --Eric
     
  2. Butterworth

    Butterworth

    Joined:
    Aug 8, 2012
    Posts:
    25
    Hello.

    I just started using Vectrosity and its a pretty slick plugin. I have one small problem. I loadup lines when entering a level, and I am trying to clean it all up when I exit a level. I am accumulating material objects but I cant figure out how to free them. I am loading materials using Resources.Load and handing the results to the VectorLine constructor. When I am done with the VectorLine I am calling VectorLine.Destroy on it. I am also removing end cap entries from the library. Is there some other step I am missing to have all of the materials used by Vectrosity to be destroyed?

    Thanks in advance.

    Sean
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,225
    In the case where you want to clean up materials, I generally find it's easier to instantiate and manage materials yourself instead of letting Unity do it. e.g., instead of this:

    Code (csharp):
    1. renderer.material.color = Color.red;
    do this:

    Code (csharp):
    1. var someMaterial : Material;
    2. private var myMaterial : Material;
    3. ...
    4. myMaterial = Instantiate (someMaterial);
    5. renderer.material = myMaterial;
    6. myMaterial.color = Color.red;
    7. ...
    8. Destroy (myMaterial);
    Also, in general I would recommend not using Resources.Load in most cases; hooking up assets in the inspector has a number of advantages.

    --Eric
     
  4. Butterworth

    Butterworth

    Joined:
    Aug 8, 2012
    Posts:
    25
    So it turns out that if I disable the endcap (by setting it to null) OR call StopDrawing3DAuto before I destroy a VectorLine, it leaks materials. I thought I was being super careful by making those calls when shutting down a VectorLine but I guess they were not needed.

    Hooking up assets in the inspector isnt an option for me. I have a commercial game that is 100% data driven. Your plugin has allowed me to prodecurally generate hundreds of slot machine paylines that used to be baked into 2D images. Fantastic.

    Thanks.

    Sean
     
  5. CHPedersen

    CHPedersen

    Joined:
    Mar 2, 2011
    Posts:
    63
    Same result, I'm afraid. I gave it a spin in a fresh scene just to make sure there was nothing else interfering (hence the standard cornflower blue background).

    The code's obviously nearly identical:

    Code (csharp):
    1.         VectorPoints test = new VectorPoints("Test", new Vector2[] { new Vector2(0, 0) }, null, 1);
    2.         VectorPoints.SetCamera(true);
    3.         test.Draw();
    4.  
    This is in 16:9:

    $169Ortho.png

    And this is when the aspect ratio is close to 1 (resized manually in the editor to near square):

    $OneOneOrtho.png

    Ignore the slightly darker pixels in the images. That's an artifact from the image processor I used to enlarge the corners.
     
  6. Banksy

    Banksy

    Joined:
    Mar 31, 2013
    Posts:
    336
    So I managed to get my object to display a vectored wireframe on another object so its masked with a Depth Mask. Looks great.

    My problem is... I am using a V.R headset ( Oculus Rift ) so the vectored object appears in the left eye camera ( great ) but the right eye camera also shows the vector lines floating around in world space. I presume this might be because of culling on each camera.. but I ahve tried many different culling combinations just to make sure the vectored lines are still in the right eyes camera... they should be visible but only within the masked object a small Hud display...

    This is so difficult to explain... as there's now stereoscopic cameras involved. It might make more sese I upload a sample video f my problem.. yes ?
     
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,225
    Did you turn off anti-aliasing? What's the exact resolution? The only way I could duplicate that was to use a window that had an odd height (as in not evenly divisible by two); even heights worked as expected. Which is actually something I've known about since forever, but I think in actual use you'd always have an even screen height.

    Sadly yes, especially since I don't have an Oculus Rift so I'm afraid I don't really know what the setup is for that.

    --Eric
     
  8. memetic-arts

    memetic-arts

    Joined:
    Feb 27, 2011
    Posts:
    82
    Hi Eric -

    I didn't see it in the docs, so maybe it's not possible, but thought I'd ask anyway. . . is there a built-in method for getting the lengths, in pixels, of discrete line segments? And if so, the ability to set their sizes? Of course, this could be calculated by getting the points and doing some math, but thought that if it's already integrated I could save some time.

    Thanks in advance . . .
     
  9. arkon

    arkon

    Joined:
    Jun 27, 2011
    Posts:
    1,097
    Hi Eric,

    I have a moving 3d object that has a vectorline attached to it. I've changed the vectorObject parent to the moving object transform. I use draw3d to draw the line and all is good. When I move the root object or rotate it the line also follows the parent transform, this is what I want. BUT I use the line to make another object follow the line using GetPoint3D01, The problem is the new object follows the path of where I initially created the line and not its new and changing position. How to I update the line to make GetPoint3D01 work?
     
  10. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,225
    That would just be Vector2.Distance, wouldn't it?

    Do you mean the ability to set the length of a line segment? I'm afraid not, though you could accomplish that pretty easily by creating a ray with one point and a direction, then using Ray.GetPoint for the second point.

    I'd generally recommend not using vectorObject in most cases, since it tends to mess up Vectrosity functionality. I would have suggested passing in the transform of the moving object when using Draw3D instead, except that the GetPoint functions don't currently take the passed-in transform into account. That will be fixed in the next version.

    --Eric
     
  11. memetic-arts

    memetic-arts

    Joined:
    Feb 27, 2011
    Posts:
    82
    D'OH!! I think I had Vectrosity Tunnel Vision, and forgot that there was this other package called Unity . . . thx.

    Yes, that's what I meant . . . just wanted to make sure I wasn't missing something like a "setSegmentLength" method.

    Thanks for the quick reply, always appreciated.

    I do have another question, though, also segment-related . . . I know that you can change line widths at the segment level, but it looks like you can only pass in an array of widths. In my case I'd be dealing with an array of 3600 segments, many of which wouldn't have their widths change . . . so a method that is constructed like SetColor, where you can specify the exact segment index and assign a value to it would be great to have for the width param as well . . . is that implemented and not documented or is it just not possible?

    thx again . . .
     
  12. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,225
    Not possible...yet....

    --Eric
     
  13. memetic-arts

    memetic-arts

    Joined:
    Feb 27, 2011
    Posts:
    82
    ah, ok, thx. well i'll take single-segment line-width settings over SVG import then . . . :)
     
  14. darrinm

    darrinm

    Joined:
    Apr 6, 2013
    Posts:
    5
    I'm having trouble drawing 3D lines of uniform thickness. I want them 3D so they're occluded by scene elements but don't want the line thickness to vary with distance. Ideas?

    Here's what I'm experiencing now, with line thickness of 1.0. I'd like a uniform thickness of 2 or 3.

    $lines.png
     
  15. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,225
    You'd probably need to subdivide the line into a few segments. In fact Vectrosity currently has no real functionality for "perspective" lines like that and is intended only for vector lines of uniform thickness, but in certain circumstances (such as a single line segment with one point in front of the camera and one point behind), it can happen anyway due to math limitations.

    --Eric
     
  16. zmeinaz

    zmeinaz

    Joined:
    Jul 3, 2012
    Posts:
    27
    Hey Eric,

    Do end caps work with Joins.Fill? I've tried it in my scenes and the DrawLinesTouch demo scene with no luck.
     
  17. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,225
    Not currently, but you're right, I don't think I've mentioned that anywhere. Joins.Weld does work though.

    --Eric
     
  18. darrinm

    darrinm

    Joined:
    Apr 6, 2013
    Posts:
    5
    Yep, that did the trick. Thanks for the ultra-rapid support Eric!
     
  19. scarpelius

    scarpelius

    Joined:
    Aug 19, 2007
    Posts:
    954
    Hi Eric, I have version 2.0. Where can I find updates?
     
  20. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,225
    If you bought from my site, you'd get update notices when a new version is released, if you turned on update notifications. If you need more help with that, send me a PM with the address you used when buying Vectrosity.

    --Eric
     
  21. scarpelius

    scarpelius

    Joined:
    Aug 19, 2007
    Posts:
    954
    Yes, I did buy it from your site. I've sent you a PM.
     
  22. tu-haq

    tu-haq

    Joined:
    Jul 6, 2012
    Posts:
    10
    I got a problem in ios .
    When i test in unity editor

    $Screen Shot 2013-08-07 at 8.59.08 AM.png

    but when i build on real ios device

    $ảnh.PNG

    my code :

    Code (csharp):
    1.  
    2. void Start () {
    3.         vLine = new VectorLine("linePathCharacter", new Vector3[]{this.transform.position, this.transform.position}, lineMat,20f, LineType.Continuous, Joins.None);
    4.         vLine.SetTextureScale(1f);
    5.     }
    6. void Update() {
    7.                 vLine.Resize(path);
    8.                 vLine.SetTextureScale(1f);
    9.             vLine.Draw3D();
    10. }
    11.  
     
    Last edited: Aug 7, 2013
  23. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,225
    Please use code tags in the future. First off, remove the Resize function; it's not really good for performance, especially if you do it every frame in Update. Use a maximum number of points instead, much like the DrawLinesMouse example. You can also remove the Draw3D function from Update, and use Draw3DAuto instead.

    As for the actual problem, the line/dot size is based on pixels, so you'll need to check the resolution/dpi and adjust the size accordingly.

    --Eric
     
  24. tu-haq

    tu-haq

    Joined:
    Jul 6, 2012
    Posts:
    10
    new my code

    Code (csharp):
    1.  
    2. // Use this for initialization
    3.     void Start () {
    4.         vLine = new VectorLine("linePathCharacter", new Vector3[2], lineMat,20f, LineType.Continuous, Joins.None);
    5.         vLine.points3[0] = new Vector3(-480f,0f,0f);
    6.         vLine.points3[1] = new Vector3(480f,0f,0f);
    7.         vLine.SetTextureScale(1f);
    8.         vLine.Draw3DAuto();
    9.     }
    10.  
    11. void Update()
    12. {
    13.                 vLine.SetTextureScale(1f);
    14.         vLine.Draw3D();
    15. }
    16.  
    On Unity Editor
    $Screen Shot 2013-08-07 at 10.17.59 AM.png

    When i build to ipod 5

    $ảnh (1).PNG

    I use camera orth with size 320 so world coordinate is device coordinate
     
    Last edited: Aug 7, 2013
  25. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,225
    Since you have Draw3DAuto, you can remove Draw3D from Update. I tried your code (with an orthographic camera size 320) on my iPod touch 5, and it results in this both in the editor and on the device.

    $IMG_0487.PNG

    You can disregard what I said earlier about changing the line size, since you're using an orthographic camera and Draw3D.

    --Eric
     
  26. tu-haq

    tu-haq

    Joined:
    Jul 6, 2012
    Posts:
    10
    Oh, can you send project for me email quangtu89@gmail.com . I will self add vectrosity library
     
  27. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,225
    All I did was make a new scene, set the camera to orthographic size 320, and attached your script (and dragged a material onto the slot).

    --Eric
     
  28. tu-haq

    tu-haq

    Joined:
    Jul 6, 2012
    Posts:
    10
    I found it . When i replace my material by your demo material, everything is OK . My Material use shader Particles/Alpha blended .

    After i got problem

    $Screen Shot 2013-08-07 at 2.18.57 PM.png $Screen Shot 2013-08-07 at 12.04.55 PM.png

    Can you help me ?
     
  29. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,225
    You can use Joins.Weld.

    --Eric
     
  30. tu-haq

    tu-haq

    Joined:
    Jul 6, 2012
    Posts:
    10
    This is result when edit Joins.None to Joins.Weld

    $Screen Shot 2013-08-07 at 2.51.17 PM.png
     
  31. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,225
    That's a limitation of UV mapping in general. You can solve that by adding more points in the line, so the texture isn't stretched out so far over a single quad.

    --Eric
     
  32. OhiraKyou

    OhiraKyou

    Joined:
    Mar 27, 2012
    Posts:
    248
    With Vectrosity, is it possible to achieve an effect in split screen (with many cameras) similar to the red wall lines in this screenshot from Tank Universal?
    http://www.zenplay.com/_images/_products/xl/tank-universal-level18_1.jpg

    If so, what level of overhead can I expect? I've seen your answer to a question at the link below and would like to know if this is a plausible solution (one without massive overhead)
    http://answers.unity3d.com/questions/366091/viewing-vectrosity-lines-from-multiple-cameras.html
     
    Last edited: Aug 11, 2013
  33. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,225
    You would have the overhead for SetCamera, which is trivial, and for drawing additional lines, which depends on how many lines there are.

    --Eric
     
  34. im

    im

    Joined:
    Jan 17, 2013
    Posts:
    1,393
    i just picked up Vectrosity and opened the TankZone demo tried to run it and got

    when i open PlayerMove.js and look at the code and check Edit->Project Settings->Input i see that non of the key mappings have been set on the project/scene and the demo does not use the standard key bindings!

    KeyRight
    KeyLeft
    RightStick
    LeftStick
    Fire

    i know i can go and define the keys mappings, but shouldn't the software ship working, including the demos!... so, please fix so that i can give you 5 stars.

    thanks in advance!

    just in case using latest unity3d release 4.2
     
    Last edited: Aug 12, 2013
  35. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,225
    See the appendix in the docs about setting up Tank Zone. Unfortunately there isn't a way to include that stuff in a Unitypackage that I know of, otherwise I would have.

    --Eric
     
  36. dstrawberrygrrl

    dstrawberrygrrl

    Joined:
    Aug 12, 2013
    Posts:
    2
    Is there a way to change the end cap colors when changing a line color? SetColor only seems to change the color of the line itself... I may be missing something obvious but all my end caps remain white. As a test, I extended one of the sample scripts to reproduce the issue - any assistance would be gratefully received!

    http://pastebin.com/kjCWxsQ6

    --Chris
     
  37. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,225
    I seem to have overlooked end cap colors entirely, sorry about that. Next version....

    --Eric
     
  38. dstrawberrygrrl

    dstrawberrygrrl

    Joined:
    Aug 12, 2013
    Posts:
    2
    No worries, thanks Eric! I'll look forward to the next edition :)
     
  39. imacoder

    imacoder

    Joined:
    Aug 13, 2013
    Posts:
    1
    Does Vectrosity support Windows 8 apps? If so, is there an example somewhere? If not, are there plans? :)

    Thanks!
     
  40. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,225
    I don't know myself, but maybe someone running Windows 8 can say. I don't use things like ArrayList or Hashtable though.

    --Eric
     
  41. lktfl

    lktfl

    Joined:
    Mar 3, 2013
    Posts:
    5
    Hi Eric,

    Sorry to add to the plethora of posts but there seems to be a problem with using the VectorCamera (Drawing any 2D line) and Graphics.DrawTexture() in unison.

    If you have a piece of code like this:
    Code (csharp):
    1.  
    2. function OnGUI () {
    3.    if (Event.current.type != EventType.Repaint){ //draws texture only in 3d space
    4.       if(texture != null){
    5.          rect.center = transform.position;
    6.          Graphics.DrawTexture(rect, texture, Rect(0,0,1,1), 0, 0, 0, 0, color, mat);
    7.       }
    8.    }
    9. }
    10.  
    while the scene also has an active VectorCamera, the Graphics.DrawTexture() will not draw the texture. I did some troubleshooting and found that if the GameObject that holds the VectorCamera or the camera component itself is disabled, then the DrawTexture function works. If the
    Code (csharp):
    1. if (Event.current.type != EventType.Repaint){
    part of the code is taken out so that the texture is also drawn in 2D space then it will show up in 2D space at 2D coordinates but still not in 3D space. So im assuming that the VectorCamera is messing with how the texture is being rendered.

    Is there a way to fix this or get around it? Or am i just being ignorant and missing something? :)

    Thanks
     
  42. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,225
    The idea of this topic is to post in it, so adding to the posts is fine. ;) At any rate, the docs say that Graphics.DrawTexture inside OnGUI code should only be done inside EventType.Repaint. I don't think it really works at all otherwise, so if you somehow got it to work anyway it was probably a fluke that shouldn't be relied on. I'm not sure what you mean by "3D space" since DrawTexture only draws textures using screen coordinates.

    --Eric
     
  43. lktfl

    lktfl

    Joined:
    Mar 3, 2013
    Posts:
    5
    Sorry, I made that unclear. If you call Graphics.DrawTexture in OnGUI() without any EventType.Repaint boolean it will draw:

    $Screenshot (12).png

    The big one being drawn correctly in what I was calling 3d space (should have called it world space coordinates without the z vector) and the small one being drawn in what I was calling 2d space (probably GUI coordinates). With an EventType.Repaint boolean it will draw one or the other. But I assume it was doing that because I called it in OnGUI() which is called multiple times a frame.


    But disregard that because I've rewritten the code to a tried and true:

    Code (csharp):
    1.  
    2. //is attached to main camera
    3.  
    4. function OnPostRender () {
    5.     if(Event.current.type.Equals(EventType.Repaint)){
    6.         if(gravityRadiusTexture != null){
    7.             rect.center = transform.position;
    8.             Graphics.DrawTexture(rect, gravityRadiusTexture, Rect(0,0,1,1), 0, 0, 0, 0, color, mat);
    9.         }
    10.     }
    11. }
    12.  
    and still the same thing happens. Nothing is drawn unless the VectorCamera is disabled or nonexistent.

    Even if I do something a little more exotic like:

    Code (csharp):
    1.  
    2. function Draw () {
    3.     while(true){
    4.         yield WaitForEndOfFrame();
    5.         if(Event.current.type.Equals(EventType.Repaint)){
    6.             if(gravityRadiusTexture != null){
    7.                 rect.center = transform.position;
    8.                 Graphics.DrawTexture(rect, gravityRadiusTexture, Rect(0,0,1,1), 0, 0, 0, 0, color, mat);
    9.             }
    10.         }
    11.     }
    12. }
    13.  
    so that it doesn't need to be attached to the main camera it still does the same thing.
     
  44. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,225
    EventType is only used in OnGUI. I'm not quite sure what your setup actually is, but I tried this (with the camera at the default 0, 1, -10) and it works fine:

    Code (csharp):
    1. var tex : Texture;
    2.  
    3. function Start () {
    4.     var ln = new VectorLine("Test", [Vector2(0, 0), Vector2(800, 400)], null, 2);
    5.     ln.Draw();
    6. }
    7.  
    8. function OnPostRender () {
    9.     Graphics.DrawTexture(Rect(0, 0, 5, 5), tex);
    10. }
    --Eric
     
  45. lktfl

    lktfl

    Joined:
    Mar 3, 2013
    Posts:
    5
    Ahhhh, know I see. I stupidly didn't attach the script I was using with the OnPostRender function to the camera. But that's the only time it works, if its called from OnPostRender and if its attached to the camera. If Graphics.DrawTexture is called in any script not attached to the camera it wont draw without the VectorCam disabled. And it wont work if its used in OnGUI at all let alone any other custom function which is where I need it.
     
  46. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,225
    Sounds to me like you might be trying to use undefined behavior; in normal usage Graphics.DrawTexture works the same (or not) regardless of the VectorCam. DrawTexture isn't super well-explained in the docs, but here's a page that might help. Depending on what you're actually trying to do, there may be better functions.

    --Eric
     
  47. tamberlain

    tamberlain

    Joined:
    Jun 16, 2013
    Posts:
    20
    Hi, I have a script that uses Vectrosity to draw a jetplane style HUD that indicates the pitch and roll via a series of lines just like this kind of real HUD: http://web.deu.edu.tr/atiksu/ana45/avi04.jpg Also see the moving lines in this video: http://www.youtube.com/watch?v=RjqrfChgijs

    My example script is here: https://dl.dropboxusercontent.com/u/11025048/horizon.cs

    I use a transform passed to the Draw3DAuto function when the horizon lines are drawn. The transform belongs to an object that follows the camera and stays aligned to its rotation, which works well to keep all the lines where they should be relative to the camera as it moves around.

    But I have a problem that as soon as the camera moves more than just 700 units from the origin, anything that is drawn that was passed object's transform starts to jitter very badly (as if I have flown past the maximum distance for comfortable floating point precision, but that should be more like 100,000 units away!).

    Anyone have any ideas what I'm doing wrong? Is there a better way to draw a "3d sphere" of horizon lines around the camera and kept in the correct rotation based on the camera position as it moves in space?

    Thanks!
     
    Last edited: Aug 19, 2013
  48. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,225
    I would guess there's some precision loss when transforming the matrix to screen space for the line-drawing part in Vectrosity. I'd be more inclined to use Draw rather than Draw3D, since you don't need the lines in the actual scene; I think that would help.

    --Eric
     
  49. tamberlain

    tamberlain

    Joined:
    Jun 16, 2013
    Posts:
    20
    Hmm yeah Draw does make it more stable, but I have to run a loop now on every update that goes through all the line objects and calls Draw on them again. Doesn't seem to be too expensive on CPU/framerate and I guess it's what Draw3DAuto was doing anyway by updating the lines automatically. thanks for the suggestion!
     
  50. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,225
    Yep. Also, Draw also has fewer calculations vs. Draw3D, so it's more efficient. I guess a DrawAuto function wouldn't hurt....

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