Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    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,401
    It already works with 3D lines.

    --Eric
     
  2. probbins

    probbins

    Joined:
    Oct 19, 2010
    Posts:
    216
    Firstly thanks for the fast response!

    This fixed it!

    I believe the issue is occuring when I use the following code. My guess is that after resizing the spline, the cap info is still using the previous length?
    Code (csharp):
    1. path.Resize(segments + 1);


    Thanks for the advice! In regards to the issue though, I wont bother you about it. I am fairly sure is just because I am using a spline, an removing points as I pass them (due to path finding recalculating path each time I get to the next tile). The solution will be to adjust the way I am updating the spline.

    Awesome! For now I am just going to draw a sprite manually at the last point.
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Aha, good catch. The fix is to put this at the very end of the RebuildMesh function (I could have sworn I had already done this, but anyway):

    Code (csharp):
    1.         if (m_capType != EndCap.None) {
    2.             AddEndCap();
    3.         }
    --Eric
     
  4. probbins

    probbins

    Joined:
    Oct 19, 2010
    Posts:
    216
    Thanks Eric!
     
  5. Mistale

    Mistale

    Joined:
    Apr 18, 2012
    Posts:
    173
    Hi Eric, and thank's for a wonderful product, I will use this for a lot of stuff I didn't even knew I needed!
    I have one quick question though:

    Is it possible to eliminate z-fighting if I use Draw3D together with the gameobjects meshrenderer?
    I want to add highlights to certain faces of a mesh (as in your Simple3DObject demo), but some of the effect goes away since the lines will flash due to z-fighting.

    Is it possible to write a shader that cheats by shifting the vertices towards the camera a very small distance in screen-space, or is there perhaps already some clever functionality to alleviate this problem in Vectrosity?

    Best regards,

    Anders
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can use Offset in a shader for that, such as "Offset -1, -1", which is typically used to eliminate z-fighting with concurrent surfaces.

    --Eric
     
  7. Mistale

    Mistale

    Joined:
    Apr 18, 2012
    Posts:
    173
    Thanks for the speedy reply! An offset by -1, -150 seems to do the trick for me. I found the explanation in the docs for Offset a bit unclear, so I'm not sure why I need -150 units to get it working, or if it would be smarter to modify the factor more and units less.

    Do you perhaps know if Offset can be trusted to give the same results across different platforms and for both DirectX and OpenGL?

    Best regards,

    Anders
     
  8. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I can't say I've seen it mentioned anywhere that Offset would behave differently on different platforms.

    --Eric
     
  9. Jtbentley_v2

    Jtbentley_v2

    Joined:
    Sep 5, 2012
    Posts:
    174
    Nice. It's one of those tools your team should just have sitting around because at some point or another, we've all had to make lines and raged about it.
     
  10. arkon

    arkon

    Joined:
    Jun 27, 2011
    Posts:
    1,122
    I have a very strange line problem.

    If I set the unity editor to 1024x768 then draw a 3d spline it all looks great. If I change the unity editor to 960x640 then the spline is drawn at the place it was on 1024x768 not the new scaled position. It also goes wrong in the other direction too, if I start off the with 960x640 it looks fine, change editor to 1024 and vectrosity seems to remember the old camera from the last time it run.
     
    Last edited: May 20, 2013
  11. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    See the entry in the FAQ (in the docs) about changing screen resolutions.

    --Eric
     
  12. arkon

    arkon

    Joined:
    Jun 27, 2011
    Posts:
    1,122
    Sorry I can't find an FAQ or any mention of it in the documentation that comes with the plugin, where exactly is it?
    I think I didn't describe the problem properly, its nothing to do with me changing resolution, but something to do with what Unity does on start up.

    In Start() I create the spline and it doesn't create it correctly based on the current resolution of the screen but seems to base it on some arbitrary res that may have been what the editor was set to last time unity was run, If I remove the line drawing code from Start and put it on a key press in update it works correctly every time. For some reason on Start() Vectrosity isn't using the screen res properly.
     
    Last edited: May 20, 2013
  13. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Page 46.

    What version of Unity are you using?

    --Eric
     
  14. arkon

    arkon

    Joined:
    Jun 27, 2011
    Posts:
    1,122
  15. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    There was an issue with an earlier version where the screen width/height wouldn't be reported correctly for the first couple of frames, but as far as I know 3.5.7 works right. You could try yielding a frame or two anyway.

    --Eric
     
  16. arkon

    arkon

    Joined:
    Jun 27, 2011
    Posts:
    1,122
    This is what I've had to do. It seems to take 2 to 3 frame updates for Screen.width etc to be correct. If you never change the editor window resolution it's fine but I actually discovered the problem on the IOS device itself! So basically I have to create the splines after a small delay.
     
  17. Yasser-Jaffal

    Yasser-Jaffal

    Joined:
    May 23, 2013
    Posts:
    8
    Hi,
    I am having a problem with bytes file generated using LineMaker. I imported a model from Blender, selected lines I wish to render, and then saved bytes file.
    At run time, however, lines are not rendered on their correct place. It looks like transforms are not applied. Lines are rendered with the wrong position and rotation, even I am using VectorLine.Draw3D(transform);
     
  18. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Did you try Draw3D(), without passing in the transform?

    --Eric
     
  19. Yasser-Jaffal

    Yasser-Jaffal

    Joined:
    May 23, 2013
    Posts:
    8
    Yes, it just draws all shapes of all instances at the center of the scene
     
  20. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Try applying the transforms in Blender before exporting.

    --Eric
     
  21. rsodre

    rsodre

    Joined:
    May 9, 2012
    Posts:
    229
    Hey Eric,

    I have Vectrosity and use it a lot, but on this project I need ultra optimisation, so I'm making my own mesh and submeshes to reuse vertices, and draw lines, points and triangles of the same model.
    But I'm having problem rendering MeshTopology.Points, and as you already made it work, can you give me some tips?

    First, points are not rendering on iOS, they look like big glitch sprites. They render ok on a mac, but
    Is there any trick?

    And have you ever tried rendering larger points with CGPROGRAM shaders and PSIZE?
    They are always 1 pixel size, no matter how large I set them.

    Thanks,
    Roger
     
  22. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    MeshTopology.Points can only be 1 pixel. How they render depends on drivers and so on, so there's really no control over whether they work or not. That's why using any of the MeshTopology options is false by default in the latest version of Vectrosity, since triangles always work everywhere.

    --Eric
     
  23. rsodre

    rsodre

    Joined:
    May 9, 2012
    Posts:
    229
    But is there any trick to render MeshTopology.Points on iOS?
    I got my points all messed up, even with the most basic shader.
     
  24. GXMark

    GXMark

    Joined:
    Oct 13, 2012
    Posts:
    501
    Just purchased the product and it wont compile complain of following

    Assets/Standard Assets/MultiDim.cs(3,14): error CS0101: The namespace `global::' already contains a definition for `MultiDim'

    Can someone please tell me why this is happening?
     
    kadirfu likes this.
  25. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    @rsodre: there are no tricks I know of...either it would work or not.

    @GXMark: you should remove duplicate scripts.

    --Eric
     
  26. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,683
    Hi Eric,
    I am researching how to draw the arc of a tangent but am coming up short. Does Vectrosity support or have a simple way to calculate an arc, given two points, considering gravity?
     
  27. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It has Bezier curves and splines, but if you need something specifically with gravity you'd have to come up with something for that.

    --Eric
     
  28. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,683
    Ok, perhaps you can help, but if not, ok.

    Simply helping a friend see about creating a gun system like peggle. It, aims a gun down, top down, 2D. Input causes or creates a projection, the arc the projectile will take when input at xy pos. so we know the rise and run of the triangle. I am unsure if a simple calculation of the arctangent will do or if gravity will warp this arc. Lets say it doesn't.

    If we can remove gravity from the equation, then by knowing two point and calculating its tangents arc, can you see an easy method Vectrosity uses to create this arc?
     
  29. Hjeldnes

    Hjeldnes

    Joined:
    Jul 22, 2012
    Posts:
    116
    $ScreenGrab01.png Hey,
    Great plugin! I just bumped into some issues regarding using vectrocity when I want to draw lines both in the game view and the ui. I use it for drawing trails and laser effects in the main game view (works great), and I would like to use it to draw lines between avialable levels on my map view.
    This map is drawn by a separate camera, rotated differently than the main camera.
    Currently the ui camera overwrites the lines. It normally should do this, except when i draw the lines on the map.

    The trails in the game view are 3dlines, and the ones in the map are 2d.

    Do you have a suggestion how this can be setup?

    Any input appreciated! :)

    Kjetil
     
    Last edited: May 26, 2013
  30. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    @renman3000: you'd have to do your own calculations for that.

    You could use the camera depth to make the vector camera appear on top of the UI camera (SetCamera() returns the vector camera). The lines in the game view are presumably drawn with Draw3D() and wouldn't use the vector camera, so they wouldn't be affected.

    --Eric
     
  31. Hjeldnes

    Hjeldnes

    Joined:
    Jul 22, 2012
    Posts:
    116
    Eric, thanks for the nudge in the right direction. I see now the vector cam is used for the 2d stuff, I aligned it to the ui camera(for easy line drawing), set correct depth, and it seems to be working fine. Thanks.
     
  32. h16

    h16

    Joined:
    May 27, 2013
    Posts:
    1
    Hi Everyone,

    We recently brought vectrosity plot software for unity. I am very grateful to Eric for releasing such a product.

    Basically we use vectrosity to generate plot image from which texture2d image is generated by using rendertexture. This texture2d is used by unity GUILayout.Label call to display it on the screen.

    We were successful in doing the above. But texture2d image has opaque background and we need transparent background with just the plot line shown.

    We use the following api to set the render texture.

    VectorLine.SetCameraRenderTexture( fdRenderTex,Color.gray);

    With above we get gray opaque background. But when we use Color.clear instead of Color.gray we see nothing on the texture.

    Kindly help in solving this issue, as we in shortage of time and need your kind help.
     
  33. gauthi24

    gauthi24

    Joined:
    Feb 4, 2012
    Posts:
    34
    What a great product! I'm having fun with this.

    One question that is likely very easy to answer...

    I'm creating my VectorLines and adding them in a List<> as they get created. At a certain point in the program all the lines need to be destroyed and naturally would want to use a for-loop for this, but VectorLine.Destroy does not like to use an indexer as a 'ref' parameter.

    I was writing it like this.

    Code (csharp):
    1.  
    2. void destroyArrows(){
    3.       for(int i = 0; i < arrowList.Count; i++){
    4.              VectorLine.Destroy(ref arrowList[i]);
    5.       }
    6. }
    7.  
    Is there a way to do this?

    Thanks!
     
  34. gauthi24

    gauthi24

    Joined:
    Feb 4, 2012
    Posts:
    34
    There sure is!!


    Code (csharp):
    1.  
    2. void destroyArrows(){
    3.       for(int i = 0; i < arrowList.Count; i++){
    4.              VectorLine lineToDestroy = arrowList[i];
    5.              VectorLine.Destroy(ref lineToDestroy);
    6.       }
    7. }
    8.  
     
  35. amunds

    amunds

    Joined:
    Mar 15, 2013
    Posts:
    2
    Bought Vectrosity not long ago and loving it so far, got so many use cases for it and whenever I tried to do the same in Unity it was a lot of head against brick wall to achieve something that looked half as good. That said, I got a question: Is it possible to have multiple methods per vectorLine and linePoints?

    I'm drawing the projectory paths for planets in solar systems and it's a bit tedious to write so many duplicate lines.
    Example:

    Code (csharp):
    1.  
    2. Vector3[] linePoints1 = new Vector3[90];
    3. Vector3[] linePoints2 = new Vector3[90];
    4. Vector3[] linePoints3 = new Vector3[90];
    5.  
    6. VectorLine orbitTrajectory1 = new VectorLine("orbitTrajectory1", linePoints1, Color.white, null, 2, LineType.Continuous);
    7. VectorLine orbitTrajectory2 = new VectorLine("orbitTrajectory2", linePoints2, Color.white, null, 2, LineType.Continuous);
    8. VectorLine orbitTrajectory3 = new VectorLine("orbitTrajectory3", linePoints3, Color.white, null, 2, LineType.Continuous);
    9.  
    10. orbitTrajectory1.MakeCircle(new Vector3(0, 0, 0), 200);
    11. orbitTrajectory2.MakeCircle(new Vector3(0, 0, 0), 400);
    12. orbitTrajectory3.MakeCircle(new Vector3(0, 0, 0), 600);
    13.  
    14. orbitTrajectory1.Draw3DAuto();
    15. orbitTrajectory2.Draw3DAuto();
    16. orbitTrajectory3.Draw3DAuto();
    There must be a better way, right? For this simple example I could just loop it, but I will have more specific needs later on.
     
  36. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    If you're talking about having multiple paths drawn in a single VectorLine, yes, you can use a discrete line and specify the index in the points array for MakeCircle to draw into (which also means specifying the number of segments and the point rotation):

    Code (csharp):
    1. Vector3[] linePoints = new Vector3[90 * 3];
    2.  
    3. VectorLine orbitTrajectories = new VectorLine("OrbitTrajectories", linePoints, Color.white, null, 2);
    4.  
    5. orbitTrajectories.MakeCircle(new Vector3(0, 0, 0), 200, 45, 0, 0);
    6. orbitTrajectories.MakeCircle(new Vector3(0, 0, 0), 400, 45, 0, 90);
    7. orbitTrajectories.MakeCircle(new Vector3(0, 0, 0), 600, 45, 0, 90 * 2);
    8.  
    9. orbitTrajectories.Draw3DAuto();
    --Eric
     
  37. amunds

    amunds

    Joined:
    Mar 15, 2013
    Posts:
    2
    That's excellent, exactly what I meant. Thanks again for this wonderful software and the outstanding support you provide.
     
  38. charcreon

    charcreon

    Joined:
    May 14, 2013
    Posts:
    5
    It is going to display the frame of NGUI(UISprite). A position shifts. Coordinate conversion is not known...:(

    UI Root(2D) > Camera > Anchor > UISprite script(void Start())
    float x = transform.localPosition.x - Screen.width / 2;
    float y = transform.localPosition.y - Screen.height / 2;
    float cx = transform.localScale.x;
    float cy = transform.localScale.y;

    VectorLine boxframe = new VectorLine("boxframe", new Vector2[] { new Vector2(x,y),new Vector2(x+cx,y),new Vector2(x+cx,y+cy),new Vector2(x,y+cy),new Vector2(x,y),}, Color.green, null, 2.0f, LineType.Continuous, Joins.Fill);
    boxframe.Draw();
     
  39. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I'm not quite sure what you mean, sorry.

    --Eric
     
  40. celaeno

    celaeno

    Joined:
    Jan 31, 2013
    Posts:
    64
    Hello, I'm making a path drawing game and experiencing some lag with the input touches. Don't know if this is the right place for asking, but I use vectrosity and you helped me before very well when I had some problem understanding vectrosity.But I don't think this problem has to do with vectrosity because in this experiment the line is drawn afterwards when the touches have ended.

    Sometimes you get a big gap between the points, when you swipe quickly a circle. I couldn't find the reason for this, so I tested it on the normal android SDK and experienced a more fluently touch input. Do you know if this a Unity3D related problem, or maybe am I doing someting wrong? Below you can see the touch input code. I hope you know a solution for this :)

    The first screenshot is from Unity, the second is from Android:

    $screenshot unity.jpg $screenshot android.jpg



    Code (csharp):
    1.  
    2. function Update ()
    3. {
    4.     if(Input.touchCount == 1)
    5.     {
    6.          // touch on screen
    7.          if(Input.GetTouch(0).phase == TouchPhase.Began)
    8.          {
    9.             pos = Input.GetTouch(0).position;      
    10.             ray = Camera.main.ScreenPointToRay(pos);
    11.            
    12.              if (Physics.Raycast (ray, hit, 50) )
    13.                     hit.transform.gameObject.SendMessage("TouchBegan");
    14.          }
    15.          
    16.          
    17.          if(Input.GetTouch(0).phase == TouchPhase.Moved)
    18.          {
    19.            
    20.              pos = Input.GetTouch(0).position;     
    21.             // pos = Camera.main.ScreenToWorldPoint(pos);
    22.            hit.transform.gameObject.SendMessage("TouchMoved",pos);
    23.                    
    24.  
    25.          }
    26.  
    27.  
    28.  
    29.         if (Input.GetTouch(0).phase == TouchPhase.Ended || Input.GetTouch(0).phase == TouchPhase.Canceled)
    30.         {
    31.        
    32.             hit.transform.gameObject.SendMessage("TouchEnded");
    33.        
    34.         }
    35.     }
    36.  
    37. }
    38.  
     
    Last edited: May 30, 2013
  41. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It's not a Vectrosity issue, so it would be better off posted elsewhere (this thread has enough posts as it is ;) ). Also, please use code tags when posting code.

    --Eric
     
  42. celaeno

    celaeno

    Joined:
    Jan 31, 2013
    Posts:
    64
    Ok, I posted it in the scripts section, they asked if I used Unity remote, but I didn't. Don't know if the'll get back to me, otherwise I post it again. This was tested on a device and could be a performance issue, touch input should be fluent.
     
  43. dwegner

    dwegner

    Joined:
    Jun 1, 2013
    Posts:
    7
    I was looking at the DrawLines example, I would like to have the same behavior for touch screen (drawing with finger). I tried changing the mouse inputs to touch but i am getting strange behavior. not sure if i am missing something.
     
  44. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    There's already an example script for touch input; see the DrawLinesTouch script.

    --Eric
     
  45. dwegner

    dwegner

    Joined:
    Jun 1, 2013
    Posts:
    7
    Thanks Eric, I saw the DrawLinesTouch but it works like a fre drawing, I am looking for something like the DrawLines where you start the line and can rotate the line before the end point is created
     
  46. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can post your code, although you might get a better response with a new topic about that since it's not really Vectrosity-specific (my demo scripts just use standard Unity input functionality).

    --Eric
     
  47. zmeinaz

    zmeinaz

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

    I am wondering if there is a way to get lines that look like chalk with vectrosity. I've tried a few textures but they weren't very convincing. Any ideas?
     
  48. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Aside from the texture and shader, you'd probably want to use SetTextureScale, as well as front and back line caps.

    --Eric
     
  49. dwegner

    dwegner

    Joined:
    Jun 1, 2013
    Posts:
    7
    Hi Eric,

    Is there an easy way to detect two lines crossing each other?
     
  50. moopi

    moopi

    Joined:
    Apr 24, 2012
    Posts:
    39
    Hi Eric,

    Is there a way to get lines visible in the editor mode? This would be very handy, as I'm planning to use Vectrosity to draw lines, boxes and other elements on my in game menus (menus are implemented as 2d planes in 3d space, no Unity GUI elements involved) -> I would be able to see the final result during edit phase.

    I tried with a simple script including "@script ExecuteInEditMode()" command. This actually showed the line in the editor after one play (created an Vector SetLine3D object). However, each time when I play the game, new version of Vector SetLine3D object is created. This will result a huge set of unnecessary lines in my scene.I check in awake and start functions if the private VectorLine variable is null before calling the VectorLine.SetLine3D to create a new line.

    Somehow, it seems that I have to either avoid creation of new VectorLine object if one already exists or destroy the existing one when returning from Play state.

    Br,
    - Moopi
     
Thread Status:
Not open for further replies.