Search Unity

Vertex count mystery.

Discussion in 'General Graphics' started by thorham3011, Jan 26, 2020.

  1. thorham3011

    thorham3011

    Joined:
    Sep 7, 2017
    Posts:
    25
    I have a skinned character model that's imported from an FBX file. In play mode the stats show that this model has 13.5k vertices. With the script below attached the stats say the model uses only 4.4k vertices.

    The script simply adds a SkinnedMeshRenderer to the model's gameobject and then copies all the relevant mesh data over from the original SkinnedMeshRenderer (gameobject child) to the newly added one.

    The original model has a several materials that are all the same (except hair), and the copy simply uses one material (looks fine, except for the hair of course).

    Can anyone explain why the copy has a much lower vertex count than the original?

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class CopyMesh : MonoBehaviour
    4. {
    5.     void Start()
    6.     {
    7.         // original
    8.  
    9.         SkinnedMeshRenderer originalSkin = transform.GetComponentInChildren<SkinnedMeshRenderer>();
    10.         Mesh originalMesh = originalSkin.sharedMesh;
    11.  
    12.         // copy
    13.  
    14.         SkinnedMeshRenderer copySkin = transform.gameObject.AddComponent<SkinnedMeshRenderer>();
    15.         Mesh copyMesh = new Mesh();
    16.  
    17.         // set up copy's SkinnedMeshRenderer
    18.  
    19.         copySkin.sharedMesh = copyMesh;
    20.         copySkin.material = originalSkin.materials[0];
    21.         copySkin.bones = originalSkin.bones;
    22.         copySkin.rootBone = originalSkin.rootBone;
    23.  
    24.         // copy over required vertex data
    25.  
    26.         copyMesh.bindposes = originalMesh.bindposes;
    27.         copyMesh.vertices = originalMesh.vertices;
    28.         copyMesh.normals = originalMesh.normals;
    29.         copyMesh.uv = originalMesh.uv;
    30.         copyMesh.boneWeights = originalMesh.boneWeights;
    31.         copyMesh.triangles = originalMesh.triangles;
    32.  
    33.         // disable original SkinnedMeshRenderer so that only the copy shows up
    34.  
    35.         originalSkin.enabled = false;
    36.     }
    37. }
    38.  
     
  2. MikeUpchat

    MikeUpchat

    Joined:
    Sep 24, 2010
    Posts:
    1,056
    The stats show the number of vertices going through the whole pipeline, so if you have multiple passes due to things like shadows or multiple lights then the count will increase, from your figures 13.5k vertices is 3 times 4.4k so there is probably three passes going on.
     
    BrandyStarbrite likes this.
  3. thorham3011

    thorham3011

    Joined:
    Sep 7, 2017
    Posts:
    25
    I highly doubt that that's what's going on here. When I split the model into separate meshes for each material in Blender, then the vertex count in Unity is small as well.

    Basically, when I have one material for each mesh the vertex count is low, when I have one mesh with several materials then the vertex count is three times as high.

    Fixing this isn't the problem, I just want to know what's going on here.