Search Unity

Vectrosity - Fast and Easy Line Drawing

Discussion in 'Assets and Asset Store' started by Eric5h5, Sep 26, 2014.

  1. MperiumGoods

    MperiumGoods

    Joined:
    May 25, 2018
    Posts:
    2
    Thanks Eric, draw3d solved my problem. Should've read the programming documents.
     
  2. jpl-mercury

    jpl-mercury

    Joined:
    Dec 13, 2016
    Posts:
    10
    Hi Eric. Thanks for the great library; our team uses it all the time.

    I'm trying to animate a ContinuousTexture from code. I've attempted to do it by changing
    line.material.mainTextureOffset
    as well as by changing
    line.textureOffset
    and neither seems to have any effect; the texture is static.

    However, if I go in the Unity Editor to the generated GameObject for the line and change the Offset X property for its material, I can (manually) make the texture animate as desired.

    How can I accomplish this from code? Is there something that I need to do in order to update the texture offset properly?

    Here's sample code for what I'm trying to do:


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Vectrosity;
    5.  
    6. public class MakeAndAnimateLine : MonoBehaviour {
    7.  
    8.     private VectorLine line;
    9.     public Texture lineTexture;
    10.     public float lineWidth;
    11.  
    12.     void Start()
    13.     {
    14.        
    15. line = new VectorLine("test line", new List<Vector3> { new Vector3(0, 0, 0), new Vector3(0, 0, 10) }, lineTexture, lineWidth, LineType.Continuous, Joins.Weld);
    16.  
    17.         line.Draw3D();
    18.     }
    19.  
    20.     void Update()
    21.     {
    22.         // Doesn't seem to work
    23.         line.material.mainTextureOffset = new Vector2(Time.time, 0.0f);
    24.         // This doesn't seem to work either    
    25.         line.textureOffset = Time.time;
    26.  
    27.         line.Draw3D();
    28.     }
    29. }
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
    Hi, assign a material to the line first.
    line.material = myMaterial;
    You can use line.textureOffset without using materials, but you need to assign line.textureScale first.

    --Eric
     
  4. jpl-mercury

    jpl-mercury

    Joined:
    Dec 13, 2016
    Posts:
    10
    Thanks for the reply. When I add a
    line.textureScale
    assignment the texture animates properly, but it ceases to scale as I would expect--how much of the texture I'm seeing depends on how far away I am from it, which I wouldn't expect for a continuous texture.

    Here's the texture I'm using:

    upload_2018-6-12_12-55-2.png

    Without a
    line.textureScale
    set, the texture on the line scales as I would expect based on the camera's distance from it.

    Far away:

    upload_2018-6-12_12-56-40.png

    Closer:

    upload_2018-6-12_12-56-44.png

    (cont. in next post)
     

    Attached Files:

  5. jpl-mercury

    jpl-mercury

    Joined:
    Dec 13, 2016
    Posts:
    10
    However, with
    line.textureScale
    set, I get animation, but with behavior that doesn't look like a continuous texture. Here's it far away at to
    line.TextureScale = 1
    :

    upload_2018-6-12_12-58-55.png

    Here's it far away at
    line.TextureScale = 10
    :

    upload_2018-6-12_13-0-17.png

    And here's it closer at
    line.TextureScale = 10
    :

    upload_2018-6-12_13-0-44.png

    It seems like the texture is being scaled to always be the same screen-space size along the x-axis. However, it wasn't doing so before I tried animating it. Why does animating it make a difference and is there a way to get this behavior working like I want? (Again, the behavior is correct if I manually manipulate the textureOffset on the material attached to the line, so long as I don't set
    line.textureScale
    .
     
    Last edited: Jun 12, 2018
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
    TextureScale isn't mean to scale with distance, it's intentional that it's screen-space. It always works that like regardless of being animated, although you could bypass that by drawing the line once and then not updating it when the camera moves. If you want the behavior of using Material.mainTextureScale, then I'd suggest using that instead. (Also, the scaling behavior with textureScale is because that particular texture is 8X as long as it needs to be, since it repeats 8 times. If you just have it repeat once, then setting textureScale to 1 would look "correct". Otherwise you'd need to set it to 0.125 (1/8) to achieve the same look.)

    --Eric
     
  7. jpl-mercury

    jpl-mercury

    Joined:
    Dec 13, 2016
    Posts:
    10
    The problem is that I'd like to use Material.mainTextureScale and Material.mainTextureOffset (the scaling works like I want it to), but they don't update properly. After I've created a line, updating these properties doesn't change the appearance of the line. However, I can edit the Tiling and Offset properties within the line's GameObject from the Editor (in the Inspector) and the line's appearance does change. What do I need to do to change Material.mainTextureScale and Material.mainTextureOffset from code and have these changes reflected?

    Here's the code I'm using:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Vectrosity;
    5.  
    6. public class MakeAndAnimateLine : MonoBehaviour
    7. {
    8.     private VectorLine line;
    9.     public Texture lineTexture;
    10.     public Material lineMaterial;
    11.     public float lineWidth;
    12.     public float textureScale;
    13.     public float scrollSpeed;
    14.  
    15.     void Start()
    16.     {
    17.         line = new VectorLine("test line", new List<Vector3> { new Vector3(0, 0, 0), new Vector3(0, 0, 10) }, lineWidth);
    18.  
    19.         line.material = lineMaterial;
    20.         line.texture = lineTexture;
    21.         line.lineType = LineType.Continuous;
    22.         line.continuousTexture = true;
    23.         line.joins = Joins.Weld;
    24.  
    25.         line.Draw3D();
    26.     }
    27.  
    28.     void Update()
    29.     {
    30.         line.material.mainTextureOffset = new Vector2(Time.time % 1, 0.0f);
    31.         line.material.mainTextureScale = new Vector2(textureScale, 1.0f);
    32.  
    33.         line.Draw3D();
    34.  
    35.     }
    36. }
    37.  
     
  8. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
    That code works fine here, so I'm not really sure what to suggest, other than making sure you're using the latest version of Vectrosity.

    --Eric
     
  9. Brian-Washechek

    Brian-Washechek

    Joined:
    Aug 5, 2015
    Posts:
    600
    I'm not aware of how I let Unity know about my need to use Vectrosity. Unity is giving me this error:

    Assets/Vectrosity_test.cs(2,0): error CS1525: Unexpected symbol 'import'

    on the simple starting test code:

    Code (CSharp):
    1. using Vectrosity;
    2. import Vectrosity; // Unityscript
    3. function Start()
    4. {
    5.     VectorLine.SetLine(Color.green, Vector2(0, 0), Vector2(Screen.width - 1, Screen.height - 1));
    6. }
    I tried following this and I immediately ran into an error. I think I have to I have to add the component or the class. I'm sorry, but I'm unaware of how to do this. I guess I'll post on forum.unity.com and see if I can be told by some kind soul.
     
  10. jpl-mercury

    jpl-mercury

    Joined:
    Dec 13, 2016
    Posts:
    10
    Thanks Eric. You were right; it was a versioning issue. It's working now under 5.6. Ugh, sorry about that, but thanks for your help!
     
  11. jpl-mercury

    jpl-mercury

    Joined:
    Dec 13, 2016
    Posts:
    10
    I don't think you need line 2 at all.
    Code (csharp):
    1. using Vectrosity;
    should be enough.
     
  12. Brian-Washechek

    Brian-Washechek

    Joined:
    Aug 5, 2015
    Posts:
    600
    "The type or namespace 'Vectrosity' could not be found" is the error it greets me with now. I think I need to know how to let Unity know that I would like to use Vectrosity.
     
  13. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
    Import is for Unityscript, using is for C#. If you use Unityscript, use "import". If you use C#, use "using". I would very strongly recommend doing some Unity programming tutorials before attempting to use Vectrosity. If you do "using Vectrosity" in C# and get a "not found" error, that means you haven't imported it. Vectrosity has to exist in your project before you can do anything with it.

    --Eric
     
  14. Brian-Washechek

    Brian-Washechek

    Joined:
    Aug 5, 2015
    Posts:
    600
    Ok. Could I get a link to the tutorials that you recommend that I watch?
     
  15. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
  16. jrhee

    jrhee

    Joined:
    Dec 5, 2013
    Posts:
    72
    I'm running into some issues with 3D lines getting distorted.

    I have two cameras:
    1. My isometric game camera, rotated 45 degrees.
    2. A disabled, top-down orthographic camera facing straight down, used only for SetCamera3D

    So I'd like the faces for my lines drawn in world space, oriented upwards. When viewed from above, the line looks correct, but when viewed from my game camera, the Z-values are wrong:

    lineZ.png

    Is there a way to address this?

    Thanks!
     
  17. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
    Are you using Joins.Weld? That will alter vertices as needed to weld lines, while looking correct for the viewing camera, but not necessarily other cameras.

    --Eric
     
  18. jrhee

    jrhee

    Joined:
    Dec 5, 2013
    Posts:
    72
    Yep- switching to Joins.Fill fixes the issue, but Joins.Weld would be ideal since my line's textured. Thanks for the quick reply!
     
  19. Ianamus

    Ianamus

    Joined:
    Jun 27, 2016
    Posts:
    4
    Hello,

    I am having issues drawing a simple 3D circle object with a consistent width. Below is the code I am using:

    Code (CSharp):
    1. VectorLine circle;
    2. circle = new VectorLine("Circle", new List<Vector3>(101), 10.0f, LineType.Continuous);
    3. circle.color = Color.red;
    4. circle.MakeCircle(new Vector3(0.0f, 0.0f, 0.0f), 30.0f, 100);
    5. circle.Draw3D();
    I have attached an image of the result below.

    As you can see the circle doesn't look quite right. The weight of the line gets progressively smaller until it disappears completely, creating a crescent shape.
     

    Attached Files:

  20. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
    That's the scene view; the lines are oriented to the camera, so you'd need to look in the game view.

    --Eric
     
  21. Ianamus

    Ianamus

    Joined:
    Jun 27, 2016
    Posts:
    4
    I was getting the same issue in the game view but I think I know what the issue is. I'm rotating the VectorLine object itself rather than a parent game object, so it is probably resulting in the circle being drawn as if from a different perspective.
     
  22. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
    Yes, for transform manipulations of VectorLines, normally you use VectorLine.drawTransform.

    --Eric
     
  23. mattchen

    mattchen

    Joined:
    Oct 24, 2017
    Posts:
    1
    can i use this tool to create 3d line like this?
    3d line.PNG
    don't facing screen

    thanks
     
  24. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
    No, sorry, it's for constant pixel-width lines.

    --Eric
     
  25. GuruRamen

    GuruRamen

    Joined:
    Jan 15, 2014
    Posts:
    13
    Hey Eric,

    Wondering if you can shed some light on a subtle problem I'm running with the texturing of vector lines.

    I've got a scene that looks like the following...
    upload_2018-6-21_16-53-3.png


    I've added a bloom filter to give a bit more of the old-school vector monitor bleed characteristic, and the results look like this...

    upload_2018-6-21_16-47-58.png

    As you can see, there's an unpleasant periodic quality to the texturing of the almost-vertical red lines.

    Zooming in on the un-bloomed original lines, you can see a periodic twist to the line's texture (using your "glow-small" BTW)...

    upload_2018-6-21_16-52-17.png

    Seems as the the bloom, being brightness-dependent, amplifies this visibility of this otherwise subtle pattern.

    So, can you clarify what's going on here? Is this just an aliasing effect?

    Any suggestion about how I can reduce it?

    Thanks much,
    Dan
     

    Attached Files:

  26. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
    Maybe just use a solid-colored line, with no texture, and do all glow/bloom with post-process. Or try making the lines a bit thicker. (Remember you can use float values.)

    --Eric
     
  27. GuruRamen

    GuruRamen

    Joined:
    Jan 15, 2014
    Posts:
    13
    I'll give that a try. Thanks very much.
     
  28. sacunha

    sacunha

    Joined:
    Apr 21, 2016
    Posts:
    144
    If I just want to draw a simple 1px width line, in 3D space, from A to B, wich of these 2 methods is lighter?
    Code (csharp):
    1. VectorLine.SetRay3D(lineColor, pos1, pos2);
    2.  
    3. //OR
    4.  
    5. VectorLine line = new VectorLine(lineName, points, 1.0f);
    6.         line.color = lineColor;
    7.         line.Draw3DAuto();
     
  29. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
    They're the same code; SetRay3D just does that for you.

    --Eric
     
  30. zoltanBorbas

    zoltanBorbas

    Joined:
    Nov 12, 2016
    Posts:
    77
    Hi there!

    I am using your asset for orbit lines of solar systems in my 4x strategy game. I have noticed that upon creating each new VectorLine() during the solar system generation procedure a RectTransform is created in the hierarchy and since i am generating the solar system data for each system in the galaxy it makes a lot of RectTransform. Is there any way to create a new VectorLine object without the RectTransform and only spawn the line's RectTransform when its presence in the hierarchy is required? Like when the player enters the solar system and all the assets are spawned using the generated data for the system. I would very much like to cash the orbit line data and use it to spawn the lines alongside the start draw call and then discard the obit line objects from the hierarchy along the stop draw call till they needed again.

    Thank you for your time!
     
  31. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
    I'd suggest re-using the VectorLines. You're probably using around 10 for a solar system, and I assume only displaying one solar system at a time, so just re-use those VectorLines for every solar system. You can use VectorLine.active to disable any VectorLines you're not using.

    --Eric
     
  32. look001

    look001

    Joined:
    Mar 23, 2017
    Posts:
    52
    I am impressed by your asset it is super usefull!
    I have a few questions i ran into:
    is it possible to use the VectorLine.Selected() Method for multi selection with a rectangular selection box? Do the points have colliders so i can somehow use a boxcast?
    also i noticed that the Selected() method outputs the index of the line point. However if i have multiple linepoints at the same spot (in my case mesh vertices) these points are merged to one single line point. Therefore the index of the linepoint won't match with the mesh vertex index. Is there a way around this without collecting the positions with all its vertex indices in a dictionary?

    Thank you for your patience!
     
  33. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
    There aren't any physics colliders involved, no. I mean, you can add a collider, but it's not used for Selected. You'd have to write your own method for that, since it's not possible with the existing methods, sorry.

    --Eric
     
  34. ChaosMage

    ChaosMage

    Joined:
    Sep 5, 2012
    Posts:
    14
    Is Vectrosity compatible with 2018.2? It looks like something is broken, at least with 3d lines.
     
  35. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
    I haven't seen any issues with 2018.2; everything seems compatible.

    --Eric
     
  36. zoltanBorbas

    zoltanBorbas

    Joined:
    Nov 12, 2016
    Posts:
    77
    Hi there!

    In my attempt to keep my hierarchy organized i am setting the parent of the line's rect transform, however when i want to start drawing the line upon calling the Draw3DAuto() function of the line the rect transform of the line that was previously tacked away is suddenly loosing its previously set parent and it is dragged under the root of the hierarchy.

    Is there any way for the line's rect transform to keep its set parent?

    Thanks!
     
  37. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
    Set the parent after using Draw3DAuto and the line has been created.

    --Eric
     
  38. PsycheMac

    PsycheMac

    Joined:
    Apr 15, 2013
    Posts:
    27
    Hello, Im having a bit of trouble sorting a 3d vectorline between sprites in an orthogonal view. I have the line in the same sorting layer and order as the sprites. Most of the sorting is done via the Transparency Sort Axis so that things that have a higher Y position are sorted behind. My main problem is I don't understand where the position of the 3d vectorline mesh is considered while Im drawing it. Im dynamically changing the length of the line along any given axis across the 2d orthogonal plane. If I stretch it out across the +Y, it seems the line's transparency sorting position increases on the Y axis. I know this because the line will start to sort behind sprites that it intersects though the starting points3 is lower on the Y axis compared to the sprites that are now sorting in front of the line.

    Is there any way to dictate where the 3d vectorline's transparency sorting origin is so that I can make sure it sorts correctly?
     
    Last edited: Jul 24, 2018
  39. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
    The position of lines is at the origin. You can try changing it with VectorLine.rectTransform, but keep in mind that isn't normally recommended.

    --Eric
     
  40. PsycheMac

    PsycheMac

    Joined:
    Apr 15, 2013
    Posts:
    27
    I tried both changing the position of the parent object which contains the vector line information and the SetLine3D object that gets created. Neither of these end up changing the transparency sorting. The only thing that seems to have an effect is changing the points3. The transparency sorting seems to do some sort of average of the vertices within the line mesh which dynamically changes its sorting as I redraw the line.

    EDIT: Im realizing now that changing the position of both is effecting it but it is still doing some sort of average of the line size/placement in space. This must be the SetLine3D rect transform. I guess Ill just have to figure out a way to change it's position via the Z axis to counteract dynamic size changes since I also look at Z for transparency sorting. Thanks for the help!
     
    Last edited: Jul 24, 2018
  41. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
    I'm afraid I don't really have an answer. If it's feasible, it's best to explicitly set the sorting order.

    --Eric
     
  42. PsycheMac

    PsycheMac

    Joined:
    Apr 15, 2013
    Posts:
    27
    Talking about it and seeing your answer has helped. This seems like a problem Ill have to solve with some creativity as Im realizing its probably just using the SetLine3D rect transform center which changes as I resize the line. Thanks for helping!
     
  43. Brian-Washechek

    Brian-Washechek

    Joined:
    Aug 5, 2015
    Posts:
    600
    A while ago I purchased Vectrosity and loaded it on my laptop, but currently I'm on my desktop. Let me guess: I'm out of luck.
     
  44. PsycheMac

    PsycheMac

    Joined:
    Apr 15, 2013
    Posts:
    27
    Alright for anyone who runs into this problem, I figured out that Unity's transparency sorting uses the 3d vector line's mesh.bounds.center to determine what position it is in space compared to other transparency objects. For some reason changing the bounds center does not do anything when placed after Draw3d(). I guess because the mesh.RecalculateBounds() when using Draw3d somehow executes later on. Im currently using the DLL's for Vectrosity but I may have to get the source code and stop the mesh bounds recalculation from happening.
     
  45. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
    It's not possible to have any form of copy protection for assets.

    --Eric
     
  46. Brian-Washechek

    Brian-Washechek

    Joined:
    Aug 5, 2015
    Posts:
    600
    ... Currently my laptop is somewhere else. A purchased version is loaded on my laptop and not my desktop. When it gets here can I use my laptop for reference and somehow get the serialized version working on my desktop so this doesn't happen again?
     
    Last edited: Jul 25, 2018
  47. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
    Go to the asset store window, find Vectrosity in your purchased list, click Import. Assets are not tied to specific machines in any way.

    --Eric
     
  48. sad-gopher

    sad-gopher

    Joined:
    Aug 1, 2018
    Posts:
    3
    Hi! I'm using vectrosity in external project, and everything was fine, but some "unknown" update happened on that external project. Its related to unity I think.

    After that update all my 3D lines are becames purple. My code did not changed. Why lines could be purple? Could you help to investigate the issue?

    This is my code (it works):
    Code (CSharp):
    1.  
    2.             LoadTextures();
    3.  
    4.             var line = new VectorLine("Line3D", new List<Vector3> {pointA, pointB}, _thinLine,
    5.                 width, LineType.Continuous, Joins.None) {color = color};
    6.  
    7.             UnitLogger.Warning($"Created line texture {_thinLine}");
    8.             UnitLogger.Warning($"Created line with color {line.color}");
    9.             line.Draw3DAuto();
    10.  
    Thats log output:
    20:11:22.883 [WARNING] Loading textures
    20:11:22.884 [WARNING] ThickLine (UnityEngine.Texture2D)
    20:11:22.884 [WARNING] ThinLine (UnityEngine.Texture2D)
    20:11:22.884 [WARNING] Created line texture ThinLine (UnityEngine.Texture2D)
    20:11:22.887 [WARNING] Created line with color RGBA(0, 0, 255, 255)

    I'm sure line texture is loaded, but line is purple. Where to find a problem?
    I attached an image with my line

    P/s: using latest Vectrosity version
     

    Attached Files:

  49. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,200
    Purple like that means a missing material/shader, so probably the DefaultLine3D material in Vectrosity/Resources was deleted.

    --Eric
     
  50. sad-gopher

    sad-gopher

    Joined:
    Aug 1, 2018
    Posts:
    3
    What is the best place to insert a Log method to check if material is OK ?
    somewhere in VectoObject3D LateUpdate?