Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Vectrosity - fast and easy line drawing

Discussion in 'Assets and Asset Store' started by Eric5h5, May 26, 2010.

Thread Status:
Not open for further replies.
  1. gregzo

    gregzo

    Joined:
    Dec 17, 2011
    Posts:
    795
    Hi Eric,

    I hope you're well!

    My question might seem obvious or have been answered already, but this is a long thread and google didn't return anything, so here it is:

    How does DrawPoints3D compare to manually managing a particle[] in the new Shuriken system (ParticleSystem.Particle) ? For 1000+ points?

    Many thanks!

    Gregzo
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,400
    I would imagine it's slower, but I don't know for sure.

    --Eric
     
  3. coolpowers

    coolpowers

    Joined:
    Mar 23, 2010
    Posts:
    125
    Is there any way of quickly hiding a VectorLine, or do I have to destroy and recreate?
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,400
    VectorLine.active

    --Eric
     
  5. coolpowers

    coolpowers

    Joined:
    Mar 23, 2010
    Posts:
    125
    Can't believe I missed that. I was searching on "visible" and "hidden" and all sorts. Cheers, and thanks again for a great lib.
     
  6. cagezero

    cagezero

    Joined:
    May 8, 2012
    Posts:
    20
    Eric,

    I just purchased Vectrosity and I am having troubles syncing my lines between the editor and play mode. I have a MonoBehaviour that is tagged with [ExecuteInEditMode]. This script creates a VectorLine in the Awake function. This setup creates a new VectorLine GO every time I play. In an attempt to mitigate this issue I added VectorLine.Destroy(line) to the OnDestroy function. Unfortunately, this generates the following error: "Destroy may not be called from edit mode! Use DestroyImmediate instead." I am using Unity 3.5.

    My ultimate goal is really very simple. I need to see the lines in the editor as well as play mode, but I am unable to serialize the VectorLine instance and I am also unable to destroy it in edit mode. Any advice?
     
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,400
    You could check for Application.isPlaying before doing your VectorLine.Destroy call.

    --Eric
     
  8. cagezero

    cagezero

    Joined:
    May 8, 2012
    Posts:
    20
    I have tried many variations on that theme. Sample code snippet:

    Code (csharp):
    1.  
    2. public VectorLine vectorLine;
    3.  
    4. void Awake() {
    5.  
    6.     if(vectorLine == null) {
    7.            
    8.         Vector3[] linePoints = new Vector3[2] {Vector3.zero, Vector3.zero};
    9.         vectorLine = new VectorLine("edge", linePoints, Color.white, null, 3.0f);
    10.     }
    11. }
    12.  
    13. void OnDestroy() {
    14.        
    15.     if(Application.isPlaying) {
    16.         VectorLine.Destroy(ref vectorLine);
    17.     }
    18. }
    19.  
    The call to VectorLine.Destroy(vectorLine) does nothing. The VectorLine Object is still in the Hierarchy and every time I hit play another appears.
     
  9. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,400
    The VectorLine.Destroy call does work, but as soon as you stop play, the Awake function will run (because of ExecuteInEditMode), and since vectorLine is null because it's not serialized, it will always create a new line. Instead of checking null you could use GameObject.Find.

    --Eric
     
  10. cagezero

    cagezero

    Joined:
    May 8, 2012
    Posts:
    20
    Great! That prevents multiple instances of the VectorLine Object from appearing in my Hierarchy, but I still have no access to the underlying VectorLine class. How do I use vectorLine.SetColor(newColor) or vectorLine.points3 once play mode is active?

    new code:

    Code (csharp):
    1.  
    2. public Transform thisTransform;
    3. public VectorLine vectorLine;
    4.    
    5. void Awake() {
    6.        
    7.     thisTransform = gameObject.transform;
    8.        
    9.     if(thisTransform.FindChild("Vector edge") == null) {
    10.            
    11.         Vector3[] linePoints = new Vector3[2] {Vector3.zero, Vector3.zero};
    12.         vectorLine = new VectorLine("edge", linePoints, Color.white, null, 3.0f);
    13.         vectorLine.vectorObject.transform.parent = thisTransform;
    14.     }
    15. }
    16.  
    17. void OnDestroy() {
    18.        
    19.     if(Application.isPlaying) {
    20.         VectorLine.Destroy(ref vectorLine);
    21.     }
    22. }
    23.  
    btw- Thanks for your quick and poignant responses.
     
  11. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,400
    Actually I'm not sure Vectrosity is really suitable for that as-is. You can try adding [System.Serializable] to the VectorLine class in VectorLine.cs.

    --Eric
     
  12. cagezero

    cagezero

    Joined:
    May 8, 2012
    Posts:
    20
    That works. Thank you.
     
  13. arkon

    arkon

    Joined:
    Jun 27, 2011
    Posts:
    1,122
    Hi Eric,

    I have an ortho camera setup and when I draw lines from 0,0 the line starts from the middle of the screen. How can I make the anchor bottom left of the screen. i.e.. 0,0 = bottom left.
     
  14. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,400
    0,0 is the bottom left actually...I don't know of any way that would change, unless you moved the vector camera (which is not recommended).

    --Eric
     
  15. arkon

    arkon

    Joined:
    Jun 27, 2011
    Posts:
    1,122
    How odd. I'll try a new project with just your plugin and try and find out why it's 0,0 is centre of the screen.
     
  16. arkon

    arkon

    Joined:
    Jun 27, 2011
    Posts:
    1,122
    I just tried a blank project with just Vectrosity included. None of your examples use an ortho camera so I couldn't replicate the problem.
    My scene has an ortho camera with a size of 384. I then use draw3d to draw the lines as I want them at different depths. But the origin 0,0
    seems to be in the centre of the screen. Any ideas?
     
  17. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,400
    Draw3D uses world coordinates, in which case (0,0,0) is the origin as usual; whether that's the middle of the screen depends on your camera location and orientation. If by "different depths" you mean layering the lines, you can use VectorLine.depth to control which lines draw on top of which other lines.

    --Eric
     
  18. BryceS

    BryceS

    Joined:
    Jun 10, 2011
    Posts:
    25
    I purchased Vectrosity awhile ago from the Unity asset store, recently I downloaded the newest version and imported it in a new project. I can't seem to find the editor scripts described in the documentation, specifically the LineMaker class. Apparently it should be in a VectrosityEditorScripts.unitypackage file... But it isn't(the only .unitypackage files I have are TankZone, VectrosityDemos, VectrositySource, Vectrosity_Unity4).

    Am I completely missing something or was this an oversight when the update was published?

    Thanks in advance, looking forward to resolving this so I can fully use this great product :).
     
  19. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,400
    The LineMaker script is supposed to be in Extras/VectrosityEditorScripts, but I accidentally left it out. I've uploaded an update which includes it. Sorry about that!

    --Eric
     
  20. grokbox

    grokbox

    Joined:
    Oct 9, 2012
    Posts:
    2
    Eric, do you have any idea when the update with LineMaker included is likely to appear on the Asset Store? I desperately need it!
     
  21. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,400
    They're usually very fast about updates.

    --Eric
     
  22. cagezero

    cagezero

    Joined:
    May 8, 2012
    Posts:
    20
    I am having problems with a line resizing itself when I redraw it, but only when I redraw it from a menu item. Any clue what I am doing wrong here? Steps to reproduce the resizing:

    1. Use the menu item "Custom/Create Edge"
    2. Select the newly created edge.
    3. Use the menu item "Custom/Redraw Edge"

    After step 3 the line is about half its original size. Perform step 3 again and the line is re-sized to about 1/8 of the original size. Further redrawing leaves the line unchanged. Here is the code:

    Code (csharp):
    1. public class EdgeController : MonoBehaviour {
    2.    
    3.     private VectorLine vectorLine;
    4.     private Vector3 position1 = new Vector3(-3, 20, 70);
    5.     private Vector3 position2 = new Vector3(-3, 0, 70);
    6.    
    7.     public void UpdateVectorLine() {
    8.        
    9.         vectorLine.points3[0] = position1;
    10.         vectorLine.points3[1] = position2;
    11.         vectorLine.Draw3D();
    12.     }
    13.    
    14.     void Awake() {
    15.        
    16.         Material lineMaterial = (Material)Instantiate(Resources.Load("Material/VectorLineGlow"));
    17.         Vector3[] linePoints = new Vector3[2] {position1, position2};
    18.         vectorLine = new VectorLine("Line", linePoints, new Color(1, 1, 0, 1), lineMaterial, 7.0f);
    19.         vectorLine.vectorObject.transform.parent = transform;
    20.     }
    21.    
    22.     void Start() {
    23.         UpdateVectorLine();
    24.     }
    25. }
    Code (csharp):
    1. public class GraphEditor : Editor {
    2.    
    3.     [MenuItem ("Custom/Create Edge")]
    4.     static void CreateEdge () {
    5.         Instantiate(Resources.Load("Models/Edge"));
    6.     }
    7.    
    8.     [MenuItem ("Custom/Redraw Edge")]
    9.     static void SetActive() {
    10.        
    11.         List<EdgeController> edges = new List<EdgeController>();
    12.         foreach(GameObject go in Selection.gameObjects) {
    13.            
    14.             EdgeController ec = (EdgeController)go.GetComponent<EdgeController>();
    15.             if(ec != null)
    16.                 edges.Add(ec); 
    17.         }
    18.        
    19.         if(edges.Count == 1)
    20.             edges[0].UpdateVectorLine();
    21.     }
    22. }
     
  23. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,400
    I don't really know offhand. Maybe you can make a simple version with no dependencies that exhibits this behavior so I can test it.

    --Eric
     
  24. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,400
    And really, please do not post projects that contain Vectrosity itself to this thread, for reasons that should be obvious....

    --Eric
     
  25. cagezero

    cagezero

    Joined:
    May 8, 2012
    Posts:
    20
    My apologies. I posted without thinking.
     
  26. ArmarageX

    ArmarageX

    Joined:
    Aug 5, 2012
    Posts:
    21
    Hey Eric

    Im using your DrawLinesMouse() script, and i converted it from drawing 2D lines to Drawing 3D lines...

    When i mouse down to draw, all is well, and i can redraw it again next time i mouse down.
    But as soon as i run this function on MouseUp.... im not able to REDRAW again, and the line remains on screen forever... no matter if i try to mouseDown again.

    It seems to break when i run the GetComponent -> Mesh.
    Am i doing something incompatible with your script?
    Thanks in advance for your help >.<

    Code (csharp):
    1.  
    2.     if (Input.GetMouseButtonUp(0))
    3.     {
    4.         CalculateBoundingBox();
    5.     }
    6.  
    7. function CalculateBoundingBox()
    8. {
    9.      var myCable:GameObject = GameObject.Find("Vector DrawnLine");
    10.      myMesh = myCable.GetComponent(MeshFilter).mesh;
    11. /*   bounds = myMesh.bounds;
    12.      LassoHitBox.transform.position = bounds.center;
    13.      col.radius = bounds.extents.x;
    14.      LassoHitBox.SendMessage("CountDown");
    15. */
    16. }
    17.  
     
  27. nitz

    nitz

    Joined:
    May 4, 2011
    Posts:
    54
    Hi again Eric!

    So I've got a question for you that should hopefully be an easy one.

    I'm trying to draw some quite long, complicated lines (Several thousands of points.) Sometimes, my lines are longer than you seem to support (which ends up being however many segments create 65534 vertices.) I know this, because when I try to Resize() I get the error saying:

    Code (csharp):
    1.  
    2. VectorLine: exceeded maximum vertex count of 65534 for "LineChart(Clone)_LineChart_Line"...use fewer points
    3.  
    I'd love too, but I'm not sure how many less points to give it? Further, this seems to 'break' the lines. None of my lines draw after this happens. (And aside from the LogError, I never see an exception or anything, so I don't know how to handle it -- be it recreate the lines or something like that -- but I wouldn't know when to do it?)

    A little advice in this matter would be much appreciated! :) Thanks again!
     
  28. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,400
    Indeed, accessing the VectorLine mesh that way seems to create interesting problems. I would suggest adding this to the VectorLine.cs script, after the "Mesh m_mesh" line:

    Code (csharp):
    1.     public Mesh mesh {
    2.         get {return m_mesh;}
    3.     }
    Then, if you have a VectorLine called myLine, you can do "var bounds = myLine.mesh.bounds" and it won't cause issues. (That change will be part of Vectrosity 2.2.) So rather than using GameObject.Find, you'll want to pass in the VectorLine that you're using.

    You can use approximately 16000 points for continuous lines, and 32000 points for discrete lines. Once you stop having the error, lines should draw without issues (since errors cause line drawing to stop, in order to prevent a possible cascade of errors which makes the original cause harder to find).

    --Eric
     
  29. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,400
    Looks like the update (with the LineMaker utility included) is on the Asset Store now.

    --Eric
     
  30. ArmarageX

    ArmarageX

    Joined:
    Aug 5, 2012
    Posts:
    21
    Thanks for such prompt response Eric! That small line fixed it! And all is working!
     
  31. nitz

    nitz

    Joined:
    May 4, 2011
    Posts:
    54
    Thanks again, Eric!
     
  32. jwinn

    jwinn

    Joined:
    Sep 1, 2012
    Posts:
    88
  33. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,400
    It's really better not to post duplicate questions both here and on UnityAnswers. Please decide whether you want to post the question here or there, thanks.

    --Eric
     
  34. deadswine

    deadswine

    Joined:
    Mar 27, 2012
    Posts:
    19
    Hey Eric!
    I'm thinking abaut using this for my starategy project.
    I would use this for drawing movement lines and issuing movement orders. Do you think that your software would be good for that?
     
  35. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,400
    It's certainly good for drawing lines. :) Do you have any more specific requirements?

    --Eric
     
  36. deadswine

    deadswine

    Joined:
    Mar 27, 2012
    Posts:
    19
    I want to achive such effect
     
  37. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,400
    Yes, that's simple enough.

    --Eric
     
  38. deadswine

    deadswine

    Joined:
    Mar 27, 2012
    Posts:
    19
    Hehe, documentation indeed is great :) best i saw yet on asset store.
     
  39. Ron8000

    Ron8000

    Joined:
    Aug 28, 2012
    Posts:
    5
    Hello,

    I was wondering if there was any issue with Vectrosity and Unity 3.5.6f4 for Mac OSx -> iOS

    When I tried to port my working Android project to iOS I am stuck at a Cross Compile issue.

    So I started a new blank project and just imported Vectrosity 2.1.2, without extracting the demos this will compile into xCode.

    When I extracted just the demo files, again only Vectrosity 2.1.2 now with extracted Demos will NOT compile to xCode.

    Instead I am getting this message:

    ----------------------------------------------------------------------------------------------------------------------------------------------------------------

    Cross compilation job Assembly-UnityScript.dll failed.
    UnityEngine.UnityException: Failed AOT cross compiler: /Applications/Unity/Unity.app/Contents/BuildTargetTools/iPhonePlayer/mono-xcompiler --aot=full,asmonly,nodebug,static,outfile="Assembly-UnityScript.dll.s" "Assembly-UnityScript.dll" current dir : /Users/mac/Projects/SS-Beta1/SSBeta/Temp/StagingArea/Data/Managed
    result file exists: True
    stdout:
    stderr:

    at UnityEditor.MonoProcessUtility.RunMonoProcess (System.Diagnostics.Process process, System.String name, System.String resultingFile) [0x00000] in <filename unknown>:0
    at UnityEditor.MonoCrossCompile.CrossCompileAOT (BuildTarget target, System.String crossCompilerAbsolutePath, System.String assembliesAbsoluteDirectory, CrossCompileOptions crossCompileOptions, System.String input, System.String output, System.String additionalOptions) [0x00000] in <filename unknown>:0
    at UnityEditor.MonoCrossCompile+JobCompileAOT.ThreadPoolCallback (System.Object threadContext) [0x00000] in <filename unknown>:0
    UnityEditor.MonoCrossCompile:CrossCompileAOTDirectoryParallel(BuildTarget, CrossCompileOptions, String, String, String)
    PostProcessiPhonePlayer:postProcess(BuildTarget, String, String, String, String, String, String, String, BuildOptions, RuntimeClassRegistry)
    UnityEditor.HostView:OnGUI()

    ----------------------------------------------------------------------------------------------------------------------------------------------------------------

    Any suggestions?

    Thanks,
    Ron
     
  40. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,400
    Yes, please see page 2 of the docs (top of the page).

    --Eric
     
  41. coolpowers

    coolpowers

    Joined:
    Mar 23, 2010
    Posts:
    125
    Is there no easy way of combining Unity's particles with a game scene otherwise composed entirely of 2D VectorLine drawing? I've been futzing around with the cameras but I just can't get anything working. My goal here is to maximize laziness so I'm juggling amount of effort required to get particles working with the amount of effort needed to re-implement a simple VectorLine particle system :D
     
    Last edited: Oct 15, 2012
  42. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,400
    I'm not entirely sure what you're getting at, but since 2D VectorLines are drawn on an overlay, I don't think so. You can use 3D VectorLines instead, probably.

    --Eric
     
  43. coolpowers

    coolpowers

    Joined:
    Mar 23, 2010
    Posts:
    125
     
  44. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,400
    Make sure you're using a material that has a shader which can use vertex colors. Most built-in shaders don't.

    --Eric
     
  45. coolpowers

    coolpowers

    Joined:
    Mar 23, 2010
    Posts:
    125
    Yeah, I am. But it turned out to be a logic error - I wasn't actually modifying the Color variable I was passing to SetColor :D
     
  46. alen13

    alen13

    Joined:
    Oct 17, 2012
    Posts:
    2
    Hi Eric,

    I am using Vectrosity 2.1 with Unity Pro 4.0.0b7 and Android Pro and whenever I make any Vectrosity line drawings and run this on my Android test device (Samsung Galaxy S3 equiped witdh Android 4.0.3) lines are not drawn as they should be. Preview in the Unity editor is OK but on the Android device it looks i.e. like this:

    Your "Curve" demo:


    Your "DrawLinesTouch" demo:


    Is this a known issue and do you have any solution for this?
     
  47. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,400
    Download the newer Unity 4 beta.

    --Eric
     
  48. alen13

    alen13

    Joined:
    Oct 17, 2012
    Posts:
    2
    great answer :)

    thank you!
     
  49. alexsan75

    alexsan75

    Joined:
    Feb 6, 2012
    Posts:
    95
    Hi Erik,
    I bought Vectrosity 2 (latest update) - great product, thanks!
    What I need for my game is that an object leave a trace when moving. This works nice thanks to one of the demo scripts - jumping ball with green dotted-line-trace. It is a 2D game with orto-camera.

    My problem is what happens after object did collided for example with something and should be deactivated or destroyed (object that have had trace).
    My 2D camera can move in XY-plane, but so does the trace after its object has been destroyed ? And I need that trace to be untill next object is in a game..


    Q: is it possible to do so that trace does not move together with my MainCamera, but stays in a scene as it was rendered with VectorCamera?
    I mean it works nicely while object-tracer is on the scene, even if my Camera is moving around and this is what I need, but not after destroying as I described above..

    p.s: part of the JS script I'm using

    Code (csharp):
    1.  function Start () {
    2.     pathPoints = new Vector3[maxPoints];
    3.     pathLine = new VectorLine("Path", pathPoints, lineMaterial, 10.0, LineType.Continuous);
    4.  ........
     
  50. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,400
    Sounds like you'd want to use Draw3D rather than Draw, then the line will be in the scene, and the VectorCamera won't be used in that case.

    --Eric
     
Thread Status:
Not open for further replies.