Search Unity

Unity seems to be creating new vertexes in my meshes... Can I make it stop? Please.

Discussion in 'Editor & General Support' started by Jaimi, Dec 19, 2011.

  1. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    6,208
    I have a literal ton of morph data stored in meshes. I have one mesh for each type of Morph. Each mesh has 396 vertexes and two materials. Exactly the same, and assigned exactly the same (except for Vertex Position of course).

    Yet when I import, they all have a different vertex count. Instead of 396, the base mesh has 479, and the Morph Mesh has 483!

    I've turned off everything that seems appropriate - ie, I have turned off Mesh Compression. I've told it to Import Normals and Import Tangents. I've even turned off animation compression, even though it's not animated.

    Is there a way I can tell Unity to behave? Ie, I don't care if it needs to insert new vertexes, but can I at least get it to do it consistently!

    Otherwise, I'm not really aware of how to figure out how to create my morphs. I suppose I could preprocess the FBX to build a delta file, and then do some matching-by-position algorithm at load time. But this is a ton of work that I won't have to do if Unity would just be consistent.
     
  2. Cameron_SM

    Cameron_SM

    Joined:
    Jun 1, 2009
    Posts:
    915
    If you have UV seams then unity will have to duplicate the vertices along those seams.

    Makes sense when you think about it, each vertex can hold only a single UV coordinate and the GPU draws triangle by triangle with 3 position and 3 UV coordinates per triangle, the vertex pipeline interpolates the UV coordinates across the face of that triangle very quickly to map your texture. The GPU doesn't need know about nearby triangles while doing this so it can do millions of these at the same time in parallel. If the UV's are seamless, Unity can save data throughput by re-using vertices for adjoining triangles as at each vertex the UV coords will be the same but if there's a seam those two triangles can't use that same vertex data. If a vertex has multiple UV coordinates, one for each triangle due to seams then the vertex pipeline of the GPU would have to decide which UV coordinate to use for the current triangle it's drawing, this kind of conditional processing in a massively parallel system like a GPU is slow, it's a million times faster just to submit a different vertex with a different UV coordinate so the GPU doesn't need to waste time making a decision and just gets on with drawing.

    Of course, the CPU could submit a separate vertex to the GPU with the other UV coordinate at runtime, but again why bother doing that, to the GPU it's still a separate vertex and it'll always be faster to "bake" the duplicate vertices into the mesh data rather then extracting the 2nd UV coordinate every frame as the information is static.

    Also, this is not unique to Unity, every game engine does this. Always keep in mind the vertex count of your 3D authoring/modelling program is probably not accurate as they don't need to store info in a real-time rendering friendly format.
     
    Last edited: Dec 19, 2011
  3. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    6,208
    I agree 100% with what you are saying. However, since the meshes are a duplicate of each other, and only the vertex positions are different, in the case where it needed to duplicate vertexes for UV reasons, shouldn't it come out with the same number of vertexes at the end? The only thing that has changed is the position of the vertex in 3d space, nothing else. It's like it's trying to do some sort of optimization on duplicated vertexes or something.
     
  4. tchpowdog

    tchpowdog

    Joined:
    Nov 25, 2011
    Posts:
    255
    did you triple the polygon mesh before you exported??

    *EDIT*
    I guess that wouldn't change the vertices...
     
  5. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
  6. Cameron_SM

    Cameron_SM

    Joined:
    Jun 1, 2009
    Posts:
    915
    Are you using any kind of automatic UV projections for either of those materials on you mesh that might be causing extra seams after the vertices are moved?

    As a general process of elimination: If you remove all materials, does it still happen?
     
  7. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    6,208
    It's using a single multi-layer material -- the meshes are character faces, and one layer of the material has transparency, for eyelashes (it's actually the same texture, just a second material def). I'll reset everything to a single-layer material, and see if it goes away. I may need to rebuild the eyelashes as a mesh. Strange, but that might even be faster to render.
     
  8. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    6,208
    No dice, even with a single material, and with normals and tangents imported, it's still off. I'm going to have to preprocess them, what a massive pain.
     
  9. MikeUpchat

    MikeUpchat

    Joined:
    Sep 24, 2010
    Posts:
    1,056
    Or get one of the morphing solutions available to take the pain out of it :)
     
  10. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    6,208
    I already bought CP Morphing, but it needs the vertex count to be the same also. I'm loathe to spend any more money for things that won't work for me... I'll write the Megafiers guy and see if his will work...
     
  11. hai_ok

    hai_ok

    Joined:
    Jun 20, 2007
    Posts:
    193
    I am looking for a Morphing solution. I am told CP Morphing Lab isn't reliably able to assign morph targets. Is this true? I want to spend the money but I want a tool that works.

    I am also looking at Megafiers. Does it work any differently?

    There was also a solution that featured an octopus, but I don't see it anymore. Anyone know where that went?
     
  12. MikeUpchat

    MikeUpchat

    Joined:
    Sep 24, 2010
    Posts:
    1,056