Search Unity

Using mesh.Topology points

Discussion in 'Scripting' started by scrawk, Jan 21, 2013.

  1. scrawk

    scrawk

    Joined:
    Nov 22, 2012
    Posts:
    804
    Hi, Im trying to create a mesh via script and render it as a point cloud.

    To start I just created a mesh with a single triangle and render as normal. Everything works fine. I see a red triangle on screen. But when trying to render as point cloud I see nothing. Im using the default diffuse shader with red as the color.

    Im thinking maybe the point size is to small to see points or the diffuse shader will not render points for some reason.

    Heres the code. Its a script attached to a game object with mesh filter and render component.

    Any ideas why this wont work?

    function Start ()
    {

    var newVertices : Vector3[] = new Vector3[3];
    var newIndices : int[] = new int[3];
    var newNormals : Vector3[] = new Vector3[3];
    var newUV : Vector2[] = new Vector2[3];

    newVertices[0] = Vector3(0,0,0);
    newVertices[1] = Vector3(0,10,0);
    newVertices[2] = Vector3(0,10,10);

    newNormals[0] = Vector3(0,1,0);
    newNormals[1] = Vector3(0,1,0);
    newNormals[2] = Vector3(0,1,0);

    newUV[0] = Vector2(0,0);
    newUV[1] = Vector2(0,0);
    newUV[2] = Vector2(0,0);

    newIndices[0] = 2;
    newIndices[1] = 1;
    newIndices[2] = 0;

    var mesh : Mesh = new Mesh();
    GetComponent(MeshFilter).mesh = mesh;

    mesh.vertices = newVertices;
    mesh.normals = newNormals;
    mesh.uv = newUV;

    //mesh.triangles = newIndices; //uncomment this and comment next line to render as triangle

    mesh.SetIndices(newIndices, MeshTopology.Points, 0);

    }
     
    Last edited: Jan 21, 2013
  2. Cameron_SM

    Cameron_SM

    Joined:
    Jun 1, 2009
    Posts:
    915
    I believe it's up to your graphics card how it wants to render in point mode as it just passes that rendering mode along to the video card so depending on your OS and API output (Direct X on Windows, Open GL on everything else) it might just ignore points as they're rarely used for actual rendering. Same goes for lines mode. I only think points typology was added for completeness, no one really uses it by itself for rendering, might be useful for DX11 or compute stuff though as it would possibly reduce FBO overheads, maybe.

    Always seemed a little pointless when I saw that addition to Unity 4, DX11/Compute is the only thing I can think of that would justify Unity adding it, but I'm by no means a GPU/Shader guru, (I just like to dabble) so don't take my word as scripture on any of this.
     
    Last edited: Jan 21, 2013
  3. scrawk

    scrawk

    Joined:
    Nov 22, 2012
    Posts:
    804
    Thanks Cameron. Yes, I do think its a rarely used feature as well. I really could find much about it google.

    I was hoping to expand the points into quads via a geometry shader for drawing billboards. This way I only need to store one vert per billboard instead of four.
    But I guess I can just store the mesh as quads instead.
     
  4. Cameron_SM

    Cameron_SM

    Joined:
    Jun 1, 2009
    Posts:
    915
    Let me know how you get on with that.

    I've used the mesh class a lot for my own sprite based stuff and particle systems. Haven't really had a chance to play with them since Unity 4 released though as I've been working on other things. I was doing some annoying buffering to help minimise per frame allocations and generally just setting four verts to the same point and overloading per-vertex normal data with info to specify quad x/y scale and rotation that would re-position the verts in a vertex shader (rather than scaling and doing rotations on the CPU).

    Was hoping the different topology modes might speed up some things (like triangle array allocations) but just haven't had the time to play around with any of it.
     
  5. superme2012

    superme2012

    Joined:
    Nov 5, 2012
    Posts:
    207
    I had the same problem, no points... Its very annoying that there is no "Mesh as Points" setting. I need to apply to multiple models within the scene. Haven't find a solution yet.
     
  6. TMPxyz

    TMPxyz

    Joined:
    Jul 20, 2012
    Posts:
    766
    The points are just too small, 1px maybe.
    You need to gaze at the screen to find it, swipe the screen clean first

    upload_2015-3-1_13-16-54.png
     
    Last edited: Mar 1, 2015
    remotedeveloper likes this.