Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    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. Clockworkservant

    Clockworkservant

    Joined:
    Nov 15, 2010
    Posts:
    7
    Yeah, bummer. I can watch the points while the game is running and there's no movement. Hmm.

    I guess my issue is that in my final setup, the two middle points of the line will almost always be in motion, so they pretty well need to be updated continuously.
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    There kind of has to be, if the texture is changing. Probably the perspective changes involved in moving the camera changes the screen space length of the lines. (Since the texture scale calculations are based on screen space.)

    --Eric
     
  3. Clockworkservant

    Clockworkservant

    Joined:
    Nov 15, 2010
    Posts:
    7
    Yes, okay I see what you mean. If you're calculating it based on screen space (and I guess I read that at some point) then it makes sense. I guess it's not exactly made for a situation with this much ambient camera motion :)
     
  4. mohamed20

    mohamed20

    Joined:
    Mar 25, 2012
    Posts:
    5
    Hello, I like drawing free surfaces using the mouse and when I finish I clik on the surface entry will display help me and give me the correct code
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Sorry, I couldn't understand that at all.

    --Eric
     
  6. mohamed20

    mohamed20

    Joined:
    Mar 25, 2012
    Posts:
    5
    I have to draw a free surface in 3D of course unity with the mouse and when I finish I CLIKE grafted on the surface appears
     
  7. wbl1

    wbl1

    Joined:
    Apr 22, 2009
    Posts:
    159
    Eric

    I have an odd problem that I need some help with.

    1) In the first attachment (3dLinesGood.jpg) you will see some lines connecting some spheres. These lines were created with vectrocity in 3d and they look fine as you can see.

    2) In the second attachment (3dLinesBad.jpg) you will see a graph created with 2d vectrocity lines with the 3d image "behind" it. As you can see, the 3d lines go haywire.

    Do you have any idea what is going on here? Once the graph (2d lines) is displayed, the 3d lines dont work. If I never display the graph the 3d lines look fine. This is quite repeatable.

    Thanks
     

    Attached Files:

  8. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Can you get someone who knows some English to help you write your question, because I'm afraid I just don't understand what you're trying to say.

    That is weird. I did a quick test here where I draw a 3D line then wait a bit and draw a 2D line, and there aren't any issues like that. Can you send me the project?

    --Eric
     
  9. wbl1

    wbl1

    Joined:
    Apr 22, 2009
    Posts:
    159
    Eric,

    Regarding the 3d lines problem, can you try your quick test the other way around? Draw the 2d lines, then 3d. If this does not repeat the problem, I'll see about sending you a contained project.

    Thanks!
     
  10. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Still works fine the other way around.

    --Eric
     
  11. wbl1

    wbl1

    Joined:
    Apr 22, 2009
    Posts:
    159
    Eric

    I sent a condensed project to your Starscenes email account. Thanks

    Tom
     
  12. badawe

    badawe

    Joined:
    Jan 17, 2011
    Posts:
    297
    Hello there!

    I'm trying to do one simple thing!

    Exactly like Flight Control, but with some distance travel limmiter, you can only draw like a 1000 pixes.

    But the problem start with this, I'm using the DrawLinesTouch example, but porting to C#, here is what i get:


    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5.  
    6. public class GameplayManager : MonoBehaviour
    7. {
    8.    
    9.     public Airplane         airMain;
    10.     public Material         matLine;
    11.    
    12.     private float           fLineWidth = 3f;
    13.    
    14.     private float           fMaxDist = 1000;
    15.    
    16.     private Vector3         v2PrevMouse;
    17.     private Vector2[]       arrLinePoints;
    18.     private VectorLine      linePath;
    19.     private int             iLineIndex;
    20.     private float           fDistCount = 0;
    21.     private int             sqrMinPixelMove = 5*5;
    22.     private bool            bPress;
    23.    
    24.  
    25.     // Use this for initialization
    26.     void Start ()
    27.     {
    28.        
    29.         arrLinePoints = new Vector2[1000];
    30.         linePath = new VectorLine("DrawnLine", arrLinePoints, matLine, fLineWidth, LineType.Discrete);
    31.    
    32.     }
    33.    
    34.    
    35.    
    36.     private void StartDrawMouse()
    37.     {
    38.         Vector.ZeroPointsInLine(linePath);
    39.         linePath.minDrawIndex   = 0;
    40.         linePath.maxDrawIndex   = 1;
    41.         iLineIndex              = 0;
    42.         fDistCount              = 0;
    43.        
    44.         arrLinePoints[0]        = Input.mousePosition;
    45.        
    46.        
    47.         bPress                  = true;
    48.     }
    49.     private void StopDrawMouse()
    50.     {
    51.         bPress = false;
    52.     }
    53.    
    54.     private void Record()
    55.     {
    56.         if(fDistCount < fMaxDist)
    57.         {
    58.             if(Vector3.Distance(Input.mousePosition, v2PrevMouse) > 10f)
    59.             {
    60.  
    61.                 fDistCount                  += Vector3.Distance(Input.mousePosition, v2PrevMouse);
    62.                 arrLinePoints[iLineIndex]   = Input.mousePosition;
    63.                
    64.                 linePath.minDrawIndex       = iLineIndex-1;
    65.                 linePath.maxDrawIndex       = iLineIndex;
    66.                
    67.                
    68.                
    69.                
    70.                 iLineIndex++;
    71.                 v2PrevMouse                 = Input.mousePosition;
    72.             }
    73.         }
    74.         else
    75.         {
    76.             StopDrawMouse();
    77.         }
    78.     }
    79.    
    80.     // Update is called once per frame
    81.     void Update ()
    82.     {
    83.         Vector.DrawLine(linePath);
    84.         if(bPress)
    85.             Record();
    86.        
    87.        
    88.         if(Input.GetMouseButtonDown(0))
    89.         {
    90.             if(airMain.myStatus == Airplane.Status.AVALIABLE)
    91.             {
    92.                 StartDrawMouse();
    93.             }
    94.         }
    95.         else if(Input.GetMouseButtonUp(0))
    96.         {
    97.             StopDrawMouse();
    98.         }
    99.    
    100.     }
    101. }
    102.  
    103.  
    But every new click i get some strange point from 0,0! Look at this video:



    Someone can help me?
     
  13. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Since you're using a discrete line, you should wait until there are at least two points before drawing anything. Otherwise it's connecting the first point with Vector2.zero.

    --Eric
     
  14. badawe

    badawe

    Joined:
    Jan 17, 2011
    Posts:
    297
    Hum..

    Looks so simple now you tell me! hahaha just to the record:

    Just this save the work:
    Code (csharp):
    1.  
    2. if(iLineIndex > 1)
    3.             Vector.DrawLine(linePath);
    4.  
     
    Last edited: Apr 3, 2012
  15. Murcho

    Murcho

    Joined:
    Mar 2, 2009
    Posts:
    309
    I've got an issue where I'm drawing two separate lines, but using instances of the same material, and are having Vector.SetTextureScale(line, 1f); called. This call is causing the first line to lose it's texture scale information and become stretched again.

    Would you have any immediate ideas on why this might be happening?
     
  16. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Are you changing the material scaling yourself somewhere? SetTextureScale only changes the UVs of the line that's passed into that function, it doesn't actually touch the material or texture at all.

    --Eric
     
  17. Pinkesh

    Pinkesh

    Joined:
    Apr 3, 2012
    Posts:
    6
    Hey hi Eric,

    Can i attach this 3D line as term of vector to my car body . The dimension and direction of this line should change as my car is moving in particular direction. Is that possible ?.
    I have physics formulas and i want to attach lines to the center of gravity of the car. Those lines are velocity and acceleration components.

    Please let me know.

    Thank You
    Pinkesh
     
  18. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    That's related to this topic, I see. Vectrosity doesn't currently have support for arrows at the ends of lines like that, so I don't think it would quite work for your particular case.

    --Eric
     
  19. holyjewsus

    holyjewsus

    Joined:
    Mar 7, 2011
    Posts:
    624
    Hello again, Eric, I've got question about adding colliders to vector lines. I'm attempting to build an erase tool by finding all vector objects in range of my cursor using a sphere collider on the cursor and then iterating the line arrays of all hit vector lines but I'm not sure how to add colliders to the lines. Can I do this at runtime? Should I add box colliders or mesh colliders? To the vector line or vector object?
     
  20. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I'm not sure adding colliders would be the best way. I'd suggesting iterating through all the points and checking the distance. (Using the (a-b).sqrMagnitude technique would be a little faster than Distance, which is the same as (a-b).magnitude and uses a square root.) Unless you have a really huge number of points, the performance should be OK. If not, there are other techniques for optimization that would be better than adding tons of colliders.

    --Eric
     
  21. holyjewsus

    holyjewsus

    Joined:
    Mar 7, 2011
    Posts:
    624
    really?

    I was thinking of using them as triggers adding them to a list then iterating through those in the list...

    I'm working on a drawing application so there could be lots of points, but I can't really know until I get some user tests done. Any clue on other optimization techniques?
     
  22. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Well, use whatever works for you. :) Can't hurt to give it a try and see what happens.

    --Eric
     
  23. holyjewsus

    holyjewsus

    Joined:
    Mar 7, 2011
    Posts:
    624
    I'm not sure why I can't figure this out, but how do get a reference from a game object to the vector line?
     
  24. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    VectorLine.vectorObject is a reference to the game object used for the line, or do you mean something else?

    --Eric
     
  25. holyjewsus

    holyjewsus

    Joined:
    Mar 7, 2011
    Posts:
    624
    I am returning a list of all game objects that have Vector in their name, I then want to get all the vector lines from these game objects so I can return the point arrays, but I'm not sure it's possible.

    This would be instead of keeping track of all vector lines at the time of their creation.
     
  26. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Oh, yeah, I don't think that's possible. The VectorLine has a reference to the game object, but not the other way around.

    --Eric
     
  27. 39thstreet

    39thstreet

    Joined:
    Jan 30, 2012
    Posts:
    104
    Hello all, just getting a handle of Vectrosity, and I'm trying to solve a little issue.

    I've been playing with various shaders to try and solve this.

    The image on the left is from Vectrosity "in game". It's a slightly modified version of the demo "GlowBig" texture with the Particles/Additive (Soft) shader (again, same one from the demo).

    The image to the right is more or less what I'm going for.


    I don't care about being exactly right, but my question is, is there any way to get rid of the places where the texture is overlapping itself and generating hard angle bright spots?

    To provide some more context, this is a line that will be following a player's finger, so "sharp turns" are possible. I was able to make the issue a little better by making sure the points were never closer than 10 or so, but it's still happening.

    I'm aware there might not be a solution here, but I'd appreciate any advice (maybe something with a shader? although this is destined for iOS and Android).

    EDIT: I tried the various settings for Joins as well, Weld seems to work the best, but it still happens.

    Thanks in advance!
     
    Last edited: Apr 9, 2012
  28. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can use Joins.Weld for that, although it doesn't work well with extreme angles, so you would probably need to smooth out sharp turns somewhat.

    --Eric
     
  29. 39thstreet

    39thstreet

    Joined:
    Jan 30, 2012
    Posts:
    104
    Ah, I see. So maybe manually check and if the turn is too sharp add some points to smooth it out? I guess that makes sense.
     
  30. holyjewsus

    holyjewsus

    Joined:
    Mar 7, 2011
    Posts:
    624


    hey again,

    so I've got a basic eraser going using just distance checking as you suggested, any idea whats going on here as these strange lines get left behind?
     
  31. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Are you using a continuous line? You'd have to use a discrete line for that.

    --Eric
     
  32. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,239
    Hi Eric,

    I'm getting quite interested in Vectrosity (which looks awesome, by the way). I would like to take a look at the documentation and API reference before buying, but couldn't find it anywhere on your site. Could you post a link to it?
     
  33. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I don't have a link to it; I'd rather not maintain it on my site. Send me a PM with your email address and I'll send it to you though.

    --Eric
     
  34. holyjewsus

    holyjewsus

    Joined:
    Mar 7, 2011
    Posts:
    624
    I changed my line type to discrete, and it appears to work better, but I still get strange line segments left, should I only be removing two points at a minimum?

    just to note seems that all these extra lines are pointing from where I'm erasing to vector.zero
     
    Last edited: Apr 11, 2012
  35. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Sounds like you should be erasing in pairs. For example, if you have points [1, 2, 3, 4], and you "erase" point 4 (set it to Vector2.zero), then it will draw points 1-2, and 3-4, except point 4 is zero, so it's drawing from wherever point 3 is to zero. So you should erase both 3 and 4. Which is also why it should be a discrete line...with a continuous line, if you have [1, 2, 3, 4] and set points 2 and 3 to 0, then it would draw from point 1 to zero, and then zero to point 4.

    --Eric
     
  36. holyjewsus

    holyjewsus

    Joined:
    Mar 7, 2011
    Posts:
    624
    Hey, if anyone else is looking to build an eraser like this, I got it working pretty well. A summary of my method:

    Take all drawn lines, after they're created store them in a list of vector lines

    When the eraser is activated, search through all vector lines in the array, then iterate all points in the point arrays.

    If the distance between the point and the mouse is less than some value then

    check if the item index in the array is odd, if it is odd then set it to vector.zero.
    then set the index - 1 to vector.zero.
     
  37. holyjewsus

    holyjewsus

    Joined:
    Mar 7, 2011
    Posts:
    624
    Hey Eric, so if I wanted to used discrete lines for all the lines that can be drawn by the user, would I actually want to put two points at each point in the line so that it appears continuous?
     
  38. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yep.

    --Eric
     
  39. holyjewsus

    holyjewsus

    Joined:
    Mar 7, 2011
    Posts:
    624
    hi again,

    I wanted to say I'm blown away by your level of support in responding to every single one of my posts... thanks so much.

    I wanted to pick your brain on those optimizations methods you mentioned before as I did some user testing of my app today, and every tester encountered an issue with the eraser slowing down to a crawl and going below 1fps after drawing for some time.

    I'm pretty sure it has to do with the point arrays being created as 500 vector 3s and then filled in as needed, leaving a giant amount of vector3.zero points that are being iterated through. 100 lines becomes 50,000 points to iterate through.

    Is there an easy way to chop off this extra part of the line after it's created?
     
  40. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Perhaps some variables that keep track of the maximum point in array, and stop checking after that point. So if you have an array of 500 points, and only the first 100 have any real data, then it would stop checking after point 100.

    --Eric
     
  41. pudd1nG

    pudd1nG

    Joined:
    Feb 21, 2012
    Posts:
    36
    Hey Eric, in love with Vectrocity once again.

    I have a rigidbody that is moving and has forces applied against it for movement but also when it gets close to other objects. I'm trying to draw a prediction curve to show the path the object would take at its current trajectory. If it weren't being acted on by other forces too this would be easier but I'm not sure how to predict how these other objects will act on it.

    Maybe not so much of a vectrocity question as me looking for a suggestion to predict this.

    Thanks for any insight.
     
  42. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    As it happens I did a routine for someone where it drew a slingshot prediction line, and the only thing I could figure was to calculate the physics on my own. Fortunately physics are pretty much physics, so my code matched up with the built-in physics. However that was just a plain trajectory (with gravity) for one object, so adding more objects would naturally complicate things.

    --Eric
     
  43. AmyJeng

    AmyJeng

    Joined:
    Apr 15, 2012
    Posts:
    1
    Hi, I'm totally new to Unity and Vectrosity. Can you help me solve some problem?
    I want to make a dashed line in my project. But it didn't work even if I paste the "Selection box example" code in Vectrosity webside. It is just a "solid line" selection box. I think the code :
    Vector.SetTextureScale (selectionLine, textureScale, -Time.time*2.0 % 1);
    make it become dashed, right? It work in the website, but doesn't work in my unity project. Why??:(

    By the way, is there a formal and complete Vectrosity document or tutorial? I really need it.
     
  44. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes, Vectrosity comes with complete documentation. It explains how to do dashed lines.

    --Eric
     
  45. holyjewsus

    holyjewsus

    Joined:
    Mar 7, 2011
    Posts:
    624
    Having a similar issue, is there something that could be done at runtime to smooth the welds?
     
  46. Overunity3d

    Overunity3d

    Joined:
    Sep 5, 2010
    Posts:
    14
    I bought Vectrosity. Am trying to apk tankzone to my HTC android. Thought this would be a good setup to do.
    The build process gives errors with the single letter variables in the for loops, i.e.:
    Assets/Scripts/AvoidObstacle.js(117,22): BCE0005: Unknown identifier: 't'.
    Assets/Scripts/PlayerRadar.js(62,14): BCE0005: Unknown identifier: 'i'.
    Assets/Scripts/PlayerRadar.js(72,40): BCE0017: The best overload for the method 'System.Collections.Generic.List.<UnityEngine.Transform>.get_Item(int)' is not compatible with the argument list '(error)'.

    I started a new project, imported vectrosity, then copied the tankzone game in.

    I read the instructions and it works on the pc. Any ideas?

    Btw: I used to repair video games and so played alot of hours! Read this as [For free!] Your version is so incredibly close I feel I am back in time, totally consumed. I would like to put the [Tune] in at 100k points(Snagged it from MAME).
    When I repaired machines I knew where all the Battle zone and Defender machines were in town. After all I had the keys. Just living the fantasy...
    When I would go to the places where the younger teens would hang out I would rack up a few clicks and tell the kid next to me to [Test this].

    Thanks in advance.
     
    Last edited: Apr 16, 2012
  47. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    As mentioned in the docs (tips/troubleshooting), the TankZone project won't work on mobile. As it happens, I was just playing it now (for testing purposes ;) )...got to 88K.

    @redmacmanz: nearly parallel lines will cause the intersection point to extend quite far. I'll probably have to put a check in that disables the weld for that segment if the intersection point is too far. It's not really possible to smooth it, unless I used more than 4 vertices per segment, but that would complicate and slow things down a fair bit.

    --Eric
     
  48. Overunity3d

    Overunity3d

    Joined:
    Sep 5, 2010
    Posts:
    14
    A buddy of mine has it working on an Android tablet. That spurred hope.
    Since you are testing then I would still be interested for any possibility.
    Thanks.
     
  49. nitz

    nitz

    Joined:
    May 4, 2011
    Posts:
    54
    Hi Eric!

    Thanks for providing such a great line solution! I'm having a small issue, and thought you might be able to help out. I'm recording input, and playing it back via a continuous line. I've got my playback mechanism working nicely, as I can see the points being plotted when I use points and the DrawPoints method. However, as I go through drawing my line, I'll get these 'flickers' of line that shoot way out of view (thousands of units off screen), but I've confirmed none of the data I'm giving DrawLine3D is that far out of range via this:

    Code (csharp):
    1.  
    2.  
    3.         foreach (Vector3 v3 in vl.points3) // after updating points...
    4.         {
    5.             if (float.IsNaN(v3.x)) Debug.LogError("x is NAN");
    6.             if (float.IsNaN(v3.y)) Debug.LogError("y is NAN");
    7.             if (float.IsNaN(v3.z)) Debug.LogError("z is NAN");
    8.             if (float.IsInfinity(v3.x)) Debug.LogError("x is INF");
    9.             if (float.IsInfinity(v3.y)) Debug.LogError("y is INF");
    10.             if (float.IsInfinity(v3.z)) Debug.LogError("z is INF");
    11.             if (Mathf.Abs(v3.x) > 500) Debug.LogError("x is G500");
    12.             if (Mathf.Abs(v3.y) > 500) Debug.LogError("y is G500");
    13.             if (Mathf.Abs(v3.z) > 500) Debug.LogError("z is G500");
    14.         }
    15.  
    None of those logs ever show up, but I end up with something that (occasionally) looks like:



    The line seems to poke out into 3000-6000 range (if I select the vector game object and follow it all the way out.) (They also poke into the -3000 to -6000 in that screenshot)

    Any ideas?

    Thanks a bunch!
     
    Last edited: Apr 16, 2012
  50. holyjewsus

    holyjewsus

    Joined:
    Mar 7, 2011
    Posts:
    624
    are you using join weld?
     
Thread Status:
Not open for further replies.