Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    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:
    31,919
    You can use VectorLine.rectTransform.parent, after the line is drawn.

    --Eric
     
  2. foxes

    foxes

    Joined:
    Oct 9, 2015
    Posts:
    8
    You need more optimization, it's possible.
    If you first replace WorldToScreenPoint with
    Code (CSharp):
    1. Vector4 v = (Camera.main.projectionMatrix * Camera.main.worldToCameraMatrix) * new Vector4(tv.x, tv.y, tv.z, 1.0f);
    2.         v.x = (v.x/v.z + 1.0f) * Camera.main.pixelWidth * 0.5f;
    3.         v.y = (v.y/v.z + 1.0f) * Camera.main.pixelHeight * 0.5f;
    and Camera.ScreenToWorldPoint with
    Code (CSharp):
    1.  
    2. Vector4 tv.x = (v.x * (2.0f / Camera.main.pixelWidth) - 1.0f) * v.z;         tv.y = (v.y * (2.0f / Camera.main.pixelHeight) - 1.0f) * v.z;         tv.z = v.z;         tv.w = v.z;         tv = (Camera.main.projectionMatrix * Camera.main.worldToCameraMatrix).inverse * tv;
    3.  
    some expressions can be taken out of the loop.
    Code (CSharp):
    1. (Camera.main.projectionMatrix * Camera.main.worldToCameraMatrix)
    2. (Camera.main.projectionMatrix * Camera.main.worldToCameraMatrix).inverse
    and to make some changes to the "if"
    Code (CSharp):
    1. if (useTransformMatrix) {
    2.   for (int i = start; i < end; i += add) {
    3.     p1 = thisMatrix.MultiplyPoint3x4 (m_points3[i]);
    4.     p2 = thisMatrix.MultiplyPoint3x4 (m_points3[i+1]);
    5.     ...
    6.   }
    7. }
    8. else {
    9.   for (int i = start; i < end; i += add) {
    10.     p1 = m_points3[i];
    11.     p2 = m_points3[i+1];
    12.     ...
    13.   }
    14. }
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    31,919
    I actually did something similar some time ago, and it made no performance difference. The fastest thing would be to have it done in a shader, but that prevents people from just being able to use whatever material they want, which has been pretty common.

    --Eric
     
  4. foxes

    foxes

    Joined:
    Oct 9, 2015
    Posts:
    8
    We tested this on larger arrays with a polygon of 15,000 positions on Unity 2018. The difference is 40mc and 20mc. Perhaps for some other tests it does not make a difference or it is a feature of the device. Аnd perhaps this difference is visible only in the Profiler

    It is also possible that this gives a particular version of unity. Do you use any improvements in the compiler?

    in fact, the transfer of calculations to the GPU does not give a big performance gain, because you have to transfer additional data. Filling in these data even without any calculations takes a lot of time.
     
    Last edited: Jan 11, 2019 at 2:41 PM
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    31,919
    I don't see where I'd need to transfer additional data, though as I mentioned, doing it in a shader has other drawbacks.

    --Eric
     
  6. foxes

    foxes

    Joined:
    Oct 9, 2015
    Posts:
    8
    To implement this on the Shader side, it is not necessary to change all functionality. Can be done as an additional or alternative feature set.

    But for the calculations on the Shader I needed to send some idea about the neighboring points of the line. Because for WebGl and other platforms, the geometric Shader does not work as well as some useful properties.
     
  7. pliska-adam

    pliska-adam

    Joined:
    Apr 13, 2014
    Posts:
    6
    Looking for some help - I'm trying to use Vectrosity to draw lines on top of my 3d unity terrain object. I started by drawing onto a flat terrain - 1 unit above where the terrain is. I then moved the camera around, and noticed the lines appeared correctly from various angles, except that some portions clipped though the terrain mesh.

    I don't understand why this is because every Vector3 that makes up the line floats above the terrain by 1 unit. At no angle should the corner of the line be below the terrain.

    here is a GIF that shows what I'm seeing as I rotate around the location with the lines
    What am I doing incorrectly here?

    Code (CSharp):
    1. var y = 16f;
    2.             var s = 10;
    3.             var line = new List<Vector3>(new[]
    4.             {
    5.                 new Vector3(0,y,0), new Vector3(0,y,s),
    6.                 new Vector3(0,y,s), new Vector3(s,y,s),
    7.                 new Vector3(s,y,s), new Vector3(s,y,0),
    8.                 new Vector3(s,y,0), new Vector3(0,y,0)
    9.             });
    10.  
    11.             selectVectorLine = new VectorLine("selectVectorLine", line, 5f);
    12.  
    13.             VectorLine.SetCamera3D(Camera.main);
    14.             selectVectorLine.Draw3DAuto();
    15.             selectVectorLine.joins = Joins.Weld;
    16.             selectVectorLine.capLength = selectVectorLine.GetWidth(0) / 2f;
    17.             selectVectorLine.material = this.Material;

    UPDATE: It's this code line that is causing the odd behavior:
    Code (CSharp):
    1. selectVectorLine.joins = Joins.Weld;
    Removing that, and seeing gaps in the joins between lines, fixes the issue.
     

    Attached Files:

    Last edited: Jan 13, 2019 at 7:40 PM
  8. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    31,919
    Joins.Weld can alter the vertex position in order to look correct from the camera viewpoint, so try turning that off. Other than that, it could be a shader issue.

    --Eric
     
  9. pliska-adam

    pliska-adam

    Joined:
    Apr 13, 2014
    Posts:
    6
    Thank you!
     
  10. JRayP

    JRayP

    Joined:
    Today
    Posts:
    2
    @Eric5h5 Do you mind checking the emails from your StarScene site? I have sent multiple emails asking for you to send the download links to the email address associated with my account (detailed in the emails I sent you). I would like to use the software I purchased from you, surprise surprise.

    If you are unwilling, or for some reason unable to send me the downloads for something I paid for, at least tell me for crying out loud. (Maybe I forgot the correct account email, which would be on me. But it would be nice to get a response.).
     
  11. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    31,919
    Hi, there's nothing from you, assuming you're using a similar name. I've been in communication with several customers using that email this week, so I know it's working. There's also no payment from you that I can see. If you bought from the Unity asset store, you don't need any download links from me, and can use the store download functions. If you want to give me more information that could help resolve this, I'd suggest using a PM.

    --Eric
     
  12. JRayP

    JRayP

    Joined:
    Today
    Posts:
    2
    Update: eric5h5 helped me over PM. Excuse my fed up tone (I had been waiting for a response for weeks lol) and get back to discussing lines ;)