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

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Hmm, there shouldn't be anything special. I've attached the grid scene that I used for the website; you can change the main camera to orthographic and it still works the same. It shouldn't make any difference, since the lines are actually drawn by another camera on top. (This package has to be imported into a project that contains the Vectrosity scripts of course.)

    --Eric
     

    Attached Files:

  2. ej2009

    ej2009

    Joined:
    Mar 2, 2009
    Posts:
    353
    Thanks mate. I can't get this to work for some reason.

    I create new project in Unity 3 beta 4, import your grid demo package, add all Vectrocity scripts.

    When I try to attach Grid script to empty game object or to main camera I get following error: "The name 'VectorLine' does not denote a valid type ('not found').

    Error is on this line:
    private var gridLine : VectorLine;

    VectorLine.js script is in the project.

    Any ideas what I'm doing wrong?
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Make sure the Vectrosity scripts are in Standard Assets, so they can be used in JS.

    --Eric
     
  4. ej2009

    ej2009

    Joined:
    Mar 2, 2009
    Posts:
    353
    oh, thanks, that will be it! Explains why grid script worked when I converted it to C#. So much to learn in Unity :)
     
  5. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    Hi,

    The screenshot of TankZone shows the following words: "SCORE" and "HIGHTSCORE. Is this a "font" build with Vectrosity?.
    I want to use it to make a "HUD". Like this


    Or
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

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

    That's certainly doable. You get the source for Tank Zone when you buy Vectrosity, so you can build off the font stuff from that if you like. I was considering making the font routine part of Vectrosity itself, but it didn't seem like something most people would use.

    --Eric
     
  7. Ony

    Ony

    Joined:
    Apr 26, 2009
    Posts:
    1,977
    This is awesome and I had no idea it was even available until today.

    I was just on your site yesterday (going to get the Object Loader in a few days for a project) and I didn't see Vectrosity on there anywhere. Sure enough I just checked and there's no link to it on the site.

    It makes me wonder what other cool stuff you have out there that I don't know about.
     
  8. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    Ok.Purchased.:D

    JP
     
  9. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It's just Vectrosity. ;) I don't normally procrastinate so much on stuff like that.... In the meantime, the link has been in my sig.

    Great! :)

    --Eric
     
  10. bobpitbull

    bobpitbull

    Joined:
    Jun 14, 2010
    Posts:
    6
    Hi Eric,

    I've purchased Vectrosity and, great stuff, it works really well :)

    Any news on the bezier curves? If you add those, are you planning to add in other types at the same time? Circles etc? I'm drawing those using my own code but it would be cool if you just had some built in functions for those too...

    Bob
     
  11. bobpitbull

    bobpitbull

    Joined:
    Jun 14, 2010
    Posts:
    6
    Actually... a quick question... I'm using the following to construct a circle from an array of points:-

    ---

    private var lineCircle : VectorLine;

    var circlePoints = new Array();
    for( segment = 0; segment < nSegments; ++segment )
    {
    var fAngle = ( Mathf.PI * 2 / nSegments ) * ( segment );
    var fX = Mathf.Sin( fAngle );
    var fY = Mathf.Cos( fAngle );
    var vPoint : Vector2 = Vector2( fX, fY ) * fRadius + vCentrePoint;
    circlePoints.Push ( vPoint );
    }

    lineCircle = new VectorLine( "Circle", circlePoints, Color.white, lineMaterial, 3, 0, 1, LineType.Continuous, Joins.Fill );

    ---

    When I do this, I get the following error:-

    Assets/Scripts/Actions/js_MyCode.js(47,26): BCE0024: The type 'VectorLine' does not have a visible constructor that matches the argument list '(String, Array, UnityEngine.Color, UnityEngine.Material, int, int, int, LineType, Joins)'.

    Any idea what the issue is...?

    Bob
     
  12. bobpitbull

    bobpitbull

    Joined:
    Jun 14, 2010
    Posts:
    6
    Ok, found the fix... doing "new array" was creating the wrong sort of array for the constructor.

    Now I have a new issue... Joins.fill doesn't seem to make any difference - I need to reinsert the 1st entry into the array (creating an array nSegments+1 in size)...?
     
  13. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yep, I do have a circle routine right now actually. Adding bezier curves is one of the things left to do.

    The first and last points in the circle should be identical, yes. If they aren't, Joins.Fill would still work on all the other segments, but there would be a gap between the first and last segments.

    --Eric
     
  14. longshot

    longshot

    Joined:
    Sep 24, 2009
    Posts:
    71
    Bought the vectrosity scripts, for those who are reading, if you are even the slightest bit interested in drawing lines, you should buy this.

    If you aren't, you should buy it, and burn it in protest.

    I do have one small nitpick though, the Vector3Pair struct. It would be nice if this was turned into a class, and made serializable.

    I'm doing a 2.5d game, and ran into the issue of having to find the closest point on two meshes. Instead of doing a very expensive mesh to mesh check, I decided to make an editor script, draw a shape with lines around the meshes, and then find the shortest line segment during runtime. For a cube in a 2.5d game, this means checking every line against every other line, for 16 checks, which is a hell of a lot cheaper than checking every triangle.

    However, since Vector3Pair isn't serializable, and is a struct( I tried to make it serializable myself, but there's no documentation on how do it with a struct, even though Unity has Vector3's serializable somehow), whenever my editor script set the Vector3Pair array in the component of the object, the changes will not take.

    I found a way to work around it, but it would be nice if in a future release Vector3Pair's could be serializable :).
     
  15. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I totally support this idea. ;)

    That really has to be a struct for the LineMaker script to work, which is the only thing I'm using it for. You can make your own class which is similar to Vector3Pair if you like.

    --Eric
     
  16. damien

    damien

    Joined:
    Jun 17, 2009
    Posts:
    32
    In the latest version of unity3 beta, most of the demos aren't working quite right, with none of the vector lines visible in the game view. Any ideas?
     
  17. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Not yet; I can't run Unity 3 on my G5. I ordered a new computer a couple days ago though, so I should be able to look into it soon.

    --Eric
     
  18. damien

    damien

    Joined:
    Jun 17, 2009
    Posts:
    32
    Ok, thanks. Can't wait to start using this!
     
  19. damien

    damien

    Joined:
    Jun 17, 2009
    Posts:
    32
    While awaiting unity3 beta fix, I'm doing some tests in latest version of unity iphone. My vector object is a long road (cube). The problem is the side lines are never visible because part of them will always be outside the clipping plane as the camera moves forward. If I move the camera far back enough where the entire road is visible in the viewport, all the lines are drawn. Is there a way to prevent this from happening?

    UPDATE: I don't think it's a clipping problem. It appears to stop drawing a line segment when a single point of that segment goes behind the camera.
     
  20. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    What happens if you subdivide the side line segments a few times?

    --Eric
     
  21. damien

    damien

    Joined:
    Jun 17, 2009
    Posts:
    32
    Is that possible with the LineMaker? What I'm doing is creating 3d objects in Maya, then using the LineMaker in unity3 to generate the vector points file, than importing that into unity iphone. Using that method, will I have to create the extra vertices in maya?
     
  22. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yeah, you'd subdivide in Maya.

    --Eric
     
  23. damien

    damien

    Joined:
    Jun 17, 2009
    Posts:
    32
    That works, but it means all my line segments have to be relatively short, creating a lot more work for me in the LineMaker. Any way around this? Something I can modify in the Vectrosity scripts?
     
  24. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I don't think there's any easy way; it has to do with the way WorldToScreenPoint works. Under certain (usually rare) circumstances it's impossible to get usable numbers out of it, and having more line segments is the only way around that I can figure. I think the marquee select tool in Unity 3 should take the work out of it in LineMaker though. (Once Vectrosity works with Unity 3 of course, assuming it's not just a bug in the current beta.)

    --Eric
     
  25. Maker16

    Maker16

    Joined:
    Mar 4, 2009
    Posts:
    779
    Ok. Here's my question. Can I use Vectrosity to draw lines on my terrain. Granted, I know the lines are mesh based, but I'm thinking of just drawing them a little above the level of the terrain. I need hexagons outlined in my game world on the actual terrain, not a map. I was reading that it uses screen points vs. world points, so, is it possible to do what I want to do?
     
  26. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The lines don't actually exist in 3D space with the terrain, they're drawn on top with another camera (in a flat plane, even for 3D lines). So no, I'm afraid it probably wouldn't work for that, unless you just had a top-down view.

    --Eric
     
  27. Disati

    Disati

    Joined:
    Oct 5, 2009
    Posts:
    111
    Looks nice, might become handy someday.
     
  28. blastone

    blastone

    Joined:
    Apr 7, 2009
    Posts:
    168
    I don't know if I will ever use it,

    but for the effort thats gone into it I bought it anyways. Looks great, Now Ill think of something to do with it.
     
  29. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Wow, that's some support! I appreciate it, and hope you find a good use for it sometime.

    --Eric
     
  30. taumel

    taumel

    Joined:
    Jun 9, 2005
    Posts:
    5,292
    This is very cool!

    I did my own lines implementation where i needed them for a few projects but yours are more advanced than mine. :O)

    It's one of these things that extremely bugs me about Unity, they often don't get the importance of such proper simple functionality which you sometimes just need, should be supported by Unity out-of-the-box since a long time already.
     
  31. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Thanks. :) Here's something I just did today:



    Yes...at last, MakeCurveInLine()....

    --Eric
     
  32. taumel

    taumel

    Joined:
    Jun 9, 2005
    Posts:
    5,292
    One thing that would need some fixing are the beginning and the start of a line if you're using them with a glow.
     
  33. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Here's a little demo for the bezier curve routine:



    It's a basic curve-drawing app where you can move anchor points and control points around, change the curve resolution, and add new points. Can't remove points though, so it's not really a competitor to Illustrator. ;) (I mean, nothing stopping that, I just didn't bother to program it in.)

    --Eric
     
  34. blastone

    blastone

    Joined:
    Apr 7, 2009
    Posts:
    168
    How do I get this fancy update!
     
  35. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Wait a bit; it's not quite done yet. :)

    --Eric
     
  36. Anim

    Anim

    Joined:
    Aug 11, 2008
    Posts:
    289
  37. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Now you can do uniform texture scaling for the lines, which makes it easy to do things like dotted or dashed lines:



    You can set the scale as desired, with 1.0 being normal width, so .5 is half width, 2.0 is double, etc. I updated the curve-making demo (here) with the option of having dotted lines, which seems oddly fun to play around with.... (i.e., try adding a few points and then drag the first anchor point around when dotted lines are turned on.)

    --Eric
     
  38. Spookytooth

    Spookytooth

    Joined:
    Jun 27, 2009
    Posts:
    57
    May have missed something in the previous posts on this topic, but this is, first of all, awesome! Does this allow for users to draw curvilinear lines in a freehand style like hand writing or graffiti?

    Nice work!
     
  39. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes, you can do something similar to the line-drawing demo, but instead of adding a point when the user clicks, you would add points at rapid intervals as long as the mouse button is held down (ignoring points that are too close together, so that holding down the mouse button and not moving the mouse wouldn't add tons of points on top of each other).

    --Eric
     
  40. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    Hi,

    Very nice. An idea for the next demo : Maybe a sort of "Audio VCO" with AudioSource.pitch? 8)

    JP
     
  41. marty

    marty

    Joined:
    Apr 27, 2005
    Posts:
    1,170
    Just started working with Vectrocity - it really is like getting a whole new Unity!

    Great work, Eric.

    I'm curious though, when will you have the new version and curve/uniform texturing demo code ready - I can't wait!
     
  42. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I'm afraid I don't actually know what that means.

    I want to test with Unity 3, since I've had a couple people say it doesn't work with it (although it did apparently work with an earlier beta). I need a new computer to be able to run Unity 3, but I ordered one and it shipped yesterday, so I should be able to do that some time next week, depending on when it arrives.

    Here's an example of drawing a line with a uniform texture scale:

    Code (csharp):
    1. Vector.DrawLine (myLine);
    2. Vector.SetTextureScale (myLine, 1.0);
    Yes, it's quite difficult. ;) Optionally you can add an offset:

    Code (csharp):
    1. Vector.SetTextureScale (myLine, 1.0, .5);
    That has the same result as setting the X offset in the line's renderer.material.mainTextureScale, but can be more convenient that way. Also it alters the actual UVs, so it won't result in scene instances of the material being created, although using mainTextureScale would be faster if you're animating it.

    --Eric
     
  43. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    In the meantime, 3D vector lines can now be drawn in 3D space using the new Vector.DrawLine3D, where they can be occluded by other objects, etc.

    --Eric
     

    Attached Files:

  44. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I've finished tweaking code and updating docs for Vectrosity 1.1...the only thing left is Unity 3 testing, which I should be able to do within a few days. I'd rather not annoy people by releasing this version now and then probably another version a few days later, but if anyone who's bought Vectrosity 1.0 wants the new version right now (minus whatever Unity 3 stuff may need to be done, obviously), let me know.

    Here's the changelog:

    Vectrosity 1.1

    Additions:
    • Vector.MakeCircleInLine and Vector.MakeEllipseInLine.
    • Vector.MakeCurveinLine for bezier curves.
    • Vector.SetTextureScale for setting a uniform texture scale, useful for dotted/dashed/etc. lines.
    • Vector.ResetTextureScale in case you want to reset the line UVs back to normal after using SetTextureScale.
    • Vector.DrawLine3D for drawing 3D vector lines in 3D space, where they can be occluded by 3D objects.
    • Vector.SetCamera3D for setting up the camera exclusively for 3D lines. In this case the standard vector camera is not used.
    • Vector.SetLayer for setting the layer of 3D lines, in case you're using SetCamera instead of SetCamera3D because you want to mix normal lines with 3D lines.
    • Vector.SetVectorCamDepth for setting the depth of the vector camera (surprise!). Rather than setting Vector.cam.depth, since Vector.cam is now private.
    • VectorManager.useDrawLine3D variable for telling VectorManager whether it should use DrawLine3D or not.

    Changes:
    • Removed LineType parameter from MakeRectInLine. Instead, the line type is picked up automatically from the line that's passed in; there doesn't seem to be a reason to specify it manually.
    • LineMaker now forces strings to use periods for decimals, which fixes problems some European users were having. If this behavior isn't desired for some reason, remove the first line of the Initialize function in the LineMaker script (the line that has the CurrentCulture stuff in it).
    • Additional overloads for defining 2D VectorLines: the default end cap width is 0.0, so if you're not using it, you can do things like "VectorLine("Name", linePoints, material, width)" without having to put 0.0 for the end cap in there.
    • This is more of an internal thing, but in case anyone was using these: VectorLine.use2Dlines is gone (check whether points2 is not null instead), and VectorLine.points is now VectorLine.points3 (just because it's a less confusing name, since it's a Vector3 array, and points2 is a Vector2 array).

    -----------

    Vectrosity 1.0

    Initial release.
     
  45. marty

    marty

    Joined:
    Apr 27, 2005
    Posts:
    1,170
    I'm all tingly!
     
  46. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I'm wondering if anyone using this with Unity 3 and was having issues could tell me what they are? Aside from adding "new" in front of the OnGUI and OnDestroy functions in the LineMaker script to get rid of a couple warnings, everything else seems to work as-is. The one problem I've seen so far is that "maximize on play" doesn't work, but unfortunately that's a Unity editor bug. (I say unfortunately because this is on f3, which might ship.) If you maximize first and then play, everything's OK. Also builds don't display any issues. It's like "maximize on play" causes some issue with camera initialization.

    --Eric
     
  47. dogzerx2

    dogzerx2

    Joined:
    Dec 27, 2009
    Posts:
    3,964
    Hey, dotted lines look quite fancy, gives me lots of ideas for gui usage hmmm
     
  48. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Of course, the texture can be whatever you want....

    --Eric
     

    Attached Files:

  49. marty

    marty

    Joined:
    Apr 27, 2005
    Posts:
    1,170
    Is 1.1 soup yet?
     
  50. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I would say so. There don't appear to be any Unity 3 issues, unless someone has found something I haven't, aside from the maximize-on-play bug. That bug is kind of annoying though...I'm going to have to mention it in the docs unless it's fixed, which means I probably should wait until Unity 3 actually ships, just in case f3 isn't the last version. So send me a PM if you want 1.1 now, which goes for anyone who's bought it.

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