Search Unity

Vectrosity - Fast and Easy Line Drawing

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

  1. notsteve

    notsteve

    Joined:
    Dec 13, 2013
    Posts:
    18
    Hi Eric, thank you for your responses.

    Doesn't everything need to be recalculated when the camera moves, regardless?

    Your second sentence appears to contradict your first one, though I'm the neophyte here. Why would I need to figure out which cubes can be seen, when that is the point of the ObjectSetup function? (It's actually the entire reason I'm using Unity.)

    Thanks and cheers,

    Bill
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,172
    No, or at least not on the CPU.

    Having millions of GameObjects will crash Unity. It would work with the ObjectSetup function if you had a more usual amount of objects (typically a few thousand at most). Anyway, it doesn't sound like Vectrosity is really a good match for this particular usage; some kind of shader sounds like it might be more appropriate.

    --Eric
     
  3. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,459
    That is great application of Vectrosity .
     
    Last edited: Nov 12, 2014
  4. notsteve

    notsteve

    Joined:
    Dec 13, 2013
    Posts:
    18
    Thanks for your thoughts.

    Cheers,

    Bill
     
  5. inakiktp

    inakiktp

    Joined:
    Nov 6, 2014
    Posts:
    34
    Hi Eric,

    First of all, I want to say thank you for developing Vectrosity, it is awesome.

    Second, my "problem", which probably is just me not understanding how Vectrosity and new Unity UI works and doing everything the wrong way.

    I would like to draw lines, polylines, circles, etc... in different Canvas, so I avoid reaching those 65K maximun vertices in the Canvas created by Vectrosity, while showing everything at the same time.

    I have been trying to do it by myself after I read you saying that it is possible to create new Canvas and assign these new Canvas to the VectorLines through "rectTransform.SetParent()". However, I have no been able.

    I tried 3 differente approached: 1) through a prefab, 2) through new instance of Canvas, 3) through new instance of GameObject with a Canvas without success. I reached a point in which I run out of ideas and I am not sure what I am doing wrong.

    Note: I am using Unity 4.6.0 Beta 20 and Vectrosity 4.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using UnityEngine.Events;
    4. using UnityEngine.EventSystems;
    5. using System.Collections;
    6. using System.Collections.Generic;
    7. using Vectrosity;
    8.  
    9. public class Drawings : MonoBehaviour {
    10.     /* Variables */
    11.     public Canvas prefabCanvas;
    12.     public Canvas myCanvas2;
    13.  
    14.     // Line Variables
    15.     private VectorLine myLine;
    16.     private List<Vector3> myLinePoints = new List<Vector3>();
    17.  
    18.     void Start () {
    19.         // Canvas through Prefab
    20.         Canvas myCanvas = Instantiate(prefabCanvas, Vector3.zero, Quaternion.identity) as Canvas;
    21.         // Canvas through new GameObject
    22.         var myCanvas3 = new GameObject("MyCanvas3", Canvas);
    23.  
    24.         /* How to Draw a Line */
    25.         // Define Line List of Points
    26.         myLinePoints.Add(new Vector3(-1.0f, 0.0f, 0.0f));
    27.         myLinePoints.Add(new Vector3(1.0f, 0.0f, 0.0f));
    28.         // Create the VectorLine Element
    29.         myLine = new VectorLine("My Line", this.myLinePoints, null, 5);
    30.         // Add Line to new Canvas
    31.         myLine.rectTransform.SetParent(myCanvas.transform);
    32.         //myLine.rectTransform.SetParent(myCanvas2.transform);
    33.         //myLine.rectTransform.SetParent(myCanvas3.transform);
    34.  
    35.         // Draw a Line
    36.         myLine.Draw3DAuto();
    37.     }
    38. }
    If I use the Prefab option, I get no errors, but the Line is drawn in the VectorCanvas3D that is generated by Vectrosity.

    If I use the Canvas option, again, no errors and the Line is drawn in the VectorCanvas3D that is generated by Vectrosity.

    If I use the GameObject option, I get a few errors complaining about:
    • GameObject("MyCanvas3", Canvas); has incorrect arguments and the System.Type[] is wrong.
    • myLine.rectTransform.SetParent(myCanvas3.transform); has incorrect arguments.
    On a side note, I tried to use "VectorLine.canvas.sortingOrder", but I could not, same with "VectorLine.canvas3D" and "VectorLine.SetCanvasCamera()".

    Any advice about this? Thanks in advance.


    Inaki.
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,172
    GameObject("MyCanvas3", Canvas) needs to be GameObject("MyCanvas3", typeof(Canvas)) in C#. You would also need to set up the canvas so that it has the same settings as the standard VectorCanvas3D. Also, the SetParent line should be after the Draw3DAuto line.

    --Eric
     
    inakiktp likes this.
  7. inakiktp

    inakiktp

    Joined:
    Nov 6, 2014
    Posts:
    34
    Hi Eric,

    Thanks a lot for the help. I made it work. I am using now the 4.6 RC1.

    The only thing I am concerned now is the performance, which is 0.3 FPS. I have about 40K elements, divided in about 160 Canvases, with 250 elements in each one drawing.

    Could it be that there are too many elements in the scene (or too many Canvases)? Maybe is the way I am using Vectrosity? Any insight about this? All those elements are all inside a List<VectorLines>.

    Any reason why I cannot access the properties I comment in my previous message?

    Thanks again for the help.

    Inaki.
     
  8. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,172
    That's an awful lot of VectorLines; I wouldn't expect that to run very well. Are you actually using them all at once? Maybe you can disable the ones you're not using. As for VectorLine.canvas.sortingOrder, it seems to work as expected:

    Code (csharp):
    1. VectorLine.canvas.sortingOrder = 5; // no errors
    --Eric
     
    inakiktp likes this.
  9. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    302
    Hi Eric,
    I figured I would ask this on the forum to see if anyone had already done this before. I am wanting to be able to grab a line with my mouse and move the mouse on an axis (X,Y or Z) and "lengthen" the line as the mouse drags. At the moment I've tried adding to the localScale of the line.vectorObject but that stretches out the texture and it acts very strangely so the line becomes deformed.

    Anyone have thoughts on how this could be accomplished? I think an example of this would be awesome to have in Vectrosity's example scenes.
     
  10. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,172
    You should change the appropriate points in the points array for the VectorLine; touching line.vectorObject is highly discouraged.

    --Eric
     
  11. inakiktp

    inakiktp

    Joined:
    Nov 6, 2014
    Posts:
    34
    Hi Eric,

    Thanks for the answer.

    Knowing those are too many VectorLines, I will figure out a way to only draw the ones within the camera field of view, since as you suspected, I am not using all of them at the same time.

    Regarding the canvas properties, after seeing your code and rereading the documentation file, I realized I missunderstood it. I thought it was a property of the VectorLines you create (i.e. myLine) and you can access their canvas and their sortingOrder through them.
    Code (CSharp):
    1. myLine.canvas.sortingOrder = 2;
    However, it is using VectorLine, and it gives you access to both canvases created by Vectrosity when Draw and Draw3D are called. Sorry for the confusion.

    Thanks again for the help.

    Inaki.
     
  12. Slev

    Slev

    Joined:
    Sep 8, 2012
    Posts:
    148
    Interesting thing I've stumbled across. Seems if you are using Unity on Linux through. Vectrosity doesn't draw where it's supposed it. (Only the visual stuff though, the colliders are fine.) Below is a quick example... I'm guessing this has to do with the finagling required to get Unity working on Linux, but was wondering if there's any way to fix it?



    The offset is uniform across all Vectrosity generated things. If the project is opened on Windows it works normally.
     
  13. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,172
    That would be a problem with WINE, so there's not really anything I can do about it I'm afraid.

    --Eric
     
  14. Slev

    Slev

    Joined:
    Sep 8, 2012
    Posts:
    148
    I figured as much. Just checking.
     
  15. EddieC

    EddieC

    Joined:
    Mar 11, 2014
    Posts:
    2
    Hi, I'm using Vectrocity and points3d to render 'tunnels' that a player can walk through. However, segments near the camera plane seem to be very confused, and are rendering across the screen when they shouldn't be. (see the attached gif) The problem happens with both draw3d and draw.
    I'm assuming this is some sort of floating point error, but I can't pin it down to any specific arrangement except that it seems to affect any point that lies near the camera plane, ruling out a lot of 3D use cases for vectrocity. Any way I can avoid this?
     

    Attached Files:

  16. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,172
    That's a limitation when using WorldToScreenPoint. I have thought that it might be time to look into a different method, since aside from this, it slows down 3D line calculations somewhat. But usually it can be fixed by subdividing the lines into more segments.

    --Eric
     
  17. EddieC

    EddieC

    Joined:
    Mar 11, 2014
    Posts:
    2
    Oh really? I use worldToScreenPoint a bunch, and assumed the issues that always seemed to crop up were my fault!
    More segments will work for now. Thanks!
     
  18. kadirfu

    kadirfu

    Joined:
    Oct 3, 2013
    Posts:
    6
    I want to create a very simple graph, where I add points in real time (e.g. X-t graph or a F-a graph)and connect the last point to the previous one with a line so that it forms a plot. It would be great if somebody gives a clear and short example of how to do this.
     
  19. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,172
    Some code that makes a graph, with a new random point added every second:

    Code (javascript):
    1. #pragma strict
    2. import Vectrosity;
    3. import System.Collections.Generic;
    4.  
    5. var dotMaterial : Material;
    6. private var graphDots : VectorPoints;
    7. private var graphLine : VectorLine;
    8. private var x = 0;
    9.  
    10. function Start () {
    11.     graphLine = new VectorLine ("Graph Line", new Vector2[0], null, 2.0, LineType.Continuous);
    12.     graphDots = new VectorPoints ("Graph Dots", new Vector2[0], dotMaterial, 8.0);
    13.     graphDots.drawDepth = 1;    // Make dots draw on top of the line
    14.     AddPoint();
    15.     InvokeRepeating ("AddPoint", 0.01, 1.0);
    16. }
    17.  
    18. function AddPoint () {
    19.     var newPoint = Vector2(x, Random.Range(0, Screen.height));
    20.     x += 20;
    21.     graphDots.points2.Add (newPoint);
    22.     graphDots.Draw();
    23.     graphLine.points2.Add (newPoint);
    24.     graphLine.Draw();
    25. }
    graph.png

    --Eric
     
  20. ViCoX

    ViCoX

    Joined:
    Nov 22, 2013
    Posts:
    25
    Hi Eric,
    Do you have any tips how to fake specular reflections? I'm doing spider webs. : )
    It would be nice to have some life in the lines. Works nice otherwise, tho.
     
  21. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,172
    Probably something involving a shader? You can use any sort of material with a VectorLine.

    --Eric
     
  22. Slev

    Slev

    Joined:
    Sep 8, 2012
    Posts:
    148
    What's the likelihood of 3D colliders someday? I know currently they're not possible but might it be at a later date?
     
  23. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,172
    3D colliders don't really seem compatible with Vectrosity...if you just used the line mesh, then collision only works on one side (plus Vectrosity 4 doesn't have a line mesh as such), and since the line width is pixels, that means lines farther away have a larger collision width, which would be weird.

    --Eric
     
  24. Slev

    Slev

    Joined:
    Sep 8, 2012
    Posts:
    148
    Well... I'm working on a custom collider setup that essentially tries to break the vector line in to a set of polygons and then creates polygons colliders to cover the surface. It's not necessarily collision with the line, but with drawn objects. This is for pseudo 3D objects though.

    Theoretically each line segment could have a cylinder or capsule collider on it which would come close to simulating how the line would behave. Neither works, but possibly a choice for 3D collisions?
     
  25. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,172
    That was one thing I had considered, but the colliders don't really match the line. e.g., if you have a line extending away from the camera, the collider width can never be correct; it will either be too wide or too narrow compared to what you see on the screen. I'm reluctant to put in any features that only kinda sorta work.

    --Eric
     
  26. AntLewis

    AntLewis

    Joined:
    Feb 2, 2010
    Posts:
    166
    Hey @Eric5h5, wonder if you can help me with an issue. I'm drawing a path 'live' (while the game is running) that I want a gameobject to follow. To achieve this I'm sampling where the mouse is and storing it in a list....

    Code (CSharp):
    1.        
    2. void Awake ()
    3.         {
    4.                 if (instance == null)
    5.                         instance = this;
    6.      
    7.                 waypoints = new List<Vector2> ();
    8.  
    9.         }
    10.         // Use this for initialization
    11.         void Start ()
    12.         {
    13.                 InvokeRepeating ("CaptureInputPosition", 1.0f, samplePeriod);
    14.         }
    15.  
    16.     void CaptureInputPosition ()
    17.         {
    18.                 Vector2 mousePositionWorld = Camera.main.ScreenToWorldPoint (Input.mousePosition);
    19.      
    20.                 // Add to list
    21.                 waypoints.Add (mousePositionWorld);
    22.  
    23.                 // Draw object
    24.                 if (drawWaypoints) Instantiate (waypointObject, mousePositionWorld, Quaternion.identity);      
    25.  
    26.      
    27.         }
    I then have a class which draws the line:

    Code (CSharp):
    1. public class VectrosityTest : MonoBehaviour {
    2.  
    3.     // Use this for initialization
    4.     public static VectrosityTest instance;
    5.  
    6.     private   Vector2[] lineArray;
    7.  
    8.     private    VectorLine myLine;
    9.     void Start () {
    10.  
    11.         if ( instance == null ) instance = this;
    12.  
    13.         myLine = new VectorLine ( "Test",ControlScriptA.instance.waypoints.ToArray(), null, 2.0f, LineType.Continuous );
    14.                            
    15.     }
    16.  
    17.  
    18.     // Update is called once per frame
    19.     public void Update () {
    20.  
    21.         if ( ControlScriptA.instance.waypoints.Count < 3 ) return;
    22.  
    23.         lineArray = ControlScriptA.instance.waypoints.ToArray();
    24.  
    25.         myLine.MakeSpline( lineArray, lineArray.Length+1 );
    26.  
    27.  
    28.         myLine.Draw();
    29.     }
    30. }
    .. but I continually get a
    I'm not sure what I'm doing wrong with the segment length? Thanks for any assistance!
     
  27. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,172
    MakeSpline takes an array and the number of segments to use in the spline, but the number of segments can't exceed the number of points already in the line. e.g., if you have 5 points in a continuous line, it has 4 segments. So if you're using lineArray.Length+1 for the number of segments, the line would need to contain at least lineArray.Length+2 points.

    --Eric
     
  28. AntLewis

    AntLewis

    Joined:
    Feb 2, 2010
    Posts:
    166
    Ok thanks for that. So as I'm adding points to my line at run time I'm creating a line with an arbitrary number of segments at the start:

    Code (CSharp):
    1.  void Start()
    2.     {
    3.         lineArray = ControlScriptA.instance.waypoints.ToArray();
    4.  
    5.         myLine = new VectorLine ( "Test",new Vector2[1000], lineMaterial, 2.0f, LineType.Continuous, Joins.Fill);
    6.  
    7.     }
    8.  
    ...and in the update:

    Code (CSharp):
    1.         lineArray = ControlScriptA.instance.waypoints.ToArray();
    2.  
    3.           myLine.MakeSpline( lineArray, lineArray.Length-1 );
    4.  
    5.         myLine.Draw();
    6.  
    ...there's no line showing in the game view, but in the scene view I', getting this (the green lines are debug)
    upload_2014-11-29_16-24-41.png

    Thanks again
     
  29. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,172
    VectorLine.Draw uses screen space coordinates, so it would depend on what's in your waypoints array.

    --Eric
     
  30. failman

    failman

    Joined:
    Sep 11, 2014
    Posts:
    23
    Hello Eric! I've upgraded Vectrosity to the new 4.0.3 version and couldn't not notice that VectorLine gameobjects are created with the VectorManager.ObjectSetup function now. Previously I was referencing to the VectorLine's gameObject (via vectorObject) so I could use LeanTween to fade the alpha, but now tweening doesn't affect this. Would be great if you can give me an advice on this. Thanks!
     
  31. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,172
    VectorLine gameobjects are still created, and placed under the VectorCanvas (or VectorCanvas3D).

    --Eric
     
  32. failman

    failman

    Joined:
    Sep 11, 2014
    Posts:
    23
    Yes, but when I try to change the VectorLine's colour via gameObject.renderer.material.color, It creates a duplicated instance of that meterial that doesn't affect the VectorLine's color

    In other words, how can I change the color referencing the gameObject? With LeanTween on iTween for an example.
     
    Last edited: Nov 30, 2014
  33. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,172
    You can use VectorLine.color; there isn't really any need to access the GameObject.

    --Eric
     
  34. inakiktp

    inakiktp

    Joined:
    Nov 6, 2014
    Posts:
    34
    Hi Eric,

    I managed to solved the "40k elements" in screen and everything is working fine. However, I am again in need of advice since I want to disable / hide / stopdrawing the VectorLines I drew earlier.

    Using Unity 4.6 Beta 20 and Vectrosity 4.0. I am aware there is already a 4.6.0f and Vectrosity to 4.0.3, I will update to both of them soon.
    Code (CSharp):
    1. void Start() {
    2. /* How to Draw a Line */
    3. // Define Line List of Points
    4. myLinePoints.Add(newVector3(-1.0f, 0.0f, 0.0f));
    5. myLinePoints.Add(newVector3(1.0f, 0.0f, 0.0f));
    6. // Create the VectorLine
    7. myLine = newVectorLine("My Line", this.myLinePoints, null, 5);
    8. //Draw a Line
    9. myLine.Draw3DAuto();
    10. }
    11.  
    12. void Update() {
    13. if (Input.GetKeyDown(KeyCode.A)) {
    14. Debug.Log("Key A Pressed");
    15. myLine.StopDrawing3DAuto();
    16. }
    The line is still being drawn, so I checked the documentation again in case, and according to it I am doing it right, but it is not working, so either I am doing it wrong or I do not understood correctly how to stop drawing a VectorLine.

    Thanks in advance.

    Inaki.
     
  35. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,172
    StopDrawing3DAuto just turns off the auto-update; it doesn't disable the line. You can use VectorLine.active for that (needs 4.0.3 or later to work).

    --Eric
     
    inakiktp likes this.
  36. gregroberts

    gregroberts

    Joined:
    Nov 21, 2014
    Posts:
    25
    Hi, I am using Vectrosity and trying to initialize a multi-dimensional array of lines.
    Basically, I have P planets with S satellites each. I want to plot a trail for each satellite, then update as time passes.
    So I need to initialize a multidimensional array of Vectorlines.... but its not working

    This is what I'm attempting:

    planetCount = 5;
    satsPerPlanet = 12;
    var g_satPaths : VectorLine[planetCount][satsPerPlanet];

    // initialize the traces
    for (p = 0; p < planetCount; p++) {
    for (s = 0; s < satsPerPlanet; s++) {
    // establish starting positions for each satellite
    var tcxa = g_PlanetX[0] + g_SatOffsetX;

    var tcya = g_PlanetY[0] + g_SatOffsetY;
    satStartPos= Vector3(tcxa, tcya, 0.0);

    // initialize the Vectrosity lines
    g_satPaths(p)(s) = VectorLine.SetLine (Color.green, satStartPos, satStartPos);

    }
    }


    Help is much appreciated! Thanks in advance!
     
  37. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,172
    Unityscript is unable to declare jagged arrays explicitly. Even if it could, you'd need to initialize the array, and each row in the array, before using them. You can use a 2D array:

    Code (javascript):
    1. var g_satPaths = new VectorLine[planetCount, satsPerPlanet];
    That's for a rectangular 2D array, though. If you have different numbers of lines per planet, a List of VectorLine Lists would work:

    Code (javascript):
    1. var g_satPaths : List.< List.<VectorLine> >;
    This is essentially the same as a jagged array, and likewise you need to initialize the main list and each row in the list.

    --Eric
     
  38. gregroberts

    gregroberts

    Joined:
    Nov 21, 2014
    Posts:
    25
    It's a "rectangular" 2D array; same number of sats per planet.
    I will modify the code now and report back ASAP. THANK YOU, Eric!

    edit : that worked perfectly!
     
    Last edited: Dec 1, 2014
  39. AntLewis

    AntLewis

    Joined:
    Feb 2, 2010
    Posts:
    166
    Hey @Eric5h5, still have trouble with this spline. Made a few stupid mistakes which have now been resolved but I'm still getting the error "VectorLine.MakeSpline: The length of the array for continuous lines needs to be at least the number of segments plus one for "Line""

    I'm logging out the array of points, and the number of segments I'm asking for is always the number of points in the line-1.

    The first file grabs the mouse position at a regular interval:

    Code (CSharp):
    1. public class ControlScriptA : MonoBehaviour
    2. {
    3.         public static ControlScriptA instance;
    4.     //    public List<Vector2> waypoints;
    5.         public float samplePeriod = 1.0f;
    6.  
    7.         //
    8.         public float totalPathLength = 0f;
    9.         //
    10.         public GameObject waypointObject;
    11.         //
    12.         public bool drawWaypoints = false;
    13.         public bool drawDebugLines = true;
    14.         private Transform objectToMove;
    15.  
    16.  
    17.     public int numberPoints =1;
    18.  
    19.     public float lineLengthPoints=0;
    20.  
    21.         void Awake ()
    22.         {
    23.                 if (instance == null)
    24.                         instance = this;
    25.         }
    26.  
    27.         // Use this for initialization
    28.         void Start ()
    29.         {
    30.    
    31.                  InvokeRepeating ("CaptureInputPosition", 1.0f, samplePeriod);
    32.         }
    33.  
    34.          void CaptureInputPosition ()
    35.         {
    36.  
    37.                       // Add to list
    38.         VectrosityTest.instance.myLine.points2.Add (Input.mousePosition);
    39.  
    40.         numberPoints++;
    41.         VectrosityTest.instance.UpdateLine();
    42.         lineLengthPoints = VectrosityTest.instance.myLine.points2.Count;
    43.                        
    44.      
    45.         }
    ...and the second deals with the line...

    Code (CSharp):
    1.        
    2. void Awake ()
    3.         {
    4.  
    5.            if (instance == null)
    6.                         instance = this;
    7.  
    8.          myLine = new VectorLine ("Line", new List<Vector2> (), null, 5.0f,LineType.Continuous, Joins.Weld);
    9.         }
    10.  
    11.         // Update is called once per frame
    12.         public void UpdateLine ()
    13.         {
    14.                 debugWaypoints = myLine.points2;
    15.  
    16.                 if (ControlScriptA.instance.numberPoints > 1) {
    17.                         // Segments need to equal number of points -1
    18.                         myLine.MakeSpline ( myLine.points2.ToArray (), myLine.points2.ToArray ().Length - 1);
    19.  
    20.                         Debug.LogWarning ("Length of Array: " + myLine.points2.ToArray ().Length + " Segments: " + (this.myLine.points2.ToArray ().Length - 1).ToString ());
    21.  
    22.                          myLine.Draw ();
    23.                 }
    24.  
    25.                 myLine.Draw ();
    26.         }
    27. }

    ...but the error persists. Aside from the number of segments being incorrect could anything else cause this error?

    Thanks so much
     
  40. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,172
    One major design problem I see is that this:

    Code (csharp):
    1. myLine.MakeSpline( myLine.points2.ToArray(), myLine.points2.ToArray().Length-1);
    won't actually accomplish anything. Making a spline from the list of points in a line, where the number of segments is equal to the total number of segments already in the line, results in no change. It's impossible to make any actual splines with those conditions. In order to make a spline properly, you need relatively few points in the spline, and many points in the VectorLine (the more points, the smoother the curves will look). Have a look at the various included examples that create splines.

    (FYI, "myLine.points2.ToArray().Length-1" is not a good idea. Use "myLine.points2.Count-1".)

    --Eric
     
  41. AntLewis

    AntLewis

    Joined:
    Feb 2, 2010
    Posts:
    166
    Ok so maybe I need to step back here - I'm trying to implement a Flight Control type system, where the path seems to be smoothed - are splines the wrong way to go? If so what would you recommend (assuming it's do-able in Vectrosity)?

    Cheers
     
  42. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,172
    Splines would work, but as I mentioned you'd need more points in the VectorLine compared to the number of points in the spline. So if you sampled 10 input points, then you'd use, say, 200 points in the line.

    --Eric
     
  43. AntLewis

    AntLewis

    Joined:
    Feb 2, 2010
    Posts:
    166
    OK got you thanks. The penny has finally dropped ;0)
     
  44. TGAlencon

    TGAlencon

    Joined:
    Aug 26, 2014
    Posts:
    3
    Hello, thanks for your work on this asset. I have a question about canvas swapping. Using Vectrosity 4 and Unity 4.6, is it possible to change a default Vectrosity canvas (the 3D canvas, specifically) to be one of our choosing instead?

    I currently have a world space canvas that I want to incorporate Vectrosity components into. This canvas is coded to turn on and off from various user input and it seems inefficient to also code the Vectrosity objects/canvas to do so as well at the same time. I am currently re-parenting my Vectrosity objects to this canvas, but apparently I must do this every frame if I re-draw every frame? Reparenting doesn't seem to be hurting performance, but I was just curious if there was an easier way to change a default canvas. Thanks.
     
  45. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,172
    Once you use SetParent to set a VectorLine.rectTransform to another canvas, it should stay there, and calling Draw3D again doesn't change that. I tested that to make sure. By "re-draw every frame", are you by chance creating a new VectorLine every frame? That's definitely not good for performance.

    --Eric
     
  46. TGAlencon

    TGAlencon

    Joined:
    Aug 26, 2014
    Posts:
    3
    Hm, okay, I'll have to check my code again. I'm definitely just redrawing and not recreating a line every frame, so something else must be going on in my code. Thanks for your reply.
     
  47. inakiktp

    inakiktp

    Joined:
    Nov 6, 2014
    Posts:
    34
    Hi Eric,

    Thanks again for the help, I updated to 4.0.3 and used the active property and everything works as I wanted to.

    I was wondering, is there a reason for which Vectrosity draws might not be shown during run time in a deployed build? I am asking because I have 2 projects, one small and one "big" (bigger than the other).

    In the small project I create and draw (3DAuto) a few VectorLines and when I deploy the build (standalone and mobile platforms) I can see everything. However, when I do the same thing in the big project and deploy a build (again standalone and mobile platforms) the only thing I can see is the UI elements (which the small projects does not have).

    Things I checked:
    - VectorCanvas3D: Same parameters in both projects.
    - VectorLines I want to draw: Same way of creating them, I literally copy and paste the code.
    - Disabling any other Canvas: Just in case one Canvas could occlude the VectorCanvas3D, not the case.
    - Added a Cube to the scene: The Cube is the only (together with the UI) that I can see.
    - Add one VectorLine alone: I commented the code in the big project and only create 1 VectorLine and Draw3DAuto it, I cannot see it.

    I am unsure of what else can be the reason for the VectorLines in the big project not being drawn in the deployed build. If I run the application in the Editor everything works fine in Editor and Game Views.

    Of course maybe this has nothing to do with Vectrosity, just I am unsure. I was not sure if I should attach code or images for the sake of clarity with this, but here are a few images (made them with Gyazo sorry for the quality):

    Small Project Editor: http://gyazo.com/b69a6ec7217d4ed5179f8794dfed3e37
    Big Project Editor: http://gyazo.com/8b3f43b9a3a5d358862524dc23ede4cf
    Standalone Deployed Build: http://gyazo.com/968eb6756654549b2de26521f8fc3bad

    If it is still unclear what I am trying to say let me know and I will try provide whatever needed in order to make it clear.

    Thanks in advance.

    Inaki.
     
  48. Slev

    Slev

    Joined:
    Sep 8, 2012
    Posts:
    148
    Is there a fast method for removing all currently drawn VectorLines? For instance if I delete the VectorCanvas and VectorCanvas3D will this also remove all current VectorLines?
     
  49. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,172
    I haven't encountered that, so I'm not really sure. What version of Unity are you using, and what platform are you building to?

    No, you should use VectorLine.Destroy. Presumably you could use FindObjectsOfType with VectorLine and pass that array into Destroy.

    --Eric
     
  50. Slev

    Slev

    Joined:
    Sep 8, 2012
    Posts:
    148
    I'm doing the following:

    Code (csharp):
    1. foreach (RectTransform r in VectorLine.canvas.GetComponentsInChildren<RectTransform>()) {
    2.        if (r.gameObject != VectorLine.canvas.gameObject)
    3.          Destroy (r.gameObject);
    4. }
    It works, just want to be sure there is no memory leak issue associated with it.