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?
using UnityEngine;
public class CopyMesh : MonoBehaviour
{
void Start()
{
// original
SkinnedMeshRenderer originalSkin = transform.GetComponentInChildren<SkinnedMeshRenderer>();
Mesh originalMesh = originalSkin.sharedMesh;
// copy
SkinnedMeshRenderer copySkin = transform.gameObject.AddComponent<SkinnedMeshRenderer>();
Mesh copyMesh = new Mesh();
// set up copy's SkinnedMeshRenderer
copySkin.sharedMesh = copyMesh;
copySkin.material = originalSkin.materials[0];
copySkin.bones = originalSkin.bones;
copySkin.rootBone = originalSkin.rootBone;
// copy over required vertex data
copyMesh.bindposes = originalMesh.bindposes;
copyMesh.vertices = originalMesh.vertices;
copyMesh.normals = originalMesh.normals;
copyMesh.uv = originalMesh.uv;
copyMesh.boneWeights = originalMesh.boneWeights;
copyMesh.triangles = originalMesh.triangles;
// disable original SkinnedMeshRenderer so that only the copy shows up
originalSkin.enabled = false;
}
}