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
    I'm afraid there's not an easy way. As far as I know, you'd have to do a line intersection test, presumably for each segment of a VectorLine compared to each segment of the other VectorLine, unless someone knows of a better way.

    I think what you've written is probably the best way to do it at this point. I haven't really done anything myself with lines in edit mode so I'm not sure if there's another way.

    --Eric
     
  2. supericon

    supericon

    Joined:
    Feb 15, 2013
    Posts:
    63
    Hi - I am working on a retro 80s style cityscape with Vectrosity, and have encountered something odd I hope you can help with.

    $Rendering01.jpg $Rendering02.jpg

    The only difference in code between those two is in "VectorManager.ObjectSetup (gameObject, line, Visibility.Always, Brightness.None);"

    Visibility.Dynamic or Visibility.Always

    Full script as follows:

    Code (csharp):
    1. import Vectrosity;
    2.  
    3. var vectorData : TextAsset;
    4. var lineMaterial : Material;
    5. var lineColor = Color.green;
    6. var lineThickness = 8.0;
    7.  
    8. function Start () {
    9.    
    10.     var linePoints = VectorLine.BytesToVector3Array (vectorData.bytes);
    11.     var line = new VectorLine ("Object", linePoints, lineColor, lineMaterial, lineThickness);
    12.        
    13.     VectorManager.useDraw3D = true;
    14.     VectorManager.ObjectSetup (gameObject, line, Visibility.Always, Brightness.None);
    15.  
    16. }
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You'd want to add "false" at the end of the ObjectSetup parameters; see the discussion of MakeBounds in the ObjectSetup section in the docs.

    --Eric
     
  4. supericon

    supericon

    Joined:
    Feb 15, 2013
    Posts:
    63
    Perfect - thanks Eric. Which leads me onto a rendering issue - the 3D meshes z-fight with the 3D lines - like in the screen below.

    Is there any way to improve this?
    $Rendering03.jpg
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You could try using a shader that has "Offset -1, -1" in it, or possibly just make the lines a little thicker.

    --Eric
     
  6. zmeinaz

    zmeinaz

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

    I am having a problem with Join.Weld on my dotted line. In certain areas the dots become stretched and look odd, especially when moving via SetTextureScale():
    pathLine.SetTextureScale( null, 1.0f, Time.time * -1.4f % 1 );

    I am using a 3D line, but am using a bogus reference camera to keep the line in the x-z plane. The line looks fine with a maxWeldDistance of 1, but the line looks broken on corners.

    Here is a video of the line in action:
    https://www.dropbox.com/s/89o0jef1ylhorsk/join weld line.mov
     
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    What does the wireframe of that line look like? Could you add more points to the line, so the segments are shorter?

    --Eric
     
  8. zmeinaz

    zmeinaz

    Joined:
    Jul 3, 2012
    Posts:
    27
    I added more paths by making the maximum line length .1, I still get the same effect... The line breakage is not super noticeable so I think I will just have to live with it. Thanks for the suggestion.
     
  9. davedev

    davedev

    Joined:
    Jan 12, 2009
    Posts:
    74
    I had problems compiling for iOS in Unity 4.1.5 on Mac OS 10.8 with an error in the AOT compiler. I tracked it down to Vectrosity and using the source code version of the plugin instead of the dll eliminated the error. Is this a known error? Or is there something I'm doing wrong? I made a simple project with the example code that shows the error. See attached. $Screen Shot 2013-06-14 at 6.11.21 AM.png
     
  10. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The DLL should be named "Vectrosity" rather than "Vectrosity_Unity4".

    --Eric
     
  11. davedev

    davedev

    Joined:
    Jan 12, 2009
    Posts:
    74
    Ah. Thanks. Vectrosity is excellent. The documentation, examples, support, and the logic of API are all top quality and has made it really easy to implement even for functionality that is not common or straight-forward. Good job!
     
  12. Griffo

    Griffo

    Joined:
    Jul 5, 2011
    Posts:
    700
    Hi, I'm a complete noob to Vectrosity and have just imported it from the asset store and are getting 2 errors straight away pointing to 2 C# scrips, can someone please tell me how to solve this problem please.

    Assets/Standard Assets/Image Effects (Pro Only)/ImageEffectBase.cs(5,14): error CS0101: The namespace `global::' already contains a definition for `ImageEffectBase'

    Assets/Standard Assets/Image Effects (Pro Only)/ImageEffects.cs(6,14): error CS0101: The namespace `global::' already contains a definition for `ImageEffects'

    I'm using Unity Pro 4.1.5f1

    Thanks.

    Kevin.
     
  13. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    One of the demos contains a couple of standard assets; you can either not import the demos, or import them into a new project (recommended).

    --Eric
     
  14. Fliperamma

    Fliperamma

    Joined:
    Apr 24, 2012
    Posts:
    31
    Hi Eric, thanks for creating this :)

    So I'm developing a game that I need to draw lines with touch input, for now I'm using LineRenderer which provide some nice results but it is not smooth enough. I decided to give a try to Vectrosity.

    I'm testing your demos (DrawLinesTouch). As you can see in the ScreenSchot I'm getting some "sharp" corners, is there a way to avoid this?

    Thanks

    $Screen Shot 2013-06-16 at 12.35.06 PM.png

    *EDIT: I'm using Unity 4.1.5f1
     
    Last edited: Jun 16, 2013
  15. Griffo

    Griffo

    Joined:
    Jul 5, 2011
    Posts:
    700
    Thanks Eric ..
     
  16. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You could reduce maxWeldDistance, which will prevent those segments from being welded at all. If that's not acceptable, you'd have to find some way to add more points at those parts to give the welding routine more to work with.

    --Eric
     
  17. code-blep

    code-blep

    Joined:
    Oct 1, 2010
    Posts:
    308
    Hi Eric5h5,

    I have a large procedural 3d plane that changes shape quite quickly during the game. What method do you recommend? I need to use Draw3D as it is FPS based. Thanks. Paul.
     
  18. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Hi, since you've already decided on Draw3D, I'm not really sure what you mean by "method". Can you explain more?

    --Eric
     
  19. Griffo

    Griffo

    Joined:
    Jul 5, 2011
    Posts:
    700
    I'm using Xray to look through walls, what I'd like to know is it possible to easily add mesh data to XrayLineData.js ?

    I'd like to add a humanoid mesh data or just the outline ..

    Thanks.
     
  20. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can use the LineMaker editor utility for new mesh data, though you may prefer to use vector files instead of putting the data in scripts (using the BytesToVector3Array function); see the Simple3D 2 example script.

    --Eric
     
  21. Griffo

    Griffo

    Joined:
    Jul 5, 2011
    Posts:
    700
    Thanks Eric,

    Is it possible for the vector of the humanoid I made to animate as the humanoid does or is that just to much ?

    Thanks.
     
  22. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You could use SkinnedMeshRenderer.BakeMesh for that, though you'd need to use VectorLine.MakeWireframe rather than a custom wireframe made with LineMaker. I suspect it wouldn't be very fast though.

    --Eric
     
  23. Griffo

    Griffo

    Joined:
    Jul 5, 2011
    Posts:
    700
    Thanks for that.
     
  24. Griffo

    Griffo

    Joined:
    Jul 5, 2011
    Posts:
    700
    Hi Eric,

    Is there any code you could point me at so I can have a look how MakeWireframe works as I'm getting a bit confused :) as I can't seem to find any relating to MakeWireframe in the demos.

    Thanks.
     
  25. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It's described with a code example on page 35 in the docs.

    --Eric
     
  26. Griffo

    Griffo

    Joined:
    Jul 5, 2011
    Posts:
    700
    Thanks ..

    I really should have seen that .. :)
     
  27. code-blep

    code-blep

    Joined:
    Oct 1, 2010
    Posts:
    308
    Hi Eric, Sorry that question was badly worded, the peril of late night posts ;)

    Effectively I am looking to have the wireframe overlay on top of a plane that forms the landscape, which is constantly changing shape. I need the lines to be occluded by other parts of the plane and objects. After reading the documentation I think I need to use Draw3D. Am I on the right track? Is there a recommended method you would suggest on how to deal with this scenario? Is it even possible? Thanks and I hope this makes more sense :)
     
  28. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    If you need the lines occluded then Draw3D is really the only choice, so I'd say you're on the right track. ;) You would of course need to feed in the data for the array of points that makes up the lines, but there's not really much else to it.

    --Eric
     
  29. CADS

    CADS

    Joined:
    Jun 20, 2013
    Posts:
    13
    Hi,

    just tinkering around with Vectrosity and came across a little problem.
    I created a VectorLine (myLine) object and set the parent for it by calling: myLine.vectorObject.transform.parent = otherTransform.
    Now when I am checking if the line was selected with: myLine.Selected... I noticed, that a selection only gets registered for world point coordinates of the line, so the parent transformation is not considered. Is this a bug, or am I missing some additional setting here?

    Many thanks in advance, any help would be much apprecciated!

    Best regards
    Mario
     
  30. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I would strongly recommend not using vectorObject in most cases, since it interferes with the functionality of Vectrosity unless you really know what you're doing. I'm not sure what you're doing with the parent, but it's likely you can pass in the transform of another object when drawing the VectorLine instead. e.g., myLine.Draw (someTransform).

    --Eric
     
  31. code-blep

    code-blep

    Joined:
    Oct 1, 2010
    Posts:
    308
    Great news! I already have an array of information I use to update the vertices etc so I guess I can use that. I'll have a play and see what happens. Thanks Eric.
     
  32. memetic-arts

    memetic-arts

    Joined:
    Feb 27, 2011
    Posts:
    82
    Hi -

    Continuing to love Vectrosity, awesome and essential addition to Unity, thank you Eric5H5!

    I have a question which I'm sure has been asked before, but neither google nor Unity's search has yielded decent results, so hopefully someone will indulge me here . . .

    A year or two back (in this thread somewhere!) there was talk of providing some support for SVG-import/conversion. I didn't see anything in the docs to that effect, but maybe there is some ad hoc method?

    This would be huge . . . at least until I can build my superformula spline generator, that is. :)

    thanks!
     
  33. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    There isn't any SVG import yet, but the more it gets mentioned the more likely it becomes. ;)

    --Eric
     
  34. memetic-arts

    memetic-arts

    Joined:
    Feb 27, 2011
    Posts:
    82
    Thanks.

    I guess I'll mention it again tomorrow.

    :)
     
  35. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    +1
     
  36. CADS

    CADS

    Joined:
    Jun 20, 2013
    Posts:
    13
    Thanks for the fast respone. Just tried it out and the drawing with myLine.Draw(someTransform) works fine. Unfortunately the myLine.Selected does still not work with the applied transformation. Line points are definitely checked as word coordinates without the transformation given to myLine.Draw().
    Any thoughts why this issue arises?
    Thank you for your help!

    Mario
     
  37. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    That would appear to be a bug/limitation...good catch on that, will be fixed in the next update.

    --Eric
     
  38. kaushik-hobb

    kaushik-hobb

    Joined:
    Oct 24, 2012
    Posts:
    9
    Hi Eric , great package ! saves us a lot of time..

    Have a few doubts about how to go about on a few things:
    1. How to go about selecting seperate segments of a vectorline? ex: Line 1 has points 0,1,2,3 and i want to select the segment from point 2 to point 3?
    2. Same thing about selecting dots?

    cheers
     
  39. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    1. Vectrosity 2.3 (not quite done yet) has the ability to get the segment index for selected lines.
    2. VectorLine.Selected doesn't really work right with points, now that you mention it, but as long as Vectrosity 2.3 isn't done yet anyway maybe I can do something about that....

    --Eric
     
  40. Jujo100

    Jujo100

    Joined:
    Jan 20, 2013
    Posts:
    14
    Hi,

    Not sure if I'm missing something but if I change the thickness of my 3d lines the thickness remains the same regardless of the distance from the camera. So if you zoom out you get huge lines relative to the objects in the scene.

    My aim is to create laser tracers by the way.

    Thanks!
     
    Last edited: Jun 25, 2013
  41. alexsan75

    alexsan75

    Joined:
    Feb 6, 2012
    Posts:
    95
    Hi Eric,
    just would like to thank you for your Vectrosity asset! Bought Vectrosity last year and loved it!
    Thanks to this we could add a cool Tracing effect to our game :cool:

    The Game is called 5 Vikings. It just has been released and is now available on the App Store:
    https://itunes.apple.com/us/app/5-vikings/id659539981?mt=8

    Thanks once more for this trully great asset!

    $5vikings_003.jpg
     
    Last edited: Jun 25, 2013
  42. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes, that's by design; Vectrosity line widths are based on pixels, so you can do things like wireframe effects. It's not really appropriate for something like tracers.

    Looks good!

    --Eric
     
  43. Fishypants

    Fishypants

    Joined:
    Jan 25, 2009
    Posts:
    444
    I'll put in my vote for SVG / Flash import. +1000
     
  44. CHPedersen

    CHPedersen

    Joined:
    Mar 2, 2011
    Posts:
    63
    I need to render single pixels to a large RenderTexture (4096x4096) in order to use the rendertexture as a sort of datastructure to hold scalars in pixels. The data will be accessed on the GPU and displayed on a 3d model as a sort of visual 3d-representation of a graph. To implement it, my idea is to create 4096 VectorLines with 4096 points each, and then just render them to the RT using VectorLine.SetCameraRenderTexture. Then I can update a single scalar value very quickly by changing a point on the appropriate VectorLine and re-render it to the rt.

    My problem is that I don't know if a VectorLine with as many points as the pixels it will cover is going to render itself pixel-perfect. That is, if I have a straight line created from 10 points, spanning 10 pixels in the RT, will point number 5 directly correspond to pixel number 5?
     
  45. Jujo100

    Jujo100

    Joined:
    Jan 20, 2013
    Posts:
    14
    Thanks Eric,

    Out of interest then. What would be the most efficient way to achieve a tracer effect? If I user trail or line renderers each laser segment incurs 1 draw call.
     
  46. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It will for sure if you make sure the vector cam is orthographic by using SetCamera (true). This code:

    Code (csharp):
    1. function Start () {
    2.     VectorLine.SetCamera (true);
    3.     var points = new Vector2[10];
    4.     for (var i = 0; i < points.Length; i++) {
    5.         points[i] = Vector2(i*2+100, 100);
    6.     }
    7.     var dots = new VectorPoints("Dots", points, null, 1.0);
    8.     dots.SetColor (Color.green, 5);
    9.     dots.Draw();
    10. }
    results in this, enlarged to make it easier to see:

    $dotscloseup.png

    That's with AA off, though of course the rendertexture would not be using AA anyway.

    Would you have more than a few visible tracers at any time? That's just a few draw calls.

    --Eric
     
  47. Jujo100

    Jujo100

    Joined:
    Jan 20, 2013
    Posts:
    14
    Probably around 50 - 100 on screen.
     
  48. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    Svg for the masses...
    haha - isn't it time for vectrosity 2 ?
     
  49. CHPedersen

    CHPedersen

    Joined:
    Mar 2, 2011
    Posts:
    63
    Thanks for the quick reply, and double thanks for providing an example, too. :)

    One more question, though: VectorLine.SetCamera is not being called by myself, so I can't pass true to it to make the camera orthogonal. I understand it's being called for me in the implementation of VectorLine.SetCameraRenderTexture? There doesn't seem to be an overload of VectorLine.SetCameraRenderTexture that accepts a boolean.

    So, rather than passing true to VectorLine.SetCamera, could I use the camera returned by SetCameraRenderTexture and modify it myself? Like this:

    Code (csharp):
    1.         Camera vectorCam = VectorLine.SetCameraRenderTexture(dataRenderTexture);
    2.         vectorCam.orthographic = true;
    3.         vectorCam.Render();
    4.         VectorLine.SetCameraRenderTexture(null);
     
  50. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    There is in Vectrosity 2.3. ;)

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