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, May 26, 2010.

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

    pickledzebra

    Joined:
    Feb 25, 2010
    Posts:
    33
    Just got Vectrosity. None of the demo scenes are working. Windows7.

    How do I turn dynamic batching off (if that's the problem here)?

    Mike
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Dynamic batching is turned off in the player settings.

    --Eric
     
  3. txblackbird

    txblackbird

    Joined:
    Mar 23, 2010
    Posts:
    36
    I was working with the Draw Point Example in the documentation to make sure I was following everything alright with an eye toward using a modified version in a project that I am working on. If I use the example exactly as it is presented in the documentation then everything is great. However, if I move the "Vector.DrawPoints(dots)" line out of the Start() and into the Update() or LateUpdate() then I get a "NullReferenceException: Object reference not set to an instance of an object" error.

    That led me to think that I had some variable declarations wrong so I modified them slightly to declare them outside of Start() so that they should be visible everywhere. However, this did not change the error that I received.

    So I am at a loss as to how to get this to work. What I ultimately want to do is initialize the "system" in Start() and then provide point updates in Update() with the Vector.DrawPoints call in LateUpdate().

    Here is my script as it is now:
    Code (csharp):
    1. // Vectrosity Draw Point Example variables
    2. var dotSize = 1.0;
    3. var numberOfDots = 50;
    4. private var dots:VectorPoints;
    5. private var dotPoints:Vector2[];
    6. private var dotColors:Color[];
    7.  
    8. function Start()
    9. {
    10.    
    11.     // vectrosity draw points example
    12.     dotPoints = new Vector2[numberOfDots];
    13.     for (p in dotPoints)
    14.         p = Vector2(Random.Range(0, Screen.width), Random.Range(0, Screen.height));
    15.     dotColors = new Color[numberOfDots];
    16.     for (c in dotColors)
    17.         c = Color(Random.value, Random.value, Random.value);
    18.        
    19.     var dots = new VectorPoints("Dots", dotPoints, dotColors, null, dotSize);
    20. //  Vector.DrawPoints(dots);
    21.    
    22. }
    23.  
    24.  
    25. function Update()
    26. {
    27.  
    28. }
    29.  
    30. function LateUpdate()
    31. {
    32.    
    33.     Vector.DrawPoints(dots);
    34.  
    35.  
    36. }
    Here is the error message I am getting:
    Code (csharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. Vector.DrawPoints (.VectorPoints vectorLine, UnityEngine.Transform thisTransform, Boolean useTransformMatrix) (at Assets/Standard Assets/Scripts/Vectrosity/Vector.cs:601)
    3. Vector.DrawPoints (.VectorPoints vectorLine) (at Assets/Standard Assets/Scripts/Vectrosity/Vector.cs:584)
    4. DrawPointEx.LateUpdate () (at Assets/DrawPointEx.js:33)
    5.  
    I have tried both "dots" and "this.dots" in the Vector.DrawPoints() call but neither works.

    I am using Unity Pro 3.1.0f4

    Any help would be appreciated.

    Regards,
    txblackbird
     
  4. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    1,008
    Is this works with unity3d free version for windows?
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You're declaring the VectorPoints locally in the Start function with a local "dots" variable, so the global "dots" variable is null and never declared. In other words, you just need to change "var dots = " to "dots = ".

    Yep.

    --Eric
     
  6. txblackbird

    txblackbird

    Joined:
    Mar 23, 2010
    Posts:
    36
    Thanks for the extra set of eyes! Can't tell you how many times I looked over this and never "saw" that. The demo works as it should again. Now, on to my project... :)
     
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I think everybody's done that..."What do you mean, 'null reference exception'? How can it be null? I'm assigning it right there, you stupid--oh." ;)

    --Eric
     
  8. Zombie Gecko

    Zombie Gecko

    Joined:
    Nov 25, 2010
    Posts:
    32
    Just bought Vectrosity and have been trying it out, so far the best unity-based 3rd party purchase I've made! Very good documentation and examples, cheers!
     
  9. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Thanks! The docs are improved some more in 1.3. This is basically done, but I can't release it just yet, since Vectrosity 1.3 requires Unity 3.2.

    --Eric
     
  10. Fidjit

    Fidjit

    Joined:
    Jan 19, 2010
    Posts:
    2
    I can't seem to get fogging working with the cube in the simple3D demo scene.

    changing
    VectorManager.ObjectSetup (gameObject, line, Visibility.Always, Brightness.Normal);

    to
    VectorManager.ObjectSetup (gameObject, line, Visibility.Always, Brightness.Fog);

    brings up a null reference exception.. anyone had a similar problem?

    Oh, and great product btw :)
     
  11. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    In order for fogging to work, the line needs to have segment colors...change the line declaration to add a color, which will make all segments have that color:

    Code (csharp):
    1. var line = new VectorLine("Line", cubePoints, Color.white, lineMaterial, 2.0);
    Good catch on that, I'll update the code so that missing segment colors will make a more helpful error message, and mention that in the docs.

    --Eric
     
  12. Fidjit

    Fidjit

    Joined:
    Jan 19, 2010
    Posts:
    2
    Works fine now, thanks for the swift reply!
     
  13. rstorm000

    rstorm000

    Joined:
    Aug 19, 2010
    Posts:
    229
    Is there any support for collisions or fill? =)
     
  14. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    No collision support, sorry.

    --Eric
     
  15. _luciano_

    _luciano_

    Joined:
    Mar 26, 2010
    Posts:
    25
    Eric5h5: Can I use Vectrosity to convert a 3ds model in Unity? ...I mean, I have wireframe model in 3ds format (only lines... no mesh) but I can't use it in Unity and I can't rebuilt it line by line inside Unity with Vectrosity...is it possible to convert my model with Vectrosity?
    thanks
    Luciano
     
  16. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Vectrosity doesn't have any conversion functions, no. The LineMaker utility relies on models already imported into Unity.

    --Eric
     
  17. Achim

    Achim

    Joined:
    Dec 19, 2007
    Posts:
    199
  18. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Those wires, while thin, are still 3D, and disappear in the distance. Vectrosity is really for drawing 2D lines...even when they exist in 3D space, they're still the same thickness no matter how far off. Generally wires are just modeled like any other 3D object (but since they are thin, AA definitely helps).

    --Eric
     
  19. CroM

    CroM

    Joined:
    Jan 25, 2011
    Posts:
    1
    Hi Eric,

    just bought vectrosity, and i have to say, it`s very usefull and I`m amazed by the possibilities. great job.
    One thing though, is there allready a way to Joins.Fill line3ds without them having to be continuous? I set up the lines i want from my 3d model with lineMaker, now, after applying some big, retro glow lines, the gaps between the lines just look ugly.(could maybe be fixed with extra geometry, but a total waste and pain?)
    If not, it would be great if there would be an option for that in a future update.

    thx

    regards
    CroM
     
  20. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Thanks! Unfortunately there isn't a way currently. I did have some code initially that attempted to do this, but it turned out to be more difficult than I thought, and the code ended up being overly complex and didn't quite work right. So I removed it since I'd rather have things work 100% or not at all. I'll try again if I can think of a different approach.

    --Eric
     
  21. wbl1

    wbl1

    Joined:
    Apr 22, 2009
    Posts:
    159
    Eric,

    I would assume this would be a great tool for creating nice graphs? Also, I see that you have some examples of some nice curves as well. Are these really curves, or lots of tiny little lines that together look like curves?

    Looks great!

    TR
     
  22. wbl1

    wbl1

    Joined:
    Apr 22, 2009
    Posts:
    159
    Also ... Unfortunately I am stuck on Unity version 2.6.1f3 for now (customers are schools and cant easily upgrade their web players). Could I get a version of Vectrocity that would work for me?
     
  23. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yep, it's good for graphs; in fact one reason I made it was for a tool I made for my own use, which has some graphing in it. Everything in realtime 3D is not "really" curved, it's always composed of flat surfaces. Mathematically speaking, the curves are defined by the usual bezier curve setup (two anchor points, two control points), and the resolution they display at is up to you (e.g., the curve resolution slider in this demo).

    If you contact me with your email address, I can send a version that works in 2.6.

    --Eric
     
  24. wbl1

    wbl1

    Joined:
    Apr 22, 2009
    Posts:
    159
    Happy to pay for the "pro" version. Please do send along the version 2.6 stuff and maybe anything you may already have to help with a simple 2D graph (i.e. labeled x and y axes perhaps???)

    Thanks!
     
    Last edited: Jan 26, 2011
  25. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I don't think you want your email address public like that...you might want to edit that. :) I actually meant that you should reply to the email you get after buying Vectrosity; sorry for being unclear. Here's a script which makes a simple line graph out of some random data:

    Code (csharp):
    1. var data : int[];
    2.  
    3. function Start () {
    4.     data = new int[10];
    5.     for (d in data) d = Random.Range(10, 50);
    6.    
    7.     var graphData = new Vector2[data.Length];
    8.     for (i = 0; i < data.Length; i++) {
    9.         graphData[i] = Vector2((i+1)*50, data[i]*5);
    10.     }
    11.    
    12.     var graph = new VectorLine ("GraphData", graphData, Color.green, null, 2.0, 0.0, 0, LineType.Continuous, Joins.Open);
    13.     Vector.DrawLine(graph);
    14.    
    15.     var linePoints = [Vector2(50, 50), Vector2(50, 250), Vector2(50, 50), Vector2(500, 50)];
    16.     var axisLine = new VectorLine ("Axes", linePoints, null, 3.0, 1.5, 1, LineType.Discrete, Joins.Open);
    17.     Vector.DrawLine(axisLine);
    18. }
    19.  
    20. function OnGUI () {
    21.     for (i = 1; i <= data.Length; i++) {
    22.         GUI.Label(Rect(i*50, Screen.height-40, 25, 25), i.ToString());
    23.     }
    24.     for (i = 1; i <= 5; i++) {
    25.         GUI.Label(Rect(30, Screen.height-50*i-10, 25, 25), (i*10).ToString());
    26.     }
    27. }
    Which results in:



    --Eric
     
  26. wbl1

    wbl1

    Joined:
    Apr 22, 2009
    Posts:
    159
    Eric,

    Sorry about all the questions, but I am having a little trouble with the camera. In the doco, it says I can set this up "manually" by using:

    Vector.SetCamera (camera);

    where camera is a camera attached to the object etc ...

    I am trying this, but your code still creates an object called VectorCam and this new object does not seem to derive all its settings from "camera". In my case, specifically I want to set VectorCam's "Normalized View Port Rect" so that the graph is rendered in a specific location on the screen.

    I suppose I can grab the VectorCam that you create and programmatically modify its Rect, but it would be a lot easier if I could just set up the camera myself with these settings where I want them from the get go ... know what I mean?

    Thoughts?
     
  27. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    That makes sense...in the Vector.cs script, in the main SetCamera function, add

    Code (csharp):
    1. cam.rect = thisCamera.rect;
    --Eric
     
  28. wbl1

    wbl1

    Joined:
    Apr 22, 2009
    Posts:
    159
    What would be the most efficient way to animate the creation of a line? Say you are plotting force vs. time and you want to step through adding a point to the line every 0.5 seconds for example?
     
  29. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Have the line points set to the maximum number that you need for a complete line; the uninitialized elements will be Vector2.zero (or Vector3.zero) and not drawn. Change the elements in the points array as necessary. That works for a discrete line, anyway...for a continuous line, there's the issue that the last segment for whatever points you have so far would be connected to Vector2.zero, so you can use transparency and Vector.SetColors to hide that (see the DrawLines script for an example of this).

    Vectrosity 1.3 (not out yet; waiting for Unity 3.2) has a Resize function, which would be simplest, although it's still more efficient to use a fixed size and the above techniques.

    --Eric
     
  30. wbl1

    wbl1

    Joined:
    Apr 22, 2009
    Posts:
    159
    OK, so I am trying to use an array of colors so that I can essentially animate the creation of the graph by changing transparency (as suggested by Eric).

    But I am getting this error:

    Assets/Green Car Scripts/makeGraph.js(65,25): BCE0004: Ambiguous reference '.ctor': VectorLine..ctor(String, (UnityEngine.Vector2), UnityEngine.Color, UnityEngine.Material, float, float, int, LineType, Joins), VectorLine..ctor(String, (UnityEngine.Vector2), (UnityEngine.Color), UnityEngine.Material, float, float, int, LineType, Joins).

    Here's the code - initColor is the culprit (works fine if this is just a single color). Its length is 1 less than the length of the points as suggested by the doco ...

    Code (csharp):
    1. function setupGraph (gName : String,axisName : String,nvHashString : String)
    2. {
    3.     var nvHash = commonFunctions.makeNVHashTable(nvHashString);
    4.     xValues = nvHash["x"].Split(","[0]);
    5.     yValues = nvHash["y"].Split(","[0]);
    6.     //print(xValues.length+","+yValues.length);
    7.        
    8.     var linePoints = [Vector2(0,0), Vector2(0,250)];
    9.     var axisLine = new VectorLine (axisName, linePoints, null, 3.0, 1.5, 1, LineType.Discrete, Joins.Open);
    10.     Vector.DrawLine(axisLine);
    11.     var initColors = new Color[xValues.length-1];
    12.     for (i=0;i<initColors.length;i++)
    13.     {
    14.         initColors[i]=Color(1,0,0,.5);
    15.     }
    16.        
    17.     var graphData = new Vector2[xValues.length];
    18.     for (i=0;i<xValues.length;i++)
    19.     {
    20.         var x= float.Parse(xValues[i]);
    21.         var y= float.Parse(yValues[i]);
    22.         graphData[i]=Vector2(x,y);
    23.     }
    24.     var graph = new VectorLine(gName,graphData,initColors,null, 2.0, 0.0, 0, LineType.Continuous, Joins.Fill);
    25.     return graph;
    26. }
    27.  
     
  31. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Does that happen at compile-time or runtime?

    --Eric
     
  32. Cameron_SM

    Cameron_SM

    Joined:
    Jun 1, 2009
    Posts:
    915
    Hi Eric, this looks great but I have a few questions that weren't obvious from the demos or features mentioned on your site.

    1) Can lines be drawn in 3D space with correct z sorting and be occluded by other game objects/meshes?

    2) Can 3D lines be displayed at a fixed scale regardless of their distance to the camera like so:


    (Screenshots from Sins of a Solar Empire, bigger version of image attached)

    I'm working on a strategy game and a lot of the dynamic interface/unit HUDs need to work in 3D, but I'd like to keep them crisp and "2Dish" like the interface lines in Sins. Is that possible with Vectrosity?

    It looks like it is but it's not specifically mentioned anywhere.
     

    Attached Files:

    Last edited: Jan 28, 2011
  33. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes, that was added in Vectrosity 1.1.

    Yes, that's the standard behavior.

    Yep. :)

    --Eric
     
  34. Cameron_SM

    Cameron_SM

    Joined:
    Jun 1, 2009
    Posts:
    915
    Thanks for the fast reply Eric :)
     
  35. wbl1

    wbl1

    Joined:
    Apr 22, 2009
    Posts:
    159
    Eric,

    Regarding the array of colors, the problem occurs at RUNTIME ...

    Thanks
     
  36. wbl1

    wbl1

    Joined:
    Apr 22, 2009
    Posts:
    159
    recall I have version 2.6 in case that has something to do with it ....
     
  37. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I edited the function so it would compile here...I removed the "var nvHash" line, and for the next two I used

    Code (csharp):
    1.     xValues = ["5", "10", "15", "20"];
    2.     yValues = ["5", "15", "10", "20"];
    just to have some data. Then I called it like this:

    Code (csharp):
    1.     var testLine = setupGraph("sdas", "adad", "asdas");
    2.     Vector.DrawLine(testLine);
    and it runs without errors. So I'm not really sure what the problem could be. I did this in Unity 2.6 with the Vectrosity 1.2 package for Unity 2.6.

    --Eric
     
  38. wbl1

    wbl1

    Joined:
    Apr 22, 2009
    Posts:
    159
    wow, that's really strange ... if I use the "explcit" data like you did, it works for me too. Strange, but at least have something to chew on here. The nvHash stuff works fine ... its only when I try to set up the colors array - the length of which depends on the length returned by the nvHash stuff. That's the only dependency.
     
  39. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Try using "#pragma strict" and remove all dynamic typing...not sure if/why that would make any difference here, but something to try.

    --Eric
     
  40. wbl1

    wbl1

    Joined:
    Apr 22, 2009
    Posts:
    159
    FYI - explicitly setting the datatype on xValues and yValues to array solved the problem!

    Also, for anyone interested in animating the graph, (based on Eric's recommendation) I initially set the colors array so that the colors are all initially transparent. Then a simple loop goes through and sets the transparency of each element of the array, uses Vector.SetColors to change the array, yields a bit and success!

    Thanks Eric!

    Code (csharp):
    1.  
    2. function setupGraph (gName : String,axisName : String,nvHashString : String,yOffset : float)
    3. {
    4.     var nvHash = commonFunctions.makeNVHashTable(nvHashString);
    5.     var xValues : Array = nvHash["x"].Split(","[0]);
    6.     var yValues : Array = nvHash["y"].Split(","[0]);
    7.    
    8.     var linePoints = [Vector2(0,yOffset), Vector2(0,yOffset+250)];
    9.     var axisLine = new VectorLine (axisName, linePoints, null, 5.0, 1.5, 1, LineType.Discrete, Joins.Open);
    10.     Vector.DrawLine(axisLine);
    11.    
    12.     var initColors = new Color[xValues.length-1];
    13.     for (i=0;i<initColors.length;i++)
    14.     {
    15.         initColors[i]=Color(1,0,0,0);
    16.     }
    17.     var graphData = new Vector2[xValues.length];
    18.     for (i=0;i<xValues.length;i++)
    19.     {
    20.         var x= float.Parse(xValues[i]);
    21.         var y= float.Parse(yValues[i]) + yOffset;
    22.         graphData[i]=Vector2(x,y);
    23.     }
    24.     var graph = new VectorLine(gName,graphData,initColors,null, 5.0, 0.0, 0, LineType.Continuous, Joins.Fill);
    25.     Vector.DrawLine(graph);
    26.     for (i=0;i<initColors.length;i++)
    27.     {
    28.         initColors[i]=Color(1,0,0,.5);
    29.         Vector.SetColors(graph,initColors);
    30.         yield WaitForSeconds(0.2);
    31.     }
    32. }
    33.  
     
  41. bbvrdev

    bbvrdev

    Joined:
    Aug 11, 2009
    Posts:
    221
    Hi Eric, I've got a situation in which I need to draw a square "speech bubble" with vectrosity, but I need it filled in with a color. Is that possible?
     
  42. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Not directly; you'd have to do the filled part separately. However a square shouldn't be too hard, since you could use a quad and set the vertices programmatically, or possibly use a GUITexture.

    --Eric
     
  43. bbvrdev

    bbvrdev

    Joined:
    Aug 11, 2009
    Posts:
    221
    Problem is, it's not a square, it's got the little dingle at the bottom that points to the guy. I was going to redraw the vector line programatically and adjust that point to face the guy speaking...

    Is there a way to do the fill programatically?
     
  44. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Is the little dingle the same size always? Perhaps the filled square could be dynamic, and the filled dingle a separate object?

    --Eric
     
  45. bbvrdev

    bbvrdev

    Joined:
    Aug 11, 2009
    Posts:
    221
    It could be... Currently I've got two planes, one with the square texture, and one with the dingle rendered as a triangle that runs transform.LookAt. Seems to work alright, but I'd love to vectorize it :)
     
  46. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    Sandworm, you could create the speech bubble using 3 triangles. With line maker you can build the line using data from your mesh. Use vector manager to parent the line to an empty gameobject. Parent the mesh in the same gameobject. Via gameobject's scale, rotation and position, you have a configurable speech bubble. If you want round edges, it gets more complicated to create the plane procedurally, so you can create it in a 3d modeling program, import it and proccede the same way.
    I am curious, how many triangles does those beautiful boxes in pushpixpull have ?
     
  47. DaveyJJ

    DaveyJJ

    Joined:
    Mar 24, 2005
    Posts:
    1,558
    Purchased. One scene, DrawLinesTouch attached to camera. Nothing else.

    Build fails with

    Code (csharp):
    1. Error building Player because scripts had compiler errors
    2. UnityEditor.HostView:OnGUI()
    error, plus

    Code (csharp):
    1. Error in file: /Applications/buildAgent/work/71ca6fec1b41cc30/Projects/../Editor/Src/Commands/BuildPlayerUtility.cpp Line: 1448
    What's this mean?
     
    Last edited: Feb 6, 2011
  48. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Um...some kind of internal Unity error? What version are you using? I don't think that has to do with Vectrosity (no problems with a build here). Could try doing a Reimport All.

    --Eric
     
  49. DaveyJJ

    DaveyJJ

    Joined:
    Mar 24, 2005
    Posts:
    1,558
    3.1.0f4 Unity Pro. Reimporting all assets does not fix error.
     
    Last edited: Feb 6, 2011
  50. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Hmm...you switched the platform to iOS? Everything in player settings is correct?

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