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. Gigiwoo

    Gigiwoo

    Joined:
    Mar 16, 2011
    Posts:
    2,981
    Yes Angel. That's basically what I'm trying to do. Use vectrosity objects to do sort of a painting visual effect.

    I'm not sure if this it the right fix, but the stumbling block I was hitting was that Vector.SetCamera() actually creates a new camera, it doesn't use the main camera itself. That stumped me. So, when I was changing the main camera to render to a target texture, it didn't work like I expected. Once I grabbed the vector camera and set its texturetarget, Walla!

    $Unity 2011-08-26 10-29-39-15.png
     
  2. DavidByers

    DavidByers

    Joined:
    Dec 31, 2010
    Posts:
    79
    I just ran into a compatibility problem that I think was caused by Vectrocity. I bought ex2d, and I got a bunch of errors related to the class "Path". It seems Vectrocity has a class named Path that overrides System.IO.Path. Is there any way to fix this?
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The only Path class in Vectrosity is the Path.js example script.

    --Eric
     
  4. DavidByers

    DavidByers

    Joined:
    Dec 31, 2010
    Posts:
    79
    Cool, so it's not important and I'm ok to delete it?
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Only the scripts in VectorScripts are necessary; all of the example scripts are just that.

    --Eric
     
  6. Gigiwoo

    Gigiwoo

    Joined:
    Mar 16, 2011
    Posts:
    2,981
    Eric,

    I realized that there is no method to get the current camera. I know that the SetCamera() method will return the camera at the end, but if I am in a variety of places in my code, I don't want to have to pass that around. I just want to get access to the current camera to make some minor mods (like a render texture target).

    Please add the following function to your base vectrosity. I added it to mine, but when I update next, I don't want to have to remember. In Vectrosity, around line 145:

    Code (csharp):
    1.  
    2.     public static Camera GetCamera() {
    3.         return cam;
    4.     }
    5.  
    Thanks,
    Gigiwoo.
     
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Makes sense.

    --Eric
     
  8. xadhoom

    xadhoom

    Joined:
    Sep 2, 2010
    Posts:
    91
    Hi Eric,

    We just purchased the Vectrosity and currently get into it.

    Doing that I currently want to create a bounding box around currently hovered/selected objects. It works great so far running the following code on the highlighted object:

    Code (csharp):
    1. Vector3[] cubePoints = boundsToArray();  // returns attached mesh bounds as lines
    2. if(cubePoints != null)
    3. {
    4.     VisibilityControlAlways vc = gameObject.AddComponent<VisibilityControlAlways>();
    5.     VectorLine line = new VectorLine( gameObject.name + "Hover", cubePoints, mHoveredMaterial, 2.0f);
    6.     vc.Setup ( line);
    7. }
    Now the problem: It is possible to destroy the object currently highlighted which means that the object is destroyed by Unity and an explosion is spawned. Whenever I destroy a highlighted object the scene camera image freezes! And I mean it like that. Everything works as expected nothing is hanging just the camera image does not update. Pausing/unpausing the simulation in the editor fixes this issue immediately.

    I´ve tried to explicitly remove the "VisibilityControlAlways" component in OnDestroy but the issue persisted.

    Any clue how I can solve this issue or how I can track it down? We are using Unity 3.4 Pro.

    xad
     
  9. Gigiwoo

    Gigiwoo

    Joined:
    Mar 16, 2011
    Posts:
    2,981
    Heya,

    Quickie. Is there a way to clear a render texture in code? When I start my app, the rendertexture has garbage in it. And, I want to be able to clear it when I switch effects. I can clear it to black, or white, or any color, or even alpha. But garbage is bad...

    Gigiwoo
     
  10. Gigiwoo

    Gigiwoo

    Joined:
    Mar 16, 2011
    Posts:
    2,981
    @xadhorn - please put the code you are using to destroy it. Without that, people won't know what you're destroying.

    Gigiwoo.
     
  11. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    @xadhoom: I would suggest making the bounding box using a manager object that isn't destroyed. Also I would recommend not adding VisibilityControlAlways and so on manually; stick with VectorManager.ObjectSetup.

    As far as rendertextures, they are textures that are rendered by a camera, so I guess you would "clear" it by making sure the camera used for the rendertexture isn't rendering anything except the background color.

    --Eric
     
  12. Gigiwoo

    Gigiwoo

    Joined:
    Mar 16, 2011
    Posts:
    2,981
    Anyone had any luck deploying vectrosity to the ipad? I can get to work in some ios device orientations, but others, it just doesn't seem to render. It's like it's offscreen somewhere and I have no idea where it is.

    Anyone been able to deploy it and rotate the ipad and not have any trouble with where there screen 2D vectrosity particles went?

    Gigiwoo.
     
  13. Gigiwoo

    Gigiwoo

    Joined:
    Mar 16, 2011
    Posts:
    2,981
    Hmm... in doing more testing, the vectrosity stuff seems to stop rendering if I resize my window while running, even in the editor. i don't know if it's my code or not. More testing is in order.

    Ok. If you open the vectrosity demos, it does the same thing. Open the Scribblecube, then run it and resize your window. Boom, everything disappears and it never comes back. This looks like a vectrosity bug. If you get it solved, please let me know and I will test ASAP.

    Gigiwoo.
     
  14. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It's not a bug; it's specifically covered in the docs (see the troubleshooting section about changing resolution).

    --Eric
     
  15. Gigiwoo

    Gigiwoo

    Joined:
    Mar 16, 2011
    Posts:
    2,981
    Hmmm... I tried that. I did a Vector.SetCamera(Vector.GetCamera()); It just looks like it stops drawing. In the inspector, the VectorCam seems to lose the culling mask. Before I resize, it's set to 'unnamed 31' or something like that. After the resize and the subsequent call to SetCamera(), it goes to Nothing. Also, everytime I call SetCamera(), it increments the depth by 1. So, it starts at 0, then 1, 2, 3, 4, 5, 6. The clear flags seem to always be 'Depth', which I assume is right.

    Ok. I think the problem is the line: thisCamera.cullingMask = thisCamera.cullingMask (-1 ^ (1 << _vectorLayer));

    Since I am setting it to itself, I believe teh culling mask gets lost. The method should be updated to allow you to set it back to itself, since I'm not actually trying to change cameras, I am just working around the quirk of resizing.

    Gigiwoo.
     
    Last edited: Aug 28, 2011
  16. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It should just be "Vector.SetCamera()"; you wouldn't pass the vector camera in.

    --Eric
     
  17. Gigiwoo

    Gigiwoo

    Joined:
    Mar 16, 2011
    Posts:
    2,981
    Thanks Eric. That did the trick.
     
  18. joeythepoey

    joeythepoey

    Joined:
    Jun 18, 2010
    Posts:
    12
    Hey Eric,

    Vectrosity looks really awesome...initially I wasn't sure what I could use it for in my current game ideas, but the selection example was useful and I wanted to ask the following:
    -is it possible to use vectrosity to draw an outline around a model/character?
    I'm looking for something like left 4 dead 2, though it wouldn't have to with a fading edge/alpha transparency like lfd2:


    Cheers,

    JOe
     
  19. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Honestly you'd be better off using a shader for that sort of thing.

    --Eric
     
  20. iisjreg

    iisjreg

    Joined:
    Mar 25, 2011
    Posts:
    101
    http://www.unifycommunity.com/wiki/index.php?title=Silhouette-Outlined_Diffuse there we go, play around with that to start with :)
     
  21. Gigiwoo

    Gigiwoo

    Joined:
    Mar 16, 2011
    Posts:
    2,981
    Eric,

    I'm having an issue with the MakeSplineInLine() behavior. Maybe a bug or maybe I'm using it wrong. If you are using points, it seems to double up the first/last location of the spline. Meaning, I get a wonderfully yummy spline with points, except the starting ending location are exactly the same - they are doubled up. If you are using a transparent-alpha type shader, you get this bright spot effect where the points are doubled up. It's pretty noticeable - see the pictures below. I've tried to use 1 less point, but I can still see it.

    Thanks for any suggestions,
    Gigiwoo.
     

    Attached Files:

  22. Gigiwoo

    Gigiwoo

    Joined:
    Mar 16, 2011
    Posts:
    2,981
    Heya,

    Here's another one of those newbie Unity questions. I am trying to rotate the vector shape around it's center point, but as far as I can tell, if I just use the Rotate() method (see below), it rotates around the 'corner' starting position of the vector shape. what is the math to get my vector to rotate around its center point?

    Code (csharp):
    1.  
    2.     myTransform.transform.position = new Vector3( centerCurrent.x, centerCurrent.y, 0.0f );
    3.     myTransform.transform.Rotate( 0.0f, 0.0f, -20.0f * Time.deltaTime );
    4.     Vector.DrawLine( theLine, myTransform.transform );
    5.  
    Thanks,
    Gigiwoo.
     
  23. joeythepoey

    joeythepoey

    Joined:
    Jun 18, 2010
    Posts:
    12
    Okay, thanks for the link...
    however, I figured there might be a problem with a shader approach to this.
    The main thing is that if you have a lot of enemy instances on screen which use the same base shader, wouldn't they all suddenly show the outline?
    Wouldn't it entail having to create at runtime a separate shader for each enemy?

    That's why I figured vectrosity could be useful...
     
  24. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    Yes :(
     
  25. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Not to let the thread drift too much off topic, but: You could have two materials, one with and one without the glow, and change the material at runtime, so there are only two materials at any given time, no?

    We should spawn a new thread to continue this conversation! (^_^)!
     
  26. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can't directly assign a shader to anything; a shader is part of a material, so you just assign different materials as necessary.

    As far as MakeSplineInLine goes, I don't think the first and last points would be the same unless you made them the same, or am I misunderstanding? Regarding rotation, you might want to use RotateAround; see the last line of the Update function in the DrawLines example script.

    --Eric
     
  27. Gigiwoo

    Gigiwoo

    Joined:
    Mar 16, 2011
    Posts:
    2,981
    Eric,

    Thanks for the RotateAround suggestion. That did the trick.

    As for the makeSplineInLineBug, I'm 99% sure that it is not my bug, though I can't be 100% certain until it's found. I looked in MakeSplineInLine() and messed around with a few cases. here's what I found. If you go to line 1661 and replace it with this:

    Code (csharp):
    1.  
    2.         var add = 0.995f / segments * numberOfPoints;
    3.  
    This causes it to not complete the full circuit from t=0.0 to t=1.0. However, what it shows is that the last 2 points are EXTREMELY close, but not overlapping as seen in these screen shots. Using this information, it seems pretty clear that there are 2 points that completely overlap. So, I tested a hack (shown below) that seems to fix the double point problem. I change the add 'value' and then clamp the number of points. It seems to work, but... it's hacky. Hopefully, you can use this to make a real fix.

    Code (csharp):
    1.  
    2. (line 1661ish)
    3.     var add = 1.0f / (segments+1.0f) * numberOfPoints;
    4.  
    5. ...
    6.  
    7. (line 1684ish)
    8.     for (i = start; (i < 1.0f  pointCount < line.points2.Length); i += add) {
    9.         line.points2[pointCount++] = GetSplinePoint (splinePoints2[p0], splinePoints2[j], splinePoints2[p2], splinePoints2[p3], i);
    10.     }
    11.  
    $Screen shot 2011-08-31 at 8.28.36 AM.png $Screen shot 2011-08-31 at 8.28.26 AM.png

    Gigiwoo
     
  28. Gigiwoo

    Gigiwoo

    Joined:
    Mar 16, 2011
    Posts:
    2,981
    *tap tap*

    Is this thing on? 2 Days with no replies? Very unusual...

    Gigiwooo
     
  29. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Late summer holidays in various parts of the world?
     
  30. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Sorry, occasionally things can slip through. Are you talking about using "true" with MakeSplineInLine to make splines a closed loop? If so, that's not a bug; the points have to be the same or else lines would not complete the loop correctly.

    --Eric
     
  31. joeythepoey

    joeythepoey

    Joined:
    Jun 18, 2010
    Posts:
    12
    Sorry to keep hassling, but Eric5h5, is there a way to use Vectrosity to draw an outline around an existing mesh?
     
  32. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I expect there is, technically, but I have no idea how. It would be far easier to use a shader for that, as discussed above.

    --Eric
     
  33. Gigiwoo

    Gigiwoo

    Joined:
    Mar 16, 2011
    Posts:
    2,981
    Heya,

    That is true for lines, but not for points. With points, if you keep the extra point at the end, then you end up with 2 overlapping points. With any sort of transparency, you end up with one spot that is 2x as bright - and your mind fixates on that, especially if the shape is moving/rotating. It's is very obvious, as you can see from the screen shots. Consider a circle with 6 points. Currently, you have 1, 2, 3, 4, 5, 6/1, 2, 3, 4, 5, 6/1, ... What you want is either: 1, 2, 3, 4, 5, 6, 1, 2, ... or 1, 2, 3, 4, 5, 1, 2, 3, ... Either. But, you don't want the start/end point to be repeated.

    I posted the code to fix it above, but I was hopeful that you could do a slightly more elegant (and permanent) solution, since you know the code better.

    Gigiwoo
     
  34. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Well, after all it is called "MakeSplineInLine". ;) I could add a MakeSplineInPoints function.

    --Eric
     
  35. strtok

    strtok

    Joined:
    Nov 6, 2010
    Posts:
    7
    Just picked up the latest version and I'm wondering if anyone has tried to create a mesh collider with the mesh generated for the lines? I'm using the lines as "walls" and I'd like to create colliders.

    I'm guessing because the mesh is a plane and not 3 dimensional, a mesh collider won't work. Is the right approach to extrude the mesh generated by Vectrosity?

    Thanks!
    --strtok
     
  36. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yeah, the line won't generate a mesh collider that's usable for most things, because of its 2D nature. You could generate box colliders for each line segment (see the LineMaker.js editor script for something similar).

    --Eric
     
  37. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    Hi,

    Why is the character "*" is he not in "Vector2 [] [] data"?


    JP

    Edit : missing "points[42]", "points[58]", "points[59]"
     
    Last edited: Sep 11, 2011
  38. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I'm sorry, I don't understand.

    --Eric
     
  39. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    It is not possible to drawing these caracters "*" "[" "]". Why?

    JP
     
  40. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Are you referring to Vector.MakeTextInLine? I didn't make all the characters, just the more common ones. You can add characters yourself if you need them (I use LineMaker for that), and add them to VectorChar.cs.

    --Eric
     
  41. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    Yes

    .
    Ok.
     
  42. Shawn123

    Shawn123

    Joined:
    Nov 17, 2010
    Posts:
    4
    Hey Eric,
    I'm trying to draw a line in world space using DrawLine3D. The main camera is orthographic. The line itself should be behind some cubes. The problem is, that the line isn't occluded by this cubes. If I use a perspective camera it works fine. I also tried to use DrawLine but in this case the line isn't drawn at the same position and also my tests show me that lines created with DrawLine were also not occluded by other 3D objects.

    Thanks for your help.
     
  43. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Can you provide an example; I tested and it works fine here. I'm not sure why the camera being orthographic would make any difference.

    --Eric
     
  44. Shawn123

    Shawn123

    Joined:
    Nov 17, 2010
    Posts:
    4
    I just tried it in a new scene and it works fine. So the problem is somehow in my scene. However, thanks for your answer.
     
  45. wbl1

    wbl1

    Joined:
    Apr 22, 2009
    Posts:
    159
    Sorry if this has already come up, but I am getting the following error in Unity:

    Assets/Editor/Vectrosity/LineMaker.js(431,18): BCW0029: WARNING: Method 'LineMaker.OnDestroy()' hides inherited non virtual method 'UnityEditor.ScriptableWizard.OnDestroy()'. Declare 'LineMaker.OnDestroy()' as a 'new' method.

    What exactly do I need to do to correct this? thanks
     
  46. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Sounds like you're using an old version, in which case you should update it. (If you bought from my site, update notices went out a couple months ago, but let me know if you can't find it.)

    --Eric
     
  47. dock

    dock

    Joined:
    Jan 2, 2008
    Posts:
    603
    I just wasted several hours trying to get Vectrosity text to align properly in 3D, or even in 2D, with different resolutions.
    Why is text so slippery in Vectrosity?

    I'd love to see some more examples of how to setup text this way. I've ended up having to give up with it.
     
  48. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Did you check the Tank Zone example? It has text in multiple resolutions (including switching resolutions at runtime, because of the possibility of the web player going full screen and back).

    --Eric
     
  49. Charbl

    Charbl

    Joined:
    Sep 28, 2011
    Posts:
    17
    I'm having a strange problem with DrawLine3D -- It doesn't seem to respect the widths I supply to it, and the widths actually change at different angles, like the mesh isn't moving to face me.

    I've attached two screenshots to show the problem:





    These two images are of the same lines at different angles.

    Here is the code I'm using to draw them:

    Code (csharp):
    1.  
    2. function createLines()
    3. {
    4.     xLine = Vector.SetLine3D(Color.red, Vector3(0, transform.position.y, transform.position.z), Vector3(2048, transform.position.y, transform.position.z));
    5.     yLine = Vector.SetLine3D(Color.green, Vector3(transform.position.x, 0, transform.position.z), Vector3(transform.position.x, 2048, transform.position.z));
    6.     zLine = Vector.SetLine3D(Color.blue, Vector3(transform.position.x, transform.position.y, 0), Vector3(transform.position.x, transform.position.y, 2048));
    7.     xLine.lineWidth = 0.15;
    8.     zLine.lineWidth = 0.15;
    9.         // y Axis line is fine for some reason?
    10.    
    11.     // Way I'd prefer to do it, but the result is even worse with way thicker lines that border on planes.
    12.     // xLine = new VectorLine("X Axis", new Vector3[2], Color.red, null, 0.3);
    13.     //yLine = new VectorLine("Y Axis", new Vector3[2], Color.green, null, 0.3);
    14.     //zLine = new VectorLine("Z Axis", new Vector3[2], Color.blue, null, 0.3);
    15. }
    16.  
    17. function Update ()
    18. {
    19.  
    20.     if (xLine)
    21.     {
    22.         xLine.points3[0] = Vector3(0, transform.position.y, transform.position.z);
    23.         xLine.points3[1] = Vector3(2048, transform.position.y, transform.position.z);
    24.         Vector.DrawLine3DAuto(xLine);
    25.            
    26.         yLine.points3[0] = Vector3(transform.position.x, 0, transform.position.z);
    27.         yLine.points3[1] = Vector3(transform.position.x, 2048, transform.position.z);
    28.         Vector.DrawLine3DAuto(yLine);
    29.            
    30.         zLine.points3[0] = Vector3(transform.position.x, transform.position.y, 0);
    31.         zLine.points3[1] = Vector3(transform.position.x, transform.position.y, 2048);
    32.             Vector.DrawLine3DAuto(zLine);
    33.     }
    34.     }
    35. }
    36.  
    37.  
    Any help would be greatly appreciated! Thanks!
     
  50. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Not sure if it's related, but the lines should be created and drawn with DrawLine3DAuto just once, not every frame in Update. Also, widths of .3 and .15 pixels isn't going to work very well.

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