Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

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,237
    There's definitely a leak; destroying the GameObject will not work. You need to destroy the VectorLine.

    --Eric
     
  2. AntLewis

    AntLewis

    Joined:
    Feb 2, 2010
    Posts:
    198
    Hey @Eric5h5, when using GetPoint to make an object follow a spline is there anyway to determine how far along the spline an object is?

    Cheers
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,237
    When you use GetPoint, you pass in the distance along the spline to get the point at that distance, so by definition you must already know.

    --Eric
     
  4. inakiktp

    inakiktp

    Joined:
    Nov 6, 2014
    Posts:
    35
    Hi Eric,

    I am using Unity 4.6.0f, Vectrosity 4.0.3 and the deployed builds were for Android and Mac platforms.

    I think I might have found the reason, but not the solution. In the big project I create a FileStream before using Vectrosity, I commented it and right now I can see Vectrosity drawings.

    Knowing this, I went to the small project and included a simple FileStream:
    Code (CSharp):
    1. string path = Application.dataPath + "/test.txt";
    2. FileStream fs = new FileStream (path, FileMode.Open);
    3. fs.Close();
    And as I expected, nothing was drawn in the small project when I deployed a build for Mac.

    I tried to flush and dispose the filestream once used, but did not work. I also tried not closing it just for the sake of trying, but no. It seems this happens anytime I create a filestream.

    ** Update **
    I was wondering if there was a way to work around this and I tried to use 2 scenes. In the first scene I load a file, generate a gameobject with data I will carry to the second scene and create a line, and in the second I just create a new line and print the data I carried from the first scene. I deployed the build for Mac and the result was that I do not see the line I create in the first scene, but I am able to see the line in the second scene.

    Editor View Scene 1: http://gyazo.com/9d26f12bf0b488f42c2268673ad18018
    Deployed Build Scene 1: http://gyazo.com/786e59dddc6c1bebb2ebbea678be12cc
    Editor View Scene 2: http://gyazo.com/9238f63aab6db73921fd38df9457d7e3
    Deployed Build Scene 2: http://gyazo.com/d773489305a490ea58cab5c48b4f4ee7

    Something else I noticed is that you carry your previously created VectorLines. At least, in Scene 2 appear under the Vector3DCanvas 2 Lines, when I only created 1 and I (theoretically) deleted the one from the Scene 1.

    Script from Scene 1:
    Code (CSharp):
    1. public class Drawings : MonoBehaviour {
    2.         // Line Variables
    3.     private VectorLine myLine;
    4.     private List<Vector3> myLinePoints = new List<Vector3>();
    5.     private List<VectorLine> listVL = new List<VectorLine>();
    6.  
    7.     void Start () {
    8.         //string path = Application.dataPath + "/test.txt";
    9.         FileStream fs = new FileStream ("test.txt", FileMode.Open);
    10.         fs.Flush ();
    11.         fs.Dispose ();
    12.         fs.Close();
    13.         /* How to Draw a Line */
    14.         // Define Line List of Points
    15.         myLinePoints.Add(new Vector3(-1.0f, 0.0f, 0.0f));
    16.         myLinePoints.Add(new Vector3(1.0f, 0.0f, 0.0f));
    17.         // Create the VectorLine Element
    18.         myLine = new VectorLine("My Line", this.myLinePoints, null, 5);
    19.         this.listVL.Add (myLine);
    20.         // Draw a Line
    21.         myLine.Draw3DAuto();
    22.     }
    23.  
    24.     public void StopAutoDraw3D () {
    25.         VectorLine.Destroy (this.listVL);
    26.         this.listVL.Clear ();
    27.     }
    28. }
    The StopAutoDraw3D is a method I call from the UI Button OnClick.

    Script from Scene 2:
    Code (CSharp):
    1. public class Drawings2 : MonoBehaviour {
    2.     // Line Variables
    3.     private VectorLine myLine;
    4.     private List<Vector3> myLinePoints = new List<Vector3>();
    5.  
    6.     void Start () {
    7.         // Set VectorLine Camera as Main Camera
    8.         VectorLine.SetCamera3D (Camera.main);
    9.         // Define Line List of Points
    10.         myLinePoints.Add (new Vector3 (-1.0f, 0.0f, 0.0f));
    11.         myLinePoints.Add (new Vector3 (1.0f, 0.0f, 0.0f));
    12.         // Create the VectorLine Element
    13.         myLine = new VectorLine ("My Line", this.myLinePoints, null, 5);
    14.  
    15.         // Draw a Line
    16.         myLine.Draw3DAuto ();
    17.         Debug.Log ("App Data: " + ApplicationData.Instance.valueA);
    18.     }
    19. }
    I am still puzzled about the FileStream "hiding" everything drawn with Vectrosity, since I can see objects and other Canvases, like the one I use for the UI, but not the one from Vectrosity it seems. Or maybe the problem is elsewhere? Very odd.


    Thanks,

    Inaki.
     
    Last edited: Dec 4, 2014
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,237
    FileStream isn't related to rendering in any way. I expect there's some error when you use it, which stops other code from running; check your logs.

    --Eric
     
  6. inakiktp

    inakiktp

    Joined:
    Nov 6, 2014
    Posts:
    35
    Hi Eric,

    Sorry if I seem like an idiot, but when you say "logs", do you mean Debug.Log("") or is there another thing related to it?

    I created an empty project with just Vectrosity 4.0.3 imported, an empty scene with just the Main Camera, a script and a txt file. Here is the script code:

    Code (CSharp):
    1. public class Drawing : MonoBehaviour {
    2.     private VectorLine myLine;
    3.     private List<Vector3> myLinePoints = new List<Vector3>();
    4.     void Start () {
    5.         FileStream fs = new FileStream (Application.dataPath + "/test.txt", FileMode.Open);
    6.         fs.Close ();
    7.         Debug.Log (fs.Length);
    8.         myLinePoints.Add (new Vector3 (-1.0f, 0.0f, 0.0f));
    9.         myLinePoints.Add (new Vector3 (1.0f, 0.0f, 0.0f));
    10.         myLine = new VectorLine ("My Line", this.myLinePoints, null, 5);
    11.         myLine.Draw3DAuto ();
    12.     }
    13. }
    Ok, after some more research I found this: http://answers.unity3d.com/questions/406787/problem-with-path-in-filestream.html

    Which makes me think that the problem is the FileStream but, as you said, in a deployed build FileStream does not work properly making my code not being executed. I changed to using Resource.Load() and everything works now.

    Lesson learned: Do not use FileStream, use Resource.Load().

    Thanks for the help. :D

    Inaki.
     
    Last edited: Dec 5, 2014
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,237
    The player log, which is always generated when you run a stand-alone. (Unless you turned it off in the Unity player settings.) Debug.Log statements go there too.

    Well, FileStream is fine, as long as the file exists and the path is correct.

    --Eric
     
  8. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    275
    Hi Eric,

    I'm currently popping Vectrosity 4 into my project, and I'm having some positioning issues. So firstly, using Vectrosity's default settings, the canvas doesn't render on top of everything. It's definitely drawing, but stays behind, despite my having another canvas in the scene with identical settings (except it has children panels) and that showing up.

    I do use sorting layers a lot in my project, I wonder if that might be it? But I tried playing with sortingLayerName and sortingOrder on the VectorLine.canvas, and neither worked (Even after toggling active).

    So I've changed to RenderMode.WorldSpace, and now it shows up on top of everything. But I'm wondering if you'd have any ideas why it would render behind everything when Overlay is meant to just print on top last?

    And secondly, the positions are slightly off from where they should be when I use MakeCircle. The left image below is a GameObject positioned at 0,0 of the parent's handle, and the image on the right is a MakeCircle being passed the parent object's transform.position as the center. I tried it with a few other gameObjects as well, and they all had the same offset.



    Any help appeciated!
     
  9. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,237
    I'm afraid I'm not able to replicate the issue with sorting...if I make UI canvases, I can control which draws on top of which, including the Vector canvas, by changing the sorting order.

    As for the circle, that depends on how you're drawing it. If you're using 2D points, then the coordinates are in screen space, so you'd have to convert the GameObject position to screen space in order to use it as the origin for MakeCircle. If you're using 3D points, then there shouldn't be any issues.

    --Eric
     
  10. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    275
    Hmm. I tried just passing in Vector3.zero and the circle started offset from there as well. Would you mind testing MakeCircle on your end?

    EDIT:

    So I just tried this:

    Code (CSharp):
    1. if (Input.GetMouseButtonUp(0)) {
    2.     Vector3 mousePositionWorld = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.transform.position.z))
    3.     var blah = new Vectrosity.VectorLine("Hello", new Vector2[128], null, 0.25f);
    4.     blah.MakeCircle((Vector3)mousePositionWorld, 2f);
    5.     blah.Draw();
    6. }
    And this is the result:



    (The blue circle is my mouse cursor.)
     
    Last edited: Dec 8, 2014
  11. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,237
    That won't work for a number of reasons. You're using Vector2 points, which means they need to be screen space. So you wouldn't convert the mouse position to world points, you'd just leave it as screen points. You're using 0.25 for the line width, which is 1/4 of a pixel, which probably isn't visible. The radius for the circle is 2, which is just 2 pixels (remember we're using Vector2 coords, which is screen space). It should be:

    Code (csharp):
    1. if (Input.GetMouseButtonUp(0)) {
    2.     var blah = new Vectrosity.VectorLine("Hello", new Vector2[128], null, 2f);
    3.     blah.MakeCircle (Input.mousePosition, 20f);
    4.     blah.Draw();
    5. }
    Which results in a 2-pixel line width, making a circle with a radius of 20 pixels being drawn centered around the mouse pointer:

    Screen-Shot-2014-12-08-at-1.png

    It seems to me that you're probably manipulating the vector canvas, which prevents Vectrosity from being able to function correctly.

    --Eric
     
  12. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    275
    You're exactly right, I'm really sorry! I figured if I passed the MakeCircle a Vector3 position then it would use world coordinates, didn't consider the Vector2 array that was being passed to it. Working as you said now!

    Thanks heaps for the help, and apologies for the simplistic errors!
     
  13. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,237
    Glad to hear you got it sorted!

    --Eric
     
  14. inakiktp

    inakiktp

    Joined:
    Nov 6, 2014
    Posts:
    35
    If it is the Console Window (I am guessing is that) I use it, if it is another thing I really have no clue of it, but I will look into it. :)

    The thing is, the path was correct, but it seems Unity "compress/compile"? does something with the file making it not readable once the build is deployed, whereas using Resources.Load() and changing the extension of the file as .bytes allows to load everything without worrying about paths, which is good to be honest.

    Inaki.
     
  15. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,237
    No...the player log, which is generated when you run a stand-alone. Not the console window, which only exists in the Unity editor. The player log...the logfile, which is logged. :) Unless you turn it off in the player settings.

    FileStream is only for external files. Unity doesn't have any of those by default; you'd have to add them yourself (and where they are exactly would vary by OS). So yes, keeping everything internal is easiest.

    --Eric
     
  16. scrotty

    scrotty

    Joined:
    Dec 3, 2014
    Posts:
    6
    Eric, thank you for the amazing software!

    I have exported a simple low-poly (156 verts, 72 tris) object from Blender to Unity as a .dae file (I've actually tried .tbx and .obj too). When I try to open the LineMaker for the object LineMaker complains that no MeshFilter is present. But looking at what I've imported, a mesh filter is present.

    By the way, when I try to active Line Maker with one of the Tank Zone meshes (e.g. "saucer") I get the same error.

    Can you please advise?

    Thank You!
    Sean
     
  17. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,237
    The format doesn't matter, since it's all converted to an internal Unity mesh format anyway once imported. As long as the mesh is actually present, it will work. You need to click on an object with a MeshRenderer component that contains the mesh.

    --Eric
     
  18. scrotty

    scrotty

    Joined:
    Dec 3, 2014
    Posts:
    6
    Thanks, Eric. What I just discovered was had to add the asset to a scene - I could not do it directly on project assets that weren't added to the scene.

    The irony is that the right-click menu for project items includes the Line Maker, but the scene hierarchy does not! I had to select a hierarchy item and then choose Menu -> Assets -> Line Maker.
     
  19. Glinko

    Glinko

    Joined:
    Jun 20, 2014
    Posts:
    1
    I'm having some problems with 3d lines. My whole line function is like this.

    Code (CSharp):
    1. public void DrawLines()
    2.         {
    3.             VectorLine.Destroy(linesToClosestStars);
    4.             linesToClosestStars.Clear();
    5.  
    6.             ICollection<PlanetarySystem> systems;
    7.             ICollection<CelestialNode> nodes;
    8.             Vector3 objectSystemPos;
    9.  
    10.             helm.GetAvailableTargets(out systems, out nodes, out objectSystemPos);
    11.  
    12.             Vector3 centre = ship.Rotation * helm.ShipOffset;
    13.  
    14.             VectorLine.SetCamera3D(map.CameraSetup.GalaxyCamera.camera);
    15.             VectorLine.canvas3D.name = "StarLines";
    16.             VectorLine.canvas3D.transform.parent = helm.GUIObject.transform;
    17.             VectorLine.canvas3D.gameObject.layer = LayerMask.NameToLayer("Galaxy");
    18.  
    19.             foreach (PlanetarySystem system in systems)
    20.             {
    21.                 List<Vector3> linePoints = new List<Vector3>
    22.                 {
    23.                     centre,
    24.                     helm.Map.SystemToWorld(system)
    25.                 };
    26.  
    27.                 VectorLine lineToStar = new VectorLine("LineToStar", linePoints, StarLineMaterial, 1f);
    28.  
    29.                 int index;
    30.                 lineToStar.SetColor(new Color(1, 1, 1, .5f));
    31.                 if (lineToStar.Selected(Input.mousePosition, 8, out index))
    32.                 {
    33.                     lineToStar.lineWidth = 4f;
    34.                     lineToStar.SetColor(new Color(1, 1, 1, 1));
    35.                 }
    36.  
    37.                 lineToStar.Draw3D();
    38.                 linesToClosestStars.Add(lineToStar);
    39.             }
    40.             //Debug.Log("systemcount: " + systems.Count + " linecount: " + linesToClosestStars.Count);
    41.         }
    For me it's complaining about MainCamera not existing, even though I'm running SetCamera3D manually, and for my friend who is running the same build is getting an error that the canvas3d doesn't exist when setting the name.

    We tracked the problem down to that when SetCanvad3D get's run from the getter of canvas3D, it runs SetCamera3D without a set camera.
    Should be at line 855 in VectorLine.cs in the source.

    For me it only complains once about the camera, and then runs fine. But for my friend who is running the exact same project, it won't run at all due to the canvas3d not existing.

    Also the line.Selected seems to be very finicky for 3d lines, as I seem to only be able to select about half the lines. Maybe it has something to do at which angle they point toward the camera.
    Any ideas?
     
    Last edited: Dec 14, 2014
  20. phi6

    phi6

    Joined:
    Nov 11, 2013
    Posts:
    7
    Hi there,

    Firstly, great work on Vectrosity. Recently upgraded to 4 and loving it. One question, would it be possible to draw partial circles? My goal is to draw several partial circles so that only the outline of the intersected circles is drawn.

    For example something like this:
    http://images.gamestar.de/images/idgwpgsgp/bdb/1023256/bigimage.jpg
    (Imagine the dotted lines are actual lines, so the intersected bits are not drawn)

    Can I combine partial lines (draw start and draw end) with MakeCircle? The tricky bit is knowing which segments to draw since we can't specify angles...

    Any ideas appreciated :)

    Cheers
    Phi
     
  21. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,237
    That's actually intentional, as a sort of last-ditch fallback. This isn't really clear in the docs, so I've added some text mentioning that if you're calling SetCamera3D manually, then it should be done before setting VectorLine.canvas3D. If it's done in that order, there aren't any errors that I can find. I suspect you have other code running that may be interfering; check the execution order of your scripts.

    Vectrosity expects lines to be drawn facing the camera; if you're preventing that, then correctness of any Vectrosity functions is not guaranteed.

    Sounds like an option to specify start and end angles would be useful. In the meantime, you could have a VectorLine that's not actually drawn, but is only there for circle drawing...after drawing a circle in the appropriate place with this "fake" line, you could extract the desired arc by copying the relevant points in the list to a "real" VectorLine that's actually drawn.

    Although it would probably be less hack-ish in the long run just to make your own function for this; Vectrosity will draw any kind of line you want as long as you supply the points, so you're not limited to the built-in functions.

    --Eric
     
  22. DrSnow

    DrSnow

    Joined:
    Sep 4, 2013
    Posts:
    2
    As far as I can see, there is no way to exlicitly set the canvas3D manually.
    SetCamera3d() works if you specify a camera, but when -afterwards- trying to set parameters of the canvas3D, the following happens:

    1. The canvas3D getter instantiates a new canvas by calling SetCanvas3D(). (see line 15 in glinko's code above)
    2. The first line in SetCanvas3D() calls SetCamera3D() (no camera) whether you have set a camera or not.
    3. SetCamera3D() throws an error if Camera.main is undefined.
    To fix this, I removed the line in SetCanvas3D that resets the camera, to instead allow the "no camera available"-error to happen (works, since the camera is already set).
    Another way would be to create a canvas if none exists when a new camera is created, instead of just updating a possibly existing one.
     
  23. kbm

    kbm

    Joined:
    Aug 7, 2014
    Posts:
    71
    Hi, I just bought Vectrosity and so far it's been super easy to set up. Thanks! :)

    However, I have a question: I am using Vectrosity to draw a line (like in the DrawLinesMouse.js Script in the Demo folder). Now, I want to check if specific objects overlap / trigger that line. So far, I haven't really been able to figure out how to do that, except from giving the line a trigger with line.trigger = true; Help would be much appreciated!

    Cheers,

    kbm
     
  24. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,237
    There will be improvements in canvas handling in the next version.

    Using line.trigger = true would be a good way; is that causing any problems?

    --Eric
     
  25. DrSnow

    DrSnow

    Joined:
    Sep 4, 2013
    Posts:
    2
    Right. We'll keep using our modified version until then then. :)
     
  26. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    275
    Hey Eric,

    I have come across a Unity issue, where it seems you can't render anything on a canvas to a RenderTexture. I want to write my Vectrosity lines to a RenderTexture to slot into my rendering arrangement, and sadly it won't let me do it.

    I've thought about changing to 3D lines, and wanted to find out what kind of performance difference there is? I think I'd need to convert my current line drawing to use world units, which wouldn't be too much of a problem, but is there a large difference between Vectrosity's 2D and 3D lines?
     
  27. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,237
    3D lines still use a canvas, so if you're having issues with canvases in general, that wouldn't help. However I'm not seeing an issue with rendering a canvas to a texture...you need to use screen space camera rather than screen space overlay. Here's a cube with some random VectorLines rendered to a texture:

    Screen Shot 2014-12-16 at 1.13.23 PM.png

    --Eric
     
  28. scrotty

    scrotty

    Joined:
    Dec 3, 2014
    Posts:
    6
    Eric, I'm having a bit of trouble getting two VectorLines to interact with each other. I'm learning Vectrosity by recreating the old Lunar Lander game and have been referring to TankDemo extensively.

    I have a lunar mountain range that is 256 Vector2 segments long. I've set collider and useViewportCoords both to true.

    The lander also has collider as true, but it is not using viewport coords. It has its drawTransform set as the transform of an empty "lander" game object. Its update method simply issues a landerLine.Draw().

    The Lander game object has Rigidbody2D and BoxCollider2D components added to it. But aside from assigning the drawTransform to the VectorLIne, the lander VectorLine itself has no attachment to the game object. And I figured that I should not use the VectorManager.ObjectSetup because I wanted to keep things 2D.

    When I run the simulation the mountain are nicely visible - as is the lander above them. The lander reacts to the effect of gravity and drops. The problem is that it falls right though the mountains. Ideally I'd like the lander to hit the mountains and fall down their peaks and into the valleys.

    I've looked at the RandomHills demo for insight. But it seems that the use of a non vector ball in that example throws me off a bit.

    Any suggestions? Thank you!
    Sean
     
    Last edited: Dec 16, 2014
  29. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,237
    The main thing I see is that the lander VectorLine should not have collider as true, since you're using a box collider. The non-vector ball in RandomHills isn't really relevant; the important thing is that is has a circle collider. The renderer could be replaced with a VectorLine without issues. Maybe try looking in the scene view, to see if the box collider is touching the line collider.

    --Eric
     
  30. scrotty

    scrotty

    Joined:
    Dec 3, 2014
    Posts:
    6
    Thanks, Eric. Your idea for me to look at the scene view was critical. What I see (image below) is that the collider for the mountain range is much smaller than the VectorLine for the mountain range. It looks exactly like it but is scaled down by a factor of about fifty. But I'm not doing much interesting with the mountains VectorLine: I create it from some Vector2 points, set its collider to true, and draw it. I've even now turned off viewport coords.

     
    Last edited: Dec 16, 2014
  31. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,237
    Well, the lines in the scene view are actually not relevant. When using a screen space canvas, 1 unit = 1 pixel, which is why it's so big, but that doesn't have anything to do with the colliders. What I'd be interested in is whether the box collider is interacting with the line colliders. You can select them both at once to see the colliders, such as the circle and hill colliders in RandomHills:

    Screen Shot 2014-12-16 at 3.48.27 PM.png

    The lines are way the heck off-screen in this scene view pic (that's the bottom-left corner of the canvas there), but that's not relevant to the colliders working.

    --Eric
     
  32. scrotty

    scrotty

    Joined:
    Dec 3, 2014
    Posts:
    6
    When the use a VectorLine.collider = true for the mountains and a BoxCollider2D game object associated with the lander VectorLine, I see the following. The collider for the lander fits the camera view while the mountain collider is tiny. So it's like they are operating on different scales.

    But, if I move the lander over to the tiny mountain collider and let it drop it does bounce off.

    If, instead, I remove the BoxCollider2D from the lander game object and just set VectorLine.collider = true for the lander as well as the mountains, the scale looks better (below) - but they don't collide!


    You can tell I used Discrete LineTypes. And in doing so I get the following warning in the VectorCanvas:


    But when I set them to Continuous I get the following mess and the collider doesn't work anyhow (guessing because they start overlapped).
     
  33. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,237
    Are you scaling down the VectorLine, or is it very thin? If I use a thickness of 1 pixel for the RandomHills line, the collider fails if it's a discrete line, but it works fine with 2 pixels and above. The collider for a continuous line works well even when it's 1 pixel thin. In the RandomHills scene, you can put this on the sphere to replace it with a diamond-shape VectorLine:

    Code (csharp):
    1. function Start () {
    2.     GetComponent(Renderer).enabled = false;
    3.     var points = [Vector3(0, .5), Vector3(.5, 0), Vector3(0, -.5), Vector3(-.5, 0), Vector3(0, .5)];
    4.     var line = new VectorLine("Vector ball renderer", points, null, 2.0, LineType.Continuous);
    5.     line.drawTransform = transform;
    6.     line.Draw3DAuto();
    7. }
    And it works fine:

    Screen Shot 2014-12-16 at 4.44.50 PM.png

    --Eric
     
  34. scrotty

    scrotty

    Joined:
    Dec 3, 2014
    Posts:
    6
    The line width is 4 pixels and I'm using the TankZoneLine material.

    Thank you for the code for the RandomHills scene to use vectors for the ball. I'll play with that to determine what I'm doing weird in my own scene.

    Thanks again, Eric!
    Sean
     
    Last edited: Dec 16, 2014
  35. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    275
    Yeah it works fine if you set a RenderTexture to the camera, but if you manually call Render the canvas camera, it doesn't render anything. I'm currently trying to get around it by rendering to a set texture, then blitting that onto my final output, but for some reason the background is solid black, and overrides everything else.

    On a seperate note, is there a way to have two different canvases for Vectrosity? My dynamic lines are supposed to slot into various layers of my render, so once I solve this I'm hoping to have some above the player and some below. Is this possible with a 2d canvas?
     
  36. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,237
    You can create other canvases, then parent VectorLines to them. However you can control drawing order within the same canvas for all the objects, so that may be better.

    --Eric
     
  37. graykos

    graykos

    Joined:
    Apr 16, 2014
    Posts:
    1
    Hello!

    I am using Vectrosity to draw a line chart. In my script there are a bunch of points used to initialize a chart and then every second new point is added to it with an animation.
    So I created a VectorLine like this:
    new VectorLine("Graph", new List<Vector3>(), lineMaterial, 12f, LineType.Continuous, Joins.Weld);

    Everything is fine except one thing - the joins of the line are like Joins.None.
    Specifically the lines that are added dinamically. The init data is drawing fine with Joins.Weld joins.

    What can be the reason of such behavior?
     
  38. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,237
    If the angles are extreme, the joins can be skipped; this can be changed with VectorLine.maxWeldDistance.

    --Eric
     
  39. Epictickle

    Epictickle

    Joined:
    Aug 12, 2012
    Posts:
    428
    @Eric5h5 ,

    Is there any way I could possibly calculate when two circles are overlapping each other and weld them together at their intersection points?

    For example, if I have two circles like this:

    OverlappingCircles.png

    Would I be able to weld them together, like so:

    FixedOverlappingCircles.png
     
  40. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,237
    Yes, although there aren't any built-in functions for that. You could possibly use the existing MakeCircle function and do calculations with that somehow, but it would be best if you made an entirely custom function that did the appropriate math stuff. It would involve making calculations with a Vector2 list and then assigning the values to VectorLine.points2.

    --Eric
     
  41. Epictickle

    Epictickle

    Joined:
    Aug 12, 2012
    Posts:
    428
    I was trying to use MakeCircle to do this, iterate over every other circle in the scene, and iterate over every point in points3. If the points3 list on the current circle I'm iterating over .Contains the current point, then it's an intersection, but I'm pretty sure that was wrong lol because it never detected any intersections. I tested with Debug.Log..

    I'm not that great at geometry math, but I'll give it a shot lol.

    Maybe there is an easier way to do this, though, so I'll give you the complete breakdown of what I'm trying to do:

    I'm building an RTS. Every building that you build has an object childed to it called BuildZone. It is a sphere primitive with IsTrigger active and the mesh renderer turned off. When trying to build buildings, if you are within the BuildZone then you may place your building. If you are outside of the BuildZone then you may not place your building. When the building is placed, it's own BuildZone becomes active and extends the radius of the original BuildZone.. Would there be a way to just draw around these colliders?

    Here's what my base looks like with the colliders:
    upload_2014-12-22_14-58-38.png

    Here's exactly what I want (but much straighter, lol):

    upload_2014-12-22_15-0-42.png

    Also, each building currently just has a BuildLine script attached to it, and each circle is made with its own script. It isn't one script.
     
    Last edited: Dec 22, 2014
  42. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,237
    I guess the thing to do would be to make each building have a VectorLine with MakeCircle, and if there are overlaps, erase the appropriate points. How exactly to find out which points to erase is an exercise left to the reader. ;)

    --Eric
     
  43. Epictickle

    Epictickle

    Joined:
    Aug 12, 2012
    Posts:
    428
    I tried using raycasts shooting down from each point in the circle and if there are was a BuildZone there that wasn't my current objects buildzone I Remove() the point from points3 and rebuild, but that jsut completely messed up my unit selection script lol.

    What would YOU do to figure out which points to erase? I'm completely out of ideas lol.
     
  44. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,237
    I would do some math stuff rather than raycasting. Since I don't really know how offhand, I'd google "circle intersection points" or similar and hopefully find something relevant that I could adapt.

    --Eric
     
  45. Epictickle

    Epictickle

    Joined:
    Aug 12, 2012
    Posts:
    428
    Yeah I tried that... Seems extremely complicated to me (I'm a math newb).
     
  46. Epictickle

    Epictickle

    Joined:
    Aug 12, 2012
    Posts:
    428
    @Eric5h5

    Okay, so this is the code I've come up with so far... It's definitely detecting intersecting circles, but I'm getting this result now:

    upload_2014-12-22_17-56-28.png


    Here's my code:

    Code (CSharp):
    1. public void CheckIntersections()
    2.     {
    3.         foreach(BuildRadiusLine brl in playerController.radiusCircles)
    4.         {
    5.             if (brl == this) continue;
    6.  
    7.             if(checkIntersect(position, radius, brl.position, brl.radius))
    8.             {
    9.                 Debug.Log("Intersects...");
    10.  
    11.                 for (int i = myLine.points3.Count - 1; i > 1; i-- )
    12.                 {
    13.                
    14.                     if (pointInIntersection(myLine.points3[i], position, radius, brl.position, brl.radius))
    15.                     {
    16.                         myLine.points3.Remove(myLine.points3[i]);
    17.                         myLine.points3.TrimExcess();
    18.                     }
    19.                 }
    20.             }
    21.         }
    22.     }
    23.  
    24.     public bool checkIntersect (Vector3 c1pos, float c1rad, Vector3 c2pos, float c2rad)
    25.     {
    26.         return (Vector3.Distance(c1pos, c2pos) <= (c1rad + c2rad));
    27.     }
    28.  
    29.     public bool pointInIntersection(Vector3 point, Vector3 c1pos, float c1rad, Vector3 c2pos, float c2rad)
    30.     {
    31.         return (Vector3.Distance(point, c1pos) <= c1rad) && (Vector3.Distance(point, c2pos) <= c2rad);
    32.     }
    I'm guessing that just using .Remove from the circle isn't enough? There's also this question: what if the starting point of my circle resides within another circle? Would that stop the drawing of my circle completely?
     
    Last edited: Dec 22, 2014
  47. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,237
    One thing, don't use TrimExcess. It just makes things worse, unless you have a really serious need to get some memory back. Anyway, Remove is enough, but I'd guess the points being removed aren't the correct ones.

    --Eric
     
  48. Epictickle

    Epictickle

    Joined:
    Aug 12, 2012
    Posts:
    428
    @Eric5h5 I'm almost positive I'm doing this the right way now. All I have to do is use the collider of the BuildZone and then iterate over every element in the points3 list, and check if Collider.bounds.contains the point.

    Now, for my main question... What if points3[0] is removed from the list? Would it draw the line at all since there is no start point anymore? I need it to be able to draw from any point on the list to the last available (not null) element.
     
  49. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,237
    Removing points[0] is fine, since points[1] then becomes points[0]. There's always a start point, as long as there are any points at all.

    --Eric
     
  50. failman

    failman

    Joined:
    Sep 11, 2014
    Posts:
    23
    Hi there! How can I make a 3D VectorLine object (with line.collider=true and line.trigger = true ) receive OnTrigger2DEnter event? Thanks!
     
unityunity