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,146
    You need to call Draw to update a 2D line, any frame that the target object moves. Keep in mind that 2D lines use screen space and 3D objects use world space, so the results might not be want you want. To make lines match world space objects, you'd need to use a 3D line.

    You already PMed me, continue this there rather than the forum please. (I don't work for Unity and would not have a unity.com address.)

    --Eric
     
  2. Brian-Washechek

    Brian-Washechek

    Joined:
    Aug 5, 2015
    Posts:
    578
    Alright, could I get a link to where you want me to post, please? I really want to get this to work. I mean I paid $29.95 for it...
     
  3. abledbody

    abledbody

    Joined:
    Dec 2, 2015
    Posts:
    5
    Ah, right. I figured it out eventually (I didn't realize there was another page to the forum so I thought you just hadn't replied yet) but thanks for your help!
     
  4. Brian-Washechek

    Brian-Washechek

    Joined:
    Aug 5, 2015
    Posts:
    578
    Ohh... PM, right! I’m sorry, I will once I get on my computer! Heh... heh... I’m sorry.
     
  5. abledbody

    abledbody

    Joined:
    Dec 2, 2015
    Posts:
    5
    Is there really no compromise between futzing with the canvas/screenspace and not being able to see my objects in the editor? I still haven't found an effective workflow for this scenario.
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,146
    You can have a stand-in (like a cube) which is replaced by a VectorLine object at runtime. The issue with 3D lines is that they are designed to face the game view camera, so this doesn't really work in the editor.

    --Eric
     
  7. Brian-Washechek

    Brian-Washechek

    Joined:
    Aug 5, 2015
    Posts:
    578
    Error on 10-18-2018.png Heh-heh.............

    When I click the "Open in Unity" button it opens the Window on the right and Vectrocity isn't there... At least I don't think... I've got to be doing something wrong...

    Heh-heh.........................................

    I suppose it's possible that it's already loading and I just don't see it. I think that's it, actually. So where do I get these demos?
    Vectrosity image 2.png
    Is help offered?
     
    Last edited: Oct 18, 2018
  8. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    4,926
    This is Unity ... how it works with the asset store. Best to have a Unity project open. Then, when you select "Open in Unity" from the asset store, it will open the UAS window in the Unity editor, and you can begin the download or import process.

    EDIT: The method used below is what I actually do, but I wonder which way is easier? Both are about the same.
     
    Last edited: Oct 18, 2018
  9. Korindian

    Korindian

    Joined:
    Jun 25, 2013
    Posts:
    446
    @Brian-Washechek It might be easiest if you use the Asset Store browser within the Unity Editor.
    Within the Unity Editor, in any project, go to:
    Window > Asset Store

    or in 2018 versions of Unity, go to:

    Window > General > Asset Store.

    In the top right of that window, you should be able to login into your Unity account, if not already.
    In the top left of that window, there is an icon you can click which takes you to "My Assets".

    From there, if you purchased Vectrosity, it should show up. Download it, then import it.

    Another window will popup showing all that will be imported into the project. Go ahead and import.

    Then Vectrosity will show up in the project folder as a folder called "Vectrosity". There should be some txt files and documentation you can look at in that folder on what to import to get the demos.

    Hope that helps. Edit: just saw @hopeful post above. Pretty much what he said is another way of doing it.
     
  10. hurleybird

    hurleybird

    Joined:
    Mar 4, 2013
    Posts:
    71
    Just want to check, does a way exist yet to draw 3D lines that face an arbitrary direction (eg. Vector3.up) and not the camera without resorting to dirty hacks?
     
  11. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,146
    No, it's designed the face the camera.

    --Eric
     
  12. hurleybird

    hurleybird

    Joined:
    Mar 4, 2013
    Posts:
    71
    I disagree that the asset is designed to face the camera. You can watch a line with a different camera that isn't flagged as Camera.Main, and, and the line behaves just fine in world space. Rather, it seems that lines are arbitrarily constrained to face Camera.Main without any technical reason this needs to be the case. So you can get it to behave properly in world-space by setting some throwaway camera to Camera.Main, at the expense of breaking every single other thing that relies on proper Camera.Main usage. That's very frustrating and very bad!

    Being able to set an arbitrary facing literally makes the asset 10x more usable. It's like, if you aren't making a straight up Battlezone clone, or working with an overlay, or you have the camera fixed to be perpendicular to some surface, there just aren't any real use cases for wanting lines to face the camera. You almost always want them to behave properly in world space. What's the point otherwise?

    I don't get it, man. The asset seems like it's technically capable of being much more than it is. Why is it handicapped this way?
     
    Last edited: Oct 25, 2018
  13. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,146
    The asset WAS designed to face the camera; I designed it that way, so that's an incontrovertible fact. ;) The whole point was to make camera-facing variable pixel-width lines. They don't face Camera.main (except by default), but rather any camera you specify. It can't be all things to all people. And even if I somehow did, it would be so bloated that people would complain about that....

    --Eric
     
  14. MateAndor

    MateAndor

    Joined:
    Nov 5, 2014
    Posts:
    42
    Hello!

    I have a little problem with vectorsity. I try to draw a line on mobile so i use the DrawLinesTouch. Thaths works nice when i move my finger slow, but when i try to draw a circle fast thats looks like in the picture (very angular).
    How can i draw smoother lines on mobile?

    Thanks
     

    Attached Files:

  15. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,146
    Increase the frames per second so input is faster (it's probably at 30 instead of 60). If that's not enough, make the line have more points, and use the input samples as points for MakeSpline, instead of using the input samples directly.

    --Eric
     
  16. omx-jonson

    omx-jonson

    Joined:
    Mar 23, 2014
    Posts:
    8
    Hey Eric,

    I draw a spline, then rotate the transform (line attached to drawTransform ). The line properly rotates. However, point3 of the line are in local (not rotated) coordinates. Any chances to get points3 in world space coordinates (rotated?), not local?

    Thanks in advance.
    Best
    Mike
     
  17. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,146
    You can use Transform.TransformPoint.

    --Eric
     
  18. omx-jonson

    omx-jonson

    Joined:
    Mar 23, 2014
    Posts:
    8
    OMG thanks!
     
  19. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    96
    Nice work, Eric!

    Just a little feedback to share. This is a high fidelity API -- I appreciate that I can replace LineRenderer and look and feel is identical. See screenshots, below.

    Line Renderer


    Vectrosity


    One thing I was a little surprised to discover is that my rendering performance is about the same between Unity LineRenderer and Vectrosity VectorLine.Draw3DAuto. Interestingly, my LineRenderer implementation is naieve and likely stupid. I create 1200 LineRenderer game objects. For the Vectrosity version I create just 9 VectorLine objects.

    Is it possible I'm missing something to unlock further performance in VectorLine? I use a shared material across lines. The material seems to be affected by lighting -- maybe that's a contributing factor.

    I'm likely to keep using LineRenderer because I'm able to maintain granular control of each line segment -- useful for things like waypointing.

    Thank you for creating a nice game asset.
     
    Last edited: Nov 9, 2018
  20. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,146
    You can get better performance with Draw rather than Draw3D, if you don't really need world-space lines. In certain cases it can be useful to do Draw3D once, rather than updating every frame, if you don't need camera-facing constant pixel line thickness. You have complete control over each line segment in Vectrosity as well. Thanks for the feedback!

    --Eric
     
  21. hecali_aj

    hecali_aj

    Joined:
    Sep 1, 2015
    Posts:
    3
    Hello, Eric. Does Vectrosity work with Unity's lightweight renderer? I'd like to know before I buy the asset. Thanks!
     
  22. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,146
    Yes, UI shaders work with LW RP by default, and you can supply your own material if desired anyway.

    --Eric
     
  23. smalleye

    smalleye

    Joined:
    Apr 18, 2018
    Posts:
    9
    Hi, I wonder if Vectrosity can draw lines on a RenderTexture. I tried drawing on canvas and it worked well for me. But when I changed the render target from camera to a render texture, I got nothing on the render texture. Maybe I did something wrong. Could someone provide some advice? Thanks!
     
  24. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,146
    Do rendertextures work with a canvas at all? You could draw 3D lines instead; that definitely works with rendertextures.

    --Eric
     
  25. smalleye

    smalleye

    Joined:
    Apr 18, 2018
    Posts:
    9
    Thank you Eric for the tips.
    I tested it with 3D lines, but still couldn't get it working. The following is my test script.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Vectrosity;
    5.  
    6. public class Test : MonoBehaviour
    7. {
    8.    
    9.     private RenderTexture renderTexture = null;
    10.     private Texture2D texture = null;
    11.  
    12.     public float lineWidth = 2.0f;
    13.     private VectorLine line;
    14.    
    15.     void Start()
    16.     {
    17.         renderTexture = new RenderTexture(Screen.width, Screen.height, 0, RenderTextureFormat.ARGB32);
    18.         texture = Resources.Load<Texture2D>("Textures/river");
    19.         Graphics.Blit(texture, renderTexture);
    20.  
    21.         var points = new List<Vector3>();
    22.         points.Add(new Vector3(0, 0, 0));
    23.         points.Add(new Vector3(100, 100, 0));
    24.  
    25.         line = new VectorLine("testLine", points, lineWidth);
    26.  
    27.     }
    28.  
    29.     void Update()
    30.     {              
    31.         RenderTexture.active = renderTexture;
    32.         line.Draw3D();
    33.         RenderTexture.active = null;                        
    34.     }
    35.  
    36.  
    37.     void OnRenderImage(RenderTexture sourceTexture, RenderTexture destTexture)
    38.     {
    39.         Graphics.Blit(renderTexture, destTexture);
    40.     }
    41.  
    42. }
    Cause I needed to do some post processing, so I had to use the OnRenderImage function here.

    With the above script, I couldn't see the line drawn with Vectrosity. See below:

    upload_2018-12-2_11-17-32.png

    So the 3D line wasn't drawn on the river texture rendered on the screen. However if I remove the entire OnRenderImage function, I would get the following result with the line on the screen:

    upload_2018-12-2_11-22-50.png

    Any suggestion?
    Thank you!
     
  26. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,146
    Try doing Draw3D first, or try waiting a frame after drawing the line before doing the rendertexture.

    --Eric
     
  27. smalleye

    smalleye

    Joined:
    Apr 18, 2018
    Posts:
    9
    Hi Eric, Thank you for the reply.
    As I haven't been in the Unity world for a long time, I couldn't figure out how to "Draw3D first", where should I place this statement in the above script?
    Regarding your second suggestion, after drawing the line, there is no extra render texture processing except blit it to the screen, so still no clue how to do it.

    I checked the Vectrosity documentation, and found there is no related section on how to draw lines on a render texture. I think this should be a very straightforward --- just switching the render target, according to my past experience in D3D, apparently it isn't in Unity. There may be some use cases like this for Vectrosity users, so a working example is greatly appreciated.
     
  28. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,146
    Draw3D doesn't immediately draw the line; rather it schedules the line to be drawn in LateUpdate. The way I have set up a rendertexture to use with lines is 1) Create the rendertexture in the editor. 2) Make a material that uses the rendertexture, apply the material to the desired object. 3) Make a camera that renders to the rendertexture. 4) Set culling masks on the main camera and the rendertexture camera appropriately, so the rendertexture camera sees the lines but the main camera doesn't. 5) In your script, use VectorLine.SetCamera3D with the rendertexture camera. So, a cube with the rendertexture:

    Screen Shot 2018-12-03 at 2.46.47 PM.png

    --Eric
     
  29. smalleye

    smalleye

    Joined:
    Apr 18, 2018
    Posts:
    9
    Hi Eric, I followed your instruction and got the result as you showed here above. However I still couldn't overlay the lines on the input 2D texture (the river image). With the approach you suggested, the render texture camera will overwrite the original image with the 3D scene's background. The final expected render result should be something like below. The background image may be changed in run-time in my application. Thank you again!

    upload_2018-12-3_22-49-49.png
     
  30. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,146
    Try using Don't Clear for the rendertexture camera's clear flags.

    --Eric
     
  31. smalleye

    smalleye

    Joined:
    Apr 18, 2018
    Posts:
    9
    Hi Eric, setting flag to "Don't Clear" works! As well, setting it to "Depth only" also works. As my purpose is to draw 2D lines on the render texture, I have to use the Camera.ScreenToWorldPoint() function to convert the screen pixel coordinates to the world unit coordinates, and then add the 3D point into the VectorLine.point3 list:

    Code (CSharp):
    1. Vector3 newPoint = camera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x , Input.mousePosition.y, camera.nearClipPlane));
    It would be great if Vectrosity can simplify this setting up process in the future releases so that users can draw 2D lines directly on render textures.

    Thank you again for your excellent support!
     
  32. smalleye

    smalleye

    Joined:
    Apr 18, 2018
    Posts:
    9
    One more question, How to change the sorting order of the 3D lines rendered on the camera? It seems the GameObject of the 3D line isn't exposed by the API, so application can't access the Mesh Renderer component to change its sorting order. Modifying the code is the only way? Thanks
     
  33. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,146
    You can access the GameObject by using VectorLine.rectTransform.gameObject.

    --Eric
     
  34. smalleye

    smalleye

    Joined:
    Apr 18, 2018
    Posts:
    9
    Thank you Eric, it works!
     
  35. captnhanky

    captnhanky

    Joined:
    Dec 31, 2015
    Posts:
    89
    Hi!

    I just purchased the vectrocity package because I could not get line renderer to work with edge collider.
    In the vectrocity manual it says in order to have a collider on the line you have to check the collider box in the "vector object 2D (script)"
    But it is not working. I used a sphere collider with rigidbody2D to test it (gizmo mode on in the game view).
    The sphere collider is falling through the line, no effect.

    What am I doing wrong?

    I need this collider to work, because I want to make a gravitar like game.

    2. Question: Is there a way to ADD points in between two existing points in the scene view? The manual mentions only deleting points.



    Thanks
     
    Last edited: Dec 13, 2018
  36. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,146
    Lines use a 2D collider, so a sphere collider won't work...the 3D and 2D physics systems are separate and don't interact. You'd need to use a circle collider. For an example, see the RandomHills demo. (Also, make sure you read the note in the docs about the collider being in world space.)

    You can insert points by using the "+" button in the line points list in the inspector. You can also edit the source code of the VectorObject2DEditor script if you want to customize the visual line editor functionality.

    --Eric
     
  37. captnhanky

    captnhanky

    Joined:
    Dec 31, 2015
    Posts:
    89
    So you tell me that one of the most basic functions of a line engine, to add points between points is missing and that I, the customer has to implement this function by myself?
    Am I right so far?
    I think, this is the most ridiculous S*** I have witnessed in a while.
    I bought your asset because of exactly two reasons:
    To easily manipulate lines and to add a collider to it, so that I can make this game I want to make.
    BOTH things are not possible with your asset, the circle collider also DOES NOT work.

    I WANT MY MONEY BACK!
     
  38. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,146
    No, the function isn't missing. Please read my post again. Also, the circle collider certainly does work. The RandomHills demo proves this. Vectrosity is primarily intended to be used through code, so the visual editor is not designed to be a super-complex bloated drawing app. I respond far better to reasonable discourse, just so you know.

    --Eric
     
  39. captnhanky

    captnhanky

    Joined:
    Dec 31, 2015
    Posts:
    89
    The insert point function in the visual line editor IS missing, as your own quote clearly says!

    ..so you argue with lies? This makes the situation even more ridiculous!

    I want to edit lines in a visible manner and not via code, because I want to see what I am doing.
    Why do you even have a visual editor for the scene view when you are saying that it is not designed to work with?
    YOU MADE A WHOLE MANUAL ON HOW TO USE THE VISUAL EDITOR AND THEN CLAIM IT IS NOT INTENDED TO BE USED AT ALL???
    Also.. when adding points between two existing points is a feature of a quote" super-complex bloated drawing app" then I am asking myself, with whom I am dealing with here..

    At leased I got the collider to work, I don´t know why but it suddenly worked.



    To prevent future discussions with angry customers I recommend that you point out in big letters that adding points between two existing points in the visual editor is a feature that you are not capable of implementing, because this would be a feature of a "super-complex bloated drawing app" (btw even the unity line renderer can do this).
     
    Last edited: Dec 13, 2018
  40. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,146
    Not sure how you could have missed that.

    Note the word "also". This is a basic comprehension issue. If you want to add additional functionality, you can do that since the source code is available. Let me know via PM when you feel like you can respond in a civil fashion, but this really isn't appropriate behavior on the forums.

    --Eric
     
  41. Andorid42

    Andorid42

    Joined:
    May 8, 2016
    Posts:
    8
    How would I get the arclength distance between two points on a spline created using makespline
    I assume myLine.GetLength() will return the entire length of the spline, but for my purposes I also need the length between two points in the spline

    More specifically, in order to draw a spline over time for a laser like weapon, I am having a gameobject walk the spline, using the projectile to act as the endpoint and adding each transform that defines the spline to the vector3 array of the actual drawn spline as it passes. If I have the distance between two points I can get those distances to set as conditionals for insertion of the transform positions as they are passed by the projectile.

    btw, loving vectrosity
    thanks for your time!
     
    Last edited: Dec 14, 2018
  42. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,146
    Well, since you know how many points there are in the line, and how many points in the spline, you can use that info...for example, say you use 3 spline points and there are 20 points in the line. Say you want the arc length between spline point 0 and spline point 1. That's 10 points, so this means you'd add up the Vector2.Distance for all points in the line between 0 and 10. That is, do Vector2.Distance(line.points2[0], line.points2[1]), then Vector2.Distance(line.points2[1], line.points2[2]), keeping a running total up through points2[10].

    --Eric
     
    Andorid42 likes this.
  43. Andorid42

    Andorid42

    Joined:
    May 8, 2016
    Posts:
    8
    The problem I am having with this is the number of points per spline section... to my mind clearly they can't be equal... as I can specify a number of points like 250 and have 4 arc segments, ie, 5 spline points which yields 62.5 points per arc section if they were equal, which doesn't make sense to me. Also the size of the sections of the spline will vary in length due to the transform positions of the spline points right? Or else the resolution of the curve would vary from section to section?
     
  44. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,146
    The number of points in each section is always the same as all other sections; there isn't any attempt to vary the number of points depending on section length. (In my experiments the minimal difference in quality wasn't worth the extra complexity.) The only time there's any difference is if the number of points doesn't divide 100% equally, but you can simply ensure that it does.

    --Eric
     
    Andorid42 likes this.
  45. Andorid42

    Andorid42

    Joined:
    May 8, 2016
    Posts:
    8
    awesome, thank you for clarifying
     
  46. Andorid42

    Andorid42

    Joined:
    May 8, 2016
    Posts:
    8
    Hi, me again... So I was able to implement a dynamic spline laser that traced itself over time instead being drawn instantaneously using the method you highlighted above, however it doesn't give me enough control over the spline shape for my purposes, unfortunately. I am trying to implement a whip like laser ala raiden:
    as you see it coils quite a bit, which is easy enough to achieve using a setup like the draw curve demo, if you set the control points in an alternating perpendicular fashion. So the question is, is it possible to draw a curve such as this in the same sort of way? eg the ability to draw calculated line over time as an object follows the path of the curve? Or alternately a way of accessing the control points of the spline created by calling the MakeSpline() function? Thanks!
     

    Attached Files:

  47. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,146
    MakeSpline doesn't have any control points; it's a centripetal Catmull-Rom spline. MakeCurve is a Bezier curve, which uses control points supplied by you. So that would probably be a better choice if you want specific control over the shape of the curve.

    --Eric
     
    Andorid42 likes this.
  48. Andorid42

    Andorid42

    Joined:
    May 8, 2016
    Posts:
    8
    Good to know makespline uses the centripetal form, which doesn't ever loop. I'll try messing with the makecurve or possibly implement a custom TCB spline with a tension factor. I'm probably just being lazy lol. Thanks for the response!
     
  49. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,146
    Nothing wrong with implementing a custom spline if that's what you need. The MakeSpline and MakeCurve code are basically added on top of Vectrosity functions, in the VectorUtilities script, and don't do anything special that can't be done just as well with user code.

    --Eric
     
    Andorid42 likes this.
  50. Jribs

    Jribs

    Joined:
    Jun 10, 2014
    Posts:
    45
    @Eric5h5
    Is there a way to set more than 1 parent gameobject that the 3d lines get drawn into?

    I have basically 2 instances of a line that need to have their own independent line parent, but they keep getting created under the same parent even when i'm setting the parent to separate transforms?

    Am I missing something?