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. ickydime

    ickydime

    Joined:
    Nov 20, 2012
    Posts:
    110
    haha, awesome. Thanks
     
  2. tatelax

    tatelax

    Joined:
    Feb 4, 2010
    Posts:
    1,168
    I had the same issue as you. I had to modify the original arrowhead that comes included in the package, in Photoshop in order to change the size. But I agree, being able to specify a different size would be fantastic.
     
  3. ShawnFeatherly

    ShawnFeatherly

    Joined:
    Feb 22, 2013
    Posts:
    57
    Not sure if this is the right spot to report a bug. I'm getting different behavior between the 2 scripts below and I believe they should show the same thing?

    This one colors in a method close to the rainbow above.
    Code (CSharp):
    1.     void Start()
    2.     {
    3.         var linePoints = new System.Collections.Generic.List<Vector3>() { Vector3.left, Vector3.zero, Vector3.up };
    4.         var theLine = new VectorLine(this.name + "Line", linePoints, null, 2.0f, LineType.Continuous);
    5.  
    6.         theLine.smoothColor = true;
    7.         theLine.SetColor(Color.green, 0);
    8.         theLine.SetColor(Color.red, 1);
    9.         theLine.Draw3D();
    10.     }
    This one performs as explained in the documentation
    Code (CSharp):
    1.     void Start()
    2.     {
    3.         var linePoints = new System.Collections.Generic.List<Vector3>() { Vector3.left, Vector3.zero, Vector3.up };
    4.         var theLine = new VectorLine(this.name + "Line", linePoints, null, 2.0f, LineType.Continuous);
    5.  
    6.         var myColors = new Color32[2];
    7.         myColors[0] = Color.green;
    8.         myColors[1] = Color.red;
    9.         theLine.smoothColor = true;
    10.         theLine.SetColors(myColors);
    11.         theLine.Draw3D();
    12.     }
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You're right, that's a bug. It's fixed for the next version; PM me if you want the code for the fixed SetColor function.

    --Eric
     
  5. Shaun_Summer

    Shaun_Summer

    Joined:
    Mar 20, 2013
    Posts:
    5
    Hi Eric!
    I saw the drawing example via website, the continuous drawn line with the weld and join features, and I have decided to buy this asset for a house plan drawing project I am working on. I just wanted to ask some questions!

    1. Can I display the dimensions of the line as I draw them (write GUI to screen with world position or something?)
    2. Is it possible to snap a final line after drawing continuously and create a line object. I draw a rectangle and that line object is saved, then I draw a triangle and it is also saved. Basically can I set an end point?
    3. Is it then possible to fill this object I made ?(thinking about setting up the concept of floors/rooms)
    4. Can I scale and rotate a line after I draw it?
    5. I have this idea that I can place a 2D prefab of a door on a wall. Would I be able to find a position on the line I draw to so that I can snap/place this prefab to it?

    Really love the object selection tool (demo 1) will come in handy later if I add 3D.
    Many thanks in advance,
    Shaun.
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    1. Yes, you have the coordinates of the line in a list so you can do whatever you like with that info. Vector2.Distance would get the distance between two points, for example.
    2. Since you have complete control over the coordinates in the line, you can do whatever you like with them including snapping etc.
    3. Vectrosity only does lines, not filled shapes.
    4. See 2, though to make things easier you can also pass in a transform when drawing a line, and if you rotate/scale the transform, the line is likewise rotated/scaled.
    5. You could use the Selected function, which tells you which line segment was selected.

    --Eric
     
  7. Shaun_Summer

    Shaun_Summer

    Joined:
    Mar 20, 2013
    Posts:
    5
    Awesome! Purchased the asset. Thanks for the tips Eric.
     
  8. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Thank you! Just in time for a new version, which features end cap scaling and independent cap offsets. Available now on my site; should be on the asset store in the near future.

    EndCapScale.png

    Vectrosity 4.4

    Changes:
    • VectorLine.SetEndCap can optionally have two offsets, where the front and end caps are offset separately, instead of a single offset that applies to both front and end.
    • VectorLine.SetEndCap can also have scale values, which scale the front and end caps by the supplied amounts.

    Fixes:
    • Joins.Weld works properly with lines where rendering for certain segments is skipped for reasons such as subsequent points with identical coords.
    • VectorLine.Selected works if the 3D camera hasn't been set and a camera hasn't been passed in. (The ability to supply a camera was added 4.3.1 but somehow didn't make it to the release notes or docs.)
    • VectorLine.SetColor works properly with smoothColor = true.

    --Eric
     
  9. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Vectrosity 5 alpha 1 is done now, so if anyone using Unity 5.2 wants to help test it, send me a PM with your invoice number (if you ordered from my site, just the email address is fine). I'm working on some "bigger" features for the beta, but right now it's mostly a drop-in replacement for Vectrosity 4, though there are some code changes required. There's an upgrade guide included to make this easier. Currently the most notable differences for users are:
    • The API is streamlined somewhat.
    • Canvases don't have the 65K vertex limit now, so there's no need for multiple canvases.
    • Lines made with Draw3D no longer use a canvas, so they can do stuff like cast shadows.
    • It's about 25% faster, because of changes in the Unity UI.
    • Lines are maskable.
    --Eric
     
    hippocoder and hopeful like this.
  10. Saevax

    Saevax

    Joined:
    Nov 3, 2012
    Posts:
    58
    I ran into another odd issue. Shapes don't seem to like List<Vector3> which is odd because I know I had it working a while back but now I can't get it working at all.



    Code (CSharp):
    1.  
    2.     public VectorLine circle;
    3.  
    4.     void Start()
    5.     {
    6.         circle = new VectorLine("Circle", new List<Vector3>(100), lineMaterial, 1.0f, LineType.Continuous);
    7.         circle.MakeCircle(Vector3.zero, 10.0f, 5);
    8.         circle.Draw3D();
    9.     }
    10.  
    gives me the error:
    Code (CSharp):
    1. VectorLine.MakeEllipse: The length of the array for continuous lines needs to be at least the number of segments plus one for "Circle"
    2. UnityEngine.Debug:LogError(Object)
    3. Vectrosity.VectorLine:CheckArrayLength(FunctionName, Int32, Int32) (at Assets/Plugins/VectrosityScripts/VectorLine.cs:1035)
    4. Vectrosity.VectorLine:MakeEllipse(Vector3, Vector3, Single, Single, Single, Single, Int32, Single, Int32) (at Assets/Plugins/VectrosityScripts/VectorLine.cs:2805)
    5. Vectrosity.VectorLine:MakeCircle(Vector3, Single, Int32) (at Assets/Plugins/VectrosityScripts/VectorLine.cs:2705)
    6. InterfaceManager:Start() (at Assets/Scripts/Managers/InterfaceManager.cs:96)
    7.  
    I've tried it without giving the List an initial capacity, with linetype Discrete, with various numbers of segments, with MakeCube, etc.
     
    Last edited: Aug 21, 2015
  11. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Giving the list a capacity of 100 doesn't add 100 points (at least not in Vectrosity 4). You need to either initialize it with an array, or add points.

    --Eric
     
  12. fieldrequired

    fieldrequired

    Joined:
    Feb 26, 2014
    Posts:
    108
    Hey there, can I draw 1px lines using Draw3DAuto() with Vectrosity? (Similar to GL.Lines)

    I'm having issues with aliasing moving the camera around the lines and it just looks awful....
     
  13. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

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

    --Eric
     
  14. danreid70

    danreid70

    Joined:
    Aug 28, 2010
    Posts:
    225
    I hope this is an easy one - it seems like it should be. Say I have a script as a manager, with a list populated by an array of GameObjects (spheres, with a radius of 1). These referenced game objects are located at various positions in 3D space in a scene. I want to draw a thick blue circle around each of these objects (using Vectrosity) at a given radius (say 2 units), and a thin green line outwards from each circle (radius) to other GameObjects in that list, if the distance is within a given range (say 10 units). Please let me know if the below is the correct sequence (not asking for the code, just that I'm understanding the sequence correctly):

    function Start()
    Initialize...

    function Initialize()
    Clear lines?
    Create a variable (array?) 'lines' -- a new vectrosity line object
    Create a variable (array?) 'circles' -- a new vectrosity circle object
    Set thickness and color of line and circle

    function Update()
    Loop through each object in the GameObjects array
    Create a new 'circle' at object position (and rotation) at a radius of 2 units
    Loop through each object / if position is within 10 units
    Draw a line from first-loop's object position to this loop's object position (starting at 2 units radius out from main, to 2 units radius out from current-loop object
    end Loop
    end Loop
    lines.Draw3D
    circles.Draw3D

    ...elsewhere, if list of objects changes (added or removed objects)
    Initialize...

    Essentially, do I create a new line for each iteration, or add on to a single line somehow?
    And do I create a new circle object or ?
    Lastly, I only call the Draw3D once only after I set all the lines in the Update, once for the lines and once for the Circles, or do I need to call Draw3D after I make a new circle in the loops, and another Draw3D for each line I create in the inner-loop above?

    I tried actually creating the circles and lines directly from each object initially, to disastrous results (draw calls through the roof - LOL! I should have realized that would happen). I hope this isn't too "n00b" a question... :) I'm just starting this and still digging through the forum (quite a long list of examples here! just haven't found a simple close enough example or I've somehow missed it... :)

    Thanks all! Loving the conversation on this thread! Great examples and it's amazing what everyone is using this plugin for!
     
  15. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I wouldn't make the circle in Update; you can just do it once. You can use VectorLine.drawTransform to pass in a Transform, which you can use to move/scale/rotate lines as desired without having to recompute points. (Though you do have to redraw the line every frame that the Transform moves.) You would call Draw3D once per frame if anything changes during that frame, but if stuff is changing mostly every frame, then it's more convenient to use Draw3DAuto. You can use a single VectorLine to draw multiple separate line segments using LineType.Discrete. You can use Add/RemoveAt with the line points2 or points3 list to add/remove points when needed. In general you create VectorLine objects once (in Start), then change the points. If you're using a number of separate VectorLines that you will be adding/removing during gameplay, it's better to use VectorLine.active to turn them on/off rather than creating/destroying lines.

    --Eric
     
  16. ZeicRavein

    ZeicRavein

    Joined:
    Aug 24, 2015
    Posts:
    7
    Hi Eric!

    I connected a line between two GameObjects that are constantly moving, but I’m getting that issue:



    How can I fix it?

    And btw, amazing job you did on that asset!
     

    Attached Files:

  17. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I can't really say without code, but maybe you're adding points instead of using existing points.

    --Eric
     
  18. ZeicRavein

    ZeicRavein

    Joined:
    Aug 24, 2015
    Posts:
    7
    I don't think so.. Take a look:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections.Generic;
    3. using Vectrosity;
    4.  
    5. public class GerarColeirasUltimateEdition : MonoBehaviour {
    6.  
    7.     public Transform ball1;
    8.     public Transform ball2;
    9.  
    10.     private VectorLine myLine;
    11.  
    12.     void Start()
    13.     {
    14.         myLine = new VectorLine("Rope", new List<Vector3>(), null, 2f);
    15.     }
    16.  
    17.     void Update()
    18.     {
    19.         myLine.points3.Add(ball1.position);
    20.         myLine.points3.Add(ball2.position);
    21.         myLine.Draw3DAuto();
    22.     }
    23. }
     
  19. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes, you're adding points every frame rather than re-using existing points. Also Draw3DAuto should not be in Update.

    --Eric
     
  20. ZeicRavein

    ZeicRavein

    Joined:
    Aug 24, 2015
    Posts:
    7
    I'm sorry Eric, but how can I re-use the existing points?

    I'm trying to figure out, but I can't. =/

    I put it on Update because if I put somewhere else, the line doesn't update and get stuck.
     
  21. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The point of Draw3DAuto is that it automatically re-draws the line every frame, so just put it in Start. For using existing points, see the section in the docs called "moving lines around".

    --Eric
     
  22. fieldrequired

    fieldrequired

    Joined:
    Feb 26, 2014
    Posts:
    108
    Very helpful thanks - I ended up using GL.Lines.
     
  23. ZeicRavein

    ZeicRavein

    Joined:
    Aug 24, 2015
    Posts:
    7
    I really can't make the line follow the two objects.

    The goal is to connect a line between two objects and the line will remain connected as the two move. I read the documentation and found that it is possible to use the VectorLine.drawTransform property . The script is attached in the cube but the line is not generated at runtime.



    Follow my code:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using Vectrosity;
    5.  
    6. public class Linha : MonoBehaviour {
    7.  
    8.     public Transform cube;
    9.     public Transform sphere;
    10.     public Material corda;
    11.  
    12.     private VectorLine myLine;
    13.  
    14.     void Start()
    15.     {
    16.         myLine = new VectorLine("Rope", new List<Vector3>(), corda, 5f);
    17.  
    18.         myLine.points3.Add(cube.position);
    19.         myLine.points3.Add(sphere.position);
    20.  
    21.         myLine.drawTransform = transform;
    22.     }
    23.  
    24.     void Update()
    25.     {
    26.         myLine.Draw3D();
    27.     }
    28. }
    When I comment that line:

    Code (CSharp):
    1.  
    2. myLine.drawTransform = transform;
    3.  
    The line is drawn, otherwise no =/

    What am I doing wrong? I read the documentation but I still not able to do it.
     

    Attached Files:

  24. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Not drawTransform; you would use that for moving the entire line. See the top of page 15 about updating points in lines.

    --Eric
     
  25. ZeicRavein

    ZeicRavein

    Joined:
    Aug 24, 2015
    Posts:
    7
    But that was the goal Eric. The entire line must follow the two objects. I can do this with the LineRenderer, but my goal with Vectrosity it's to generate each line individually when I put several objects at same time.

    It's like the Highlight Demo for example.

    And I already saw the top of page 15, and that problem continues:

     
  26. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    No, that's not the goal. ;) The goal is to update the points in the line, not move the entire thing. You're adding points, not updating existing points. See the top of page 15:

    Look at the code example. It sets up the line in Start, then updates the existing points as needed in Update.

    --Eric
     
  27. ZeicRavein

    ZeicRavein

    Joined:
    Aug 24, 2015
    Posts:
    7
    Awesome Eric! Finally I did it *-* and you were right.

    The problem was in the updating the list that I was doing wrong. The right thing was to remove the previous point and upgrade to a new one. So I update the Update function like that:

    Code (CSharp):
    1. myLine.points3.RemoveAt (0);
    2. myLine.points3.Insert (0, cube.position);
    3. myLine.points3.RemoveAt(1);
    4. myLine.points3.Insert (1, sphere.position);
    5. myLine.Draw3D();
    And works great for me, thank you!
     
  28. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    No, that's still not right. ;) Don't remove and insert points (bad for performance), just reuse existing points. Like the code on page 15 in the docs; exactly what you need to do is spelled out right there.

    --Eric
     
  29. Devanstator

    Devanstator

    Joined:
    Sep 27, 2013
    Posts:
    7
    Hi Eric

    I'd like to make sure of one thing before buying. I need to draw bezier curves between UI elements and these lines need to respect the uGUI draw heirarchy. That is, they need to draw behind anything that is "below" them in the heirarchy, and above anything that is above them in the heirarchy, regardless of z-position or rotation.
    Can vectrosity do this? If so, are there any limitations incurred by doing this, or does it work the same as all the other lines?

    Thanks
     
  30. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes, you can set VectorLine.drawDepth, which basically just does SetSiblingIndex().

    --Eric
     
  31. Devanstator

    Devanstator

    Joined:
    Sep 27, 2013
    Posts:
    7
    Thanks for the quick response Eric

    I've got the asset now and have generally got the lines behaving the way I want them to. However, I had to use myVectorLine.rectTransform.SetParent() to move the line to where I wanted it (in my UI canvas, so it would be drawn on top of some UI elements and underneath others). I didn't find anything in the documentation about moving the lines to canvases other than the two Vectrosity creates and I wanted to check to make sure it's not going to cause problems.

    The steps I'm taking are:
    - Create a VectorLine
    - Call Draw3D() (to actually create the GameObject)
    - Call myVectorLine.rectTransform.SetParent() to make it a child of a UI element in my UI canvas.
    - Call MakeCurve()
    - Call Draw3D() again

    Is that alright?
     
  32. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It's fine to use rectTransform.SetParent. Since Vectrosity lines are UI elements, they follow the same rules as other UI elements. Vectrosity 5 has a SetCanvas function to make that a bit more convenient. (Speaking of which, anyone else using Unity 5.2, let me know if you want to help test Vectrosity 5.)

    --Eric
     
  33. Devanstator

    Devanstator

    Joined:
    Sep 27, 2013
    Posts:
    7
    Thanks Eric. I've got another question.
    I'm trying to hide/show a line by using SetActive() on a parent GameObject. However, deactivating a parent does not seem to cause the line to disappear, at least not right away. If I reposition an ancestor after deactivating the line's container then it will disappear. Can you tell me how to make it so the line disappears when the parent is deactivated?
    I tried calling Draw3D() after it's disabled but that didn't do the trick.

    Thanks
     
  34. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Use VectorLine.active.

    --Eric
     
  35. tbg10101_

    tbg10101_

    Joined:
    Mar 13, 2011
    Posts:
    192
    Hey Eric,

    I'm interested in testing for Unity 5.2.

    -Tristan
     
  36. dred

    dred

    Joined:
    Apr 8, 2013
    Posts:
    30
    Hi, I'm also try to show\hide my lines trought VectorLine.active = false; but it doesn't work.
     
  37. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    What version are you using?

    --Eric
     
  38. wxxhrt

    wxxhrt

    Joined:
    Mar 18, 2014
    Posts:
    163
    Hi, is it possible to use Vectrosity on a imported object with Shape Keys (blender) or bones? I'd like the wireframe to be recalculated as the object animates (just simple geometric objects).

    Thanks
     
  39. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    As long as you supply the points, Vectrosity will draw lines for anything. Basically what you do is

    Code (csharp):
    1. myLine = new VectorLine(...);
    Then myLine.points2 (for Vector2 points) or myLine.points3 (for Vector3 points) is a list of points that are drawn as a line. So you make some method to fill points2 or points3 with data and Vectrosity draws it.

    --Eric
     
  40. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Last call for Vectrosity 5 beta testing! Send me a PM with your invoice number if you want to test it, but I'll be releasing within a few days (this needs to be out for Unity 5.2), so it would be best if you had time to look at it right away. The editor script is done, though it's pretty basic right now. (Don't expect Adobe Illustrator or anything. ;) ) I'll add more stuff to the next version.

    screen2.png

    screen1.png

    You can also use this at runtime for lines that you create in code. (But only in the editor, not in builds. Also right now it's only for 2D lines.)

    --Eric
     
    hopeful likes this.
  41. wxxhrt

    wxxhrt

    Joined:
    Mar 18, 2014
    Posts:
    163
    Thanks Eric, is there a way to use Line Maker to get the meshes vertex integers for particular corners, so i can feed the moving vertexes.positions into a VectorLine
     
  42. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The LineMaker only works in the editor. Probably you would just use Mesh.bounds?

    --Eric
     
  43. J_P_

    J_P_

    Joined:
    Jan 9, 2010
    Posts:
    1,027
    Is it not possible to set a start and end width with a line that has n number of segments? I thought that was the point of enabling smoothWidth, but I'm getting "VectorLine.SetWidths: Length of line widths array in "RightTrail" must be exactly half the length of points array for a discrete line (one entry per line segment)"
     
  44. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    SmoothWidth smooths the transitions between different line widths; see the "Line Widths" section of the docs on page 28.

    --Eric
     
  45. Slawo

    Slawo

    Joined:
    Jan 29, 2014
    Posts:
    11
    Hi!

    I just bought Vectrosity and I was trying to render splines to draw a path inside a moving object.

    I have a list of waypoints I use to generate the spline with MakeSpline.
    This works quite fine.
    When the object moves or the camera moves I update the list of points ant I regenerate the splines (I don't know if this is right).

    The effect is not at all what I expected. So far the rendered spline's with does not fit with the object's position, and the texture inside tends to travel back and forth.

    The closer the object gets to the camera the thiner the line appears compared to the object and the further the object gets away the thicker it appears until the line gets larger than the object.

    Is there a way to lock the line's thickness to the points z distance or do I have to handle this manually?

    If there is a way to set the canvas for a given line in Vectrosity 5 then I'd like to test it too.

    Will Vectrosity 5 work in Unity 4?
     
  46. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Vectrosity line width is measured in pixels, so if you use 2, for example, the line will always be 2 pixels wide on-screen.

    No, it depends on UI mesh functions that only exist in Unity 5.2.

    --Eric
     
  47. wxxhrt

    wxxhrt

    Joined:
    Mar 18, 2014
    Posts:
    163
    Hi Eric,

    I've written a script that does most of what I want but am running into problems when it comes to redrawing the lines as the blend shape changes.

    The script does the following:

    Step 1. I Use Line Maker in the editor to output a list of Vec3's.

    Step 2. I traverse this list of Vec3's finding the first Mesh's vertex that lies at that point, the index of which gets saved.
    Step 3. I then send the vertex positions into a VectorLine function to draw the points.

    The problem I'm having is redrawing the lines. I'm using a VectorManager.ObjectSetup as i want the lines to be obscured by the object they're being drawn around and be able to move when I move that GameObject.

    Once it's been setup can I feed a new VectorLine into the vector manager draw the lines in different places. Or is there a way(something undocumented) to destroy the lines without destroying the GameObject (the manual says otherwise).

    If these aren't possible is the only way round to destroy and re-instantiate the object at with a new blend shape weight value each frame, these seems like it would be really expensive.

    Thanks,
    Will

    Here's the code:

    Code (JavaScript):
    1.  
    2. #pragma strict
    3.  
    4. import Vectrosity;
    5. import System.Collections.Generic;
    6.  
    7. var lineMaterial : Material;
    8.  
    9. private var lineMakerArray : Vector3[] = [  Vector3(0.369, -0.793, 0.011), Vector3(0.369, -0.791, -1.173),
    10.                                             Vector3(0.369, -0.793, 0.011), Vector3(-0.377, -0.788, 0.011),
    11.                                             Vector3(-0.377, -0.785, -1.173), Vector3(-0.377, -0.788, 0.011),
    12.                                             Vector3(-0.377, -0.785, -1.173), Vector3(0.369, -0.791, -1.173),
    13.                                             Vector3(0.371, -0.645, -1.173), Vector3(0.369, -0.791, -1.173),
    14.                                             Vector3(-0.377, -0.785, -1.173), Vector3(-0.376, -0.639, -1.173),
    15.                                             Vector3(0.371, -0.645, -1.173), Vector3(-0.376, -0.639, -1.173),
    16.                                             Vector3(-0.363, 1.212, 0.015), Vector3(-0.376, -0.639, -1.173),
    17.                                             Vector3(0.371, -0.645, -1.173), Vector3(0.384, 1.207, 0.015),
    18.                                             Vector3(-0.363, 1.212, 0.015), Vector3(0.384, 1.207, 0.015),
    19.                                             Vector3(-0.363, 1.212, 0.015), Vector3(-0.377, -0.788, 0.011),
    20.                                             Vector3(0.369, -0.793, 0.011), Vector3(0.384, 1.207, 0.015)   ]; // these are copied from
    21.                                            
    22. private var indicesList : List.<int> = new List.<int>();
    23.  
    24. private var blendShapeWeight_old : float;
    25.  
    26. // could be sped up by only redrawing lines that have moved. Q. is checking and comparing the vertex poistion more costly than redrawing the line?
    27. function Start ()
    28. {
    29.     BuildVertexIndices();
    30.     DrawLines();
    31.    
    32. }
    33.  
    34. // should only be called when skinnedMeshRender blend shape changes
    35. function Update()
    36. {
    37.     var smr : SkinnedMeshRenderer = this.gameObject.GetComponent.<SkinnedMeshRenderer>();
    38.    
    39.     if (smr.GetBlendShapeWeight(0) != blendShapeWeight_old)
    40.     {
    41.         Debug.Log("Rebuild the vectorline");
    42.         DrawLines();
    43.        
    44.         blendShapeWeight_old = smr.GetBlendShapeWeight(0);
    45.     }
    46.    
    47.    
    48.    
    49. }
    50.  
    51. function BuildVertexIndices()
    52. {
    53.     var mesh : Mesh = this.gameObject.GetComponent.<SkinnedMeshRenderer>().sharedMesh;
    54.    
    55.     var vertices : Vector3[] = mesh.vertices;
    56.    
    57.     for (var l : int = 0; l < lineMakerArray.Length; l++)
    58.     {
    59.         for (var v : int = 0; v < vertices.Length; v++)
    60.         {
    61.             if (lineMakerArray[l].ToString("F3") == vertices[v].ToString("F3")) // if the line maker vertex is in the same position as the mesh vertex
    62.             {
    63.                 //Debug.Log(v);
    64.                 indicesList.Add(v);
    65.                 v = vertices.Length; // exit this for loop  
    66.             }
    67.         }
    68.     }
    69. }
    70.  
    71. function GetIndicesVertexPositions(indexList : List.<int>)
    72. {
    73.     var mesh : Mesh = this.gameObject.GetComponent.<SkinnedMeshRenderer>().sharedMesh;
    74.     var bakedMesh : Mesh = new Mesh(); // this is used by BakeMesh to store a copy of the current Mesh afters its been deformed by shapekeys
    75.     this.gameObject.GetComponent.<SkinnedMeshRenderer>().BakeMesh(bakedMesh);
    76.    
    77.     var vertices : Vector3[] = bakedMesh.vertices;
    78.    
    79.     var vertexPositions : List.<Vector3> = new List.<Vector3>(); // this will be the output
    80.    
    81.     //mesh.RecalculateBounds();
    82.  
    83.     //Debug.Log(vertices[0]);
    84.  
    85.     for (var n : int = 0; n < indexList.Count; n++) // for each index
    86.     {
    87.         var i : int = indexList[n]; //find that index's value
    88.         vertexPositions.Add(vertices[i]); // add the vertex's current position
    89.     }
    90.    
    91.     return vertexPositions;
    92. }
    93.  
    94.  
    95. function DrawLines()
    96. {
    97.     var linePoints = GetIndicesVertexPositions(indicesList).ToArray(); //pass the indices list we got form buildVertexIndices into INdicesVertexPoistiosn to get there Positions
    98.    
    99.     // Make a line using the above points and material, with a width of 2 pixels
    100.     var rVal : float = Random.value;
    101.     var str : String = rVal.ToString();
    102.     var line : VectorLine = new VectorLine(str, linePoints, lineMaterial, 3.0);
    103.     //line.Draw3DAuto(); //!!! NOT REALLY SURE WAHT THIS DOES
    104.  
    105.     // Make this transform have the vector line object that's defined above
    106.     // This object is a rigidbody, so the vector object will do exactly what this object does
    107.     // "false" is added at the end, so that the cube mesh is not replaced by an invisible bounds mesh
    108.  
    109.     VectorManager.useDraw3D = true; //!!!!!!!!!!!!!  does the inner cube obscure back of wireframe
    110.     VectorManager.ObjectSetup (gameObject, line, Visibility.Dynamic, Brightness.None, false); //!!!!!!!!!!!!!!!!  TRUE FALSE AT END DETERMINES WHETHER INNER CUBE IS DRAWN
    111.    
    112. }
     
  48. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Seems like you should be using a standard VectorLine. ObjectSetup is a way to basically use a VectorLine as a renderer for a GameObject, but you have more control if you manage things yourself. Use Draw3D to have lines be drawn in the scene.

    --Eric
     
  49. Slawo

    Slawo

    Joined:
    Jan 29, 2014
    Posts:
    11
    OK, Is there a way to attach and draw some VectorLine elements on different given canvases?

    An unrelated question: It's possible to use GetPoint3D01 to retrieve a point at which I want to place an object in order to increase the progress on a path.

    Code (C#):
    1.  
    2.     Vector3 pos = vectorLines[0].GetPoint3D01(percent/100f);
    3.     cursor.transform.position = pos; // sets the cursor at the right place
    4.     vectorLines[0].drawEnd = Mathf.RoundToInt(percent * segmentsCount / 100f); // doesn't draw the line based on the distance but on the number of segments used
    5.  
    Is is possible to cap the length of the drawn VectorLine to the desired distance (to the same point returned by GetPoint3D01)?
     
  50. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

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

    Yes, you can pass in an int for the index corresponding to the distance; see the reference guide.

    --Eric