Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Odd results trying to get a mesh's vertex count

Discussion in 'Scripting' started by Nanako, Dec 5, 2014.

  1. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    I'm using this code snippet, from a script inside the object in question:

    Code (CSharp):
    1. Mesh temp = gameObject.GetComponent<MeshFilter>().sharedMesh;
    2.         if (temp)
    3.             print("Name|Vertices: " +gameObject.name+"|"+ temp.vertices.Length);
    And here's a sample object;

    As far as i'm concerned, this object should take exactly 14 vertices to create. and yet my debug output for it is:

    Name|Vertices: Brickwall68|314

    314 vertices. What?
    Is this correct? Did i screw up the code somewhere?

    These objects are dynamically generated by an editor extension i purchased, i want to be sure this is correct before i go shouting at the author.
     
  2. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    Uh, yeah... that's quite clearly got more than 14 verts

    ...etc
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    There's no way that could be done with 14 vertices even if you get rid of all the redundant geometry; just the visible faces alone would need 19 vertices. If the rest of it looks like I imagine, it would be 42 verts.

    --Eric
     
  4. ZO5KmUG6R

    ZO5KmUG6R

    Joined:
    Jul 15, 2010
    Posts:
    490
    There's also this

    [this not thos. xD]


    And in Unity each texture is on its separate set of vertices, due to the way the UV works
     
  5. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    this can't be right, if constructed correctly (which admittedly, it isn't,) the number of vertices couldn't possibly be odd. It's basically just a somewhat complex front face extruded forward a bit, so the vertex count should be 2n, the entire area between the front and back should be all squares and contain no additional verts of its own.

    all that said, it seems like theere's a ton of worthless geometry on the side parts: http://puu.sh/diHZ7/1f30caff13.jpg

    is my code correct then? is this really over 300 vertices?
     
  6. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    you know, i don't actyually need sharp edges here, infact i'd prefer them to be rendered more smoothly. if this is indeed the case, is there any way to join those up and make it not split ?
     
  7. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    does anyone know of a simple tool to fix this object? All i'd really need is something to check the angle between two edges, and to merge them(and remove the intervening vertex) if that angle is below a certain value. I think in most of these cases, that angle is almost zero/180

    how complex would it be to write such a thing myself? mesh processing is a new area for me.
     
  8. ZO5KmUG6R

    ZO5KmUG6R

    Joined:
    Jul 15, 2010
    Posts:
    490
    If you do end up merging them though the mesh will end up looking like this shading-wise. Like i said black spots will appear and it'll be odd
     
  9. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Erm, 42 isn't an odd number last I checked. (Significant, maybe, but not odd.)

    You don't want that; vertices must be split on normals and UV edges and can't be merged. Or at least not without completely screwing up the model.

    --Eric
     
    ZO5KmUG6R likes this.