Search Unity

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
    You definitely shouldn't do that; the purpose of using ObjectSetup is to create a "vector GameObject" which is controlled by the GameObject you pass in to ObjectSetup. So attempting to directly override it by using line.vectorObject basically defeats the purpose. I would generally recommend not using vectorObject; consider it an "advanced" feature. You never need to use it, and doing so can break Vectrosity's functionality unless you completely understand how it works. (In certain cases it can be a more efficient way to move lines around, which is why it's accessible at all.)

    --Eric
     
  2. c-Row

    c-Row

    Joined:
    Nov 10, 2009
    Posts:
    853
    Yes, but unlike the VectorManager, Draw3D() seems to place the hexagon at the world coordinates rather than the local coordinates of the GameObject my script is attached to, and I didn't find anything in the manual to change this.
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can pass in the transform of a game object when using Draw3D in order to alter the position of the line's coordinates according to that game object.

    --Eric
     
  4. c-Row

    c-Row

    Joined:
    Nov 10, 2009
    Posts:
    853
    Well... ouch. Now I see what it's good for. The documentation mentions this but I didn't understand what it's good for. The reference guide is indeed a bit clearer on that since it mentions the matrix of the passed transform.

    Now with parenting out of the question, how can I make sure that the transform it is connected to can still influence the line? Like changing its material when the player enters the game object's collider for example. Is there something in the background that keeps track of which line is connected to which transform, or would I need to take care of this myself by passing a reference to the line to the game object in question for example?
     
    Last edited: Aug 15, 2012
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes, that sounds reasonable.

    --Eric
     
  6. kdd_9000

    kdd_9000

    Joined:
    Aug 13, 2012
    Posts:
    6
    Alright I got it workin now, thanks for the help. To delete them I couldn't figure out how to use the Destroy to work properly with the list, but what I'm doing is disabling the line. Essentially it's just hiding the specific line from the user which is good enough for me hah.
     
  7. niall_obrien

    niall_obrien

    Joined:
    Dec 18, 2008
    Posts:
    9
    Hi Eric, this may seem like a silly question, but I'm just wondering that if I create say for example a wireframe cube using Vectrosity, is it as easy as assigning that to a Unity game object and rotating that object using its transform controls to see my wireframe rotate accordingly? Thanks!
     
  8. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yep. You can use ObjectSetup, or pass in that transform when using VectorLine.Draw or Draw3D.

    --Eric
     
  9. Xavier Wielemans

    Xavier Wielemans

    Joined:
    Jul 16, 2012
    Posts:
    7
    Hi Eric!
    First of all, many thanks for that great toolkit. This is my first Unity project, and it helped me a lot in saving time and moving forward efficiently! Which is so exciting when using a new environment... So really, thank you VERY much! It was so much worth buying the very affordable license from you. :)
    I would like to know if you or another Vectrosity user has any idea why I have unwanted artifacts appearing on my Vectrosity splines when they are textured with "glowing" textures (such as the ones you demonstrate in the tankzone demo). Typically, when a spline is "bent" too sharply, or in the special case where all 4 control points are equally spaced along a straight line, I get "hand fan" articats. I guess they must be side effects due to the fact that the spline is composed of a multitude of line segments, each with its own texture tile, so I tried several things, increasing/decreasing the number of segments, playing with the joins type, etc. but nothing helped...
    Is there something I miss here, in the way I set up my textures/materials? A specific shader I'm supposed to use?
    Any advice/tip/opinion/encouragement will be much appreciated, I'm rather stuck here... :)
    Thanks again, and good continuation with Vectrosity!
    Willy

    PS : here are a few example screenshots from my project:
    image1
    image2
    image3
    image4

    I can send you the whole Unity project if you like - don't hesitate to ask!
     
  10. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I'd recommend using Joins.Weld. If that's not it, maybe you have z-fighting? In which case try using different depths for the lines, so they're not all on the same plane.

    --Eric
     
  11. Xavier Wielemans

    Xavier Wielemans

    Joined:
    Jul 16, 2012
    Posts:
    7
    Thanks for your quick reply! All curves and splines already use Joins.Weld. I'm not familiar with z-fighting, but given that the artifacts show up even if I draw a single curve on screen, it seems to me that they are caused by something "internal" to the curve/spline, not to an interference between two overlapping curve.
    Also, I work in 2D for all these elements, with only Vector2's, so I don't have a Z coord (I'm using Vectrosity's Draw function, not Draw3D).
    Do you think I should transform everything to 3D curves, and make the Z coord of each control point (or spline pass-through point) vary slightly so as to avoid Z-fighting?
     
  12. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Judging from the straight lines in this screenshot:

    https://dl.dropbox.com/u/84958258/V...tifacts/GlowTree 2012-08-17 00-09-52-29_1.png

    that looks like multiple overlapping lines with z-fighting. I'm not sure what would cause artifacts like that otherwise. A single spline using Joins.Weld looks like this, with the mesh selected on the bottom, so there really isn't a way that I can see where artifacts like that could happen with only one line:



    All lines have a z coord, since they are meshes in 3D space, even 2D lines. Making different lines have different z coords (AKA VectorLine.depth) can be used to prevent overlapping lines from having artifacts due to z-fighting.

    Not necessary; 2D is preferable where possible since it's faster.

    --Eric
     
  13. Xavier Wielemans

    Xavier Wielemans

    Joined:
    Jul 16, 2012
    Posts:
    7
    To further test this, I have isolated individuals splines and curves in my Unity scene. Here is a screenshot showing one single curve. As you can see, everything works fine except in the place where the curve is sharply bent upon itself. I suppose this introduces sorts of tiny overlaps between adjacent polygons, because their vertices become so close to each other.


    Here are some additionnal individual examples:

    • 3 curves
    • 1 curve whose 4 control points are aligned, making it a straight line (this is the end of a morphing anim transforming a curve into a straight line) - this is the case in which most artifacts appear, oddly enough
    • A set of curves
    • A single spline passing through a set of 2D points - textured using an asymetric texture, giving the "inner glow" effect. Some artifacts can be noticed, but not much.
    • Same spline as previous example, more developed on screen. Again, artifacts can be seen at the end of the envelope, where the spline path bends sharply on itself.

    Is there a simple way to draw the curve mesh on top of the curve itself, like you did in your example image? It would be helpful...

    Many thanks for your support so far! :)
     
    Last edited: Aug 17, 2012
  14. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It would be good to provide some code. For the spline I posted, it's this:

    Code (csharp):
    1. var mat : Material;
    2. var splinePoints = [Vector2(50, 100), Vector2(100, 200), Vector2(300, 50), Vector2(400, 100)];
    3.  
    4. function Start () {
    5.     var line = new VectorLine("spline", new Vector2[50], mat, 20.0, LineType.Continuous, Joins.Weld);
    6.     line.MakeSpline (splinePoints);
    7.     line.Draw();
    8. }
    Select the line in the scene view.

    --Eric
     
  15. Xavier Wielemans

    Xavier Wielemans

    Joined:
    Jul 16, 2012
    Posts:
    7
    Thanks Eric!

    I'll send you some code. I am cleaning useless parts of my project so you can have a lightweight example code.
    By the way, are you coming to Unite12 in Amsterdam? I'll be there from tomorrow to Friday.

    Cheers,

    Willy
     
  16. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    No, sorry.

    --Eric
     
  17. newborne

    newborne

    Joined:
    Jul 16, 2012
    Posts:
    31
    Hi!

    I was wondering how you destroy VectorPoints?
    i destroy vector lines like this:

    Code (csharp):
    1. public void DestroyVectorLines()
    2.     {
    3.         for(int i = 0; i < vectorLines.Count;i++)
    4.         {
    5.             VectorLine tmp = vectorLines[i];
    6.             Vector.DestroyLine(ref tmp);
    7.         }  
    8.        
    9.         vectorLines.Clear();
    10.     }
    but i am not sure how to destroy VectorPoints since there is no Vector.DestroyPoint or something like that.
    Also one more, question, is this working with flash?
     
  18. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You should upgrade to the latest version (currently 2.0.1). As far as I know it doesn't work with Flash publishing since there is still missing functionality, and trying to work around that would degrade it too much.

    --Eric
     
  19. newborne

    newborne

    Joined:
    Jul 16, 2012
    Posts:
    31

    ok, i just sent you the email for upgrade... my bro bought it for me last year
     
  20. gregzo

    gregzo

    Joined:
    Dec 17, 2011
    Posts:
    795
    Hi Eric,

    I hope you're well and trust you're busy.

    Quick question about res : I'm currently working on the finishing touches of an iPad 3 app, which of course uses Vectrosity for line drawing. Trouble is, it's very inconvenient to test in the editor because the biggest game window I can afford on my monitor is 1616*1212... I'm using NGUI, which scales everything nicely, and was wondering if there might be a simple way to do the same with Vectrosity.

    If not, I can always write a helper function to translate coordinates according to the current size of the Game Window, but of course would rather use a ready made solution if there is one!

    Cheers,

    Gregzo
     
  21. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    3D lines are of course always scaled since they use world space. When it comes to 2D lines, there's the option of using viewport coords (along with DrawViewport), in which case (0.0, 0.0) is always the bottom-left, and (1.0, 1.0) is always the top-right, regardless of resolution.

    --Eric
     
  22. gregzo

    gregzo

    Joined:
    Dec 17, 2011
    Posts:
    795
    Thanks, will use ViewPort.

    Have a nice day,

    Gregzo
     
  23. vonchor

    vonchor

    Joined:
    Jun 30, 2009
    Posts:
    249
    In the Reference Guide your second and third examples of constructors show joins = joins.open. I assume that you meant joins.none but just wanted to pass this along
     
  24. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Thanks for pointing that out...Joins.Open used to be an alternative to Joins.None and I neglected to update that.

    --Eric
     
  25. bfoddy

    bfoddy

    Joined:
    Mar 27, 2012
    Posts:
    85
    if I try setting line.SetVectorCamDepth(5) with the newest version, I get

    "NullReferenceException: Object reference not set to an instance of an object
    VectorLine.SetVectorCamDepth (Int32 depth)"

    What am I doing wrong?
     
  26. DougMcFarlane

    DougMcFarlane

    Joined:
    Apr 25, 2009
    Posts:
    197
    That error generally means you didn't instantiate your variable (regardless of its class / type).

    When declaring your 'line' variable (prior to above code), did you just do something like this?:
    Code (csharp):
    1. VectorLine line;  // c#
    2. var line : VectorLine;  // or UnityScript
    If so, instantiate it using something like: (needs to be done BEFORE using it!)
    Code (csharp):
    1. VectorLine line = new VectorLine();// c#
    2. var line : VectorLine = new VectorLine();  // or UnityScript
    3. var line = new VectorLine();  // or optional UnityScript syntax
     
    Last edited: Sep 7, 2012
  27. bfoddy

    bfoddy

    Joined:
    Mar 27, 2012
    Posts:
    85
    I declared a private variable and then instantiated it using the constructor

    Code (csharp):
    1. private var frontArm:VectorLine;
    Code (csharp):
    1. frontArm = new VectorLine("frontArm", lineArray, lineMaterial, lineWidth, LineType.Continuous, Joins.Fill);
    It draws fine, but it's still throwing this error when I try to set the depth using

    Code (csharp):
    1. frontArm.SetVectorCamDepth(0);
     
  28. DougMcFarlane

    DougMcFarlane

    Joined:
    Apr 25, 2009
    Posts:
    197
    Ah, ya, that looks right. Then something strange must be occurring in the newest version!

    [Disclaimer] I don't own or use Vectrosity (yet :D (amazing asset!)), just thought it may have been a simple problem.
     
  29. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    SetVectorCamDepth is a static function, so just do

    Code (csharp):
    1. VectorLine.SetVectorCamDepth(5);
    Also it should be called after using SetCamera, otherwise the vector camera doesn't exist. The next version will have a better error message about this.

    --Eric
     
  30. bfoddy

    bfoddy

    Joined:
    Mar 27, 2012
    Posts:
    85
    Thanks, that works. I hadn't been using SetCamera.

    For a future version it would be nice to be able to set depth per line. I'm using Vectrosity to represent the limbs of cartoon characters.
     
  31. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can set the depth of each line by using VectorLine.depth (which is not a static function). e.g., myLine.depth = 6; The depth for cameras is used for layering cameras on top of other cameras in a particular order.

    --Eric
     
  32. PotatoAlchemist

    PotatoAlchemist

    Joined:
    Sep 8, 2012
    Posts:
    2
    Are the API documents available for this before we purchase?
     
  33. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Not currently, but I'll be re-doing my website...sometime....

    --Eric
     
  34. PotatoAlchemist

    PotatoAlchemist

    Joined:
    Sep 8, 2012
    Posts:
    2
    I understand. In that case, I'd like to know how advanced and feasible the 3D line rendering is, if it can be used to highlight silhouette edges on a model, and if it can respond to animated meshes.
    Moreover, I'd like to know if the UV coordinates for the textured line supports can be oriented based on line rotation. Also, are they allowed in 3D?
     
  35. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Animated meshes are not readable (at least not in Unity 3). Silhouetting edges would be a lot better off done as a shader; while technically it would be possible in Vectrosity, you'd have to get the line coordinates somehow. The UV coordinates for lines are generally fixed, though the SetTextureScale function can be used to expand or contract the texture; it's not based on line rotation. Everything that 2D lines do can also be done by 3D lines.

    --Eric
     
  36. Brad-Smithee

    Brad-Smithee

    Joined:
    Sep 9, 2012
    Posts:
    33
    What a marvelously swift reply! May have to consider purchasing your software simply for the sake of your concise forum responses here.

    Wouldn't you be able to use mesh.vertexes along with mesh.bindposes to offset and find the current animation frame pose? If I am mistaken about the usages of these attributes, I would imagine that using the separate Animation/AnimationClip classes would at least provide some kind of frame data if nothing else.

    Besides a screen-space image shader via edge detection, a 'fatboy' style vertex extrusion (flip normals and push), a proper-winded wireframe pass, or generation of an edge mesh (one camera-facing quad per edge) there aren't too many practical solutions with a short development cycle. Only the latter of these solutions offers textured outlines and other brush stroke types, but would certainly require the most development time since Unity doesn't expose edge lists -- not to mention the large growth of additional (difficult to cull) screen-oriented quads.

    Certainly disappointing at the time being, but definitely something I would love to see implemented. You could just use the 2D direction or 3D poly normal per quad in your chain as the UV abasement in such a case.

    -----

    Sadly, Unity's ventures into inking and brushing techniques are crudely limited to basic early 2000s techniques and don't begin to dip into (realtime) SIGGRAPH/NPAR papers on the relative subjects. If Vectrosity is as performance-capable as I have seen it praised by your userbase, it could be an idealic solution into a large range of non-photo-realistic approaches given the right amount of tweaking!
     
  37. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Hmm...I'd much rather use SkinnedMeshRenderer.BakeMesh in Unity 4. ;) Otherwise I'd be essentially re-implementing mesh skinning, which I'd rather not do.

    I'm finishing up version 2.1 now, but I'll keep that in mind for the next version.

    --Eric
     
  38. rsouza

    rsouza

    Joined:
    Dec 1, 2011
    Posts:
    67
    Why my line not is appearing? OBS: The Spline and Path Points are correct!

    Code (csharp):
    1.  
    2.  
    3.     private Vector3[] pathPoints = new Vector3[500];
    4.     private Vector3[] splinePoints =  new Vector3[500];
    5.        private VectorLine pathLine;
    6.  
    7.         void Start ()
    8.        {
    9.          pathLine = new VectorLine("Path", pathPoints, linePathMaterial, 2, LineType.Continuous);
    10.        }
    11.  
    12.       void Update
    13.       {
    14.           void DrawPath()  ;
    15.       }
    16.  
    17.  
    18.     void DrawPath()
    19.     {
    20.         Vector.MakeSplineInLine (pathLine, splinePoints, false);
    21.        }
    22.  
     
  39. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You're not drawing the line anywhere. MakeSplineInLine doesn't draw the line, plus you should only call it once, not every frame (unless the spline points change every frame). Also, I'd recommend upgrading since the version you're using is outdated.

    --Eric
     
  40. rsouza

    rsouza

    Joined:
    Dec 1, 2011
    Posts:
    67
    I drawed a path correctly. How can i remove the last tail of the path when i pass for this path?
     
  41. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I'm sorry but I'm not sure what you mean; can you rephrase?

    --Eric
     
  42. rsouza

    rsouza

    Joined:
    Dec 1, 2011
    Posts:
    67
  43. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    There's a demo script already included for touch-based line drawing.

    --Eric
     
  44. Crazy Robot

    Crazy Robot

    Joined:
    Apr 18, 2009
    Posts:
    921
    Hey Eric,

    I just bought this, are you going to upgrade it for Unity 4.0? I just imported it and it gave me 31 Red Errors.

    Thanks,

    Edit, I just tried to import this into Unity 3.5.5 and I'm getting the same red errors.

    As a note, I'm using Unity iOS Pro.

    Here are some of them:

    Assets/Vectrosity/Scripts/Curve/DrawCurve.js(12,20): BCE0004: Ambiguous reference 'VectorLine': VectorLine, VectorLine.

    Assets/Vectrosity/Scripts/Curve/DrawCurve.js(14,27): BCE0004: Ambiguous reference 'VectorLine': VectorLine, VectorLine.

    Assets/Vectrosity/Scripts/DrawLines/DrawLines.js(5,20): BCE0004: Ambiguous reference 'VectorLine': VectorLine, VectorLine.

    Assets/Vectrosity/Scripts/DrawLines/DrawLinesMouse.js(8,20): BCE0004: Ambiguous reference 'VectorLine': VectorLine, VectorLine.

    Assets/Vectrosity/Scripts/DrawLines/DrawLinesTouch.js(8,20): BCE0004: Ambiguous reference 'VectorLine': VectorLine, VectorLine.


    There are a bunch of yellow errors as well
     
    Last edited: Sep 19, 2012
  45. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Actually it works as-is with Unity 4 and doesn't need to be updated for that purpose. If you're getting errors, I suspect you imported both the .dll and the core scripts; you should only use one or the other. That said, I'm done with Vectrosity 2.1, aside from updating the docs, which does have some Unity 4 enhancements (but still works on Unity 3).

    --Eric
     
  46. Crazy Robot

    Crazy Robot

    Joined:
    Apr 18, 2009
    Posts:
    921
    Ok, I just deleted the .dll's and all of the errors are gone.

    I do have a question, I have the "DrawLinesTouch" demo scene up and it works great, how can I get another object to follow the line I drew?

    Thanks,

    JL
     
  47. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    In general, I'd recommend using the .dll rather than the source code (that is, the Standard Assets/VectorScripts folder).

    Have a look at the SplineFollow demo.

    --Eric
     
  48. Crazy Robot

    Crazy Robot

    Joined:
    Apr 18, 2009
    Posts:
    921
    Yeah, but when I import the demo package I get 16 red errors.
     
  49. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Ah yes, that's one change I made in Vectrosity 2.1. The source code is currently included with the demo package, which would create the problem you're having if you also have the .dll in the project. (I wasn't including the .dll previous to Vectrosity 2.0, and the way Vectrosity is distributed makes a little more sense if you don't have the Asset Store version.) So I'm not including the source with the demo package anymore, but only in the source code package, which should improve things generally.

    --Eric
     
  50. Crazy Robot

    Crazy Robot

    Joined:
    Apr 18, 2009
    Posts:
    921
    Hey Eric,

    Ok, so I took a look at both the touch scene and the SplineFollow scene, I just can't figure out how to get the cube to follow the touch generated line. I see that in the SplineFollow scene the cube position is moved via the line.GetPoint01 (dist). but when I try to input that into an Update function it does not work.

    Can you nudge me in the right direction?

    Thanks,

    JL
     
Thread Status:
Not open for further replies.