Search Unity

Vectrosity - Fast and Easy Line Drawing

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

  1. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,089
    Yes, it's definitely visible with those settings.

    Screen Shot 2015-09-22 at 4.44.58 PM.png

    --Eric
     
  2. JLA02

    JLA02

    Joined:
    Dec 12, 2012
    Posts:
    2
    Hello,
    Like show below, when i try to create a circle with a segment size > 1.0f (here 50), when the circle is oriented the generated mesh seems TWISTED and remains not FLAT like expected, could you investigate.
    Maybe than the first and the last segment are not correctly oriented so there is a twisted effect....

    Thank you in advance.
    upload_2015-9-23_12-43-53.png

    Here my component code :
    Code (csharp):
    1.  
    2. using Vectrosity;
    3.  
    4. public class ElongataDefenseZone : MonoBehaviour
    5. {
    6.     public Camera camera3D;
    7.     public float widthSegment = 1.0f;
    8.     public float radiusZone = 1.0f;
    9.     public int segments = 3;//Default Minimal
    10.     public Vector3 offset = Vector3.zero;
    11.     public Material segmentsMaterial;
    12.     public Texture segmentTexture;
    13.     public float segmentsTexureScale = 1.0f;
    14.  
    15.     private VectorLine zone;
    16.  
    17.     void Awake()
    18.     {
    19.         if (segments < 3)
    20.             segments = 3;
    21.  
    22.         VectorManager.useDraw3D = true;
    23.         VectorLine.SetCamera3D(camera3D);
    24.        
    25.         Vector3[] segmentsArray = new Vector3[segments+1];
    26.  
    27.         zone = VectorLine.SetLine3D(Color.green, segmentsArray);
    28.         zone.lineWidth = widthSegment;
    29.         zone.lineType = LineType.Continuous;
    30.         zone.joins = Joins.Fill;
    31.         zone.material = segmentsMaterial;
    32.         zone.textureScale = segmentsTexureScale;
    33.      
    34.         zone.texture = segmentTexture;
    35.         zone.continuousTexture = true;
    36.         zone.AddNormals();
    37.  
    38.         //For test when we rotate the gameObject on which the script is attached(same issue)
    39.         zone.drawTransform = gameObject.transform;
    40.     }
    41.  
    42.     // Use this for initialization
    43.     void Start ()
    44.     {
    45.         //With Vector3.up or other value, the issue is the same
    46.         zone.MakeCircle(gameObject.transform.position+offset,Vector3.down,radiusZone,segments);
    47.     }
    48.  
    49.     // Update is called once per frame
    50.     void Update ()
    51.     {
    52.         zone.Draw3D();
    53.     }
    54. }
    55.  
    56.  
     
    Last edited: Sep 24, 2015
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,089
    Lines are oriented to a camera, so from the perspective of the camera that you're using, it will look right. (Please use code tags when posting code.)

    --Eric
     
  4. zee_ola05

    zee_ola05

    Joined:
    Feb 2, 2014
    Posts:
    165
    Hi Eric! Can you help me with this? I'm trying to get a zigzag, thick, textured line to work. But I'm getting these undesirable results. I'm using a circle texture.

    I get the pink one with Join.Weld. I get the blue one with Join.Fill.

    The blue one is more desirable, but two circles (or two non-full circles) overlap at the end of the two line segments, forming what looks like a pac-man. What I want to have are smooth-flowing circles on the line, without the overlaps. How can I do that?

    Screen Shot 2015-09-23 at 3.46.37 PM.png Screen Shot 2015-09-23 at 3.48.07 PM.png
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,089
    There's really no physical way to get a perfect result with lines, due to how they're made (stretched quads, basically). You can use more segments in the line with Joins.Weld to get rid of the warping, but it will still be weird at intersections. What you should do is use points instead; one point for each dot.

    --Eric
     
  6. zee_ola05

    zee_ola05

    Joined:
    Feb 2, 2014
    Posts:
    165
    Okay, thanks! I'll just do points.
     
  7. JLA02

    JLA02

    Joined:
    Dec 12, 2012
    Posts:
    2
    Hello Eric,

    Regarding your answer, i chose to create another camera with a position at top of my mesh and oriented to 90° in order to get the good perpesctive and a FLAT circle.
    upload_2015-9-24_8-36-5.png

    And it looks correct. But it remains a question, is there a trick for create a circle untwisted independently of the camera used, in order to keep a single camera in the scene ?
     
  8. any_user

    any_user

    Joined:
    Oct 19, 2008
    Posts:
    337
    Hello, I hope here's the right place to ask a question about the new Vectrosity 5.

    In the old version I had my (3d-)lines parented under other objects, of which some have DontDestroyOnLoad enabled. I don't move these parents, I mainly use them for organizing the scene. In Vectrosity 5 all the line objects (VectorObject3D) are always in the root of the scene and can't be parented to anything for some reason. Setting the parent of a VectorLine rectTransform doesn't do anything (it's immediately resetted?). Is this intended or is it a bug?

    In my case it breaks everything because the some of the lines are deleted on scene transitions. Strangely, after changing the scene the VectorLine reference still works, I can still change points etc., just the actual displaying game object is missing.
     
  9. DannyCheng

    DannyCheng

    Joined:
    Feb 25, 2013
    Posts:
    29
    Hello!

    Vectrosity noob here so please bear with me.

    I am trying to combine vectrosity elements with my existing UI (built with UnityEngine.UI)

    My UI has a CanvasScaler component which scales with the size of the screen.

    At the moment, in order to get everything to match properly I am having to

    1. create a dummy line to get the main Vectrosity canvas object to create itself
    2. attach a CanvasScaler to the Vectrosity canvas
    3. set its properties to be the same as my UI's main canvas
    4. get rid of the dummy line as I only need it for Vectrosity initialisation
    5. now I can use vectrosity without any scale/position matching issues


    Does this sound right? I get the desired results but it just feels a bit hacky. Specifically, is there a nice way to intialise vectrosity (i.e. without creating a dummy vectrosity element). Is there a way to preattach a CanvasScaler to it? Is there a "good practice" way to do this sort of thing that I am unaware of?

    Many thanks!
     
  10. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,089
    No, sorry. You can disable the extra camera when you don't need it.

    Neither; I can't see any problems setting the parent to another object, and there's nothing in the code that would have any effect on parenting.

    The best thing is to use the next version of Vectrosity, which has an option to pass worldPositionStays into SetCanvas, since right now it just uses true. So you'd use "SetCanvas (myCanvas, false)". But in the meantime you could edit the source of the SetCanvas function and replace "SetParent (canvas.transform, true)" with "SetParent (canvas.transform, false)". That way you can use SetCanvas with your scaled canvas.

    --Eric
     
  11. maciekfreak

    maciekfreak

    Joined:
    Sep 21, 2015
    Posts:
    21
    Does Vectrosity have any method to get nearest distance and heading between gameobject and Line3D?
     
  12. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,089
    I'm not sure what that means exactly, but you can see a list of all functions in the Vectrosity Reference Guide.

    --Eric
     
  13. maciekfreak

    maciekfreak

    Joined:
    Sep 21, 2015
    Posts:
    21
    I have a player and straight VectorLine.SetLine3D .. I want to display distance between player and this line.

    I can get GetPoint3D from this line and calculate distance between this point and GameObject. But how to find nearest Point on this line?
     
  14. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,089
    That's more of a general math question; there are no specific functions in Vectrosity for that.

    --Eric
     
  15. maciekfreak

    maciekfreak

    Joined:
    Sep 21, 2015
    Posts:
    21
    Ok Thanks.
    I have also another problem. 3D lines disappear sometime when camera is rotating/ moving
     
  16. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,089
    Assuming you're updating the line when the camera moves, then it's probably related to Vectrosity culling the segment because one point is too far outside the camera frustum. Add more segments in the line to prevent this.

    --Eric
     
  17. maciekfreak

    maciekfreak

    Joined:
    Sep 21, 2015
    Posts:
    21
    Now, some segments disappearing after adding more points.

    How many points is needed? Is there any option to add this segments? I'm creating line from two points.
     
  18. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,089
    It depends on the line. If one point in a segment is too far outside the frustum, then it will be culled. If you have really huge segments then you'll need to subdivide them more.

    --Eric
     
  19. maciekfreak

    maciekfreak

    Joined:
    Sep 21, 2015
    Posts:
    21
    Ok. I will try to figure it something by myself here.

    Could you tell me why line at first point have other width than on the second one?

    I set the .lineWidth = 3f.. But on the begin of line line is 3f, but on the end it is much bigger.
     
  20. maciekfreak

    maciekfreak

    Joined:
    Sep 21, 2015
    Posts:
    21
    This lines changing width (or it looks only like this) when camera is rotating. Please see attached examples from orthographic and perspective camera.

    I'm creating lines like this.
    VectorLine.SetLine3D (Color.white, point1, point2)
    I have tried also changing SetWidth(3f) and lineWidth = 3f ... nothing helps.






     
  21. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,089
    It doesn't look like you have the lines oriented to the camera that you used for the screenshots.

    --Eric
     
  22. maciekfreak

    maciekfreak

    Joined:
    Sep 21, 2015
    Posts:
    21
    Second screenshot is from MainCamera.. So it should be oriented to the camera out of the box.
    I have tried also Draw3DAuto(), Draw3D() in update function, and setCamera3D(Camera.main);

    Nothing helps. Nothing changes anything.
     
  23. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,089
    I'd have to see some code that demonstrates the effect.

    --Eric
     
  24. maciekfreak

    maciekfreak

    Joined:
    Sep 21, 2015
    Posts:
    21
    Ok

    Player (3D Cube)

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using Vectrosity;
    4.  
    5. public class LineTest : MonoBehaviour {
    6.     private GameObject playerObject;
    7.     public float movementSpeed = 10;
    8.     public float turningSpeed = 60;
    9.  
    10.     // Use this for initialization
    11.     void Start () {
    12.         VectorLine line = VectorLine.SetLine3D (Color.white, new Vector3(4787.1f,0,1443.7f), new Vector3(-4584.5f,0,-1382.6f));
    13.         line.Draw3DAuto ();
    14.     }
    15.    
    16.     // Update is called once per frame
    17.     void Update () {
    18.         var playerObject = GameObject.Find ("Player");
    19.         Vector3 playerPos = playerObject.transform.position;
    20.         Quaternion playerRot = playerObject.transform.rotation;
    21.        
    22.        
    23.        
    24.         float horizontal = Input.GetAxis ("Horizontal") * turningSpeed * Time.deltaTime;
    25.         transform.Rotate (0, horizontal, 0);
    26.        
    27.        
    28.         float vertical = Input.GetAxis ("Vertical") * movementSpeed * Time.deltaTime;
    29.         transform.Translate (0, 0, vertical);
    30.    
    31.     }
    32. }
    33.  

    Main Camera script to follow object with rigidbody

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class CarSmoothFollow : MonoBehaviour {
    5.    
    6.     public Transform target;
    7.     public float distance = 20.0f;
    8.     public float height = 5.0f;
    9.     public float heightDamping = 2.0f;
    10.    
    11.     public float lookAtHeight = 0.0f;
    12.    
    13.     public Rigidbody parentRigidbody;
    14.    
    15.     public float rotationSnapTime = 0.3F;
    16.    
    17.     public float distanceSnapTime;
    18.     public float distanceMultiplier;
    19.    
    20.     private Vector3 lookAtVector;
    21.    
    22.     private float usedDistance;
    23.    
    24.     float wantedRotationAngle;
    25.     float wantedHeight;
    26.    
    27.     float currentRotationAngle;
    28.     float currentHeight;
    29.    
    30.     Quaternion currentRotation;
    31.     Vector3 wantedPosition;
    32.    
    33.     private float yVelocity = 0.5F;
    34.     private float zVelocity = 0.5F;
    35.    
    36.     void Start () {
    37.        
    38.         lookAtVector =  new Vector3(0,lookAtHeight,0);
    39.        
    40.     }
    41.    
    42.     void LateUpdate () {
    43.        
    44.         wantedHeight = target.position.y + height;
    45.         currentHeight = transform.position.y;
    46.        
    47.         wantedRotationAngle = target.eulerAngles.y;
    48.         currentRotationAngle = transform.eulerAngles.y;
    49.        
    50.         currentRotationAngle = Mathf.SmoothDampAngle(currentRotationAngle, wantedRotationAngle, ref yVelocity, rotationSnapTime);
    51.        
    52.         currentHeight = Mathf.Lerp(currentHeight, wantedHeight, heightDamping * Time.deltaTime);
    53.        
    54.         wantedPosition = target.position;
    55.         wantedPosition.y = currentHeight;
    56.        
    57.         usedDistance = Mathf.SmoothDampAngle(usedDistance, distance + (parentRigidbody.velocity.magnitude * distanceMultiplier), ref zVelocity, distanceSnapTime);
    58.        
    59.         wantedPosition += Quaternion.Euler(0, currentRotationAngle, 0) * new Vector3(0, 0, -usedDistance);
    60.        
    61.         transform.position = wantedPosition;
    62.        
    63.         transform.LookAt(target.position + lookAtVector);
    64.        
    65.     }
    66.    
    67. }




     
  25. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,089
    I can't actually run that code since I don't have your project, but I doubt that coordinates which are so far apart are going to work. See what I wrote earlier about points being outside the view frustum. Also SetLine3D already uses Draw3DAuto, so don't use that twice.

    --Eric
     
  26. maciekfreak

    maciekfreak

    Joined:
    Sep 21, 2015
    Posts:
    21
    I tried to make more LineSegments.. Its the same..
    Problem is somewhere in camera. If I use other camera (for example orthographic) top view camera. Lines looks good.

    Do you know maybe what from camera script can make conflict with Vectrosity?
     
  27. maciekfreak

    maciekfreak

    Joined:
    Sep 21, 2015
    Posts:
    21
    I make another test.. Nothing more than camera, cube, and line.. Effect in attachment.
    I think that I make somewhere simple mistake but can't find it.

    I can send you project on e-mail because I can't attach it here.

    This is New project in Unity 5..

    Main camera position -4.72,3.44,-10
    Main camera rotation 18.68698,16.18596,359.7587

    And the Cube with name "Player" with following script
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using Vectrosity;
    4.  
    5. public class LineTest : MonoBehaviour {
    6.     private GameObject playerObject;
    7.     public float movementSpeed = 10;
    8.     public float turningSpeed = 60;
    9.    
    10.     // Use this for initialization
    11.     void Start () {
    12.         VectorLine line = VectorLine.SetLine3D (Color.white, new Vector3(4787.1f,0,1443.7f), new Vector3(-4584.5f,0,-1382.6f));
    13.         line.Draw3DAuto ();
    14.     }
    15.    
    16.     // Update is called once per frame
    17.     void Update () {
    18.         var playerObject = GameObject.Find ("Player");
    19.         Vector3 playerPos = playerObject.transform.position;
    20.         Quaternion playerRot = playerObject.transform.rotation;
    21.        
    22.        
    23.        
    24.         float horizontal = Input.GetAxis ("Horizontal") * turningSpeed * Time.deltaTime;
    25.         transform.Rotate (0, horizontal, 0);
    26.        
    27.        
    28.         float vertical = Input.GetAxis ("Vertical") * movementSpeed * Time.deltaTime;
    29.         transform.Translate (0, 0, vertical);
    30.        
    31.     }
    32. }
    33.  
     
  28. Morpheus

    Morpheus

    Joined:
    Feb 2, 2014
    Posts:
    13
    What did you do to get that screenshot? Telling me it works, when it obviously does not on my end with no explanation of what you did is not very helpful. . .
     
  29. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,089
    Yes, the points in the line are just much too far apart for that to work considering where the camera is. This is what it's like when dividing the line into 100 segments:

    Screen Shot 2015-09-25 at 3.14.40 PM.png

    I put your code in a script and attached it to an object, with the camera using the settings you mentioned, then ran the scene.

    --Eric
     
  30. Morpheus

    Morpheus

    Joined:
    Feb 2, 2014
    Posts:
    13
    That is counter to everything I am trying to do. The whole point is that I need a line to be visible without running the scene. What I am doing is creating a custom editor window, and then running the script in the editor without ever pressing the play button, thus without the scene ever running.
     
  31. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,089
    Sorry, I missed that. If you mean 3D lines in terms of creating line objects without a canvas, I don't actually know about that. I assumed you meant lines using Vector3 points, but still using a canvas.

    --Eric
     
  32. Morpheus

    Morpheus

    Joined:
    Feb 2, 2014
    Posts:
    13
    So, are you saying that Vectrosity now uses a canvas in order to have lines, and this canvas is something that is created when you run the scene, and thus you can't have lines if you don't run the scene. . .? Or something. . .?
    All I care about is having visible lines without ever pressing the big Play button at the top.
     
  33. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,089
    No, a canvas is used for when you use VectorLine.Draw(). VectorLine.Draw3D creates a standard mesh object. Vectrosity 4 used a canvas for all lines. Note that there's never been any support for editor-only lines until Vectrosity 5, and currently only for Vector2 lines.

    --Eric
     
  34. Ninjuit

    Ninjuit

    Joined:
    Jul 7, 2012
    Posts:
    7
    Hello Eric,

    I purchased your unity asset and I'm trying to build a circle vector using Joins.Fill and then "mask" parts of the circle so that it fills radially. All of this works fine, but with Joins.Fill active, it seems to be automatically joining the beginning/end of the points list to the origin of the scene, creating an undesired line.

    Do you know if this is a bug, or am I perhaps doing something wrong?
     
  35. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,089
    Do you have any code which shows that? If I change the power bar demo code to use Joins.Fill instead of Joins.Weld, it's still fine.

    --Eric
     
  36. maciekfreak

    maciekfreak

    Joined:
    Sep 21, 2015
    Posts:
    21
    In my case, (I have many lines and these lines are very long) to show them correctly I need many lineSegments.

    I have performance issues.
    Is there any easy way to call Draw3D on lines that are visible in the camera view at the moment? This will help me to keep frame rate.
     
  37. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,089
    If you use ObjectSetup, it uses bounding boxes to not render lines when appropriate. However I don't know how well that would work with lines that are so long.

    --Eric
     
  38. N3uRo

    N3uRo

    Joined:
    Dec 10, 2011
    Posts:
    627
    I have this warning in the Unity 5.2 version:

    It has no easy fix on my side because the correct overload has a "VertexHelper" param that is not the same as "Mesh".
     
  39. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,089
    Yes, I just found out that the latest patch changed things without any warning. I'd recommend reverting to 5.2.1 (no patch) if possible for now. Hopefully it will be sorted out on Unity's end, but if not, then I'll have to figure some workaround.

    --Eric
     
  40. bitbutter

    bitbutter

    Joined:
    Jul 19, 2012
    Posts:
    60
    I have a problem where in my project, frame rate drops are coinciding with unexpected gaps in my vectrosity trails. I've made a simple scene to show the problem, attached to this post.

    To replicate:
    • I'm using Unity 5.2.0f3.
    • In a new project import the trailgaps package.
    • Import Vectrosity (I'm using Vectrosity 5).
    • Open TrailGlitches scene and run it.
    • Use arrow keys (or a joypad, latest unity breaks key input on my mac) to move the distant cube around.
    • Every ten seconds 'DoExpensiveTask' will be repeated, which contains a loop that takes two seconds to complete.
    • When this slow task has finished and the screen updates, the trail at the corresponding point has a gap like the one shown below:

     

    Attached Files:

  41. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,089
    You have subsequent points in the line that are identical. In general you should only add points if a sufficient distance exists between them, such as in the DrawLinesMouse demo script.

    --Eric
     
  42. lilithgame

    lilithgame

    Joined:
    Sep 29, 2015
    Posts:
    2
    Hi Eric,
    How can I draw lines that face to up-direction, like a tape stuck on the ground. The only way I know is to put a temp camera on the top, but I believe there should be a better way. Thank you!

    Stephen Zhou
     
  43. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,089
    That's currently the only way.

    --Eric
     
  44. Ninjuit

    Ninjuit

    Joined:
    Jul 7, 2012
    Posts:
    7
    I use these two functions to make a base circle and then expand the size of it.


    Code (CSharp):
    1. public static List<Vector2> GetBasicCircle(int _resolution)
    2.     {
    3.         float _angleChange = 360.0f / _resolution;
    4.         List<Vector2> _circle = new List<Vector2>();
    5.         float _end = 360.0f;
    6.         for (float _angle = 0; _angle <= _end; _angle += _angleChange)
    7.         {
    8.             float _newAngle = _angle * Mathf.Deg2Rad;
    9.             _circle.Add(new Vector2(Mathf.Cos(_newAngle), Mathf.Sin(_newAngle)));
    10.         }
    11.         return _circle;
    12.     }
    13.    
    14.     public static List<Vector3> CreateCircle(List<Vector2> _normalizedCircle, Vector3 _position, float _radius)
    15.     {
    16.         List<Vector3> _circle = new List<Vector3>();
    17.         int _length = _normalizedCircle.Count;
    18.         for (int i = 0; i < _length; i++)
    19.         {
    20.             _circle.Add(new Vector3(_position.x + _normalizedCircle[i].x * _radius, _position.y + _normalizedCircle[i].y * _radius, _position.z));
    21.         }
    22.         return _circle;
    23.     }
    And then I use Vectrosity like this...

    Code (CSharp):
    1. public static void InitializeVectors()
    2.     {
    3.         List<Vector3> _circle = ProceduralGeometry.CreateCircle(ProceduralGeometry.GetBasicCircle(180), Vector3.zero, 4.5f);
    4.         if (ejectTimeUI == null)
    5.             ejectTimeUI = new VectorLine("EjectTimeCircle", _circle, 10.0f, LineType.Continuous, Joins.Fill);
    6.         ejectTimeUI.SetColor(Color.white);
    7.         ejectTimeUI.drawTransform = currentPlayerRef.transform.Find("PlayerUI/EjectTime");
    8.         ejectTimeUI.layer = LayerMask.NameToLayer("Player");
    9.         ejectTimeUI.Draw3DAuto();
    10.        
    11.         if (ejectZoomTimeUI == null)
    12.             ejectZoomTimeUI = new VectorLine("EjectZoomTimeCircle", _circle, 5.0f, LineType.Continuous, Joins.Fill);
    13.         ejectZoomTimeUI.layer = LayerMask.NameToLayer("Player");
    14.         ejectZoomTimeUI.SetColor((Color32)ejectTimeColor);
    15.         ejectZoomTimeUI.drawTransform = currentPlayerRef.transform.Find("PlayerUI/EjectZoom");
    16.         ejectZoomTimeUI.Draw3DAuto();
    17.     }
    This is code that sets the start and end points of the circle to draw.
    Code (CSharp):
    1. float _ejectZoomFactor = Mathf.Min(1, (ejectTimer - ejectTime) / ejectThresholdTime);
    2.         float _ejectTimeFactor = Mathf.Min(1, ejectTimer / ejectTime);
    3.         if (ejectTimer <= ejectTime)
    4.         {
    5.             if (PlayerManagerScript.ejectZoomTimeUI != null)
    6.                 PlayerManagerScript.ejectZoomTimeUI.drawEnd = (int)Mathf.Floor(PlayerManagerScript.ejectZoomTimeUI.points3.Count * _ejectTimeFactor);
    7.             if (PlayerManagerScript.ejectTimeUI != null)
    8.                 PlayerManagerScript.ejectTimeUI.drawEnd = (int)Mathf.Floor(PlayerManagerScript.ejectTimeUI.points3.Count * _ejectTimeFactor);
    9.         }
    10.         else if (ejectTimer >= ejectTime)
    11.         {
    12.             if (PlayerManagerScript.ejectZoomTimeUI != null)
    13.                 PlayerManagerScript.ejectZoomTimeUI.drawStart = (int)Mathf.Floor(PlayerManagerScript.ejectZoomTimeUI.points3.Count - PlayerManagerScript.ejectZoomTimeUI.points3.Count * (1.0f - _ejectZoomFactor));
    14.             if (PlayerManagerScript.ejectTimeUI != null)
    15.                 PlayerManagerScript.ejectTimeUI.drawEnd = (int)Mathf.Floor(PlayerManagerScript.ejectTimeUI.points3.Count * _ejectTimeFactor);
    16.         }
     
  45. any_user

    any_user

    Joined:
    Oct 19, 2008
    Posts:
    337
    There's a problem with that. All 3D lines are automatically unparented when calling VectorLine.Draw3D(). This means they will lose their parents each time they're drawn... Here's again the project attached that shows the issue (without Vectrosity.dll this time). I'm using v 5.0.
     

    Attached Files:

  46. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,089
    They don't "really" exist properly until you've called Draw3D; "new VectorLine" sort of primes them. So you can call Draw3D immediately when creating the line, then parent it as you like after that.

    Do you have any code I can run that doesn't have external dependencies? Or you can post a project (don't include Vectrosity). I'm not able to get the issue to happen with my own code.

    --Eric
     
  47. ababab5

    ababab5

    Joined:
    Apr 15, 2014
    Posts:
    505
    Hi,

    I have one draw call by vector line I draw. Is it normal ?

    Thanks !
     
  48. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,089
    Yes, that's normal.

    --Eric
     
  49. ababab5

    ababab5

    Joined:
    Apr 15, 2014
    Posts:
    505
    Hi,

    Thanks for the quick reply.

    Is there a way to optimize it ?

    Thanks
     
  50. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,089
    It's already about as optimized as it can get.

    --Eric