Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Vectrosity - Fast and Easy Line Drawing

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

  1. shayan_315

    shayan_315

    Joined:
    Sep 24, 2013
    Posts:
    28
    I used Debug.log("I am working") into
    Code (CSharp):
    1.                 if (ListOfFL[i].Selected (touch.position, extraThickness,out index))
    2.                 {
    3.                     print ("I am working");
    4.                     VectorLine Temp=ListOfFL[i];
    5.                     VectorLine.Destroy(ref Temp);
    6.  
    7.                     ListOfFL.RemoveAt(i--);
    8.                     lineCounter--;
    9.                     break;
    10.                 }
    11.             }
    but print statement never works when I touch freeline. I think my ListOfFL.Selected never works.
    Besides, what is !dest.m_MultiFrameGUIState.m_NamedKeyControlList problem
    whenever I touch to draw I see this error how ever I can draw and remove other kind of lines
    when I see this error
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Confirm that all the other conditions are true (eraseButton is actually true, the loop is running, etc.). Also look at the SelectLine demo and see if there are any differences between that and your code.


    A Unity bug when using GUI.SetNextControlName, so nothing to do with Vectrosity. (Also harmless; it doesn't do anything except be annoying.)

    --Eric
     
    shayan_315 likes this.
  3. shayan_315

    shayan_315

    Joined:
    Sep 24, 2013
    Posts:
    28
    I changed touch.position to Input.mousePosition and the problem solved !! wierd solution.
     
  4. Rikrok

    Rikrok

    Joined:
    Apr 11, 2013
    Posts:
    50
    Hi. End caps don't seem to batch (making them unusable for me, and I really need them). Am I doing something wrong or can this be implemented?
     
  5. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,459
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It's up to Unity what it batches in canvases. Not batching doesn't make them unusable, though. Look at actual performance in the profiler; draw calls by themselves aren't a measure of performance.

    You can use VectorLine.MakeCurve, which creates Bezier curves. Note that Vectrosity is for use at runtime, not in the editor.

    --Eric
     
  7. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,459
    I am trying to convert an editor script to be used at run time. Handles.Bezier uses startTangent, endTangent. How would this map to VectorLine.MakeCurve ?

    public static void DrawBezier(Vector3 startPosition, Vector3 endPosition, Vector3 startTangent, Vector3 endTangent, Color color, Texture2D texture, float width);
     
  8. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I think if you rearranged that so it was startPosition, startTangent, endPosition, endTangent, that would match MakeCurve.

    --Eric
     
  9. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,459
    Cheers, I'll give it a go.
     
  10. shayan_315

    shayan_315

    Joined:
    Sep 24, 2013
    Posts:
    28
    Hi, I don't have any idea how use Linemaker editor to save the lines in vectrosity3.1 when user is playing my game.
    Is there any PDF or sample code to start with? I read my Vectory Documentaion but I don't get gist
    of mater.
     
  11. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    LineMaker is for use in the editor, not runtime. The VectrosityDemos package has many example scripts.

    --Eric
     
  12. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,459
    It would be super awesome if Vectrosity supported 2D Boolean operations. Having this feature would open so many possibilities.
     
  13. narf03

    narf03

    Joined:
    Aug 11, 2014
    Posts:
    222
    Hi, wanted to know if i can draw a 3D spline with the "selection box" effect ? I wanted to make a 3D turret defense game, and use Vectrosity to draw the path of enemy movement, I able to draw the line but i want the effect to show the direction. Thanks.
     
  14. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Are you referring the texture? If so, sure, just use a material with the appropriate texture, along with VectorLine.textureScale to make it look right.

    --Eric
     
  15. shayan_315

    shayan_315

    Joined:
    Sep 24, 2013
    Posts:
    28
    How I can change lines tag from UnTag to my favorite Tag Name when I am drawing them?
     
  16. narf03

    narf03

    Joined:
    Aug 11, 2014
    Posts:
    222
    Hi, thanks for your reply, I copied the following code from your "SplineFollow" example. And modify it a bit, I couldnt get the effect i want, can you point out where is my problem ? thanks.

    Code (JavaScript):
    1. import Vectrosity;
    2. import System.Collections.Generic;
    3.  
    4. var segments = 250;
    5. var loop = true;
    6. var cube : Transform;
    7. var speed = .05;
    8. var material : Material;
    9.  
    10. function Start () {
    11.     var splinePoints = new List.<Vector3>();
    12.     var i = 1;
    13.     var obj = GameObject.Find("Sphere"+(i++));
    14.     while (obj != null) {
    15.         splinePoints.Add(obj.transform.position);
    16.         obj = GameObject.Find("Sphere"+(i++));
    17.     }
    18.  
    19.     var line = new VectorLine("Spline", new Vector3[segments+1], material, 2.0, LineType.Continuous);
    20.     line.MakeSpline (splinePoints.ToArray(), segments, loop);
    21.     line.Draw3D();
    22.  
    23.     // Make the cube "ride" the spline at a constant speed
    24.     do {
    25.         for (var dist = 0.0; dist < 1.0; dist += Time.deltaTime*speed) {
    26.             cube.position = line.GetPoint3D01 (dist);
    27.             yield;
    28.         }
    29.         line.textureOffset = -Time.time * 10 % 1;      // <------------ This 1 doesnt work.
    30.         line.Draw3D();
    31.     } while (loop);
    32. }
     
  17. matias-e

    matias-e

    Joined:
    Sep 29, 2014
    Posts:
    106
    I translated the DrawLinesMouse script into C# and it works normally. I'm trying to change the position of the line through 'drawTransform'. Here's the bit of code I'm using to try it out:

    Code (CSharp):
    1. if(Input.GetKeyDown(KeyCode.Space)) {
    2.  
    3.             line[indx].drawTransform = GameObject.Find("Thing").transform;
    4.  
    5.         }
    The line does not move at all for some reason. Why could that be? I have a cube named 'Thing' placed in the scene.
     
  18. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Use VectorLine.rectTransform.gameObject.tag.

    The textureOffset line is outside the loop; also you didn't set textureScale.

    You need to draw the line again.

    --Eric
     
    shayan_315 likes this.
  19. Ogdy

    Ogdy

    Joined:
    Dec 26, 2014
    Posts:
    21
    Hi everyone.
    I don't really know where to ask for this...
    I've been working on a project with a friend and we needed Vectrosity to draw a path in ou 3D game. Unfortunately, as the lineWidth is in pixels (we don't really get how it scales actually) and seem to depend on the screen resolution, we are unable find a way to make the lineWidth in world coordinates. We tried to scale it with Screen.width, it works (although it seems like it's not perfectly linear) but it fails when the camera is moved along the Y axis.
    Is there a workaround for this ?
    Thanks :)
     
  20. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes, the line width is in pixels. I'd suggest using Screen.dpi rather than Screen.width.

    --Eric
     
  21. narf03

    narf03

    Joined:
    Aug 11, 2014
    Posts:
    222
    Got it working, thank you.
     
  22. matias-e

    matias-e

    Joined:
    Sep 29, 2014
    Posts:
    106
    Hmm.. I added "line[indx].Draw3D();" but the line still does not move. The line is a 3D line.
     
    Last edited: May 6, 2015
  23. Rikrok

    Rikrok

    Joined:
    Apr 11, 2013
    Posts:
    50
    I'm looking at FPS on the mobile device and it has a significant impact.
    All the lines manage to be done in one draw call, surely this could be achieved for caps?
     
  24. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Actually no, caps use a separate material so it's not possible to batch them with the line.

    Code (csharp):
    1. var someTransform : Transform;
    2.  
    3. function Start () {
    4.     var line = new VectorLine("Spline", [Vector3.zero, Vector3.one], null, 2.0);
    5.     line.drawTransform = someTransform;
    6.     line.Draw3D();
    7. }
    If you move "someTransform", the line is offset by that amount.

    --Eric
     
  25. Rikrok

    Rikrok

    Joined:
    Apr 11, 2013
    Posts:
    50
    I'd be fine with a separate call for the caps from the lines, but I get a separate call for every single cap displayed, even though they're all using the same material. Therefore 10 lines with caps = 21 draw calls. 2 would be nicer.
     
  26. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Well, that's up to Unity how it batches things. Keep in mind that batching costs performance, so it's not necessarily the case that eliminating draw calls will actually improve anything.

    --Eric
     
  27. Rikrok

    Rikrok

    Joined:
    Apr 11, 2013
    Posts:
    50
    I know it's not appropriate in all cases but if it weren't in some it wouldn't exist. Unity has a set of criteria which if you adhere to results in batching. People go to a lot of effort to use texture atlases, single materials with changing vertex colours, limiting vertex counts etc so they can adhere to those criteria, because it can reap real rewards. I've done plenty of tests myself comparing performance with and without. Please humour me and suppose you can get better performance with batching. Would you be able to look into it and see if it's possible?
     
  28. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Once I put objects in canvases, it's up to Unity to decide what to batch, and I'm afraid there's no API that can influence it. Also it seems like a separate system from dynamic batching. Unless they open it up, I'm restricted in what I can do as far as draw calls go. The end caps do have to be a separate material so I can't combine them with the rest of the line. The best I could do is arrange things so the end caps are a single material, which is why you have 2 draw calls for a line with both end caps, rather than 3.

    In any case, mobile hardware has come a long way from the iPhone 1 days, where 20 draw calls was kind of a lot. Modern hardware can handle many times that without problems.

    --Eric
     
  29. matias-e

    matias-e

    Joined:
    Sep 29, 2014
    Posts:
    106
    Ok, I translated the Javascript bit you posted into C# and it works exactly as it should. However, the drawn freehand line doesn't move an inch. I wonder what I'm doing wrong here. Here's the script I'm using. Its got the 'testLine' drawn at the beginning there and just about rest of the stuff is just the DrawLinesMouse script translated into C# with some small additions. Drawing the line works just as it should, but for some reason it isn't following the object linked to the 'someTrans' variable.
    Code (CSharp):
    1. using Vectrosity;
    2. using UnityEngine;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5.  
    6. public class DrawMouseCS : MonoBehaviour {
    7.  
    8.     public Material lineMaterial;
    9.     public int maxPoints = 20000;
    10.     public float lineWidth = 1.25f;
    11.     public int minPixelMove;
    12.     public float distanceFromCamera = 10.0f;
    13.  
    14.     public Transform someTrans;
    15.  
    16.     static private VectorLine[] line = new VectorLine[9999];
    17.     VectorLine testLine;
    18.     private Vector3 previousPosition;
    19.     private int sqrMinPixelMove;
    20.     private bool canDraw = true;
    21.     private Vector3 newPoint;
    22.     private int pointCount;
    23.  
    24.     static int indx = -1;
    25.     Vector3[] lineAr = new Vector3[2];
    26.  
    27.  
    28.     void Start () {
    29.  
    30.         indx++;
    31.  
    32.         lineAr[0] = new Vector3(0.0f, 0.0f, 0.0f);
    33.         lineAr[1] = new Vector3(0.0f, 10.0f, 0.0f);
    34.  
    35.         testLine = new VectorLine("Thingy", lineAr, lineMaterial, 10.0f);
    36.         testLine.drawTransform = someTrans;
    37.         testLine.Draw3D();
    38.  
    39.  
    40.         // Used for .sqrMagnitude, which is faster than .magnitude
    41.         sqrMinPixelMove = minPixelMove*minPixelMove;
    42.  
    43.     }
    44.  
    45.     void Update () {
    46.  
    47.         newPoint = GetMousePos(Input.mousePosition);
    48.  
    49.         // Mouse button clicked, so start a new line
    50.         if (Input.GetMouseButtonDown(0)) {
    51.  
    52.             Debug.Log(indx);
    53.  
    54.             line[indx] = new VectorLine("DrawnLine", new List<Vector3>(), lineMaterial, lineWidth,
    55.                                         LineType.Continuous, Joins.Weld);
    56.          
    57.             line[indx].endPointsUpdate = 1;  
    58.             line[indx].collider = true;
    59.  
    60.             // Optimization for updating only the last point of the line, and the rest is not re-computed
    61.  
    62.             line[indx].Draw3D();
    63.             previousPosition = Input.mousePosition;
    64.             line[indx].points3.Add (newPoint);
    65.             canDraw = true;
    66.  
    67.         }
    68.         // Mouse button held down and mouse has moved far enough to make a new point
    69.         else if (Input.GetMouseButton(0) &&
    70.                  (Input.mousePosition - previousPosition).sqrMagnitude > sqrMinPixelMove && canDraw) {
    71.             previousPosition = Input.mousePosition;
    72.  
    73.             line[indx].points3.Add(newPoint);
    74.             pointCount = line[indx].points3.Count;
    75.             line[indx].Draw3D();
    76.  
    77.             if (pointCount >= maxPoints) {
    78.                 canDraw = false;
    79.             }
    80.         }
    81.  
    82.  
    83.         if(Input.GetKeyDown(KeyCode.Space)) {
    84.  
    85.             //line[indx].drawTransform = GameObject.Find("Thing").transform;
    86.             line[indx].drawTransform = someTrans;
    87.             line[indx].Draw3D();
    88.  
    89.             testLine.drawTransform = someTrans;
    90.             testLine.Draw3D();
    91.  
    92.             Debug.Log(line[indx].drawTransform);
    93.  
    94.         }
    95.     }
    96.  
    97.     Vector3 GetMousePos (Vector3 p) {
    98.         p.z = distanceFromCamera;
    99.         return Camera.main.ScreenToWorldPoint(p);
    100.     }
    101. }
     
  30. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You're using endPointsUpdate = 1, so only the last segment will be updated when you call Draw3D.

    --Eric
     
  31. matias-e

    matias-e

    Joined:
    Sep 29, 2014
    Posts:
    106
    Ok, it works now. A huge thank you! :)
     
  32. ctp

    ctp

    Joined:
    Apr 21, 2013
    Posts:
    9
    Hi, I recently purchased the Vectrosity asset, and I'm trying to set up waveform plots in world space. I would like to be able to create a few canvases and assign specific VectorLine objects to those canvases. I'm using Vectrosity 4 and Unity 5, scripting in C#.

    I looked at the discussion here, but I am still unsure how to set up new canvases, assign the vector lines, and preferably destroy the screen space VectorCanvas that is set up by default, which I won't be using. Would anybody be so kind to provide example code of this workflow?
     
  33. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    That's somewhat old; since Vectrosity 4.1 you can just use VectorLine.canvasID. I wouldn't recommend destroying the default canvas; it won't use any CPU if you're not using it.

    --Eric
     
  34. ctp

    ctp

    Joined:
    Apr 21, 2013
    Posts:
    9
    Thanks Eric!

    The code shown below is working for me now... I set up 2 lines in world space, with each their own canvasID.
    I get a total of 3 VectorCanvas3D canvases. One is the default, named "VectorCanvas3D", but the other two both get named "VectorCanvas3D_3" ... Why not "VectorCanvas3D_1" and "VectorCanvas3D_2"?

    Code (CSharp):
    1. using UnityEngine;
    2. using System;
    3. using Vectrosity;
    4. using System.Collections.Generic;
    5.  
    6. public class vectrosityTest_001 : MonoBehaviour
    7. {
    8.     public int maxLinePoints = 200;
    9.     public Material line1Material, line2Material;
    10.     public Texture2D frontTexture1, frontTexture2;
    11.     VectorLine bioLine1, bioLine2, bioLine3;
    12.     Transform bioLine1Transform, bioLine2Transform;
    13.     float heightScale = 10;
    14.  
    15.     // Use this for initialization
    16.     void Start()
    17.     {
    18.         VectorLine.SetEndCap("RoundedEnd1", EndCap.Mirror, line1Material, frontTexture1);
    19.         bioLine1 = new VectorLine("bioLine1", new List<Vector3>(), line1Material, 5.0f, LineType.Continuous, Joins.Fill);
    20.         bioLine1.points3.Add(new Vector3(0, 0, 0));
    21.         bioLine1.endCap = "RoundedEnd1";
    22.         bioLine1Transform = new GameObject("line1TransformGameObj").transform;
    23.         bioLine1.canvasID = 1;
    24.  
    25.         VectorLine.SetEndCap("RoundedEnd2", EndCap.Mirror, line2Material, frontTexture2);
    26.         bioLine2 = new VectorLine("bioLine2", new List<Vector3>(), line2Material, 5.0f, LineType.Continuous, Joins.Fill);
    27.         bioLine2.points3.Add(new Vector3(0, 0, 0));
    28.         bioLine2.endCap = "RoundedEnd2";
    29.         bioLine2Transform = new GameObject("line2TransformGameObj").transform;
    30.         bioLine2.canvasID = 2;
    31.     }
    32.  
    33.     // Update is called once per frame
    34.     void Update()
    35.     {
    36.         updateLines();
    37.     }
    38.  
    39.     void updateLines()
    40.     {
    41.         if (Time.frameCount % 2 == 0) // for every 2 frames
    42.         {
    43.             float x1 = Time.time * 3;
    44.             float y1 = heightScale * Mathf.Sin(x1);
    45.             bioLine1.points3.Add(new Vector3(x1, y1, 0));
    46.             if (bioLine1.points3.Count > maxLinePoints)
    47.             {
    48.                 bioLine1.points3.RemoveAt(0);
    49.                 bioLine1Transform.position = new Vector3(-bioLine1.points3[0].x, 0, 0);
    50.                 bioLine1.drawTransform = bioLine1Transform;
    51.             }          
    52.             bioLine1.Draw3D();
    53.         }
    54.  
    55.         if (Time.frameCount % 10 == 0) // for every 10 frames
    56.         {
    57.             float x2 = Time.time;
    58.             float y2 = heightScale * Mathf.PerlinNoise(2*x2, 0.0F);
    59.             bioLine2.points3.Add(new Vector3(x2, y2, 0));
    60.             if (bioLine2.points3.Count > maxLinePoints)
    61.             {
    62.                 bioLine2.points3.RemoveAt(0);
    63.                 bioLine2Transform.position = new Vector3(-bioLine2.points3[0].x, 0, 0);
    64.                 bioLine2.drawTransform = bioLine2Transform;
    65.             }
    66.             bioLine2.Draw3D();
    67.         }
    68.     }
    69. }
     
  35. David Wagg

    David Wagg

    Joined:
    Aug 5, 2013
    Posts:
    8
    Hi Eric,

    I'm still having problems with using smooth width (Unity 5.0.1 and Vectrosity 4.2). This is only apparent when I use a material:
    Code (CSharp):
    1. public class LineTest : MonoBehaviour
    2. {
    3.     public Material lineMaterial;
    4.  
    5.     public void Start()
    6.     {
    7.         Vector2[] linePoints = { new Vector2(100, 100), new Vector2(400, 100), new Vector2(600, 100) };
    8.         var myLine = new VectorLine("MyLine", linePoints, lineMaterial, 2f, LineType.Continuous);
    9.         float[] widths = { 20f, 60f };
    10.         myLine.SetWidths(widths);
    11.         myLine.smoothWidth = true;
    12.         myLine.Draw();
    13.     }
    14. }
    With lineMaterial = null I see this:

    But with a valid line material (Unlit/Transparent shader and ThinLine texture) I see this:

    Any idea what's going wrong?
     
  36. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,459
    This works great..

    Another question: What is the recommended way to "Redraw" the VectorLine in the case of users modifying the Bezier curve. Do I have to destroy the previously drawn vectorLine and draw a new one?
     
  37. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Seems to be a bug; I'll look into it.

    A limitation of UV mapping; there was a forum topic about that recently. You can fix it by subdividing the segment into several segments.

    --Eric
     
  38. fahd

    fahd

    Joined:
    Aug 7, 2014
    Posts:
    31
    Hi,
    I'm working on a project were
    1 - user upload photo of a room then .
    2 - draw over the room walls with pen tool.
    3 - paint the walls with different color.

    my question is can i create a pen tool where user start adding points and lines will connects between the points then when user click the first point he added it will be a complete shape then ill fill color or add texture to that shape
    ( basic photoshop pen tool )


    Thank you so much for the awesome work you guys doing :) .
     

    Attached Files:

  39. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can do the line stuff with Vectrosity (example), but you'd have to do the filled shape stuff yourself.

    --Eric
     
  40. Devanstator

    Devanstator

    Joined:
    Sep 27, 2013
    Posts:
    7
    Hello

    I would like to know if everything in Vectrosity works correctly when rendered with an orthographic camera. I want advanced lines in my UI and have my root Canvas set to "Screen Space - Camera" with an orthographic camera set up (so I can have particles etc). I notice that LineRenderer doesn't billboard correctly when using orthographic, so I want to check whether there are similar constraints in Vectrosity.

    Thanks
     
  41. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It work fine with an orthographic camera.

    --Eric
     
  42. David Wagg

    David Wagg

    Joined:
    Aug 5, 2013
    Posts:
    8
    Thanks Eric, 50+ line segments makes the problem more or less imperceptible. Perhaps you could add a note to the documentation? The example for smoothWidth uses 3 segments, so it's not immediately obvious that a textured line requires many more segments.
     
  43. fahd

    fahd

    Joined:
    Aug 7, 2014
    Posts:
    31
    thanks for the replay,
    can you help me to do the shape fill with color or point me somewhere to do it
     
  44. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You could start by reading the Unity docs about the Mesh class. That's not related to Vectrosity, though, so if you need more help you should start a topic for it.

    --Eric
     
  45. tbg10101_

    tbg10101_

    Joined:
    Mar 13, 2011
    Posts:
    192
    Hello,

    I was looking at how to get lines to render on multiple cameras and stumbled upon this:
    http://answers.unity3d.com/questions/366091/viewing-vectrosity-lines-from-multiple-cameras.html

    This seems very slow for some reason and it doesn't work.

    I add this to my two cameras:
    Code (CSharp):
    1. using UnityEngine;
    2. using Vectrosity;
    3.  
    4. public class DrawLines : MonoBehaviour {
    5.     void OnPreRender () {
    6.         Camera c = (Camera)GetComponent<Camera>();
    7.  
    8.         if (c != null) {
    9.             VectorLine.SetCamera3D(c);
    10.         }
    11.  
    12.         foreach (VectorLine l in LineList.lines) {
    13.             l.Draw3D();
    14.         }
    15.     }
    16. }
    LineList.lines is a static List of all the VectorLines I created. (about 2000)


    Another attempt I made is this on the object that the lines relate to I draw the lines once per camera:
    Code (CSharp):
    1.             foreach (Camera c in PlayerController.instance.camerasThatRenderLines) {
    2.                 VectorLine.SetCamera3D(c);
    3.                 cardinalZPlusIndicator.Draw3D();
    4.                 cardinalZMinusIndicator.Draw3D();
    5.                 cardinalXPlusIndicator.Draw3D();
    6.                 cardinalXMinusIndicator.Draw3D();
    7.                 directionIndicator.Draw3D();
    8.                 elevationIndicator.Draw3D();
    9.                 radiusIndicator.Draw3D();
    10.                 targetLocationIndicator.Draw3D();
    11.             }
    This is much faster than the method above but similarly only draws the lines on the main camera.

    Is there some 'official' way that I am supposed to get lines to render on both cameras?
     
    Last edited: May 12, 2015
  46. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    That answer only applies to Vectrosity 3; with Vectrosity 4, Camera.OnPreRender won't work. You'd need to make two sets of lines, one for each camera. To make this easier to manage, use a generic List for the points, so that way the List is a reference, and updating the List will update the points for both lines that use it.

    --Eric
     
  47. matias-e

    matias-e

    Joined:
    Sep 29, 2014
    Posts:
    106
    Is the script for this thingy available anywhere?
     
  48. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    All scripts for all demos (plus some more) are included.

    --Eric
     
  49. tbg10101_

    tbg10101_

    Joined:
    Mar 13, 2011
    Posts:
    192
    Unfortunately I am having circles aligned to the x-z pane track objects so I have to call MakeCircle every frame. :/

    So, here is how I changed my code:
    Code (CSharp):
    1. public class Ownership : MonoBehaviour {
    2.     //lines
    3.     private Dictionary<Camera, VectorLine> planeIndicator = new Dictionary<Camera, VectorLine>();
    4.     private Dictionary<Camera, VectorLine> yIndicator = new Dictionary<Camera, VectorLine>();
    5.  
    6.     void Start () {
    7.         foreach (Camera c in PlayerController.instance.camerasThatRenderLines) {
    8.             planeIndicator[c] = new VectorLine("On-Plane Indicator", new Vector3[12 + (int)(3.1415f * radius * 2)], null, 2, LineType.Continuous);
    9.             yIndicator[c] = new VectorLine("Y-Axis Indicator", new Vector3[2], null, 2);
    10.         }
    11.     }
    12.  
    13.     void LateUpdate () {
    14.         //update the lines
    15.         if (selected || selectionConsideration) {
    16.             foreach (Camera c in PlayerController.instance.camerasThatRenderLines) {
    17.                 planeIndicator[c].active = (Camera.main.transform.position - transform.position).sqrMagnitude < endFadeDistance * endFadeDistance;
    18.  
    19.                 planeIndicator[c].MakeCircle(transform.position, Vector3.up, radius);
    20.             }
    21.         }
    22.  
    23.         //draw lines (only drawn if active)
    24.         foreach (Camera c in PlayerController.instance.camerasThatRenderLines) {
    25.             VectorLine.SetCamera3D(c);
    26.             planeIndicator[c].Draw3D();
    27.             yIndicator[c].Draw3D();
    28.         }
    29.     }
    30. }
    I still only see the lines on the main camera.
     
  50. matias-e

    matias-e

    Joined:
    Sep 29, 2014
    Posts:
    106
    Ahh, it was packed with the freeform draw line scripts. Found it now.

    I wonder, is there a way to apply 'transform.Translate' to a line?