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. Game-Whiz

    Game-Whiz

    Joined:
    Nov 10, 2011
    Posts:
    122
    I tried zooming in/out in the DrawLines example (by moving the VectorCam) and it worked, but when I drawed a line in the changed camera position, the mouse pointer was offset in relation to the line.

    Is there a supported zoom feature?
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can use .drawTransform with an empty object and scale the object. Altering the VectorCam will break Vectrosity.

    --Eric
     
  3. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    Nice work.

    How long does it usually take before it appears in the asset store?
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Two-three days, but I submitted on Friday so it will probably take longer because of the weekend.

    --Eric
     
  5. ichini

    ichini

    Joined:
    Oct 13, 2012
    Posts:
    23
    Hi Eric,

    I tried to get LineMaker to work with continuous lines, but I'm not sure how this can work (or I'm missing something).

    Given a square

    AB
    DC

    LineMaker generates a Vector3Array [B, A, C, B, D, C, A, D] if I select the points in clockwise order and create a line segment from each pair (also note the reverse order - the segments have to be selected in end point, start point order to get an [A, B, B, C, ...] array).
    Continuous lines however require an array like [A, B, C, D, A], which I can only get from LineMaker if the generate a complete line and delete the superfluous points from it manually.

    Wouldn't it be nice if LineMaker had a 'Create Continuous Line' option that parses multiple points in selected order to avoid this?

    Also (please excuse my ignorance), if I edit the Vector3Array manually outside LineMaker, how do I create a .bytes file from it?

    Thanks and all the best,

    Georg.
     
    Last edited: Jun 24, 2014
  6. pretender

    pretender

    Joined:
    Mar 6, 2010
    Posts:
    862
    Hi Eric.

    I have a problem and I know it should be relatively easy to solve with vectrosity, but there are so much options that I am not sure what is the correct way of setting it up.

    in short, i have a shape drawn (spline for testing purposes), and I want to be able to get intersection point with the line i drawn using touch input.

    but i can't make it work it out so that ray, that has the origin and destination from line drawn with input touch, to register raycastall hit with circle.

    i would highly appreciate if you could tell me what i am doing wrong, and what is the workflow to get this to work. There are lot of options and combinations, ortho and perspective camera, colliders 2d and 3d, converting from ScreenToWorld…. it's overwhelming!

    here is the code i have:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using Vectrosity;
    4.  
    5. public class lines : MonoBehaviour
    6. {
    7.     VectorLine sliceLine;
    8.     Vector3[] points = new Vector3[32];
    9.  
    10.     void Awake()
    11.     {
    12.         VectorLine.SetCamera(true);
    13.     }
    14.  
    15.     void OnEnable()
    16.     {
    17.         IT_Gesture.onDraggingStartE += OnDragStart;
    18.         IT_Gesture.onDraggingE += OnDrag;
    19.         IT_Gesture.onDraggingEndE += OnDragEnd;
    20.     }
    21.  
    22.     void OnDisable()
    23.     {
    24.         IT_Gesture.onDraggingStartE -= OnDragStart;
    25.         IT_Gesture.onDraggingE -= OnDrag;
    26.         IT_Gesture.onDraggingEndE -= OnDragEnd;
    27.     }
    28.  
    29.     void Start ()
    30.     {
    31.         var line = new VectorLine("spline", points, Color.white, null, 1f, LineType.Continuous,Joins.Weld);
    32.  
    33.         Vector3[] spline = new Vector3[16];
    34.  
    35.         for (int i = 0; i < spline.Length; i++)
    36.         {
    37.             spline[i].x = Mathf.Sin((2f * Mathf.PI / spline.Length) * i);
    38.             spline[i].y = Mathf.Cos((2f * Mathf.PI / spline.Length) * i);
    39.         }
    40.  
    41.         line.MakeSpline(spline,true);
    42.         line.collider = true;
    43.         line.trigger = true;
    44.  
    45.         line.Draw();
    46.     }
    47.  
    48.     void OnDragStart(DragInfo dragInfo)
    49.     {
    50.         sliceLine = new VectorLine("Slice", new Vector2[] { new Vector2(dragInfo.pos.x, dragInfo.pos.y), Vector3.zero }, Color.white, null, 1f);
    51.     }
    52.  
    53.     void OnDrag(DragInfo dragInfo)
    54.     {
    55.         sliceLine.points2[1] = new Vector2(dragInfo.pos.x, dragInfo.pos.y);
    56.  
    57.         RaycastHit2D[] hits;
    58.         hits = Physics2D.RaycastAll(sliceLine.points2[0], sliceLine.points2[1],1000f);
    59.  
    60.         if(hits.Length>0)
    61.         foreach(RaycastHit2D h in hits)
    62.             Debug.Log("hit: " + h.collider.name + " " + h.point.ToString());
    63.  
    64.         RaycastHit[] hits3D;
    65.         Vector3 origin = new Vector3(sliceLine.points2[0].x,sliceLine.points2[0].y,0f);
    66.         Vector3 destination = new Vector3(sliceLine.points2[1].x,sliceLine.points2[1].y,0f);
    67.  
    68.         hits3D = Physics.RaycastAll(origin,destination,1000f);
    69.  
    70.         if(hits3D.Length > 0)
    71.             foreach(RaycastHit h in hits3D)
    72.                 Debug.Log("hit: " + h.collider.name + " " + h.point.ToString());
    73.  
    74.         sliceLine.Draw();
    75.     }
    76.  
    77.     void OnDragEnd(DragInfo dragInfo)
    78.     {
    79.         //VectorLine.Destroy(ref sliceLine);
    80.     }
    81.  
    82. }
    83.  
     
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Not missing anything; LineMaker only makes discrete lines. Also the BytesToVector2/3 functions only make arrays that work with discrete lines.

    Unfortunately it's not that simple, since connecting all points for example doesn't have a defined order in which the segments are made. It could work if the user creates one segment at a time and doesn't delete any of the segments from the middle, but I'm a little reluctant to have a feature that depends on using the tool in a very specific way.

    In the LineMaker script, the WriteLineToFile function shows the code that's used. Basically it uses System.BitConverter.GetBytes to convert each float in each Vector3 to a byte array.

    Vectrosity doesn't have any functions for doing that, so this is really a general programming question. I think you'd be better off posting a topic about this, but you could start by doing a search for line intersection algorithms. I would say a plain math solution is more straightforward than trying to use raycasting.

    --Eric
     
  8. pretender

    pretender

    Joined:
    Mar 6, 2010
    Posts:
    862
    i was under impression, especially now when edgecollider is possible, that it could be utilized for a situation like this.
    it's just a constant ray casting (using start and end point of line drawn on the screen) and checking any collisions with the existing shape with some of the collider.

    i will search for algorithms that you are proposing, is it going to be a problem because i use 2d with extra added z = 0?
    also i noticed that when i use Debug.DrawLine(origin,destination) with line drawn with touch input, vector line and debug line don't have same z value? maybe that is causing ray not to detect any collisions.

    thanks!
     
  9. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    2D physics are 2D only and don't use any z coords.

    --Eric
     
  10. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    Eric,

    3.1 is now available in the asset store. Since the update downloads to the same package name is there a simple way to diff them to determine what versions the package is which?

    So it a more basic issue how to diff/check versions between different versions of the same unity package.
     
  11. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Good to know...would have been nice if I'd gotten a notification about that from the store like I usually do....

    I don't think there's a way. Vectrosity does have the Version function though.

    --Eric
     
  12. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    Not too much of a problem since you did mention that you posted it the store and gave an estimated timeframe for availability.

    Actually not so much as a diff of the contents as a way to indicate the version number without having to load the package into Unity to figure out what it is. Consider a Microsoft's PrintDialogs.dll which by a simple right click and I can see the version number without having to load it in another program. If I have directories full of different Vectrosity versions it would be nice to be able just to right click and see the version. I guess it is time for me to do more investigating and reading of the Unity documentation.
     
  13. pretender

    pretender

    Joined:
    Mar 6, 2010
    Posts:
    862
    Hi Eric.

    Is there an easy way to get all points between two certain points in the shape or line? Check out the image.
    If I have A and B points, how to get all points between them? I suspect it's trivial… :) but i don't see it

    vectrosity_forum.png
     
  14. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I assume you would cycle through the array?

    --Eric
     
  15. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    Actually version number is present if you just to look at the file in a binary editor(I used the one in Visual Studio). If you start at byte 16 (from the beginning of the file) then there is large amount of information present and it is human readable. I also looked at my small number of packages from the asset store and they all had similar information.
     
  16. MikesNameIsMike

    MikesNameIsMike

    Joined:
    Jun 5, 2014
    Posts:
    2
    I just bought it that night anyway - no issues so far.
    Great work and good documentation!
     
  17. pretender

    pretender

    Joined:
    Mar 6, 2010
    Posts:
    862
    Hi! Great plugin, I have some problems though. Check out the attached images and read comments below please! vectrosity.jpg vectrosity2.jpg vectrosity3.jpg
    vectrosity4.jpg
    Here is the code I am using to draw the line:

    Code (CSharp):
    1. line = new VectorLine("line", new Vector2[segments + 1],Color.yellow,shapeMaterial, 24f,LineType.Continuous,Joins.Weld);
    2.         line.MakeSpline(NormalizePoints(points),segments);
    3.         line.Draw();
    1.) first image is related to quality of a line. No matter what material I use (beside plain color) there are some artifacts on the corners. I tried using different materials, join types,line width, maxWeldDistance but no good results! What I need to do to get best looking results for this kind of situation. As less artifacts on the corners?

    2., 3. and 4.) second, third and fourth image are there to demonstrate that there are much denser mesh at the beginning no matter there is a no loop (2 and 3) or there is a loop in the spline (4). On the fourth image, when making spline and loop is set to true connection is not properly made!

    these are the things that bother me the most, can you help me out with this?

    Thanks for great plugin!
     
  18. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    1. It should work better if you use fewer segments; it looks like they're too dense and overlapping for the weld algorithm to work effectively.

    2. The spline function uses the same number of vertices per line segment, so short segments will be denser than long segments. While it's technically possible to "fix" this, it would complicate and slow down the function for no real gain since visually it doesn't actually matter. (Nobody's looking at the wireframe mesh in an actual build. ;) )

    As for the loop, I would guess you have the first and last points in the spline the same. They shouldn't be; have a look at the spline demos in the demo scenes.

    --Eric
     
  19. pretender

    pretender

    Joined:
    Mar 6, 2010
    Posts:
    862
    You were right! Thanks for the support!
     
  20. TechnicalArtist

    TechnicalArtist

    Joined:
    Jul 9, 2012
    Posts:
    736
    hi,

    Is it works in oculus rift?
     
  21. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes, with a bit of work (since you have to manage lines for two cameras).

    --Eric
     
  22. TechnicalArtist

    TechnicalArtist

    Joined:
    Jul 9, 2012
    Posts:
    736
    Do u have any working example?
     
  23. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Not personally, since I don't own one, but I was told that it worked by someone who does. (That's where the entry about the OR in the Tips section in the docs came from.)

    --Eric
     
  24. BilboStabbins

    BilboStabbins

    Joined:
    Aug 13, 2012
    Posts:
    5
    Hi,
    Really enjoying playing around with Vectrosity, it's saving a lot of man hours!:)

    However, I was wondering if you might be able to steer me in the right direction with something I'd like to try.

    I'd like to create a spline which is connected by two objects (the start and end points if you will), but with a bend in the middle. I'd like this bend to remain consistant in shape so that it just scales up depending on the distance between the starting and end points.

    Also, if achievable, I'd like to animate the line so that once the end point is clicked (for example), the line begins to 'travel' from the start point to the end point.

    Any help would be great - Thanks!
     
  25. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can either use a bezier curve, or a spline. The bezier curve would give you more control over the shape of the curve, but you'd need to fiddle with the control points. With a spline, it could work if you use the start point, end point, and another point that's in the middle and offset some distance.

    If I'm understanding what you mean by "travel", you can animate .drawStart over time, such as in the PartialLine demo.

    --Eric
     
  26. Karl_Bot

    Karl_Bot

    Joined:
    Jul 9, 2013
    Posts:
    6
    Hello,

    I have a question about overlapping 3D lines:

    Is there any way to render them in correct order?

    Here's what often happens: (closest sphere renders after further sphere)


    Is there any way to solve this? (I tried changing materials, but it didn't seem to have any effect)

    Other than that it's a great plugin, nice job!
     
  27. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can use VectorLine.sortingLayerID and/or VectorLine.sortingOrder.

    --Eric
     
  28. TechnicalArtist

    TechnicalArtist

    Joined:
    Jul 9, 2012
    Posts:
    736
    thanks for reply.
     
  29. kampagner

    kampagner

    Joined:
    Sep 3, 2013
    Posts:
    1
    Hi there,
    I am thrilled with the editable curve. How can I change the 2D curve to a 3D curve? see here
     
  30. ArefS

    ArefS

    Joined:
    Jul 11, 2014
    Posts:
    1
    Hi.
    I want to assign a suitable collider when using makecurve(). is there anybody who can help me?
     
  31. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You'd have to ask Ippokratis what he did for that. On the Vectrosity side, you'd use an array of Vector3 points instead of Vector2.

    Use .collider = true for the VectorLine in question.

    --Eric
     
  32. wbl1

    wbl1

    Joined:
    Apr 22, 2009
    Posts:
    159
    Eric,

    You certain that GetLength() returns a length in pixels when drawing a line with Vector2 points?

    I am not getting expected results ... Using Vectrocity 3.0.

    Thanks
     
  33. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Quite certain. Make sure you called SetDistances before using GetLength if necessary.

    --Eric
     
  34. Patrick234

    Patrick234

    Joined:
    Jun 25, 2014
    Posts:
    88
    Does this work well in 3D? look at this: I have a problem with LineRenderer and they say its Impossible to avoid with LineRendere :/ So i guess i will have to buy this to make it to work?! But would it work? And how hard would it be?



    -edit-
    So in the 2nd screen (bottom) i am using the AngryBots laser, (which is just UV offsetting a texture) and the laser needs to be a bit thicker, hence this enlarges the issue with LineRenderer to be extra visable.
     
  35. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yeah, that's standard behavior for the LineRenderer. Vectrosity doesn't do that, and would be pretty simple. Just make an array of Vector3 points for the laser, apply the appropriate texture, call Draw3D, and that should do it.

    --Eric
     
  36. Patrick234

    Patrick234

    Joined:
    Jun 25, 2014
    Posts:
    88
    Ok, before i buy this can you confirm how the code would look like if i where to use your lib?

    Heres what i do now.

    Code (csharp):
    1.  
    2.     void UpdateLaser(){
    3.         laserSize = 1;
    4.         laser.SetPosition(0, turretBarrelExit.transform.position);
    5.  
    6.         Vector3 position = turretBarrelExit.transform.position;
    7.         Vector3 direction = turretBarrelExit.transform.forward;
    8.  
    9.         while(CastLaser(position, direction)){
    10.             if(hitInfo.collider.tag=="Mirror"){
    11.                 position = hitInfo.point;
    12.                 direction = Vector3.Reflect(lastDirection, hitInfo.normal);
    13.                 //if(laserSize>10)
    14.                 //  break;
    15.             }else{
    16.                 break;
    17.             }
    18.         }
    19.     }
    20.  
    21.     bool CastLaser(Vector3 position, Vector3 direction){
    22.         lastDirection = direction;
    23.         laserSize++;
    24.         if(laserSizeOld!=laserSize){
    25.             laser.SetVertexCount(laserSize);
    26.             laserSizeOld=laserSize;
    27.         }
    28.         if(Physics.Raycast(position, direction, out hitInfo)){
    29.             laser.SetPosition(laserSize-1, hitInfo.point);
    30.             testObject.transform.position = hitInfo.point;
    31.             return true;
    32.         }else{
    33.             laser.SetPosition(laserSize-1, direction * 100);
    34.             return false;
    35.         }
    36.     }
    37.  
     
  37. BilboStabbins

    BilboStabbins

    Joined:
    Aug 13, 2012
    Posts:
    5
    Thanks Eric! I've managed to sort that problem out by messing around with the Partial Line Demo :)

    What I'd like to attempt now is to split the segments of the line (and eventually add then add colliders to them). I came across a mesh splitting script that you wrote on this thread which I have tried to apply to the Vector Spline object. However, it gives an 'IndexOutOfRangeException: Array index is out of range.' error (when the script is dragged onto the Vector Spline object after it has been drawn). The line it points to is: newNormals = myNormals[myTriangles]; when it's trying to rebuild the mesh.

    Unfortunately, I'm not too familiar with how to deconstruct meshes yet so any guidance you can provide on how to achieve this would be appreciated!

    Thanks
     
    Last edited: Jul 15, 2014
  38. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You don't want to alter the mesh; that will break Vectrosity. If you use a discrete line, you can have multiple separate segments in a single VectorLine, and can add collision using VectorLine.collider.

    --Eric
     
  39. Patrick234

    Patrick234

    Joined:
    Jun 25, 2014
    Posts:
    88
    Would anyone mind giving me a code sample, like, how easy is easy? Because usualy easy doesnt work, the next easy is still a days work i dont want to get from one pit into another...
     
  40. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    There are some code examples on my site.

    --Eric
     
  41. BilboStabbins

    BilboStabbins

    Joined:
    Aug 13, 2012
    Posts:
    5
    Thanks for the heads up! I've created the Discrete line, however I'm getting an error when trying to set the collider to true. This error also popped up a few days ago as you use it in the RandomHills demo scene, but it cleared itself up somehow, Not sure what the issue could be but it seems to have lost connection to the file containing the 'collider' definition. :confused:
    FYI, the error is: Assets/VectrosityDemos/Scripts/RandomHills/CreateHills.js(21,15): BCE0019: 'collider' is not a member of 'Vectrosity.VectorLine'.

    What I'm trying to do eventually is create a dashed line where each dash is clickable, hence trying to add colliders onto each segment.

    Thanks
     
  42. Patrick234

    Patrick234

    Joined:
    Jun 25, 2014
    Posts:
    88
  43. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Sounds like an old version of Vectrosity.

    You can use VectorLine.Selected for that, which has an index for which segment was selected; no colliders needed.

    I put the demo package here; it won't actually work without Vectrosity of course but you can read all the scripts.

    --Eric
     
  44. Patrick234

    Patrick234

    Joined:
    Jun 25, 2014
    Posts:
    88
    Is everything JavaScript? I work with C#
     
  45. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The demos scripts are; it's mostly the same as C# so converting is quite easy.

    --Eric
     
  46. GentleForge

    GentleForge

    Joined:
    Sep 7, 2013
    Posts:
    29
    I want to make an Signature Pad with Vectrosity, can you say me how to save the drawed line to a Texture?
    I need a picture with the signature to upload it, to my database.
     
  47. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You could use Texture2D.ReadPixels.

    --Eric
     
  48. ZeroSumGames

    ZeroSumGames

    Joined:
    May 7, 2013
    Posts:
    27
    I am getting a huge performance hit from LineManager.LateUpdate. I thought Vectrosity only needs to draw once? I have a pretty large set of points and it chokes out the LineManager. Any ideas?

    Maybe there is a better solution for what I'm doing. I have large areas of space in a space 4x empire-building game. I use MakeCircle to display the range of my ships, overlapping several different circles and cutting out the unused points. Then I draw the remainder using Draw3DAuto only once after I compute the circles.

    The thing is, I have to use high resolution circles to get clean overlapping circles. I need the intersection points to be fairly accurate. I really wish there was a cleaner way to overlap circles and cut out the redundant parts like I need.
     
    Last edited: Jul 22, 2014
  49. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    If you're using Draw3DAuto, then it has to update every frame. If you use Draw3D or Draw, then it's just once.

    --Eric
     
  50. ZeroSumGames

    ZeroSumGames

    Joined:
    May 7, 2013
    Posts:
    27
    Why would I want to use Draw3DAuto instead of Draw3D? Do I need to manually call Draw3D every frame then?
     
Thread Status:
Not open for further replies.