Search Unity

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

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,633
    Been wanting this for ages, finally bought it!! Unfortunately there appears to be something wrong with it, I cannot get the scenes to load, I get errors about multiple unity instances. It looks great but why arent the scenes like normal asset scenes? I can do without this extra complication really. How do I run it?
     
  2. Liviuss

    Liviuss

    Joined:
    Apr 2, 2014
    Posts:
    101
    Hi eric, just bought v.4 and i have a few questions about parenting lines.

    I use Vectrosity to draw circles(orbits) around moving objects by parenting circles to moving object. With vectrosity 3.0 reparenting was fine but in 4.0 it's not working as expected.

    The code is simple:
    Code (CSharp):
    1. VectorLine orbitLine = new VectorLine ("OrbitLine", new Vector3[SegmentsLength], RingMaterial, RingWidth, LineType.Continuous);
    2. orbitLine.SetColor (RingColor);        
    3. orbitLine.MakeCircle (ParentGo.transform.position, Vector3.forward, Radius);
    4. orbitLine.drawTransform = ParentGo.transform;
    5. orbitLine.Draw3DAuto ();
    The line get parented but with an offset.
    I have to mention that ParentGO is also parented in another GameObject and has a localPosition on Y axis.

    Thanks.

    P.S. If the object localPosition is Vector3.zero, everything works fine.
    P.S.S. As a workaround i can use drawTransform.localPosition to compensate the offset but as side effect i can't rotate the object in localspace :/
     
    Last edited: Nov 28, 2014
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Thank you for buying! However there's nothing wrong with it...just import the packages you want. See the "What to import" file about, er, what to import. It's slightly complicated at this point since there are several Vectrosity versions that work with several Unity versions, but the "what to import" file clarifies that. Don't just import everything though, since that won't work.

    Hi, I'm not seeing any differences in parenting behavior between Vectrosity 3 and 4. The code used in Vectrosity for that functionality is exactly the same in both versions, so maybe you're actually experiencing changes in Unity, specifically the SetParent function (which can take a boolean worldPositionStays parameter)?

    --Eric
     
  4. Liviuss

    Liviuss

    Joined:
    Apr 2, 2014
    Posts:
    101

    Hi Eric,

    First let me explain a bit more how the hierarchy objects is set in my scene.

    PivotGO (The main object in the scene aka Sun : LocalPosition = Vector3.zero)
    |
    |___ PlanetRotationGO (Object with script to rotate nested planet around PivotGO : LocalPosition = Vector3.zero)
    |
    |___ PlanetGO (Object container for visual stuff and so on : LocalPosition = Vector3(0, 20, 0))​

    What i do is to instantiate a GameObject that will host the orbit ring with following code:
    Code (CSharp):
    1. GameObject RingGo = new GameObject ("OrbitRing");
    2. RingGo.transform.SetParent (PlanetGO.transform, false);
    3. RingGo.transform.localPosition = Vector3.zero;
    Next i add the ring with:

    Code (CSharp):
    1. VectorLine orbitLine = new VectorLine ("OrbitLine", new Vector3[SegmentsLength], RingMaterial, RingWidth, LineType.Continuous);
    2. orbitLine.SetColor (RingColor);  
    3. orbitLine.MakeCircle (RingGo.transform.position, Vector3.forward, Radius);
    4. orbitLine.drawTransform = RingGo.transform;
    5. orbitLine.Draw3DAuto ();
    6.  
    Setting to true/false in RingGo.transform.SetParent (PlanetGO.transform, false) has no effect;
    And it seems that this behavior is related to Unity 4.6 i upgraded to, in order to use vectrosity 4.x :/

    Thanks for your time

    P.S. My temporary solution is to draw the circle around PivotGO and after reparent to RingGo, but i feel like it's a hack
     
    Last edited: Nov 28, 2014
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I made a scene and tried your code (substituting transform.parent in Unity 4.5 rather than SetParent of course), and I get the exact same result in Vectrosity 3.1.3 as I do in Vectrosity 4.0.3. So apparently something is different for you somewhere but unfortunately I have no idea what it might be. As I mentioned, the VectorLine.drawTransform code hasn't changed; it just gets a transform matrix from the supplied transform and applies that to all the points in the line.

    --Eric
     
  6. Liviuss

    Liviuss

    Joined:
    Apr 2, 2014
    Posts:
    101
    Hi Eric,

    Thanks again for your support. As i mentioned before, in Unity 4.5+ everything work ok, i get the strange results only in Unity 4.6(official release). Anyway, for the moment i will use the workaround described in previous message and will try to investigate it more.
     
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I get the same results in Unity 4.6 and 4.5, as described above, so I'm a bit stuck about suggesting any solutions.

    --Eric
     
  8. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,305
    Hi,

    what is the easiest way of creating a prefab from a line mesh created with line maker ? I suppose extending the line maker such that it will create complete game object in the scene with correct material / mesh instead of writing the vector data to a file - is that correct ?
     
  9. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The LineMaker doesn't create a mesh, but rather a series of points that can be used with a VectorLine. A prefab would probably be an empty game object with a script attached, that either contains the line data in code, or loads a file with the line data.

    --Eric
     
  10. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,305
    ah, I was referencing the actual mesh as created by Vectrosity in runtime
    e.g.
    Code (csharp):
    1.  
    2. void Start ()
    3. {
    4.   var linePoints = VectorLine.BytesToVector3Array( lineData.bytes );
    5.   var line = newVectorLine(lineData.name, linePoints, null, 2f );
    6.   line.Draw3D();
    7. }
    8.  
    creates a gameobject in scene with proper mesh constructed from loaded vector points
    So I wonder whether it is ( reasonably easily ) possible have this in edit time - would surely help with prefabs since you have preview of it a can be further visually tweaked. - as you can see I use Draw3D, so the vectrosity line is common world space gameobject which suits me rather well at this point.

    edit: note: I'm using Vectrosity 3.x so no new Unity 4.6 suff for now
     
    Last edited: Dec 1, 2014
  11. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Vectrosity wasn't designed to have lines in edit time; you could simulate it to some degree by using Handles.DrawLine, which would at least give you an idea of what the line would look like in world space.

    --Eric
     
  12. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,305
    I see, slightly more cumbersome than I anticipated, but thanks nevertheless

    One more/last question: do you think it would be feasible if I tried to get to the actual mesh construction for Draw3D in vectrosity code and tried to tweak it such that it could be called from the editor or rather should I expect 2D monsters and other flying spaghetti which would deem this impossible ? :)
     
  13. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You could possibly call it from the editor, but there's no way to save the VectorLine in the scene. But you could potentially get the mesh, and save that as an object.

    --Eric
     
  14. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,305
    to (partly) answer my own question: this http://wiki.unity3d.com/index.php?title=CreatePrefabFromSelected works almost good (yay); the only problem is that saved mesh is one faced ( I suppose Eric maybe mirrors the faces on lines and this gets not saved this way ( for some reason ) )
    I suppose I *can* live with this for now, esp. when all other options seem to be exhausted ^
     
  15. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The meshes do only have one face, since they're intended to face the camera, and therefore you'd never see the other side.

    --Eric
     
  16. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,305
    I will possibly look into it, thanks

    Right, this seems to be a shader thing; the Vectrosity default shader Vertex Colors/Alpha works fine in 3D; saved mesh with e.g. Diffuse has only front faces visible; I am not versed with shaders whatsoever so maybe I'm doing something completely wrong ]; but this is a minor issue for me right now ( Sprites/Default shader works fine too, I suppose they are similar );


    Main point is that it's possible to save vectrosityfied 3d meshes as prefabs and that's great for them to be further manipulated

    Thanks for replies!
     
    Last edited: Nov 30, 2014
  17. alibaadshah

    alibaadshah

    Joined:
    Oct 7, 2013
    Posts:
    5
    eric please help me how i draw line it is trail render line i want to straight line
    give me coding


    wire connected.png
     
  18. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I couldn't really understand what you're asking; can you re-phrase that?

    --Eric
     
  19. alibaadshah

    alibaadshah

    Joined:
    Oct 7, 2013
    Posts:
    5
    my english is not good please help me
    i want to make draw straight line in my project can you give me coding of straight line javascript or c#
     
  20. alibaadshah

    alibaadshah

    Joined:
    Oct 7, 2013
    Posts:
    5
    i need coding of this function
    thick line
    weld joins
    straight line

    please give me coding

    111.png
     
  21. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The code for all the examples on the website (and more) is included with Vectrosity. So you can look at the code to see how it's done. If you have any specific questions, please ask.

    --Eric
     
  22. alibaadshah

    alibaadshah

    Joined:
    Oct 7, 2013
    Posts:
    5
    ok when i click digital switch led light is not glowing i think my script is one line missing i cant do this can you help me how to make this function when i click digital switch led glowing with wire as line if line is not connect then led will be not glowing

    this is my project
    [edit-removed]

    this is my script file
    [edit-removed]
     
    Last edited by a moderator: Dec 3, 2014
  23. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I'm sorry but I can't really help with general programming. If you have a specific question about how to use Vectrosity, you can post that here.

    --Eric
     
  24. alibaadshah

    alibaadshah

    Joined:
    Oct 7, 2013
    Posts:
    5
    thank you are good person you are hide my project file and script
    have you any idea unity3D game engine can be make voltage and current system for connect line and LED light will show like www.123d.circuits.io

    electronic simulation 2D game for student
    you are best for me because you a
     
  25. ferretnt

    ferretnt

    Joined:
    Apr 10, 2012
    Posts:
    412
    Hi Eric,

    I'm trying to reduce a 2D line to a dense grid of points along its length and within its width. This doesn't need to be a mesh, just a point cloud.

    Extracting a dense field of points along the centre of the line is trivial, using GetPoint01() and interpolating (really, I should write my own GetAllPoints01ForDeltaT to save looping over the points so many times, but it basially works...)

    I would also like to be able to extract points outwards from the centre line, but within the line width. One way to do this would be to compute the line gradient at each point where I previously computed DeltaT (using a point and the previous point, then taking the right-angle gradient) and iterate along this line. However, you might already have code that does this somewhere, so before I code, I wanted to ask "do you?"

    Thanks,
    Alex
     
  26. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I do not. Code away. :)

    --Eric
     
  27. ferretnt

    ferretnt

    Joined:
    Apr 10, 2012
    Posts:
    412
    Hi Eric,

    Done - thank you.

    There are also cases where I would like to use Vectrosity to generate a line mesh, but I don't want to draw it as a vectorLine object. As far as I can see, there's no way to do this, other than by explicitly creating a VectorLine and calling Draw() on it, because otherwise m_linePoints isn't valid. My quick attempts at forcing calls to RebuildMesh() etc haven't resulted in anything useful.

    Is there a way to create a vectorLine and ensure that it sets up its mesh (immediately), without explicitly calling draw()? I don't mind modifying source code if necessary.

    Thanks,
    Alex
     
  28. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Calling Draw() is indeed the only way to create the line mesh, so you'd need to modify the code.

    --Eric
     
  29. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    I was wondering if there is a way to get rid of this artifact:


    Basically, I want a fake dropshadow around my line, so my line texture has a drop shadow sort of bit along the top and bottom edges. But it seems the line segments are overlapping as the line bends as shown here, causing the shadow to double-up on itself, which looks incorrect. Is there a way to have the vertices/faces perfectly contiguous and not overlapping? I'm sure there is a setting somewhere that I'm missing. Thanks!
     
  30. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can use Joins.Weld for that.

    --Eric
     
  31. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    Thanks, but I'm still having the issue even with Weld. I was using Fill to get away from a nasty problem where if I had two nodes of the spline too close together, I'd get triangles jumping out to weird places. But with Weld, that problem occurs, plus I still get the overlapping if the angle is either too acute, or if the spline nodes are too close together:


    Apart from the acuteness issue, is there a way to "scale" something about the line (not using transform scale) so that the distance between nodes doesn't become a factor?
     
  32. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It's true that weld doesn't work in more extreme cases, but what you have in your image there looks like it would work fine with weld. I'm not quite sure what you mean about scaling; it works best if points aren't very close to each other.

    --Eric
     
  33. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    That latest screenshot is using Weld. As for the scaling, I guess what it boils down to is line width in relation to the distance between spline nodes. If my line is pretty wide, then the nodes seem to need to be further apart. If they're very close, the vertices jump wildly around. And in my case, "very close" seems to be a distance that is about twice the line's width, or less. Sometimes even a bit further than that, depending on the angle of subsequent nodes. It seems like I should be able to position nodes that close together without the radical issues I'm seeing with Weld.
     
  34. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I'm not able to replicate that; here's a transparent texture using Joins.Weld:

    Screen Shot 2014-12-10 at 3.30.53 PM.png

    Do you maybe have some duplicate points in the line? That will mess up Joins.Weld; all points should be unique and not extremely close to each other.

    --Eric
     
  35. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    The problem is probably the line width. I can send you a package if you'd like to see it in action. Just let me know how you'd like me to get it to you.
     
  36. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I may have been misunderstanding your texture...the entire thing is the line texture? I was assuming just the gray transparent part was. If the entire thing is the texture, yes, I would say that's far too thick for welding to work, and I don't think there's much I could do about it. I'd recommend making the gray transparent part a separate line.

    --Eric
     
  37. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    Okay, thanks. That'll be a bit difficult, however, since the line's width tapers toward one end, and changes with the passage of time, meaning the additional line that represents the shadow would have to constantly be updated based on where the edge of that line lands. Ahh well... I may just have to go without the drop shadow.
     
  38. xdotcommer

    xdotcommer

    Joined:
    Aug 20, 2014
    Posts:
    33
    Does Vectrosity work on iOS devices? I am working with GridFramework together with Vectrosity and had a really cool effect going, but it doesn't display at all when I put it on my iPhone 6.
     
  39. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I haven't seen any issues with Vectrosity on iOS, though I don't have an iPhone 6.

    --Eric
     
  40. lloydhooson

    lloydhooson

    Joined:
    Apr 7, 2008
    Posts:
    77
    Hi, I think the asset is great - Already using it in 1 project with another on the way.

    Thanks.

    I have made an adjustment with the line maker instead of having to change the bool for C# and Java I have changed these lines to around 280ish in the linemaker.

    Code (JavaScript):
    1. if (Button("Generate JavaScript Complete Line")) {
    2.             floatSuffix = "";
    3.             newPrefix = "";
    4.             message = "";
    5.             ComputeLine(true);
    6.         }
    7.  
    8.         if (Button("Generate C# Script Complete Line")) {
    9.             floatSuffix = "f";
    10.             newPrefix = "new ";
    11.             message = "";
    12.             ComputeLine(true);
    13.         }
    And removed the boolean for the c# completely.

    Makes it easier to have 2 buttons rather than changing.

    Also any chance to have a C# version of the line maker?
     
  41. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I wasn't planning on it; since it's an editor script, and wouldn't be accessed by other scripts, there didn't seem to be any advantages.

    --Eric
     
  42. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
Thread Status:
Not open for further replies.