Search Unity

Fast Line Renderer

Discussion in 'Assets and Asset Store' started by jjxtra, Apr 25, 2016.

  1. frederic-moulis

    frederic-moulis

    Joined:
    Jul 6, 2017
    Posts:
    17
    Hi, I would like to do two things I'm not sure how to do. I've got a scene where I need to draw many lines (various thousands). For that reason, I have to create them with a unique FastLineRenderer object (more precisely, I create lines of the same type with the same FastLineRenderer object, which makes me using less than 10 FLR objects). What I would like :
    • being able to modify the colour of a single line
    • being able to select a line via a mouse click, that is, being able to catch a click on a particular line.
    Is it possible to do this with this asset ?
    Thank you !
     
  2. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,041
    Yes to 1. For 2 you’ll need to write your own utility function.
     
  3. frederic-moulis

    frederic-moulis

    Joined:
    Jul 6, 2017
    Posts:
    17
    1. well, ok, so how do I do that ? The AddLine function does not return any object, so I do not know how to change the colour of one line without rewriting the thousand lines I've created with my FastLineRenderer object

    About 2. do you mean that there is for now no way to do a raycast and know which line is on the ray path ?
     
  4. MV10

    MV10

    Joined:
    Nov 6, 2015
    Posts:
    1,889
    I think he interpreted your question to mean, can you change the color when the line is created (to be different than the color in the FastLineRenderer component) -- that's how I read it, too. In that case you would set the Color property on the FastLineRendererProperties object that you pass into AddLine.

    However, you can't change them once they've been added, which is what it seems you're asking. When you're adding lines, the FLR scripts are generating 3D mesh data, and all those lines are really one giant mesh which is then rendered by a shader. There is no individual "line" to reference after it has been added. This is also why you have to call Apply when you're done adding -- it's all one big mesh and that wraps up the loose-ends.
     
  5. frederic-moulis

    frederic-moulis

    Joined:
    Jul 6, 2017
    Posts:
    17
    ok, that's what I imagined, but I was hoping I had missed something. Thank you !
     
  6. MV10

    MV10

    Joined:
    Nov 6, 2015
    Posts:
    1,889
    Since they're drawn in 3D, depending on your application and whether you're using things like glow or transparency, you might be able to keep one extra FLR around and use it to re-draw the differently-colored line closer to the camera (temporarily hiding the default-colored one). Worth a shot, maybe.
     
  7. frederic-moulis

    frederic-moulis

    Joined:
    Jul 6, 2017
    Posts:
    17
    well, no, that's not a solution, but thanks anyway :)
     
  8. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,041
    Yes you have to set the color when you create the line. Since it uses a mesh underneath, the only way to change a color is to recreate the mesh. Unity does not provide a way to quickly change a few vertices of a mesh (yet). Maybe send them a bug report or feature request if you want that.

    For #2, you have to do your own raycast, there is nothing built into the asset.
     
  9. matros

    matros

    Joined:
    Feb 1, 2014
    Posts:
    8
    @jjxtra
    Do you answer to mails sent to support email?
    I bought your asset and have been waiting for almost a week to get help with one severe issue I have faced.
     
  10. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,041
    Been dealing with influenza. I see the email and will respond when I can.
     
  11. westerthomas

    westerthomas

    Joined:
    Apr 4, 2013
    Posts:
    4
    @jjxtra Thank you for this great asset!

    Is there a way to control where the line segments face. Right now it looks like they always face the camera. I would like to create a "flat" line that is always aligned along a plane but at a loss on where to start.
     
  12. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,041
    There's currently no option to not billboard, but you could tweak the shader and comment out the billboard code. Let me know if you have trouble finding it. I'll add a future option to turn off billboarding.
     
  13. westerthomas

    westerthomas

    Joined:
    Apr 4, 2013
    Posts:
    4
    Thank you I found it.

    I modified the computeVertexOutput function in FastLineRendererShader. Replacing "directionToCamera.xyz" with the relevant vector in this line.

    float3 tangent = cross(dirNorm.xyz, directionToCamera.xyz);

    -T
     
  14. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,041
    Thanks so much for sharing!
     
  15. Beloudest

    Beloudest

    Joined:
    Mar 13, 2015
    Posts:
    206
    Are there tools in this asset for configuring splines in the editor with control points without having to configure within the inspector? I can't seem to see any?
     
  16. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,041
    Not currently. Inspector or a custom script is it right now.
     
  17. Beloudest

    Beloudest

    Joined:
    Mar 13, 2015
    Posts:
    206
    No problem really, the Asset is great and I can see why most folks might just code the line generation but it would be really helpful to have a tool to do it by eye quickly. For example you cant even paste transform positions of pre existing game objects into the list section of lines list in the inspector. The only way to really get the data in his to write the values down elsewhere on paper and then manually type the values back into the FLR script. I've ended up using another line tool to visualise what I'm doing and then coded a way to pass that to FLR but it was very far from ideal to work quickly.


    I have one more burning question! How I can I get a callback from the main script for when a line animation completes. I want to trigger more line generation when my animation finishes please? I can see the lifetime params but I can't suss where I could latch onto a completion event.

    It would also be fantastic if I could track the position of end of the end of line during the animation. Imagine a camera panning along as the line moves from point A to B with some light modification on my end?

    thanks again!
     
    Last edited: Jan 11, 2018
  18. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,041
    Easiest way is start a couroutine with a wait for seconds of the total animation duration
     
  19. Beloudest

    Beloudest

    Joined:
    Mar 13, 2015
    Posts:
    206
    Thanks, I've done this and it works pretty well. As for tracking the point on the line, I assume I have to track the time gone since started and then get the point on the path for that time. Thanks.
     
  20. Beloudest

    Beloudest

    Joined:
    Mar 13, 2015
    Posts:
    206
    I've just realised when I call a function to generate an animated line for a second time on the same line renderer the animation does not play over time it just creates the line instantly. Have I missed something, here is my function, do you know what I may be doing wrong? Do I need a new line renderer to start the animation correctly?

    EDIT:

    I just tried Instantiating a new instance of the line renderer gameobject I'm calling and the problem still persists with the second line generating having no animation. Out of curiousity I decided to change the animation time of the first line I create to 0, as soon as I did this my second line would then animate. To me it seems like the animationTime is not taking into account time before LineRenderer.Apply() is called - something like that anyway. It would be great if I can solve this, maybe its something in the shader.. thx

    Code (CSharp):
    1.     private void DrawArch(CurveConnection curve){
    2.  
    3.         List<Vector3> splinePoints = curve.points;
    4.         const float animationTime = 0.025f;
    5.         FastLineRendererProperties props = new FastLineRendererProperties();
    6.         props.GlowIntensityMultiplier = 0.5f;
    7.         props.Radius = 0.01f;
    8.         props.Color = UnityEngine.Color.white;
    9.         props.Start = new Vector3 (splinePoints [0].x, splinePoints [0].y, splinePoints [0].z);
    10.         props.End = new  Vector3(splinePoints[4].x, splinePoints[4].y, splinePoints[4].z);
    11.         Vector3[] spline = new Vector3[]
    12.         {
    13.             props.Start,
    14.             //new Vector3(splinePoints[0].position.x, splinePoints[0].position.y, splinePoints[0].position.z),
    15.             new Vector3(splinePoints[1].x, splinePoints[1].y, splinePoints[1].z),
    16.             new Vector3(splinePoints[2].x, splinePoints[2].y, splinePoints[2].z),
    17.             new Vector3(splinePoints[3].x, splinePoints[3].y, splinePoints[3].z),
    18.             //new Vector3(splinePoints[4].position.x, splinePoints[4].position.y, splinePoints[4].position.z),
    19.             props.End
    20.         };
    21.  
    22.         LineRenderer.AppendSpline(props, spline, 128, FastLineRendererSplineFlags.StartCap |          FastLineRendererSplineFlags.EndCap, curve.animationTime);
    23.         LineRenderer.Apply();
    24.         startTime = Time.time;
    25.         curve.lineComplete = StartCoroutine (curve.animationTimer (props.FullAnimationTime));
    26.         created = true;
    27.     }
     
    Last edited: Jan 11, 2018
  21. Beloudest

    Beloudest

    Joined:
    Mar 13, 2015
    Posts:
    206
  22. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,041
    In theory yes. I haven't gotten it to work like the new Unity line renderer billboard algorithm which is very good. If you have any ideas I am open to suggestions.
     
  23. Rotecks

    Rotecks

    Joined:
    Dec 17, 2014
    Posts:
    56
    Hi jjxtra!
    Does Fast Line Renderer support Long thin lines in 3D with texture mapping?
     
  24. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,041
    Yes, you can change the material and use your own texture.
     
  25. Rotecks

    Rotecks

    Joined:
    Dec 17, 2014
    Posts:
    56
    Hi jjxtra!
    I'm writing here because in private messages you do not answer.

    You confirmed earlier:
    I bought a "Fast Line Renderer", but I'm very disappointed. The "Fast Line Renderer" can not draw long, thin lines, the lines somehow change(spontaneously) their thickness and I sent you a link to the video. If the 3D line itself changes its thickness, then I bought the asset in vain.
     
  26. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,041
    Have you set the screen width multiplier by chance? Is it set to 0?
     
  27. Rotecks

    Rotecks

    Joined:
    Dec 17, 2014
    Posts:
    56
    What do you mean by "screen width multiplayer"? I think not, all settings are standard, the project is new.
     
  28. Rotecks

    Rotecks

    Joined:
    Dec 17, 2014
    Posts:
    56
    jjxtra, do you have any other suggestions about why the line itself changes its thickness?
     
  29. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,041
    The width parameter is not perfect, there are some fixes and optimizations that need to be done.

    Also, just FYI all I am having carpal tunnel surgery today. Going to take a few days off from everything, be back sometime next week.
     
  30. ISM3DVS

    ISM3DVS

    Joined:
    Feb 5, 2014
    Posts:
    10
    jjxtra,

    I am interested in this asset, but I'm wondering if it is possible to do what I'm thinking of.

    I want to draw lines from one object to another, having the short lines move in one direction.

    I'm not sure how to do this entirely, but hoping that this asset would make it easer.

    Thanks!
     
  31. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,041
    You can animate the lines easily. The demo scenes and script show how to do this.
     
  32. flyingaudio

    flyingaudio

    Joined:
    Dec 3, 2010
    Posts:
    89
    Does it work in VR?
     
  33. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,041
    It should work in VR, but not "single pass instanced" mode.
     
  34. tcmeric

    tcmeric

    Joined:
    Dec 21, 2016
    Posts:
    181
    Hi, hoping to buy this as a replacement for the trail renderer. Can it be used similarly?
     
  35. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,041
    Yes it can, you must manager each line segment each frame.
     
  36. Daniel-Talis

    Daniel-Talis

    Joined:
    Dec 10, 2011
    Posts:
    367
    I have a collection of spheres in 3D space. Can I use this asset to draw a line between each sphere and have them appear relatively the same when moving around and through the collection? Also, each sphere is at a particular coordinate, can the line be drawn exactly and easily between coordinates? Thanks.
     
  37. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,041
    Yes, you can specify exact coordinates. You can turn on a mode where it tries to keep lines the same width as well.
     
  38. antonsem

    antonsem

    Joined:
    Dec 13, 2012
    Posts:
    10
    TL;DR: Is there a way to save the generated mesh and reuse it in the runtime?

    Hi! I like the asset so far, however, I have a question. Can I save generated lines to a mesh and reload it on the next run. I need to draw the road network of a city in the Hololens so generating the lines in runtime is not an option. Here is what I tried so far;

    1. Cloning the mesh from lineRenderer.Mesh and saving it using AssetDatabase.
    2. Serializing the mesh to the byte array and saving it with File.WriteAllBytes.

    When I save the mesh as an asset I can see the preview in the inspector but I cannot find the mesh on the scene. Vertex positions seem to be correct, I checked them with Debug.DrawLine.

    Also when I try to assign a mesh to the lineRenderer.Mesh and call the Apply() function it gives the following error:

    Code (CSharp):
    1. Mesh.vertices is too small. The supplied vertex array has less vertices than are referenced by the triangles array.
    2. UnityEngine.Mesh:SetVertices(List`1)
    3. DigitalRuby.FastLineRenderer.FastLineRenderer:ApplyListsToMeshes() (at Assets/FastLineRenderer/Script/FastLineRenderer.cs:707)
    4. DigitalRuby.FastLineRenderer.FastLineRenderer:Apply() (at Assets/FastLineRenderer/Script/FastLineRenderer.cs:1895)
    5. <DrawArea>c__Iterator1:MoveNext() (at Assets/Scripts/TrafficDataManager.cs:178)
    6. UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
    7.  
    So is there a way to save the generated mesh and reuse it in the runtime?
     
  39. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,041
    You should be able to assign the mesh to a regular mesh renderer with fast line renderer material. Let me know if that works.
     
  40. antonsem

    antonsem

    Joined:
    Dec 13, 2012
    Posts:
    10
    Thanks for the answer. I tried that and it works :) But now when I try to load the saved mesh (which looks correct in the inspector) and assign it to the same meshFilter with the same material, individual line segments turns around their pivots. And also they are almost invisible and renders only agains lineRenderer's lines.
    Here is what I mean:
    lineRenderer.gif

    The lines below are from the LineRenderer and they are correct. The outlined line segments are from the mesh I loaded.

    Edit: Ok I solved the rotation problem by removing rotation from the shader but the loaded mesh is still invisible.

    Edit 2: Removing lerpFade method from the shader solved the invisibility problem. It seems like I can store colors of the mesh separately in a List<Color>. It does work now, but is there any other more straight forward way of doing this?
     
    Last edited: Jul 30, 2018
  41. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,041
    That's probably the easiest way for now. The rotation and fade should be optional, I will post an updated shader with keywords that can be turned off.
     
    antonsem likes this.
  42. midsummer

    midsummer

    Joined:
    Jan 12, 2017
    Posts:
    6
    I'm currently doing a project requires drawing a lot of randomly zig-zagging lines in 3D space (like roots or rhizomes). Unity's TrailRenderer more or less does what it needs to do, but performance drops very fast as the lines get longer and their number increases. I think the performance hit is caused by the large number of vertices in the scene (around 1 million, is that simply too much?), and not by rendering as such.

    Would Fast Line Renderer be of any help here? The lines I'm drawing are currently using a simple unlit Shader Graph material in the Lightweight Render Pipeline. The lines are long and thin, if that is of any significance?

    Thanks in advance.

    EDIT: Just went ahead and bought the asset. Let's see what happens...
     
    Last edited: Aug 2, 2018
  43. midsummer

    midsummer

    Joined:
    Jan 12, 2017
    Posts:
    6
    First hurdle encountered. When I add the FastLineRenderer component to an empty GameObject in my scene, I get a bunch of these errors. What could be causing this? The demo scenes do work (although I had to get rid of the Lightweight Render Pipeline for the lines to appear), and I can add the component to an empty GameObject in a new empty scene. I'm using Unity 2018.2.1f1.

    EDIT: I think I solved this. My camera simply didn't have the MainCamera tag.
     
    Last edited: Aug 2, 2018
  44. ziemlich3D

    ziemlich3D

    Joined:
    Aug 21, 2017
    Posts:
    21
    Hi,
    I bought your asset some time ago and now I wanted to use it in my current project, but discovered a problem using it with prefabs in Unity 2018.2.11f1 (don't know if other version are affected, too). If I save my prefab with the attached Script and drop it into the scene again (or instantiate it by code), then the material gets deleted. This is also reproducable with the prefabs you shipped with the asset. Just edit some parameters, safe it. remove it from the scene and finally drop it back into the scene again and the material is gone. I think it must be related to the serialization, because the original prefab has a material attached.
    Thanks for helping me out with this :)
     
  45. antonsem

    antonsem

    Joined:
    Dec 13, 2012
    Posts:
    10
    Yeah I'm having the same problem. As a workaround I'm assigning the material through the following script:

    Code (CSharp):
    1. using DigitalRuby.FastLineRenderer;
    2. using UnityEngine;
    3.  
    4. /// <summary>
    5. /// For some reason material on BusDataParser's FastLineRenderer doesn't
    6. /// want to stay there. This is a quick fix for that...
    7. /// </summary>
    8. [RequireComponent(typeof(FastLineRenderer)), ExecuteInEditMode]
    9. public class LineRendererMaterialFix : MonoBehaviour
    10. {
    11.     [SerializeField]
    12.     private Material mat;
    13.     [SerializeField]
    14.     private FastLineRenderer line;
    15.  
    16.     private void Awake()
    17.     {
    18.         if ((line || transform.SetComponent(out line)) && !line.Material)
    19.             line.Material = mat;
    20.     }
    21. }
    The SetComponent<>() part is the following "shortcut" method:

    Code (CSharp):
    1. public static bool SetComponent<T>(this Transform t, out T obj, bool needWarning = false) where T : Component
    2.         {
    3.             obj = t.GetComponent<T>();
    4.             if (obj == null && needWarning)
    5.                 Debug.LogError("Cannot find component " + typeof(T) + " on " + t.name);
    6.             return obj != null;
    7.         }
     
  46. ziemlich3D

    ziemlich3D

    Joined:
    Aug 21, 2017
    Posts:
    21
    Hey antonsem,
    thank you very much for your post! This is a much more "cleaner" way, as my workaround is actually. I'm editing the prefab with a texteditor and paste the material manually into it... had to re-paste it everytime a change was made to the prefab. So thanks for sharing your solution :)
     
  47. antonsem

    antonsem

    Joined:
    Dec 13, 2012
    Posts:
    10
    Glad that it worked for you, happy to help :)
     
  48. ziemlich3D

    ziemlich3D

    Joined:
    Aug 21, 2017
    Posts:
    21
    Hi all,
    I'm writing this lines, as I can't help myself out with the problem I encountered while using the asset in my current project. I discovered misscaling of the line-segment-ends with the line-joints in "adjust position" (other modes, too). If I spawn a GameObject at runtime and scale it below or above the standard (1.0,1.0,1.0) the line gets distorted. If the scale is below 1.0, then the line is "too short" about exact the amount of the scale. For example: Scale is 0.5 the line is only half way to close the gap to the next segment. If the scale is for example 2.0, then the line is exact one time over the limit to the next segment.
    You can see this from the screenshots I made, as describing this problem isn't that easy :(

    At scale 1.0,1.0,1.0 all is fine
    FLR_01.JPG

    Scale 0.5,0.5,0.5 it is "too short" to bridge the gap to the next segment
    FLR_02.JPG

    Scale of 2.0,2.0,2.0 makes it "overshoot" the gap to the next segment
    FLR_03.JPG

    How could I solve this? I know my problem is related to the scale-change of the GameObject at runtime, but I can't find a method to recreate the line using the current scale to fix the issue or a checkbox to do this automatically.
    Does anybody know how to fix this or has encountered the same problems?
     

    Attached Files:

  49. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,041
    I'm not sure this will work out of the box without some bug fixes, so email me the order number and I will refund.
     
  50. hecali_aj

    hecali_aj

    Joined:
    Sep 1, 2015
    Posts:
    3
    Hello, Jeff! I bought the asset and I'm currently having problems making it work on the lightweight renderer. Can you help me?