Search Unity

  1. Click here to see what's on sale for the "Best of Super Sale" on the Asset Store
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Vectrosity - Fast and Easy Line Drawing

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

  1. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,264
    What version of Unity are you using? As far as I'm aware it shouldn't be possible for GameObjects created in play mode to persist afterwards. I'm not able to get that to happen here.

    --Eric
     
  2. crazymonkay

    crazymonkay

    Joined:
    Apr 1, 2013
    Posts:
    120
    Oh, whoops... I still had the ExecuteInEditMode attribute on my script from when I was using GL.Lines to draw my grid :eek:. My bad.
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,264
    Oh, well, actually that's good because there's a reasonable explanation (and easy solution). :)

    --Eric
     
  4. DenisM

    DenisM

    Joined:
    Dec 6, 2013
    Posts:
    62
    Why 3d lines change their width, when camera change distance from them?
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,264
    They don't, they keep a constant pixel width. That's the idea of Vectrosity, so you can do things like orbit lines (e.g. Kerbal Space Program) effectively.

    --Eric
     
  6. DenisM

    DenisM

    Joined:
    Dec 6, 2013
    Posts:
    62
    When moving camera, mesh of line is changing like object but in camera view stay the same size compare to viewport. So if i want my lighting bolts stay the same like other objects i need to decrease line width when camera go away?

    512.jpg

    So to fix this i need to change width when zoom or resolution change?

    widthLine = Screen.width / 1280.0f * CameraFar.

    Right?

    5123.jpg


    What else should i change if resolution or zoom change? What about texture tiling and offsets, texture size etc? Do i need to care about this also if resolution changed?
     
    Last edited: May 14, 2016
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,264
    Yes, as mentioned the idea of Vectrosity lines is they have a constant pixel width, so if you are in a situation where you want the width to change, you'd need to recalculate it.

    --Eric
     
  8. andyland

    andyland

    Joined:
    Nov 2, 2013
    Posts:
    2
    What will it take to implement Vectrosity in a game using Google Cardboard? I've been trying to get the TankZone demo to work with Cardboard, but I can't seem to "draw" lines into the stereo cameras. What am I missing here? Is combining the two non trivial?

    Apologies if this has been asked before, but I couldn't find anything by searching the forum.

    Any help would be appreciated. thanks!
     
  9. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,264
    With two cameras, you can use SetCamera3D with one camera, draw the line(s), use SetCamera3D with the other, and draw lines again. This should be repeated every frame. It would be non-trivial for the TankZone demo, since it wasn't created with that in mind.

    --Eric
     
  10. MythicalCity

    MythicalCity

    Joined:
    Feb 10, 2011
    Posts:
    410
    Hi, I'm trying to make my dotted line work but the dots (dashes) dance around when I move the camera and the in some lines they also stretch at closer zoom levels:
    https://gyazo.com/8d5ddb62a8d370b03090f2a119b97f83

    I have tried both making the line using Draw3DAuto and just using a regular 2d Draw command in the update function, but they both exhibit similar effects.

    My code is:
    Code (CSharp):
    1. List<Vector3> borderPoints = new List<Vector3>();
    2.         borderPoints.Add(new Vector3(-CameraControlManager.Instance.gameMapXLimit, 10f, -CameraControlManager.Instance.gameMapZLimit));
    3.         borderPoints.Add(new Vector3(-CameraControlManager.Instance.gameMapXLimit, 10f, CameraControlManager.Instance.gameMapZLimit));
    4.         borderPoints.Add(new Vector3(CameraControlManager.Instance.gameMapXLimit, 10f, CameraControlManager.Instance.gameMapZLimit));
    5.         borderPoints.Add(new Vector3(CameraControlManager.Instance.gameMapXLimit, 10f, -CameraControlManager.Instance.gameMapZLimit));
    6.         borderPoints.Add(new Vector3(-CameraControlManager.Instance.gameMapXLimit, 10f, -CameraControlManager.Instance.gameMapZLimit));
    7.         borderLine = new VectorLine("Border", borderPoints, borderMaterial.mainTexture, 20f, LineType.Continuous);
    8.         borderLine.textureScale = 1f;
    9.         borderLine.layer = Globals.Instance.layerVectrosity;
    10.         borderLine.material = borderMaterial;
    11.         borderLine.Draw();
     
  11. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,264
    That's intended behavior, since VectorLines have a constant pixel width. Setting textureScale to 1 means the UVs have to be recalculated if the line changes on-screen. For what you're doing, you should use a material where you set the tiling as desired.

    --Eric
     
  12. MythicalCity

    MythicalCity

    Joined:
    Feb 10, 2011
    Posts:
    410
    Do you have a suggestion in that case for what to set the textureScale to? or the tiling in the material? I tried changing the material tiling but it doesn't seem to have any effect. The material is using the Dash texture included in vectrosity and the UnlitAlphaOverlay shader.
     
  13. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,264
    The point is that you wouldn't use textureScale at all. What to use for the tiling in the material depends on what you want it to do exactly. Make sure the shader is capable of using tiling; I tried Unlit/Texture and it seems fine.

    --Eric
     
  14. MythicalCity

    MythicalCity

    Joined:
    Feb 10, 2011
    Posts:
    410
    Ok, I tried turning off the texturescale line and set the shader to UnlitTexture but this is how it looks. I just want it to look like in my gif with the yellow dashes that stay consistent.
     

    Attached Files:

  15. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,264
    Did you set the texture for the line as well as the material?

    --Eric
     
  16. MythicalCity

    MythicalCity

    Joined:
    Feb 10, 2011
    Posts:
    410
    borderLine =new VectorLine("Border", borderPoints, borderMaterial.mainTexture, 20f, LineType.Continuous);

    I used the texture from the material reference and also set the material afterwards as per my code sample above. Is that the correct way of doing this?
     
  17. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,264
    Yes, I tried that and it works fine.

    Screen Shot 2016-05-20 at 12.48.03 PM.png

    --Eric
     
  18. MythicalCity

    MythicalCity

    Joined:
    Feb 10, 2011
    Posts:
    410
    So.. how do I fix it on my end? Why is it showing up as a solid line when I set the tiling?
     
  19. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,264
    I'm not really sure. Does it work if you set the tiling to 1?

    --Eric
     
  20. MythicalCity

    MythicalCity

    Joined:
    Feb 10, 2011
    Posts:
    410
    Changing the tiling to any value doesn't make any difference, it's always a solid line. I also tried to change the import setting on the included dash texture to use alpha as transparency but that didn't do anything either. I tried changing to other textures like the dots, still nothing.

    I am also using a separate camera to render the vector lines that is parented to the main camera.
     
  21. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,264
    Unlit/Texture doesn't use transparency. You would need to use a shader that uses transparency; also make sure the texture is set to repeat and not clamp.

    --Eric
     
  22. MythicalCity

    MythicalCity

    Joined:
    Feb 10, 2011
    Posts:
    410
    Right, but you said that Unlit/Texture worked for you, so that's why I used it. I've tried other shaders like unlit transparent, unlit alpha, mobile particles, etc. none of them tile. Yes the import setting is set to repeat on the texture. Here are my settings once the lines are created. No matter what the shader or tiling it will only stretch the texture across the line. The shader only makes a difference with the color of the line and the transparency.
     

    Attached Files:

  23. MythicalCity

    MythicalCity

    Joined:
    Feb 10, 2011
    Posts:
    410
    Update: I tried rendering it with draw3DAuto and now the tiling works (regular 2D draw doesn't seem to tile), but it's back to the same issues as using the texturescale where the texture gets very skinny to the point of being invisible:
    https://gyazo.com/6371a6ffed30f077f1fa57e9feffd811
     
  24. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,264
    It works fine here with Draw as well as Draw3D, but I'm starting to think you're attempting mutually exclusive things. Since the design of Vectrosity is to keep the line width the same always, something has to give with the texture when you zoom. Perhaps for this you'd be better off with a static mesh.

    --Eric
     
  25. MythicalCity

    MythicalCity

    Joined:
    Feb 10, 2011
    Posts:
    410
    I'm not clear on how the line width stays the same when zoomed out it takes up 10pixels and zoomed in it takes 1 pixel and then completely disappears when I zoom in more. Shouldn't the lines look the same no matter what the zoom level is?

    Would it be possible to give me some step by step instructions on how you were able to achieve tiling and a consistent line width?
     
  26. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,264
    The line is always 10 pixels; remove the texture and you'll see that more clearly. The issue is trying to combine tiling with a consistent line width, which as I mentioned are two incompatible things, assuming you still want the texture to not move. What you seem to need is for the line width to not stay the same, hence the suggestion of using a static mesh instead.

    --Eric
     
  27. MythicalCity

    MythicalCity

    Joined:
    Feb 10, 2011
    Posts:
    410
    So dashed lines are impossible in Vectrosity if you want them to not jiggle around and you want to be able to zoom in/out?
     
  28. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,264
    Yes, think about what happens when a line width is maintained at e.g. 10 pixels, and the length of the line (on-screen) changes. As I said, you're asking for contradictory things. You can do one, or the other, but not both. Not really specific to Vectrosity per se.

    --Eric
     
  29. Exuro89

    Exuro89

    Joined:
    Mar 31, 2015
    Posts:
    2
    Apologies if this has been asked. I just found out about this software a few days ago and have just now been researching it.

    Are you able to lerp colors on a single segment? I think I see it in the Scribblecube demo but wanted to be sure.

    Also how feasible is it to imitate single sided wireframes? I really love the look of the tank zone, and it's something I want to try out in VR, but I'm possibly interested in only drawing lines that would be visible to me for solid objects. So example, in the X-ray demo we see edges of the cubes and sphere, but say I only want to see the lines that contribute to the front face and the sides that are visible. Then if the sphere is rotated the edges that are no longer visible have their lines removed/modified and vice versa for new visible edges.

    If both of these are easily doable then I'll pick this up after work. I've been using wireframe shaders(I have the ability to use both single and double sided views though which is nice) but always hated having to draw the two triangles in "quads" that would give flat surfaces a diagonal line and this looks like the right way to get the look I'm going for.

    Thanks!
     
  30. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,264
    There's no hidden line removal, and I don't know what would be involved in implementing that, sorry. You can fake it if you're using a solid-colored background by using an object that's the same color as the background, and making a 3D wireframe over that. This way the object occludes the wireframe:

    Screen Shot 2016-05-23 at 12.39.38 PM.png

    In other words, there's an actual cube there in addition to the VectorLine. The scribblecube demo uses a single color per line segment, but there's an option to set smoothColor = true for a line, in which case the line segment colors are blended.

    --Eric
     
  31. Exuro89

    Exuro89

    Joined:
    Mar 31, 2015
    Posts:
    2
    That looks good enough for me. I actually bought it before your post and am messing around with it. I'm in the linemaker section trying to make lines from one of the given meshes, but I'm sort of confused by how to use it. It says in step 2 to choose LineMaker from the Assets menu after the object is selected, so I had to search for LineMaker in the project and theres a single file with the name and I'm not sure what it is, but double clicking it just brings up the dll. Could you clarify this? I'm not sure where LineMaker is supposed to be.

    edit: Nevermind I'm dumb. I don't use assets that often as you may tell. >_>
     
  32. Freaking-Pingo

    Freaking-Pingo

    Joined:
    Aug 1, 2012
    Posts:
    308
    I am in need of a bit of assistance.

    We are trying to render a set of 3D lines in the editor scene for level design purposes. We can see that the lines are being created but nothing is being rendered. We can see that their colliders are being created but the meshfilter is empty.



    When selecting the meshfilter of a single line, there are no verts or tris to be shown.



    We use the following code. The code is executed once in a Monobehaviour script using the [ExecuteInEditMode] tag. Note that the same code is used to render the same lines during runtime, and there it works like a charm:
    Code (CSharp):
    1.         for (int i = 0; i < pathPoints.Length - 2; i += 2)
    2.         {
    3.             VectorLine line = new VectorLine("pathLine", new List<Vector3>(3 * POINTS_PER_PATH_POINT), 3, LineType.Continuous, Joins.None) {collider = true, trigger = true };
    4.        
    5.             /* GENERATE POINTS */
    6.  
    7.             lines[lines.Count - 1].color = new Color(Random.Range(0.2f, 1f), Random.Range(0.2f, 1f), Random.Range(0.2f, 1f));
    8.             lines[lines.Count - 1].MakeCurve(points);
    9.             lines[lines.Count - 1].Draw3D();
    10.         }
    Some code have been omitted for the sake of clarity
     
    Last edited: May 24, 2016
  33. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,264
    I'm sorry but 3D lines aren't supported in edit mode at this time, only 2D lines. For editor level design purposes, I'd recommend using gizmos. e.g. Gizmos.DrawLine etc.

    --Eric
     
  34. Freaking-Pingo

    Freaking-Pingo

    Joined:
    Aug 1, 2012
    Posts:
    308
    I haven't really dived into the source code as of yet, but how much tinkering do you expect it requires before that is possible? Would it require a complete overhaul of the internal system, or should it be possible?
     
  35. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,264
    I haven't looked into it so I can't really offer anything useful, sorry.

    --Eric
     
  36. Freaking-Pingo

    Freaking-Pingo

    Joined:
    Aug 1, 2012
    Posts:
    308
    I looked into the source code, and it appears that 3D Vectors are dependent on the LateUpdate function from Monobehaviour. By adding the [ExecuteInEditMode] tag on VectorObject3D, I can render the lines within the editor.



    Next step for me, is to get the line to render, when I modify each point.
     
  37. Slowin

    Slowin

    Joined:
    Mar 6, 2015
    Posts:
    60
    Hi,

    I have a problem with drawTransform in conjunction with Get3DPoint01().

    I create my line like this:

    VectorLine path = new VectorLine("Spline", new List<Vector3>(60+1), null, 2.0f, LineType.Continuous);
    path.MakeSpline (points.ToArray(), 60, true);
    path.SetWidth (6.0f);
    path.drawTransform = gameObject.transform;
    path.Draw3DAuto();

    Then I update an object following the path like this:

    transform.position = path.GetPoint3D01 (distance);

    My problem is that drawTransform is affecting the line (which is drawn correctly), but not the positions I get from GetPoint3D01 (the position is off and there is no rotation).

    Is this a bug or am I doing something wrong?
     
  38. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,264
    Sorry about that, the code I have for handling drawTransform would only work for non-rotated transforms, which is dumb since I definitely knew better than that. You can fix this now by using the source code, and in the GetPoint3D function in the VectorLine script, in the "if (m_drawTransform) {" part, change it to:

    Code (csharp):
    1.         if (m_drawTransform) {
    2.             point = m_drawTransform.localToWorldMatrix.MultiplyPoint3x4 (point);
    3.         }
    --Eric
     
  39. recon0303

    recon0303

    Joined:
    Apr 20, 2014
    Posts:
    1,634
    Hi, I have not used this in for ever, I needed to use, so I wanted to brush up a bit, so I went to down the demo's and the tank one is full of errors i DELETED and re-imported a few times, same issues..

    Is there a fix ? SO I can check out the demo's?


    EDIT:

    I have not used this in about 2 years but soon as I installed this it was fine, soon as I tried to download the demo's I got a ton of errors, and then Unity crashed and locked up many times, I tried to reboot, it keep doing it...Once un-installed Vectrosity, it keep coming back.. So look like folders went inside some of my other assets, which was odd.... Never seen that with any asset before, I own a far amount of assets...

    Then one of my other assets broke after this happen, it no longer would work properly... So I thought that was odd... SO I made a new scene, with Vectorsity and my other asset and it crashed again... They have nothing to do with one another, so surprised it was doing this.. If I have the other asset with out Vectorsity it has been fine... So Vectrosity demo's seem to hate me and caused me to lose some work.

    Sounds like one of the DLLs or assemblies is no longer valid or accessible. after I did installed the demo's for this asset.... So is there a known bug that your aware of??


    I'm going to try in a fresh file, by itself and see what is going on...
     
    Last edited: May 29, 2016
  40. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,264
    There aren't any bugs like that; all of the demos work fine. Just make sure you're importing demos appropriate for the version you have. i.e. Vectrosity 5 demos won't work with Vectrosity 4, and vice versa.

    --Eric
     
  41. gheeler

    gheeler

    Joined:
    Nov 7, 2012
    Posts:
    18
    Im creating vectorlines in code with
    Code (CSharp):
    1. VectorLine vl = VectorLine.SetLine3D(...)
    How do I access the vectorline's gameObject or transform so I can set a parent? My hierarchy is a mess of lines at the moment.

    Also, with 'ThinLine' texture applied to the material in the Vectrosity/Resources folder my lines still don't have the material when using the default material, do I have to set the texture in code?

    Then when applying colours to a VectorLine I have to set the material colour. vl.SetColor doesn't work for me.

    NB these are all 3d lines.
     
    Last edited: May 31, 2016
  42. ok_remi_ok

    ok_remi_ok

    Joined:
    Sep 16, 2014
    Posts:
    7
    Hello,
    Is it possible to set the collider to true only for a segment of a line?
     
  43. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,264
    VectorLine.rectTransform.SetParent

    Yes, VectorLine.texture, or specify the texture when creating the line.

    As noted in the docs, VectorLine colors require a shader that does vertex colors.

    No, but you could make a separate VectorLine that has one segment, and use a collider for that.

    --Eric
     
  44. ok_remi_ok

    ok_remi_ok

    Joined:
    Sep 16, 2014
    Posts:
    7
    Thank you!
    To make another line is not very convenient as I use Joins.Weld for the line but I will find a workaround!
     
  45. Meceka

    Meceka

    Joined:
    Dec 23, 2013
    Posts:
    380
    Hello, I am right now drawing a 3D map with vectrosity's vectorline. But line width option makes it get complicated as it only sets width based on pixel. I couldn't find a world side width option.

    We need a constant width for the line in world size. In example, when I set world size width to 10m, it should be 10 meters width for the line. independent from the camera's distance. Is it possible to do this with vectrosity?

    If it's not possible, is there a workaround?
     
  46. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,264
    It's not possible with Vectrosity; you probably want to use the Unity LineRenderer component.

    --Eric
     
  47. Meceka

    Meceka

    Joined:
    Dec 23, 2013
    Posts:
    380
    I tried Unity LineRenderer and it didn't work. Thank's anyway, I will try to find a workaround to width problem.

    I have another problem, it's about sorting of 3d navlines (Vector Object 3D). I have a camera that looks top-down to act as a minimap camera. I have two 3d vectorlines. They are drawn on top of each other, and to draw shorter line on top, I made it's points3d higher. It looks good on scene view and game view cameras, but on top-down minimap camera, longer vectorline always renders on top.

    I tried exaggerating the difference between meshes by modifying their rect transforms. Whatever I do, longer one always renders on top on that camera. Happens the same on both perspective and orthographic. I tried changing material, changing clipping planes, distance of camera, etc.

    Do you have any idea why this happens? Thanks.
     
  48. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,264
    Probably the shader you're using doesn't do z sorting.

    --Eric
     
  49. rahuxx

    rahuxx

    Joined:
    May 8, 2009
    Posts:
    538
    can it be used to create animation like writing on a black board?
     
  50. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,264
    Yes; probably the easiest way would be to draw the complete set of points, initially all transparent, and set the line segments to non-transparent over time.

    --Eric
     
unityunity