Search Unity

Vectrosity - Fast and Easy Line Drawing

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

  1. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    Hi Eric.

    Code (csharp):
    1.  
    2. // This script draws an ellipse using a continuous line
    3. import Vectrosity;
    4.  
    5. var lineMaterial : Material;
    6. var xRadius = 120.0;
    7. var segments = 60;
    8. var pointRotation = 0.0;
    9.  
    10. function  Start ()
    11. {
    12.    var linePoints = new Vector2[segments+1];
    13.  
    14.    // Make a VectorLine object using the above points and a material as defined in the inspector, with a width of 3 pixels
    15.    var line = new VectorLine("Line", linePoints, lineMaterial, 3.0, LineType.Continuous);
    16.    line.MakeCircle (Vector2(Screen.width/2, Screen.height/2), xRadius, segments, pointRotation);
    17.  
    18.    // Draw the line
    19.    line.Draw();
    20. }
    21.  
    According with the demo (and doc) This code draws a circle in the 'Start function'. But what is the best way to change in real time (Update function) the number of "segments" (and the 'pointRotation').


    Thanks.
     
    Last edited: Jan 20, 2015
  2. yezzer

    yezzer

    Joined:
    Oct 30, 2009
    Posts:
    143
    I've had a Webplayer project live for about 6 months, and I've just been informed that during that time, a Webplayer update has caused Vectrosity lines to stop being drawn.. Anyone else encountered this?
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It's not possible, sorry.

    The VectorLine should be a global variable, then you can change the line.points2 list to have more or fewer points (the Resize function is the easiest way), and call MakeCircle again.

    You probably need to re-publish with Unity 4.6.

    --Eric
     
  4. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    Thanks. :cool:
     
  5. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,633
    Hey guys, so this requires coding to make things wireframe? I have searched the demos a lot I am simply looking for a way to make meshes draw in wireframe. Seems Unity have made this an insanely hard task, lol.. I thought somehow that this would contain a wireframe shader or something. So is there any drag and drop way to make my whole scene or even one model wireframe using this ?
     
  6. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    Maybe this helps?
     
  7. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    Btw, it seem there is no natif function for drawing an arc. Why not two news options in the circle function: startAngle and endAngle?

    I will take a look in the source. :p
     
  8. XGT08

    XGT08

    Joined:
    Aug 1, 2013
    Posts:
    1,905
    Hello,

    I just bought your package and I am really glad about it :D. I am planning on using it in a strategy game that I have started working on. However, I believe I have found a bug. I was just experimenting and I wrote the following code to create a circle:

    VectorLine line = new VectorLine("Line", new Vector3[30], null, 1.0f, LineType.Continuous, Joins.Weld);
    line.color = Color.green;
    line.MakeCircle(Vector3.zero, Vector3.up, 2.0f);
    line.Draw3D();

    I am using this code to create a circle which lies in the XZ plane, but I get the following resut:
    Circle_Error.png
    As you can see, instead of being perfectly aligned with the XZ plane, the circle is slightly rotated around the forward vector. This only happens when I use Joins.Weld.

    When I use Joins.Fill, the circle is correctly aligned, however, there are a bunch of segments which are not properly joined:
    Join_Error.png

    Other than that, the package is great! Thanks a lot and I really hope you can help me out!
     
  9. shayan_315

    shayan_315

    Joined:
    Sep 24, 2013
    Posts:
    28
    Hi,
    I used this code to draw number of lines,It works well but I have great problem.In my project. user should be allowed
    to delete each line which he likes.but when I tried to use :
    Code (CSharp):
    1.         if (Input.touchCount > 0 && (line.Selected (Input.mousePosition, out lineIndex)))
    2.  
    3. VectorLine.Destroy (ref line);
    it only delete last created line. how I can delete each line separately without receiving null reference error.

    Code (CSharp):
    1.     using UnityEngine;
    2.     using System.Collections;
    3.     using Vectrosity;
    4.     public class Vectors : MonoBehaviour {
    5.     //public Material lineMaterial;
    6.     public int numOfLines = 5;
    7.     public float minLineWidth = 2f;
    8.     public float maxLineWidth = 15f;
    9.     private int maxPoints = 1000; //maximum points a line can have
    10.     private int lineCounter = 0; //incrementor that represents the current stroke the user is drawing
    11.     private VectorLine[] linesArray;
    12.     private Vector2[] pointsArray;
    13.     private Vector2 previousPosition;
    14.     private int minPixelMove = 5; // Must move at least this many pixels per sample for a new segment to be recorded
    15.     private int sqrMinPixelMove;
    16.     private bool canDraw = false; //var to toggle drawing
    17.     private Vector2 mousePos;
    18.     private int lineIndex = 0; //what is this?
    19.     private VectorLine line; //shortcut for the VectorLine line inside update functions
    20.     void Start () {
    21.     linesArray = new VectorLine[numOfLines]; //set array to have numOfLines as a maximum amount of lines a player can draw
    22.     pointsArray = new Vector2[maxPoints]; //set up an array of vectro2 points to use for the lines
    23.     for(int i=0; i < numOfLines;i++){
    24.     linesArray[i] = new VectorLine("Stroke", pointsArray, null, maxLineWidth, LineType.Continuous, Joins.Weld);
    25.     }
    26.     sqrMinPixelMove = minPixelMove*minPixelMove; //not sure what this does
    27.     }
    28.     // Update is called once per frame
    29.     void Update () {
    30.     mousePos = Input.mousePosition;
    31.     if ( Input.GetMouseButtonDown(0) && lineCounter < numOfLines) {
    32.     StartLine ();
    33.     }
    34.     //Checks if the mouse is held down and mouse moved more than a certain minimum of pixels and if line counter
    35.     else if (Input.GetMouseButton(0) && (mousePos - previousPosition).sqrMagnitude > sqrMinPixelMove && (canDraw && lineCounter < numOfLines) ) {
    36.     ContinueLine();
    37.     }
    38.     else if( Input.GetMouseButtonUp (0) )
    39.     lineCounter++;
    40.     }
    41.     public void StartLine() {
    42.     line = linesArray[lineCounter];
    43.     line.ZeroPoints(); //sets all points of the current line being drawn to Vector.zero
    44.     line.minDrawIndex = 0; //sets the lowest Vector2 point in the current line to be drawn(updated)
    45.     //draw the current line
    46.     line.Draw();
    47.     //set the previous position of the mouse to the first vector2 coords of the points array, but why?
    48.     previousPosition = pointsArray[0] = mousePos;
    49.     canDraw = true;
    50.     lineIndex = 0;
    51.     line.lineWidth = maxLineWidth; //reset line width on mouse press
    52.     print (lineCounter);
    53.     }
    54.     public void ContinueLine() {
    55.     line = linesArray[lineCounter];
    56.     previousPosition = pointsArray[++lineIndex] = mousePos; //set the point in the line as its being drawn
    57.     line.minDrawIndex = lineIndex - 1; //set the least most point to be redrawn to be the next one below
    58.     line.maxDrawIndex = lineIndex; //only redraw the current point
    59.     if (lineIndex >= maxPoints) canDraw = false; //if maximum points have been exceeded, end the line
    60.     if(line.lineWidth > minLineWidth) line.lineWidth--; //decrease linewidth
    61.     line.Draw ();
    62.     }
    63.     }
    I
     
  10. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The lines are oriented to the camera; if you want them oriented a specific way, you can have a camera pointing straight down and use that with SetCamera3D. As for the segments not properly joined, I'm not seeing that regardless of camera orientation or Joins type. Is that the actual code you're using? Any other code that might be interfering? What version are you using?

    You'd want to have a List of lines, and loop through the list to check which one is selected. Then destroy the selected one and remove it from the List.

    --Eric
     
  11. joan

    joan

    Joined:
    Jul 14, 2012
    Posts:
    3
    Hi, i´m trying to make a draw line with mouse with colliders in all extension of the line, but it´s getting very difficult. Can someone please give me some light about how can i do that.
    Here´s my modification on script:
    Code (CSharp):
    1. @script RequireComponent(BoxCollider)
    2. var lineMaterial : Material;
    3. var maxPoints = 1000;
    4. var lineWidth = 4.0;
    5. var minPixelMove = 5;    // Must move at least this many pixels per sample for a new segment to be recorded
    6. private var linePoints : Vector2[];
    7. private var line : VectorLine;
    8. private var lineIndex = 0;
    9. private var previousPosition : Vector2;
    10. private var sqrMinPixelMove : int;
    11. private var canDraw = false;
    12. var colider:GameObject;
    13.  
    14. function Start () {
    15.     linePoints = new Vector2[maxPoints];
    16.     line = new VectorLine("DrawnLine", linePoints, lineMaterial, lineWidth, LineType.Continuous);
    17.     sqrMinPixelMove = minPixelMove*minPixelMove;
    18. }
    19.  
    20. function Update () {
    21.     var mousePos = Input.mousePosition;
    22.     if (Input.GetMouseButtonDown(0)) {
    23.         Vector.ZeroPointsInLine(line);
    24.         line.minDrawIndex = 0;
    25.         Vector.DrawLine(line);
    26.         previousPosition = linePoints[0] = mousePos;
    27.         lineIndex = 0;
    28.         canDraw = true;
    29.        
    30.         colider.AddComponent(BoxCollider);
    31.         colider.transform.localScale= new Vector3(0.1f, 0.1f, 0.1f);
    32.         colider.transform.position=linePoints[0];
    33.     }
    34.     else if (Input.GetMouseButton(0) && (mousePos - previousPosition).sqrMagnitude > sqrMinPixelMove && canDraw) {
    35.         previousPosition = linePoints[++lineIndex] = mousePos;
    36.         line.minDrawIndex = lineIndex-1;
    37.         line.maxDrawIndex = lineIndex;
    38.         if (lineIndex >= maxPoints-1) canDraw = false;
    39.         Vector.DrawLine(line);
    40.     }
    41.    
    42.    
    43. }
    Thanks
     
  12. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can just use line.collider = true.

    --Eric
     
  13. shayan_315

    shayan_315

    Joined:
    Sep 24, 2013
    Posts:
    28
    but how I can select one of lines and destroy it. my codes don't work properly.
     
  14. joan

    joan

    Joined:
    Jul 14, 2012
    Posts:
    3
    It still does not work. When i code line.collider=true, it give´s me a error "MissingFieldException: VectorLine.collider". I can make static lines only use line.collider=true, but drawing the line with mouse give´s me that error all the time. Am i forgetting anything???
     
  15. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Have a look at the example (RandomHills) that uses a VectorLine.collider. (Unless you're using a very old version of Vectrosity which doesn't have VectorLine.collider, in which case I'd recommend upgrading.)

    --Eric
     
  16. wbl1

    wbl1

    Joined:
    Apr 22, 2009
    Posts:
    159
    sketcher.jpg

    Eric,

    I have a situation here in which I have a 2D "sketcher" that needs to align with a 3D object. In the image you see that the 3D object is sort of a transparent gray ... and the 2d sketcher is where I want it. The image you see here was developed with a previous version of vectrocity that used cameras. I managed to get the 2D and 3D images in alignment by simply using the same orthographic size on each.

    Since more recent versions of Vectrocity are based on the canvas, can you give any advice on how to do this?

    Thanks
     
  17. joan

    joan

    Joined:
    Jul 14, 2012
    Posts:
    3
    Hi Eric
    I updated my version and now i'm using version 4 but in the script, in fact i can put a collider, but a (small) edge collider at the beginning of the line and it does not follow all the line. Is there a way to make a collider in all extension of the line? Like RandomHills, but with mouse input? I try make a collider vertex by vertex but it seems not possible.
     
  18. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Unless I'm misunderstanding, you can still do the same thing...use an orthographic camera for the 3D part.

    If you use VectorLine.collider, the edge/polygon collider is updated whenever the line is redrawn. If you just put line.collider = true in the DrawLinesMouse example, you have an user-drawn line with collision.

    --Eric
     
  19. Sykoo

    Sykoo

    Joined:
    Jul 25, 2014
    Posts:
    1,394
    This is super cool! :)
     
  20. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I'm glad you think so. :)

    --Eric
     
    Sykoo likes this.
  21. wbl1

    wbl1

    Joined:
    Apr 22, 2009
    Posts:
    159
    I am still using an orthographic camera for the 3D part. The issue is that the 2d sketcher is no longer rendered with a camera - SetCamera(-some camera with the same ortho size as the 3d part-) doesn't exist anymore. So, what's the best way to render these 2d vectrocity entities- that are now utilizing a canvas - such that they align perfectly with the 3D geom?
     
  22. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Sounds like SetCanvasCamera is what you want, where it uses a screen space-camera canvas with the supplied camera.

    --Eric
     
  23. shayan_315

    shayan_315

    Joined:
    Sep 24, 2013
    Posts:
    28
    I use Vectrosity 3.1.
    I defined a list and saved each line that I have created one by one.I defined maximum numbers of line that I can create(var name is numOfLines). Now, I want to know, after user touch Eraser button which line of this list was touched and then remove it from list and clear it from screen and user be allowed to create a new line instead of cleared line.
    But my problem is,Selected() function is always true for each line before even I touch that specific line from list.
    I search trough list of lines and try to delete selected line but it doesn't work:
    Code (CSharp):
    1.         if (EraserButton )
    2.         {
    3.             for(int i=0;i<lineCounter;i++)
    4.             {
    5.                 if (Input.GetMouseButtonDown(0) && ListOfLines[i].Selected (Input.mousePosition))
    6.                {
    7.                   ListOfLines.RemoveAt(ListOfLines[i]);
    8.                   lineCounter--;
    9.                 }
    10.             }
    11.         }

    besides,I create an array of vector line with this code
    Code (CSharp):
    1.         for(int i =0 ; i<numOfLines; i++)
    2.         {
    3.             linesArray[i] = new VectorLine("DrawnLine", linePoints, lineMaterial, lineWidth, LineType.Continuous, Joins.Weld);
    4.         }
    in my Start() function If I destrory one of my linesArray would I allowed to create another one and can user draw another line on it?
     
  24. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Don't use an array, just use a List. You can see in the SelectLine demo that Selected does work as advertised, so try to see what differences you might have in your code compared to the demo.

    --Eric
     
  25. shayan_315

    shayan_315

    Joined:
    Sep 24, 2013
    Posts:
    28
    Thank you for your useful answer, I stopped using array in creating list of lines, thus performance of project obviously is better.
    Now, I create each VectorLine trough my list with
    Code (CSharp):
    1.                 ListOfLines.Add(new VectorLine("DrawnLine", linePoints, lineMaterial, lineThickness, LineType.Continuous, Joins.Weld));
    2.  
    after each time that mouse button is down .As you said , for solving Line.Selected problem, I tried to change selectedLine project. That project was OK first. But, my problem happened in that project too when I tried to select a drawn line from my list. in both case, when I use
    Code (CSharp):
    1.             if (ListOfLines[1].Selected(Input.mousePosition,out index))
    2.  
    3.         {
    4.                 ListOfLines[1].SetColor (Color.green);
    5.           }
    to change color of second element of ListOflines to green(lists elements start from 0) when I choose last
    drawn line, the second second line color changes.I think this is because, all vector line that drawn on the camera have the same name and the last one is only available.What should I do? why a line which is added to my list cannot use selected function just by ListOfLines[1].Selected... script?

    I have tested SelectedLine project and I have tried to create 2 random line in one list it is impossible to choose true selected line from your list index. Only when you are on the last drawn line the result would be true . what do you suggest?
     
    Last edited: Jan 25, 2015
  26. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    No, lines are never referred to by name in Vectrosity. If you have a reference to a line then it refers to that line only. Here's a quick modification of the SelectLine demo to use an array:

    Code (csharp):
    1. #pragma strict
    2. import Vectrosity;
    3.  
    4. var lineThickness = 10.0;
    5. var extraThickness = 2;
    6. var numberOfLines = 10;
    7. private var lines : VectorLine[];
    8. private var wasSelected : boolean[];
    9. private var index = 0;
    10.  
    11. function Start () {
    12.     lines = new VectorLine[numberOfLines];
    13.     wasSelected = new boolean[numberOfLines];
    14.     for (var i = 0; i < numberOfLines; i++) {
    15.         lines[i] = new VectorLine("SelectLine", new Vector2[5], null, lineThickness, LineType.Continuous, Joins.Fill);
    16.         SetPoints (i);
    17.     }
    18. }
    19.  
    20. function SetPoints (i : int) {
    21.     for (var j = 0; j < lines[i].points2.Count; j++) {
    22.         lines[i].points2[j] = Vector2(Random.Range(0, Screen.width), Random.Range(0, Screen.height-20));
    23.     }
    24.     lines[i].Draw();  
    25. }
    26.  
    27. function Update () {
    28.     for (var i = 0; i < numberOfLines; i++) {
    29.         if (lines[i].Selected (Input.mousePosition, extraThickness, index)) {
    30.             if (!wasSelected[i]) {    // We use wasSelected to update the line color only when needed, instead of every frame
    31.                 lines[i].SetColor (Color.green);
    32.                 wasSelected[i] = true;
    33.             }
    34.             if (Input.GetMouseButtonDown(0)) {
    35.                 SetPoints (i);
    36.             }
    37.         }
    38.         else {
    39.             if (wasSelected[i]) {
    40.                 wasSelected[i] = false;
    41.                 lines[i].SetColor (Color.white);
    42.             }
    43.         }
    44.     }
    45. }
    46.  
    47. function OnGUI () {
    48.     GUI.Label (Rect(10, 10, 800, 30), "Click a line to make a new line");
    49. }
    --Eric
     
  27. ichini

    ichini

    Joined:
    Oct 13, 2012
    Posts:
    23
    Hi Eric,

    I'm having trouble porting a script to Vectrosity 4: The script sets up a grid of rigidbodies with physics properties, saves their positions to a Vector3 array and correctly creates a VectorLine like this:

    grid = new VectorLine ("Grid", drawPoints, gridMaterial, lineWidth);

    Now I update the Vector3 array ('drawPoints') each frame, but the VectorLine doesn't update accordingly, no matter if i use grid.Draw3DAuto(), call grid.Draw3D() on LateUpdate, or use the VectorManager. The only thing that works is destroying the line each frame, creating a new one and redrawing it. Oddly all three ways to update the line work fine in Vectrosity 3. Has the API changed in this regard?

    Apologies if I'm missing something obvious, might be my sunday state of mind...

    Thank you,
    georg.-

    Edit: Ah, found it. This part is new: "the contents of the array or list is copied to the VectorLine, and the array/list is no longer used afterward." Instead, the VectorLine comes with its own List. So (e.g):

    grid.points3.Clear();
    grid.points3.AddRange(drawPoints.ToList());
    grid.Draw3D();

    sorry for the bother!
     
    Last edited: Jan 25, 2015
  28. shayan_315

    shayan_315

    Joined:
    Sep 24, 2013
    Posts:
    28
    Wow, it works very well,Thanks a lot.
    So,why I try to mix with my code and I try to choose one of lines all of them become green :( ?
    This is my code :
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using Vectrosity;
    4.  
    5. public class DrawingLine : MonoBehaviour
    6. {
    7.     private Vector2[] points ;
    8.     private Touch touch;
    9.     private VectorLine line ;
    10.     private Vector2[] linePoints ;
    11.     private Vector2 previousPosition;
    12.     private int lineIndex=0;
    13.     private bool canDraw = false;
    14.     private int maxPoints = 1000;
    15.  
    16.     private int sqrMinPixelMove ;
    17.     private int minPixelMove = 5;
    18.     private Material lineMaterial;
    19.     private int lineCounter=0;
    20.     private bool EraserButton=false;
    21.  
    22.     private Vector2 mousePos;
    23.     private float lineThickness = 3f;
    24.     private int extraThickness = 2;
    25.     private int numberOfLines = 10;
    26.     private VectorLine[] lines ;
    27.     private bool[] wasSelected ;
    28.     private int index = 0;
    29.  
    30.     void Start ()
    31.     {
    32.       lines = new VectorLine[numberOfLines];
    33.       wasSelected = new bool[numberOfLines];
    34.  
    35.       linePoints = new Vector2[maxPoints];
    36.       sqrMinPixelMove = minPixelMove*minPixelMove;
    37.     }
    38.     void DrawFreeLine()
    39.     {
    40.         if (!EraserButton && lineCounter<numberOfLines)
    41.         {
    42.             mousePos = Input.mousePosition;
    43.             if (Input.GetMouseButtonDown(0))
    44.             {
    45.                 lines[lineCounter]= new VectorLine("DrawnLine", linePoints, lineMaterial, lineThickness
    46.                                                    , LineType.Continuous, Joins.Fill);
    47.                 lines[lineCounter].ZeroPoints();
    48.                 lines[lineCounter].minDrawIndex = 0;
    49.                 lines[lineCounter].Draw();
    50.                 previousPosition = linePoints[0] = mousePos;
    51.                 lineIndex = 0;
    52.                 canDraw = true;
    53.             }
    54.             else if (Input.GetMouseButton(0) && (mousePos - previousPosition).sqrMagnitude > sqrMinPixelMove && canDraw) {
    55.                 previousPosition = linePoints[++lineIndex] = mousePos;
    56.                 lines[lineCounter].minDrawIndex = lineIndex-1;
    57.                 lines[lineCounter].maxDrawIndex = lineIndex;
    58.                 if (lineIndex >= maxPoints-1) canDraw = false;
    59.                 lines[lineCounter].Draw();
    60.             }else if(Input.GetMouseButtonUp(0))
    61.             {
    62.                 lineCounter++;
    63.             }
    64.         }
    65.     }
    66.     void Update ()
    67.     {
    68.       DrawFreeLine ();
    69.       SelectOnOff();
    70.       if(EraserButton)
    71.         {
    72.             for (int i = 0; i <lineCounter; i++)
    73.             {
    74.                 if (lines[i].Selected (Input.mousePosition, extraThickness,out index))
    75.                 {
    76.                     if (!wasSelected[i]) {
    77.                         lines[i].SetColor (Color.green);
    78.                         wasSelected[i] = true;
    79.                     }
    80.                 }
    81.                 else {
    82.                     if (wasSelected[i]) {
    83.                         wasSelected[i] = false;
    84.                         lines[i].SetColor (Color.white);
    85.                     }
    86.                 }
    87.             }
    88.         }
    89.     }
    90.   void SelectOnOff()
    91.     {
    92.             if (Input.GetKey("up"))
    93.             {
    94.                 EraserButton=true;
    95.             }
    96.             if (Input.GetKey("down"))
    97.                 EraserButton=false;
    98.         }
    99. }
    100.  
    what is your Idea?
     
    Last edited: Jan 26, 2015
  29. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You're using the same linePoints array for all the lines.

    --Eric
     
    shayan_315 likes this.
  30. wbl1

    wbl1

    Joined:
    Apr 22, 2009
    Posts:
    159
    It looks like drawTransform does not work when using VectorPoints? When you do this, the points look to be drawn at the center of the drawTransform regardless of points2.

    Is this a bug or am I missing something?
     
  31. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I'm not sure what you mean; drawTransform applies the transform attributes of the specified transform to the VectorLine when drawn. This works the same for VectorPoints as well as VectorLine.

    --Eric
     
  32. MornFall

    MornFall

    Joined:
    Jan 11, 2013
    Posts:
    160
    Hi all, i could use some help to get started.
    I am a newb scripter so please forgive my ignorance...

    Basically, i am simply trying to make a kind of laser for my turret, and i am stuck with the update of the line. It draws it first but then never updates the line.
    Here is the code :

    Code (CSharp):
    1. void Start ()
    2.     {
    3.         myLine = VectorLine.SetRay3D (Color.green, Mathf.Infinity, shootingPoint.transform.position, shootingPoint.transform.forward) ;
    4.     }
    5.  
    6. void Update ()
    7.     {
    8.         //SOME Complicated coded that rotates the shootingPoint towards the target
    9.  
    10.         myLine.Draw3D() ;
    11.      }
    The line is being drawn the first frame and then never updates its position ( does not follow my shootingPoint ).
    What am i missing ?
     
  33. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You'd need to update the points in the line, using myLine.points3. Also you can use Draw3DAuto in Start rather than calling Draw3D every frame in Update.

    --Eric
     
  34. MornFall

    MornFall

    Joined:
    Jan 11, 2013
    Posts:
    160
    Thank you Eric. II understand the idea but not too sure how to do it, but i ll search for that in the reference.
     
  35. shayan_315

    shayan_315

    Joined:
    Sep 24, 2013
    Posts:
    28
    Thanks a lot I have done it.
    I want to delete each VectorLine that I select. My codes works great when I choose each line from last one to first one,
    But when for example I have drawn 5 lines and I decide to erase second one first and the fourth I recieve :"NullReferenceException: Object reference not set to an instance of an object"
    error , I think the problem happens because I remove one index of my array so I decided to use swap form codes
    to change place of last one with selected one but it doesn't work.

    Code (CSharp):
    1.             for (int i = 0; i <lineCounter; i++)
    2.             {
    3.                 if (lines[i].Selected (Input.mousePosition, extraThickness,out index))
    4.                 {
    5.                     VectorLine tempLine=lines[i];
    6.                     lines[i]=lines[lineCounter];
    7.                     lines[lineCounter]=tempLine;
    8.                     VectorLine.Destroy(ref lines[lineCounter]);
    9.  
    10.                     lineCounter--;
    11.                     break;
    12.                    
    13.                 }
    14.             }
     
  36. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You need to use a List, not an array (as discussed earlier).

    --Eric
     
  37. skelly

    skelly

    Joined:
    Oct 21, 2012
    Posts:
    3
    Hi Eric- liking the new version. One issue im having is trying to figure out how to render a unity 4.6 Canvas to a rendertexture- is there any way you know of to get vectrosity lines to show up on a texture? Ideally i need to be able to postprocess them as a bitmap.

    thanks!

    Sean
     
  38. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can use VectorLine.SetCanvasCamera.

    --Eric
     
  39. TBruce

    TBruce

    Joined:
    Jan 18, 2015
    Posts:
    86
    Hi Eric,

    Great tool. I am having a problem though. I have some static lines defines in my class that are created at runtime. When I run the game I see the lines appear in the scene but they are not visible in the game. If I create a line in the same code using code taken from the DrawLines example and place it in my game only the newly created line is seen. I am sure there is something I am missing here but I can not find it. I have attached a sample class, please help. Thanks in advance!
     

    Attached Files:

  40. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    A few things:

    1) You're using Vector2 points, thus screen space, but coordinates like (-16.8f, 7.65f) don't really make sense in that context. If you want world space, the coords need to be Vector3.
    2) Using 0.3 pixel width won't look like much; the line width should be at least 1 pixel.
    3) I don't know if the Self Illumin/Diffuse shader would even work; try a different shader or just use the default (null) if you want a solid unlit line.
    4) Using drawTransform = transform applies the transform of whatever object the script is attached to, so depending on where that object is, it could have moved the line somewhere not visible.

    --Eric
     
  41. TBruce

    TBruce

    Joined:
    Jan 18, 2015
    Posts:
    86
    Great, that worked. But now my Joins.Weld is not working.
     
  42. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Increase the line maxWeldDistance.

    --Eric
     
  43. TBruce

    TBruce

    Joined:
    Jan 18, 2015
    Posts:
    86
    That worked. Thanks for the help!
     
  44. ichini

    ichini

    Joined:
    Oct 13, 2012
    Posts:
    23
    Hi Eric,

    Is there a way to clone an object with a 'vectormanaged' vectorline directly from the scene? If I do, I always seem to get the dreaded:
    NullReferenceException: Object reference not set to an instance of an object VisibilityControl.OnBecameVisible ()

    I can instantiate a prefab, no problem, but if i do the same with a live object, the clone's VectorManager doesn't seem to be able to set it up correctly.

    Any ideas? Thanks a lot!

    georg.
     
  45. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    No, sorry, you'd need to use ObjectSetup for each VectorLine. Using Instantiate won't run the code that sets up VectorLines.

    --Eric
     
  46. ichini

    ichini

    Joined:
    Oct 13, 2012
    Posts:
    23
    Hi Eric - thank you, but I'm not sure I follow. I set a new VectorLine and run VectorManager.ObjectSetup in the cloned object's Start() function - shouldn't this execute indiscriminately for a prefab instance or scene instance?

    Anyhow, for my purpose I can use Draw3DAuto(), which doesn't seem to care where the instance is coming from.

    georg.
     
  47. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It will work like that if you instantiate a prefab, but not if you try to instantiate an instance that already exists in the scene, since they've already been initialized and can't be initialized again just by cloning them.

    --Eric
     
  48. shayan_315

    shayan_315

    Joined:
    Sep 24, 2013
    Posts:
    28
    before drawing each line I should add it to a list and I draw each index of list or it should be added after drawing before removing?should I use both of list.removeAt() function and Vectoreline.Destroy function at removing time
    .It is necessary to mention that I can make free line without problem and I can choose them one by one with Selected
    function through my codes and points of each of line has stored accurately .
     
  49. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

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

    Yes.

    --Eric
     
  50. Lautaro-Arino

    Lautaro-Arino

    Joined:
    Sep 18, 2013
    Posts:
    93
    Hi Eric! I just got Vectrosity and im very inspired. Ive read through the manual. I have a strange problem that makes me think i misunderstood something. I have a class caleld Shape for storing information about a shape i want to draw with Vectrosity. It has a VectorLine as a . From a GameObject i instantiate a Shape object. In the constructor i instantiate a VectorLine like this:


    Code (CSharp):
    1.  
    2.     public Shape()
    3.     {
    4.    
    5.         AddPoint();
    6.         VectorLine line = new Vectrosity.VectorLine("line", points, null, thickness, LineType.Continuous);
    7.         Debug.Log(line != null);
    8.     }
    As you can see i check to see that the VectorLine is instantiated. I get a true in the log.

    Then i call the Shape.Draw() from a GameObjects Update(). It looks like this:


    Code (CSharp):
    1.     public void Draw () {
    2.  
    3.  
    4.         if (line == null)
    5.         {
    6.             Debug.Log("line is null");
    7.         }
    8.         else {
    9.             line.Draw();
    10.         }
    11.        
    12.    
    13.     }
    And each time i get that the line is null! How can it be instantiated and then suddenly null? How am i supposed to work with Vectrosity?

    Thanks in advance.