Search Unity

Vectrosity - Fast and Easy Line Drawing

Discussion in 'Assets and Asset Store' started by Eric5h5, Sep 26, 2014.

  1. kurismakku

    kurismakku

    Joined:
    Sep 18, 2013
    Posts:
    66
    Is it possible to draw lines inside of the scene view, while game is not running?
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes, that was one of the major additions in Vectrosity 5.

    --Eric
     
  3. mcmorry

    mcmorry

    Joined:
    Dec 2, 2012
    Posts:
    580
    Hi, I'm starting to implement Vectrosity and I'd like to have the origin of the lines based on the pivot of the canvas, and have the coordinate using a range [0, 1] in x and y that will correspond to the width and height of the canvas.
    The canvas will be placed in the center bottom of the screen, and scaled based on the resolution.
    I'll go by code, but now I'm trying to get the result visually in the editor. The problem that as soon as I change the position of the line transform, the line starts to move by itself forever.
    Thanks
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Hi, could you provide more details about what it is you're doing? I'm not really following.

    --Eric
     
  5. mcmorry

    mcmorry

    Joined:
    Dec 2, 2012
    Posts:
    580
    Ok, first of all I want to report you some bugs:

    1. if I move the Line gameobject inside another Canvas of my UI, when I resize the viewport the gizmos are not updated, and they don't match anymore the position of the points:
    Screenshot 2016-02-12 09.18.09.jpg

    2. if I move the Line gameobject, it starts moving by itself:
    https://blueriverarts.box.com/s/o2pmpwicwzxf40s2k7wftimsif9omn5h

    3. if I move the parent of the Line gameobject, the line initially is displayed correctly, but as soon as I select it, it goes away as by previous point.

    Now to what I'm trying to do:
    I have a rect transform in my UI that should contain a graph.
    I need to have the origin of the coordinate system aligned to its pivot (I tried to move the Line gameobject but then it starts moving away by itself as I shown before.)
    As you see in next screenshot the origin is at the bottom left of the screen. This makes hard to place the line in the correct position by code.
    So let me know how to do it, and if this bug occurs only when using the editor (because it seems that happens only when the Line object is selected).
    Screenshot 2016-02-12 09.29.18.jpg
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Currently changing the viewport size isn't supported if using some canvas scale mode other than constant pixel size (in terms of the editor...in code it doesn't matter). Also directly moving the line's transform isn't generally recommended; you'd typically use VectorLine.drawTransform to have a line "follow" the assigned transform.

    --Eric
     
  7. mcmorry

    mcmorry

    Joined:
    Dec 2, 2012
    Posts:
    580
    After many trial and error this is what I did to make it work:

    Code (CSharp):
    1. var lines = new List<Vector2>();
    2. var vl = new VectorLine("ScannerLine", lines, 2);
    3. vl.Draw(); // required otherwise changing parent before to draw doesn't work
    4. var lineTr = GameObject.Find("ScannerLine").GetComponent<RectTransform>();
    5. lineTr.SetParent(_parentTransform, false);
    6. lineTr.anchorMax = lineTr.anchorMin = new Vector2(0.2507213f, 0.3643132f);
    7. GameObject.Destroy(GameObject.Find("VectorCanvas"));
    It's a little dirty to first create the line, search for it and change its parent. Then also delete the default canvas that Vectrosity generates automatically.
    All this could be solved having a SetParent method to the VectorLine instance and a method to get the GameObject of the line without searching it (or just a method to set the anchor to custom position);

    Another minor thing that is not clear if is a bug/limitation or by design. I have my graph a few levels inside a tree of rect transforms. The root of the tree has an Overlay canvas but in the editor view it still says "Line must be attached to a canvas". I also tried to add a canvas component to the parent of the line, but is the same.
     
  8. mcmorry

    mcmorry

    Joined:
    Dec 2, 2012
    Posts:
    580
    I tried to use the drawTransform instead of using SetParent.
    It works, but with two limitation:
    1. when I resize the viewport it doesn't follow the UI rescaling
    2. I still need to change the parent to use a mask.
     
  9. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Use VectorLine.SetMask for setting a mask. (In code; in the editor, setting the parent works...see "masking" on page 15 in the docs.)

    --Eric
     
    mcmorry likes this.
  10. jprocha101

    jprocha101

    Joined:
    Apr 8, 2015
    Posts:
    134
    Hi - I am using Draw3D, and and everything looks great in the editor. When running a build on my mobile device the resolution causes the the lines to be extremely thin and my end caps extremely small. I am using Draw3D because I want the line to appear behind a 3D object.

    Is there a way to get the lines to scale with screen size using Draw3D?

    Thanks!
     
  11. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can use Screen.dpi for the computation of line width.

    --Eric
     
    jprocha101 likes this.
  12. jprocha101

    jprocha101

    Joined:
    Apr 8, 2015
    Posts:
    134
    Ok. I thought there would be an easier way :) Thanks for the quick response.
     
  13. Ommand

    Ommand

    Joined:
    Apr 29, 2015
    Posts:
    6
    Hello!
    Just started learning Vectrosity5 and I have a small question, could anyone help with it please? I want to use Vectrosity in my 2D game to draw roads as a textured splines in the world space. What is the best way to do this thing? Is it to use LineManager like in the demo Simple3D? And what is the best way to draw this kind of world-space roads in editor, is there any way though? Thank you very much! :)
     
  14. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    There isn't a way to do it in the editor, since that's only for 2D lines. Vectrosity isn't meant as a road creation tool, but if they're strictly 2D, you can probably use MakeSpline and Draw3D.

    --Eric
     
  15. Maxii

    Maxii

    Joined:
    May 28, 2012
    Posts:
    45
    I'm looking to move my collection of 3D lines under a dedicated transform to get the clutter out of my root. I've tried VectorLine.rectTransform.parent = and VectorLIne.rectTransform.SetParent() but neither seem to have any affect.

    If it matters, my lines typically track a target as in VectorLine.drawTransform = targetTransform.

    Also, I'm doing the above right after making the line, before it is drawn if that matters.
     
    Last edited: Feb 14, 2016
  16. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You should draw the line first, then set the parent.

    --Eric
     
  17. Maxii

    Maxii

    Joined:
    May 28, 2012
    Posts:
    45
    Thanks for the quick response. I tried what you suggested but without results.

    After creating the line, I draw it once using Draw3D, then assign the parent using line.rectTransform.SetParent(), then launch a coroutine to continuously call Draw3D.

    After watching for a minute, some of the lines then moved and some didn't. Very strange. I'll do some more diagnosis work and report back.

    Anything wrong with my approach above that pops out at you?
     
    Last edited: Feb 14, 2016
  18. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Don't use the coroutine, instead use Draw3DAuto.

    --Eric
     
  19. Slawo

    Slawo

    Joined:
    Jan 29, 2014
    Posts:
    11
    Hi,

    I have a question, is it possible to retrieve the end index by using one of the points passed to build a VectorLine?

    For example I know the point I want to reach, and I want the line to animate up to that particular point...

    How should I proceed? (Using Vectrosity 4)
     
  20. Maxii

    Maxii

    Joined:
    May 28, 2012
    Posts:
    45
    I'd like to use Draw3DAuto, but I have to update the value of points3[1] every draw as my line is effectively a 'VelocityRay' visually showing movement direction and speed. I don't see a 'hook method' in your code that would allow me to do that just prior to Draw3DAuto using line.Draw3D in LateUpdate. Am I missing something or is this a defacto "feature request"? :)

    To my earlier question, do you see anything wrong with my "draw once, change parent, draw continuously" approach to changing the parent? It doesn't appear to lead to a very predictable outcome.

    Update: I got the parenting to work. I was attempting the parenting change after the first Draw3D but before I activated the line. Once I activated the line before calling Draw3D and then changing the parent, the results are reliable. ... To my point above, a hook to allow point changes just prior to drawing in LateUpdate would allow use of Draw3DAuto. What do you think?
     
    Last edited: Feb 15, 2016
  21. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Draw3DAuto does every frame in LateUpdate. If you do your changes in Update, then they are guaranteed to be done when the line is drawn.

    You could use List.IndexOf.

    --Eric
     
  22. Maxii

    Maxii

    Joined:
    May 28, 2012
    Posts:
    45
    I thought of that before I suggested the hook. Unfortunately, my class that sets up and operates Vectrosity is not a Monobehaviour so Update is not readily available, although I know I can make it happen if there is additional benefit using Draw3DAuto. Looking at the code, I see that Draw3DAuto deals with camera movement, which I'm not accounting for in my coroutine which only calls line.Draw3D. That would appear to be an additional benefit. Any others that come to mind?
     
  23. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    That's pretty much it.

    --Eric
     
  24. Maxii

    Maxii

    Joined:
    May 28, 2012
    Posts:
    45
    Eric, Well I can report that I've fully adopted Draw3DAuto and it is dealing with Camera motion well. I'm using a coroutine to update VelocityRay.points3[1] with current speed values, so that is working fine.

    Draw3DAuto of course needs to know the camera to deal with its motion and of course its default is Camera.main which I know I can change with VectorLine.SetCamera3D(). Here's my issue:

    I've got 2 cameras: MainCamera_Near (clip plane: .01 - 100, depth: -1) and MainCamera_Far (clip plane: 100 - 10000, depth: -2) to cover the range of distances I need to render. MainCamera_Near is tagged MainCamera. MainCamera_Far is a child of MainCamera_Near. When the camera that Vectrosity uses is MainCamera_Near , my lines that are far away jitter alot (I assume this is because MainCamera_Far is rendering them, but Draw3DAuto isn't compensating as it uses MainCamera_Near?). When I switch the camera Vectrosity knows about to MainCamera_Far, the jittering completely stops, but my lines that are close no longer render (not sure why?).

    From your experience and intimate knowledge of Unity and Vectrosity, how would you suggest handling this?

    Correction: When using MainCamera_Near, lines both close and far jitter alot. When using MainCamera_Far all jittering stops.
     
    Last edited: Feb 16, 2016
  25. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Vectrosity uses the camera's near clipping plane, so if you're using 100 for that, then line segments closer than that wouldn't render. You could use the source code, and in the IntersectAndDoSkip function, comment out everything except the last line ("return false"). (There would be potentially adverse effects as a result, of course, but just as a starting point to see if that fixes the immediate problem.)

    --Eric
     
  26. Liviuss

    Liviuss

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

    Just updated Vectrosity to 5.2.2 and i have some questions about 3D lines.
    I have 4 GameObjects with a different rotations from which i draw some direction lines with the code:
    Code (CSharp):
    1.  
    2. public Transform WeaponSlotTurret;
    3. public GameObject FollowLineL;
    4. public Material IndicatorMaterial;
    5. public float IndicatorTextureWidth;
    6. public float IndicatorTextureScale;
    7. public float LIndicatorLength;
    8. private Transform cTransform;
    9.  
    10. void Awake(){
    11.    cTransform = GetComponent<Transform> ();
    12.    VectorManager.useDraw3D = true;
    13. }
    14.  
    15. void Start(){
    16.    List<Vector3> LPoints = new List<Vector3> ();
    17.    Vector3 endPosL = WeaponSlotTurret.localPosition + (cTransform.InverseTransformVector (cTransform.up) * LIndicatorLength);
    18.    LPoints.Add (Vector3.zero);
    19.    LPoints.Add (endPosL);
    20.  
    21.    Lline = new VectorLine (FollowLineL.GetInstanceID().ToString(), LPoints, IndicatorTextureWidth);
    22.    Lline.material = IndicatorMaterial;
    23.    Lline.texture = IndicatorMaterial.mainTexture;
    24.    Lline.textureScale = IndicatorTextureScale;
    25.    Lline.layer = LayerMask.NameToLayer ("MiscEnv");
    26.  
    27.    VectorManager.ObjectSetup (FollowLineL, Lline, Visibility.Dynamic, Brightness.None);
    28. }
    29.  
    First issue(or it's normal behavior) i noticed that line does not pick the texture from material. After inspecting line object i saw that material does not contain texture. You have to set it in constructor or by setter. Seems that a new material is generated?

    Second issue i want to ask it's about dynamic batching. I expected batching to work with the 4 lines i created but it doesn't. It should or not batch the lines? Or a new material is created for each line? I have noticed in patch notes that it shouldn't create a new material if it's assigned by setter and material should be shared.

    Thanks.
    P.S. Unity 5.3.2p3, MacOS, Vectrosity 5.2.2
    P.S.S. I have attached the shader used on material in case you need it

    Code (CSharp):
    1. Shader "CustomAdditive" {
    2. Properties {
    3.     _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5)
    4.     _MainTex ("Particle Texture", 2D) = "white" {}
    5.     _InvFade ("Soft Particles Factor", Range(0.01,3.0)) = 1.0
    6. }
    7.  
    8. Category {
    9.     Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
    10.     Blend SrcAlpha One
    11.     AlphaTest Greater .01
    12.     ColorMask RGB
    13.     Cull Off Lighting Off ZWrite Off Fog { Mode Off }
    14.  
    15.     SubShader {
    16.         Pass {
    17.    
    18.             CGPROGRAM
    19.             #pragma vertex vert
    20.             #pragma fragment frag
    21.             #pragma multi_compile_particles
    22.  
    23.             #include "UnityCG.cginc"
    24.  
    25.             sampler2D _MainTex;
    26.             fixed4 _TintColor;        
    27.        
    28.             struct appdata_t {
    29.                 float4 vertex : POSITION;
    30.                 fixed4 color : COLOR;
    31.                 float2 texcoord : TEXCOORD0;
    32.             };
    33.  
    34.             struct v2f {
    35.                 float4 vertex : SV_POSITION;
    36.                 fixed4 color : COLOR;
    37.                 float2 texcoord : TEXCOORD0;
    38.                 #ifdef SOFTPARTICLES_ON
    39.                 float4 projPos : TEXCOORD1;
    40.                 #endif
    41.             };
    42.        
    43.             float4 _MainTex_ST;
    44.  
    45.             v2f vert (appdata_t v)
    46.             {
    47.                 v2f o;
    48.                 o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
    49.                 #ifdef SOFTPARTICLES_ON
    50.                 o.projPos = ComputeScreenPos (o.vertex);
    51.                 COMPUTE_EYEDEPTH(o.projPos.z);
    52.                 #endif
    53.                 o.color = v.color;
    54.                 o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);
    55.                 return o;
    56.             }
    57.  
    58.             sampler2D_float _CameraDepthTexture;
    59.             float _InvFade;
    60.        
    61.             fixed4 frag (v2f i) : SV_Target
    62.             {
    63.                 #ifdef SOFTPARTICLES_ON
    64.                 float sceneZ = LinearEyeDepth (SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)));
    65.                 float partZ = i.projPos.z;
    66.                 float fade = saturate (_InvFade * (sceneZ-partZ));
    67.                 i.color.a *= fade;
    68.                 #endif
    69.            
    70.                 return pow(i.color * _TintColor * tex2D(_MainTex, i.texcoord), 1);
    71.             }
    72.             ENDCG
    73.         }
    74.     }
    75. }
    76. }
     
    Last edited: Feb 17, 2016
  27. Maxii

    Maxii

    Joined:
    May 28, 2012
    Posts:
    45
    Eric, I worked things out to a satisfactory level for now by moving my MainCamera_Far nearClipPlane to < 10 which minimizes the lines that get clipped. Drawing the lines with this camera (vs MainCamera_Near) takes out all the jitter, although I'm not sure why.

    A couple of observations I'll share as I went through this process:
    1. In my efforts to cleanup my heirarchy, I moved the LineManager that now appears (since I'm now using Draw3DAuto) to another location under a GameObject. That of course keeps LineManager.DontDestroyOnLoad from working which means LineManager gets destroyed in a scene change without getting recreated. No biggee for me as I know how to relocate it back to the root if I need to when a scene is changing. As this is likely to happen to others, you might consider some kind of warning if you can detect that. Just a thought.
    2. I'm noticing a little flicker in my VelocityRay caused by points3[0] being updated via line.drawTransform during Update or LateUpdate. I'm guessing the flicker is a result of my ships being driven by physics during FixedUpdate - aka the ship changes position every FixedUpdate but is drawn in LateUpdate. I'm guessing this could be remedied if there was an option to run Draw3DAuto from other updates besides LateUpdate. Just a thought. The flickering is minor but noticeable when you get up close.

    Thanks for all your help. Great product!
     
  28. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes, sorry if that's confusing; it's intentional though.

    It should batch; here are 3 separate lines with the same material:

    Screen Shot 2016-02-17 at 5.05.11 PM.png

    There isn't really a way to handle it as far as I know; there's an OnLevelWasLoaded callback (at which point it's too late) but not OnLevelIsGonnaLoad.

    According to the documented execution order, LateUpdate always executes after FixedUpdate, and I'm not able to replicate any flickering as the result of physics here. Not that it should make any difference, but have you tried turning on physics interpolation?

    --Eric
     
  29. Liviuss

    Liviuss

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

    Well, for some reason it does not batch. Also i noticed that if you create a line outside frustrum and make the line inactive by Vectorline.enabled = false; when it come to the frustrum it's visible, i think it's an interference with Visibility.Dynamic from Vectormanager, can you confirm that?
    Also i have some weird issues with lines being shown with no reason (when i show 1 line another line from other gameobject also get visible but is set Vectorline.enabled = false). I have tried to disable gameobject instead of Vectorline.enabled but the line get visible with gameobject disabled.
     
  30. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Dynamic batching has some fairly severe limitations on the amount of vertex attributes you can use; otherwise the batching process would take more time than is saved by avoiding draw calls. As for the enabled stuff, it sounds like you shouldn't be using VectorManager; that's a way to make a VectorLine essentially be a "renderer" for a GameObject. Instead create lines and use Draw3D, then you can manage visibility yourself as you like.

    --Eric
     
  31. naatiq

    naatiq

    Joined:
    Sep 28, 2013
    Posts:
    7
    Does vectrosity work for animating lines, self drawing
    like this


    How is the performance compared to line renderer
     
  32. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can do whatever you want with lines, since you have complete control over the points used to draw them. The performance compared to the line renderer depends on what you're doing and what features you're using; it can either be faster or slower.

    --Eric
     
  33. naatiq

    naatiq

    Joined:
    Sep 28, 2013
    Posts:
    7
    Thanks for the quick reply

    I am talking of travelling line like in this game

    http://www.shockwave.com/gamelanding/thelinegamelimeedition.jsp

    is such thing possible using vectorsity,
     
  34. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    As I mentioned, you have complete control over the points used to draw lines in Vectrosity, so you can animate them however you like.

    --Eric
     
  35. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
  36. Scotty_

    Scotty_

    Joined:
    Dec 16, 2014
    Posts:
    3
    Hi Eric,

    I'm having a bit of trouble trying to change the color of a line at runtime.

    I'm using a shader that doesn't support myLine.SetColor() so I need to change it through it's renderer, but the vectorObject property doesn't appear to exist in Vectrosity 5 (is this correct?).

    Is there any way to access the actual line GameObject at runtime so I can access it's renderer component (ideally without just doing a GameObject.Find)?

    Thanks! Brilliant asset, by the way.
     
  37. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    VectorLine.rectTransform.GetComponent(Renderer)

    --Eric
     
  38. fbbgo

    fbbgo

    Joined:
    Oct 14, 2014
    Posts:
    20
    hello, I have a problem.

    why VectorManager.ObjectSetup working in start() function , but not working in update() or fixed update function?

    thanks.
     
  39. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It works in any function, but since it's something you'd only do once, I wouldn't recommend trying to use it in Update.

    --Eric
     
  40. fbbgo

    fbbgo

    Joined:
    Oct 14, 2014
    Posts:
    20
    below is my code, it just create gameobject has a rect canvas.

    void makeBound(GameObject obj)
    {
    List<Vector3> bb = new List<Vector3>(){new Vector3(-0.5f, -0.5f, 0.5f), new Vector3(0.5f, -0.5f, 0.5f), new Vector3(-0.5f, 0.5f, 0.5f), new Vector3(-0.5f, -0.5f, 0.5f), new Vector3(0.5f, -0.5f, 0.5f), new Vector3(0.5f, 0.5f, 0.5f), new Vector3(0.5f, 0.5f, 0.5f), new Vector3(-0.5f, 0.5f, 0.5f), new Vector3(-0.5f, 0.5f, -0.5f), new Vector3(-0.5f, 0.5f, 0.5f), new Vector3(0.5f, 0.5f, 0.5f), new Vector3(0.5f, 0.5f, -0.5f), new Vector3(0.5f, 0.5f, -0.5f), new Vector3(-0.5f, 0.5f, -0.5f), new Vector3(-0.5f, -0.5f, -0.5f), new Vector3(-0.5f, 0.5f, -0.5f), new Vector3(0.5f, 0.5f, -0.5f), new Vector3(0.5f, -0.5f, -0.5f), new Vector3(0.5f, -0.5f, -0.5f), new Vector3(-0.5f, -0.5f, -0.5f), new Vector3(-0.5f, -0.5f, 0.5f), new Vector3(-0.5f, -0.5f, -0.5f), new Vector3(0.5f, -0.5f, -0.5f), new Vector3(0.5f, -0.5f, 0.5f)};
    line = new VectorLine ("Shape", bb, null, 1.0f);
    line.color = Color.red;
    VectorManager.ObjectSetup(obj, line, Visibility.Dynamic, Brightness.None, false);
    }
    void FixedUpdate()
    {

    if (Input.GetMouseButtonUp(0))
    {
    makeBound(obj1);
    makeBound(obj2);
    VectorManager.useDraw3D = true;
    }
    }
     
  41. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Aha, I didn't test Visibility.Dynamic (the others work). You can fix this in the source, where at the end of the Setup function in the VisibilityControl script, add this:

    Code (csharp):
    1.         if (GetComponent<Renderer>().isVisible) {
    2.             OnBecameVisible();
    3.         }
    A few things: 1) Use code tags when posting code. 2) Never use input like that in FixedUpdate, since it doesn't run every frame and will miss input events. Always use Update. 3) You can use MakeCube instead of creating the cube with a bunch of points.

    --Eric
     
  42. fbbgo

    fbbgo

    Joined:
    Oct 14, 2014
    Posts:
    20
    thanks. It works but have other problems. I make select/unselect function, I guess it not works with complex situation. for example dynamically created GameObject.
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using Vectrosity;
    5.  
    6. public class Test : MonoBehaviour {
    7.     public GameObject obj1;
    8.     public GameObject obj2;
    9.     List<Vector3> bb;
    10.     VectorLine line;
    11.     void Start ()
    12.     {  
    13.         bb = new List<Vector3>(){new Vector3(-0.5f, -0.5f, 0.5f), new Vector3(0.5f, -0.5f, 0.5f), new Vector3(-0.5f, 0.5f, 0.5f), new Vector3(-0.5f, -0.5f, 0.5f), new Vector3(0.5f, -0.5f, 0.5f), new Vector3(0.5f, 0.5f, 0.5f), new Vector3(0.5f, 0.5f, 0.5f), new Vector3(-0.5f, 0.5f, 0.5f), new Vector3(-0.5f, 0.5f, -0.5f), new Vector3(-0.5f, 0.5f, 0.5f), new Vector3(0.5f, 0.5f, 0.5f), new Vector3(0.5f, 0.5f, -0.5f), new Vector3(0.5f, 0.5f, -0.5f), new Vector3(-0.5f, 0.5f, -0.5f), new Vector3(-0.5f, -0.5f, -0.5f), new Vector3(-0.5f, 0.5f, -0.5f), new Vector3(0.5f, 0.5f, -0.5f), new Vector3(0.5f, -0.5f, -0.5f), new Vector3(0.5f, -0.5f, -0.5f), new Vector3(-0.5f, -0.5f, -0.5f), new Vector3(-0.5f, -0.5f, 0.5f), new Vector3(-0.5f, -0.5f, -0.5f), new Vector3(0.5f, -0.5f, -0.5f), new Vector3(0.5f, -0.5f, 0.5f)};      
    14.         line = new VectorLine("Shape", bb, null, 1.0f);
    15.         line.color = Color.red;
    16.         VectorManager.ObjectSetup(obj2, line, Visibility.Dynamic, Brightness.None, false);
    17.         VectorManager.useDraw3D = true;
    18.     }
    19.        
    20.     void Update()
    21.     {
    22.  
    23.         if (Input.GetMouseButtonUp(0))
    24.         {  
    25.             VectorManager.ObjectSetup(obj2, line, Visibility.None, Brightness.None, false);
    26.            
    27.             Vector3 position = new Vector3(obj2.transform.position.x, obj2.transform.position.y * 2, obj2.transform.position.z);
    28.             GameObject obj3 = Instantiate(obj2, position, obj2.transform.rotation) as GameObject;
    29.             line = new VectorLine("Shape1", bb, null, 1.0f);
    30.             line.color = Color.red;
    31.             VectorManager.ObjectSetup(obj3, line, Visibility.Dynamic, Brightness.None, false);
    32.         }
    33.     }
    34. }
    above code throws error,
    NullReferenceException: Object reference not set to an instance of an object
    VisibilityControl.OnBecameVisible () (at Assets/Plugins/Vectrosity/Scripts/VisibilityControl.cs:32)

    what is problem, and you have other solutions?
     
  43. maciekfreak

    maciekfreak

    Joined:
    Sep 21, 2015
    Posts:
    23
    Hi Eric,

    I have issues with performance especially on mobile devices. In my project I have about 100 lines (flat - with y=0) and each line length is about 5000 (from pointA to pointB).

    For this lines I'm using following code:
    Code (CSharp):
    1. var points = new List<Vector3> ();
    2. points.Add (pointA);
    3. points.Add (pointB);
    4.  
    5. VectorLine.SetCamera3D(_camera2DObject);
    6. VectorLine line = new VectorLine ("test", points, 2f, LineType.Continuous);
    7. line.Draw3DAuto();
    Do you have any idea how to improve performance on this? Is there any "tricks" that I can use? After drawing these lines FPS on mobile drops to 8fps :/
     
  44. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    There are several logical problems with your code, such as attempting to use the same VectorLine for two objects, and creating an instance of a GameObject that's already had ObjectSetup applied to it, and trying to use ObjectSetup again with the instance. For any object using ObjectSetup, it must have a unique VectorLine, and you can't use ObjectSetup multiple times on the same object.

    That's just way too much for a typical mobile device to handle; there's not much you can do except to reduce the amount of lines and/or the number of points in each line.

    --Eric
     
  45. jrhee

    jrhee

    Joined:
    Dec 5, 2013
    Posts:
    74
    Hi,

    I'm getting some artifacts on my lines:



    It's a continuous line, using vector3s and weld joins with a width of .5f. The problem seems to occur when I use higher line widths, but I need thicker lines for some of the effects I'm going for.

    Any quick things I ought to check for?
     

    Attached Files:

  46. jrhee

    jrhee

    Joined:
    Dec 5, 2013
    Posts:
    74
    Figured it out, had the aniso level on my texture set too low. Thanks anyways!
     
  47. maciekfreak

    maciekfreak

    Joined:
    Sep 21, 2015
    Posts:
    23
    I do several things that help in my situation. Like changing shader for the lines. Don't using VectorLine.color to change color - instead changing material.

    I realised also that there is no problem with lines length (I'm creating each line from only two points - these are straight lines) but there is a problem with number of lines because each line is a new gameobject. Is there anything that can be done with this?
     
  48. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Oh, by "length" I thought you meant the number of points. So, you're using two points each, not 5000. In that case use a discrete line, and put all the line segments in a single VectorLine.

    --Eric
     
  49. maciekfreak

    maciekfreak

    Joined:
    Sep 21, 2015
    Posts:
    23
    I didn't know about discrete line :) Works perfectly. Is it possible to change color of one segment of the Line.discrete?
     
  50. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes, use SetColor.

    --Eric