Search Unity

Vectrosity - Fast and Easy Line Drawing

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

  1. iivo_k

    iivo_k

    Joined:
    Jan 28, 2013
    Posts:
    314
    I know how it works, that's why I asked. :)
    I have purchased Vectrosity and used it in places where I was going to do everything from scripts anyway and it was fine for that. Now however I just wanted add some quick line graph in an UI panel and it was much simpler to just attach a script that's inherited from MaskedGraphic and draws lines between points in OnFillVBO. It's visible in edit mode, too. Compared to that, the way Vectrosity works feels a bit convoluted and dated.

    Edit: Of course the lines drawn by the simple script don't look good at all, which is why it would be great if Vectrosity could be used like that.
     
  2. wbl1

    wbl1

    Joined:
    Apr 22, 2009
    Posts:
    159
    Using "Selected" function ... I assume there is some built in tolerance to determine if a line is selected. Is there a way to get the exact point on the line that is selected? So, if you have a discrete line, for example, the returned point could be proven (mathematically) to be on the line?
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    There's no way to get the exact point, but if you don't use extraWidth, then there's no tolerance, and therefore Selected returning true means the point mathematically must be on the line.

    --Eric
     
    wbl1 likes this.
  4. wbl1

    wbl1

    Joined:
    Apr 22, 2009
    Posts:
    159
    Can you control the depth of Vectrocity lines relative to UI items? For example, I have a UI Image and vectrocity lines in the same scene. The vectrocity line is drawn on top of the UI image seemingly regardless of which one is first in the hierarchy.
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
  6. Rikrok

    Rikrok

    Joined:
    Apr 11, 2013
    Posts:
    50
    I'm not adding/removing points though, I'm changing ones I already have. Clear then add is the only way I've found of doing this.

    On another note, I've started having an issue where most of my lines are not moving when I build the game, though they work fine when running in Unity. Any ideas what could be causing that?
     
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Don't use Clear; that rebuilds the line and slows things down. Just change existing points. If you used a list when creating the line, then VectorLine.points3 is a reference to that list, so you can use the original list, otherwise use VectorLine.points3.

    As for the other question, Vectrosity works the same in a build as in the editor, so I'd guess you have some behavior that depends on the editor.

    --Eric
     
  8. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I think the code in the existing Spline example is about as stripped down as it gets:

    Code (csharp):
    1.         for (var dist = 0.0; dist < 1.0; dist += Time.deltaTime*speed) {
    2.             cube.position = line.GetPoint3D01 (dist);
    3.             yield;
    4.         }
    --Eric
     
  9. SupremeBeing

    SupremeBeing

    Joined:
    Jun 28, 2013
    Posts:
    7
    Hi there
    Is there a way to draw part of a spline? I tried copying part of the points3 array and making a new spline but since the end point is different the curve is slightly different from the original. I want to gradually draw a spline over time starting at first point and ending at last one.
    Thanks.
     
  10. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You could change the color of the unwanted segments of the spline to 100% transparent.

    --Eric
     
  11. Maxter

    Maxter

    Joined:
    Mar 9, 2013
    Posts:
    7
    Having problem with line width. Game is 2D with Orthographic camera.
    I create a line using the following code
    Code (CSharp):
    1.     PreviewPathLine = new VectorLine("PreviewPath", new List<Vector3>(), PreviewPathMaterial, 4.0f);
    2.     PreviewPathLine.points3.Add(Vector3.zero);
    3.     PreviewPathLine.points3.Add(Vector3.zero);
    4.     PreviewPathLine.capLength = 2.0f;
    5.     PreviewPathLine.active = false;
    6.     PreviewPathLine.textureScale = 2.0f;
    After that each Update() I re-draw the line (to keep up with mouse position)
    Code (CSharp):
    1. // ... somewhere inside Update()
    2. PreviewPathLine.active = true;
    3. PreviewPathLine.points3[0] = myTransform.position;
    4. PreviewPathLine.points3[1] = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    5. PreviewPathLine.Draw3D();
    Problem: When I zoom in (by changing camera's "size" property), the line width shrinks relatively to every other object. I understand that this is default behavior but I want the line to be of consistent size in world space, not screen space.
    Is there an easy way to achieve that? I really don't want to do something like width *= maxCameraSize / currentCameraSize. It looks ugly :/
     
    Last edited: Jul 3, 2015
  12. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Vectrosity was designed as a vector line utility, where line width is measured in pixels, so there isn't any built-in functionality to use world space width.

    --Eric
     
  13. Rikrok

    Rikrok

    Joined:
    Apr 11, 2013
    Posts:
    50
    Ah I see, I was being silly and didn't realise points3 was like a normal list and I could use VectorLine.points3.

    My other problem turned out to be I had moved the line set up stuff to awake instead of start, worked in the editor not in the build for whatever reason.
     
  14. docsavage

    docsavage

    Joined:
    Jun 20, 2014
    Posts:
    1,021
    Just left a review on the asset store page. No point repeating it but really happy bought this when I did. Fantastic work.

    Only thing I think could be added is if you implemented some drag and drop type inspector and prefab system to enable quicker changes that could be seen immediately in scene view and game view without having to test via code. It would also allow easy experimentation with some of the features that are waiting to be used and make it easier for more non coders.

    Thanks again
     
    hopeful likes this.
  15. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Well, I will say that Vectrosity 5 is in the works for various reasons (including Unity 5.2 compatibility).

    --Eric
     
    docsavage likes this.
  16. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Hi Eric,

    After playing GTA5 at length, I notice most objects from fencing to electricity pylons, to bridges have a robust line renderer included in the final LOD, and it got me thinking about Vectrosity, how it can be extended for better LOD rendering of 3D meshes.

    For example a pirate ship will probably go to pieces at a distance with the rigging and ropes becoming pixelated garbage. Enter a LOD which includes Vectrosity wire rendering, so we can guarantee a thickness even at large distances, and simply fade these out gracefully when it no longer makes sense to render thin things. So level of detail isn't just about reducing detail, it's about maintaining detail, and I think Vectrosity can really help here.

    My game will need ziplines, cover many of the above cases. In my tests, meshes can't ever handle it but line rendering can.

    I just wondered what your thoughts were about this process, and if it's worth noting anything since I haven't touched Vectrosity for a few years!
     
    hopeful likes this.
  17. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    That's a good question. I'll have to think about that, and see if there's some way to incorporate that in a way that makes sense.

    --Eric
     
  18. docsavage

    docsavage

    Joined:
    Jun 20, 2014
    Posts:
    1,021
    Didn't know about Vectrosity5. 4's great and comprehensive so will be interesting to see what you implement.

    I have just been learning about crossfadealpha for a fade in script I need. I will be trying to use this with Vectrosity when I get chance. Do you think it's will work and be efficient or am I going down a dead end?

    Thanks Eric5h5
     
  19. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    CrossFadeAlpha wouldn't do anything currently; you can change the line color's alpha value over time instead (VectorLine.color).

    --Eric
     
  20. docsavage

    docsavage

    Joined:
    Jun 20, 2014
    Posts:
    1,021
    Good to know. I will try the lines alpha value.

    Thanks for the info Eric5h5
     
  21. Vandell

    Vandell

    Joined:
    Jan 7, 2013
    Posts:
    4
    I'm trying to create a increasing width line but I idon't know why this exception is happening.

    >> points 2. widths 1
    >>
    VectorLine.SetWidths: Length of line widths array for "Drop Trail" must be length of points array minus one for a continuous line (one entry per line segment)
    UnityEngine.Debug:LogError(Object)
    Vectrosity.VectorLine:WrongArrayLength(Int32, FunctionName)
    Vectrosity.VectorLine:SetWidths(Single[], Int32[], Int32, Boolean)
    Vectrosity.VectorLine:SetWidths(List`1)
    <DoGoToIndexAnimation>c__AnonStorey9:<>m__E() (at Assets/Scripts/UI/DropsAnimator.cs:149)
    DG.Tweening.Tween:OnTweenCallback(TweenCallback) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Tween.cs:267)
    DG.Tweening.Tween:DoGoto(Tween, Single, Int32, UpdateMode) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Tween.cs:242)
    DG.Tweening.Core.TweenManager:Update(UpdateType, Single, Single) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Core/TweenManager.cs:391)
    DG.Tweening.Core.DOTweenComponent:Update() (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Core/DOTweenComponent.cs:50)

    I'm sure that that the number of widths is corret because I'm logging it just before calling SetWidths. But I'm using a list of floats, could that be the problem?
     
  22. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    How many points are in the line, and what is the length of the widths array? As the error says, for a continuous line, there needs to be one entry per line segment (note: not per point...for a continuous line, if the number of points is n, then the number of segments is n-1).

    --Eric
     
  23. Dazzid

    Dazzid

    Joined:
    Apr 15, 2014
    Posts:
    61
    Hi!

    I have some problems deleting lines.
    In my code you can see that the lines are created inside a List which are a bunch of dot connections.
    But if I try to delete them I have errors with the "ref"


    Code (CSharp):
    1.     for (int i = 1; i <= gm.Nodes.Count; i++) {
    2.             Material line_material = new Material (Shader.Find ("Custom/cBasic"));
    3.             //line_material.SetFloat("_Mode", 0);
    4.             //line_material.renderQueue = 3000;
    5.             Color lineColor = new Color (gm.Nodes [i].myColor.r, gm.Nodes [i].myColor.g, gm.Nodes [i].myColor.b, 0.01f);
    6.             line_material.SetColor ("_Color", lineColor);
    7.             line_material.SetFloat ("_Glossiness", 0.01f);
    8.             line_material.SetColor ("_EmissionColor", lineColor);
    9.          
    10.             List<Vector3> nodeArray = new List<Vector3>();
    11.             //Debug.Log ("array: " + gm.Nodes [i].EdgesTo.Count);
    12.             for (int j = 0; j < gm.Nodes [i].EdgesTo.Count/4; j++) {
    13.                 nodeArray.Add(new Vector3(gm.Nodes [i].currentCoordinates.x, gm.Nodes [i].currentCoordinates.y+0.5f, gm.Nodes [i].currentCoordinates.z));
    14.                 Vector3 nodePos = gm.Nodes [gm.Nodes [i].EdgesTo [j].NodeTo].currentCoordinates;
    15.                 nodeArray.Add(new Vector3( nodePos.x, nodePos.y+0.25f, nodePos.z)) ;
    16.             }
    17.             myLine.Add (new VectorLine ("name_" + i.ToString (), nodeArray, line_material, gm.Nodes[i].totalWeight*0.1f, LineType.Discrete, Joins.None));
    18.         }
    I try deleting only some lines with this code:
    Code (CSharp):
    1. VectorLine destroyThis = myLine[0];
    2. VectorLine.Destroy (ref destroyThis, gameObject);
    But it gives me a nullReference
     
  24. Dazzid

    Dazzid

    Joined:
    Apr 15, 2014
    Posts:
    61
    OK! Sorry. It is even more easy than I thought.
    VectorLine.Destroy (myLine);

    That's all!
     
  25. socoman3

    socoman3

    Joined:
    Jan 31, 2014
    Posts:
    19
    Hello Eric!

    I see that 3D lines interact well (visually) with 3D objects in scene. However, between multiple 3D lines, it seems like they interact in 2D mode. I'm just getting to know the limitations of this software, I hope you can help me with this.

    For example, I have 2 cubes made with a VectorLine, and then applied to gameObjects with VectorManager. These are cube gameObject number 1 in red color, and cube gameObject number 2 in blue.

    Then these cubes are changing their position in relation to the camera at runtime, so first, cube 1 is closer to the camera than cube 2, and then, cube 2 is closer to the camera than cube 1.

    I recently discovered that the order of the cubes to be drawn is determined by its drawDepth in VectorCanvas3D. So all lines of a cube are always overlapping all lines of the other cube, am I right?
    If this is true, Is there at least a way to have the position cube affect it's drawDepth while at runtime? So when they change positions they also change the order in which are are drawn?

    I hope my question is understandable... Thanks!
     
  26. davebutlerenator2

    davebutlerenator2

    Joined:
    Nov 8, 2014
    Posts:
    26
    Can you estimate how many lines this can draw on an average machine before it starts to slow down? I'm looking to draw something on on the order of 30,000 lines.
     
  27. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Correct.

    You'd have to add some kind of sorting function yourself, which sets drawDepth appropriately.

    Lines, or line segments? 30,000 lines would be too much for any machine; 30,000 line segments is probably fine. It also depends on what you're doing, since re-drawing every frame is quite a bit slower than drawing once.

    --Eric
     
  28. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    889
    Would it be possible to draw anti-aliased lines into a EditorWindow (inspector window) with your asset?

    Kind regards,
    Q
     
  29. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    No, that would require use of the OnGUI system and Vectrosity works with the new UI system.

    --Eric
     
  30. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The last (probably, aside from potential bugfixes) Vectrosity 4 version is out, featuring the MakeRoundedRect function:

    Screen Shot 2015-07-19 at 7.25.14 PM.png

    Vectrosity 4.3

    Additions:
    • VectorLine.MakeRoundedRect function, which is like MakeRect but has rounded corners with a user-defined radius and number of segments.
    • VectorLine.is2D property, which returns true if the line was made with Vector2 points.

    Changes:
    • VectorLine.SetColors and VectorLine.SetWidths can be called before Draw/Draw3D.

    Fixes:
    • Fixed case where the canvas name could be incorrect when using VectorLine.canvasID with Draw3D.

    The next version will be Vectrosity 5.0.

    --Eric
     
    docsavage and hopeful like this.
  31. Dazzid

    Dazzid

    Joined:
    Apr 15, 2014
    Posts:
    61
    Hi,
    I'm drawing a line from a guiButton to many nodes placed on the scene in 3D. When I draw them using myLine.Draw(), everything goes fine. But when I use myLine.Draw3D(), everytime I move the GUI Object, the lines moves away of the screen with the mouse small movements, and when I stop, the lines come back to the GUI position. Why this is happening?

    Here is how I create the lines:
    Code (CSharp):
    1. textPos = new Vector3 (xix * 100 + xDistance, yiy * 100, 0.0f);
    2.         Material line_material = new Material (Shader.Find ("FobiaAlpha"));
    3.         Color lineColor = new Color (0.0f, 0.5f, 1.0f, 0.3f);
    4.         line_material.SetColor ("_Color", lineColor);
    5.         myLine = new VectorLine ("Line", linePositions, null, 1.5f, LineType.Discrete, Joins.None);
    6.  
    7.         for (int i = 1; i <= thisEngine.cc.CurrentGV.gm.Nodes.Count; i++) {
    8.             thisEngine.cc.CurrentGV.gm.Nodes [i].iShowMyNetwork = false;
    9.         }
    10.         for (int i = 0; i < myLine.GetSegmentNumber(); i++) {
    11.             Color32 thisColor = new Color (thisEngine.cc.CurrentGV.gm.Nodes [nodeIds [i]].myColor.r,
    12.                                           thisEngine.cc.CurrentGV.gm.Nodes [nodeIds [i]].myColor.g,
    13.                                           thisEngine.cc.CurrentGV.gm.Nodes [nodeIds [i]].myColor.b,
    14.                                           0.19f);
    15.             float myWidth = myWidths [i] * 0.33333f;
    16.             myLine.SetColor (thisColor, i);
    17.             myLine.SetWidth (myWidth, i);
    18.             //myLine.SetEndCap ("Arrow", EndCap.Both, line_material, null, null);
    19.             myLine.endCap = "Arrow";
    20.             thisEngine.cc.CurrentGV.gm.Nodes [nodeIds [i]].iShowMyNetwork = true;
    21.         }
    And this is my code in update:
    Code (CSharp):
    1. void Update ()
    2.     {
    3.         tp += (textPos - tp) * smoothTime;
    4.  
    5.         Vector3 translate = new Vector3 (tp.x + 50, tp.y + 50, 0.0f);
    6.         float yi = translate.y;
    7.         yi = Screen.height - yi;
    8.         translate.y = yi;
    9.      
    10.         Ray lineScreenPos = Camera.main.ScreenPointToRay (translate);
    11.         Vector3 pointNode = lineScreenPos.GetPoint (0);
    12.      
    13.         Vector3 heading = translate - Input.mousePosition;
    14.         distance = heading.magnitude;
    15.         //Debug.Log ("distance " + distance);
    16.  
    17.         if (linePositions.Count > 0) {
    18.  
    19.             int lineReference = 0;
    20.             for (int i = 0; i <linePositions.Count; i++) {
    21.                 linePositions [lineReference] = pointNode;
    22.                 lineReference += 2;
    23.                 lineReference = lineReference % linePositions.Count;
    24.             }
    25.             myLine.Draw ();
    26.         }
    27.  
    28.         if (matches.Count > 0) {
    29.             Debug.Log ("Info----> " + matches);
    30.         }
    31.  
    32.  
    33.         if (Input.GetMouseButtonDown (0) && distance < 50.0f) {
    34.             clicked = true;
    35.             if (pMousePos != Input.mousePosition) {
    36.                 //Debug.Log ("mouse " + Input.mousePosition);
    37.                 dragged = true;
    38.             }
    39.         }
    40.         if (Input.GetMouseButtonUp (0)) {
    41.             clicked = false;
    42.             dragged = false;
    43.             pMousePos = Input.mousePosition;
    44.         }
    45.  
    46.         if (clicked) {
    47.             Vector2 translateThis = new Vector2 (Input.mousePosition.x - 50, Input.mousePosition.y + 50);
    48.             float y = translateThis.y;
    49.             y = Screen.height - y;
    50.             translateThis.y = y;
    51.             textPos = translateThis;
    52.         }
    53.     }
     
  32. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Do you have any example code without external dependencies? I can't run the code you posted.

    --Eric
     
  33. DigiScot

    DigiScot

    Joined:
    Aug 23, 2013
    Posts:
    27
    Hi Eric,

    Absolutely loving this plugin, it's exceeded my expectations and was so easy to implement, thank you!

    I do have one scenario that I need some advice. I have a free roaming isometric camera, and a waypoint system in full 3D, so they can be anywhere and everywhere. Currently I am using Draw3DAuto and this works perfectly.

    The problem is I actually want my lines shown above most other objects, so I actually render the lines on my UI camera, which does just that, but being the performance junkie I am, I feel I'm missing something and should be able to use just VectorLine.Draw(), but when I do, and move the camera, the lines don't update to their Vector3's.

    Without really understanding the difference between Draw3D and Draw, what is the better performer, using Draw3DAuto, or using Draw and updating it constantly when I move my camera?

    Or is there a more efficient way of doing it?

    Thanks,
    Geordie
     
  34. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Draw3DAuto updates the line every frame, but that said, Draw is somewhat more efficient than Draw3D. So calling Draw when moving the camera is fine.

    --Eric
     
  35. tatelax

    tatelax

    Joined:
    Feb 4, 2010
    Posts:
    1,168
    Hi Eric,

    Just purchased Vectrosity, and it's working really well. I have one need that I'm not sure how to do. I'm currently rending a line that has an end cap offset of -1.0f. This is working great for the end of the line, but I need to add an offset to be beginning of the line of 1.0f; How would I go about having two offsets on one line?

    Thank you so much.

     
  36. 1chaos_

    1chaos_

    Joined:
    Jul 27, 2015
    Posts:
    3
    Hi Eric,

    Great plugin but I'm having an issue with camera movement and drawing orbits using MakeEllipse. As the camera moves and position/rotation is changed, the ellipses appear to wobble or shake. This wobbling persists as long as the camera's position/rotation is being changed, even slight changes. If the camera is stationary, no wobbling occurs. The issue is noticed more as the camera gets further away from the ellipse.

    The issue is also noticeable if the camera is following a moving object that has Ellipses around it (moons to an orbiting planet). Since the camera is moving (following an orbiting planet), the moon orbits (MakeEllipse) wobble. As your distance grows from the planet, the wobbling becomes worse.

    I use a variation of the MouseOrbitImproved script to move my camera around my planets, which follow elliptical orbits. I've set my camera using VectorLine.SetCamera3D. I've limited the call to Draw3D to only when the camera position or rotation has changed. I've also noticed that the wobbling only occurs when using Draw3D, if I use Draw there is no wobbling. Unfortunately, I need these orbits drawn in 3D space.

    Please let me know if you have any ideas as to what may be causing this wobbling. Thanks for any help!
     
  37. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    That's not supported currently, but I'll put it on the to-do list. In the meantime you could use two separate lines.

    Sounds like you're using very large values and are running into floating-point precision limitations. The only real solution is to use smaller values; in general you should keep things <10K units from the origin.

    --Eric
     
  38. tatelax

    tatelax

    Joined:
    Feb 4, 2010
    Posts:
    1,168
    Thanks for the quick response. Any ETA on the next update? Weeks, days, or months?
     
  39. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Longer than days.

    --Eric
     
  40. 1chaos_

    1chaos_

    Joined:
    Jul 27, 2015
    Posts:
    3
    Hmm, I forgot to mention in my original post that my values are relatively small. I only allow distances of 500 from origin, so I'm much closer than 10K units. I've also tested on different line widths which all display the same behavior. While viewing my camera transform from the inspection window, I see that the position and rotation are sometimes float values to the 6th decimal point, could this be causing the floating point precision problems?
     
  41. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Unfortunately I can't reproduce this; maybe you're using some kind of parenting behavior that's causing it?

    --Eric
     
  42. 1chaos_

    1chaos_

    Joined:
    Jul 27, 2015
    Posts:
    3
    Thanks for the suggestion, Eric. it ended up being an issue with the clipping plane on my perspective camera. Anything less than 0.1 for the near plane causes wobbling, with it becoming more severe around 0.05.
     
  43. Dazzid

    Dazzid

    Joined:
    Apr 15, 2014
    Posts:
    61
    HI,
    I have a very simple question. I have an array of lines created like this:
    And how can i change the color of the lines independently???

    Code (CSharp):
    1. myLine.Add (new VectorLine (gm.Nodes [i].currentRegionIndex + "_" + i.ToString (), nodeArray, line_material, Map (gm.Nodes [i].weight_node, 0.001f, 1.2f, 0.025f, 2.0f), LineType.Discrete, Joins.None));
    my line_material initialise like this:

    Code (CSharp):
    1.             Material line_material = new Material (Shader.Find ("Simple Glass"));
    2.             //line_material.SetFloat("_Mode", 0);
    3.             //line_material.renderQueue = 3000;
    4.             float alpha;
    5.             if (nodeIndex == i){
    6.                 alpha = 1.0f;
    7.                 myFactor = 1.5f;
    8.             }
    9.             else{
    10.                 alpha = gm.Nodes [i].weight_node * 0.05f;
    11.                 myFactor = 0.7f;
    12.             }
    13.             Color lineColor = new Color (gm.Nodes [i].myColor.r * myFactor, gm.Nodes [i].myColor.g * myFactor, gm.Nodes [i].myColor.b * myFactor, alpha);
    14.             line_material.SetColor ("_Color", lineColor);
    15.             line_material.SetColor ("_Emission", lineColor);
    16.             line_material.SetFloat ("_Mode", 2f);
    17.             line_material.SetFloat ("_ZWrite", 1f);
    18.             line_material.SetFloat ("_Shininess", 0.05f);
    line_Material is a shader:

    Code (CSharp):
    1. Shader "Simple Glass" {
    2.     Properties {
    3.         _Color ("Main Color", Color) = (1,1,1,1)
    4.         _SpecColor ("Spec Color", Color) = (1,1,1,1)
    5.         _Emission ("Emmisive Color", Color) = (1,1,0,0)
    6.         _Shininess ("Shininess", Range (0.01, 1)) = 0.21
    7.         _MainTex ("Base", 2D) = "white" { }
    8.     }
    9.  
    10.     SubShader {
    11.         // We use the material in many passes by defining them in the subshader.
    12.         // Anything defined here becomes default values for all contained passes.
    13.      Tags { "RenderType" = "Opaque" }
    14.    
    15.         Material {
    16.             Diffuse [_Color]
    17.             Ambient [_Color]
    18.             Shininess [_Shininess]
    19.             Specular [_SpecColor]
    20.             Emission [_Emission]
    21.         }
    22.         Lighting On
    23.         SeparateSpecular On
    24.  
    25.         // Set up alpha blending
    26.      
    27.  
    28.         // Render the back facing parts of the object.
    29.         // If the object is convex, these will always be further away
    30.         // than the front-faces.
    31.         Pass {
    32.         Blend SrcAlpha OneMinusSrcAlpha
    33.          Material {
    34.                 Diffuse (0.1,0.1,0.1,1.0)
    35.             }
    36.             Cull Front
    37.             SetTexture [_MainTex] {
    38.                 Combine Primary * Texture
    39.             }
    40.      
    41.         }
    42.         // Render the parts of the object facing us.
    43.         // If the object is convex, these will be closer than the
    44.         // back-faces.
    45.         Pass {
    46.  
    47.             Cull Back
    48.             Blend SrcAlpha OneMinusSrcAlpha
    49.             SetTexture [_MainTex] {
    50.                 Combine Primary * Texture
    51.             }
    52.         }
    53.       }
    54. }
     
  44. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Line color is done with vertex colors, so any custom shaders you use should use vertex colors too.

    --Eric
     
  45. Dazzid

    Dazzid

    Joined:
    Apr 15, 2014
    Posts:
    61
    Ok, But then just using myLine[number].setColor(some color) I can change it?
     
  46. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes.

    --Eric
     
  47. dred

    dred

    Joined:
    Apr 8, 2013
    Posts:
    30
    Hello!

    I want to do something when user click on line that I create by your tool, is there simple way to do this? I try to add collider and attach some logic script to line but it's doesn't work. Note, that I have many lines ( more than 100).
     
  48. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Use VectorLine.Selected().

    --Eric
     
  49. bitbutter

    bitbutter

    Joined:
    Jul 19, 2012
    Posts:
    60
    Hi Eric. I'm having some difficulty with using Joins.Weld in conjunction with specifying an endPointsUpdate. I wondered if the issue I'm having was expected behaviour or if I'm making a mistake somewhere.

    I've set up a line using Joins.Weld and endPointsUpdate set to some value (say 10). The line is a 'trail' that gets extended with new segments over time. The most newly added points on the trail create segments welded together as expected, but older ones (further back than the endPointsUpdate limit) appear without any welds, the previous welds appear to break. Do you have an idea why the older connections might be behaving this way?

     
  50. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I set endPointsUpdate to 10 with the DrawLinesMouse demo script and it works as expected. What version are you using?

    --Eric