Whinarn / UnityMeshSimplifier

Mesh simplification for Unity.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Meshsimply error

zj831007 opened this issue · comments

I use as this:

public class TestSimplifier : MonoBehaviour {

// Use this for initialization
void Start () {

    SkinnedMeshRenderer mr =  this.GetComponent<SkinnedMeshRenderer>();

    float quality = 0.5f;
    var meshSimplifier = new UnityMeshSimplifier.MeshSimplifier();
    meshSimplifier.Initialize(mr.sharedMesh);
    meshSimplifier.EnableSmartLink = true;
    meshSimplifier.PreserveBorders = true;
    meshSimplifier.SimplifyMesh(quality);

    var destMesh = meshSimplifier.ToMesh();
    mr.sharedMesh = destMesh;
}

// Update is called once per frame
void Update () {
	
}

}
and the result is that, the simply mesh is rotation wrong, see the attach file:
image

I am very certain that this has to do with bindposes not being copied over automatically, seeing that you are simplifying a skinned mesh.

At this time you would have to do that manually.

Example:

void Start()
{
    SkinnedMeshRenderer mr =  this.GetComponent<SkinnedMeshRenderer>();

    float quality = 0.5f;
    var meshSimplifier = new UnityMeshSimplifier.MeshSimplifier();´
    var bindposes = mr.sharedMesh.bindposes; // <--- This line
    meshSimplifier.Initialize(mr.sharedMesh);
    meshSimplifier.EnableSmartLink = true;
    meshSimplifier.PreserveBorders = true;
    meshSimplifier.SimplifyMesh(quality);

    var destMesh = meshSimplifier.ToMesh();
    destMesh.bindposes = bindposes; // <--- As well as this line
    mr.sharedMesh = destMesh;
}

But I have to warn you that bone weights are not properly merged at the moment so you might experience holes and artifacts if the mesh is animated. This is something that I have planned to look into. But please post your results once you try what I posted above.

Could you please try out the latest release https://github.com/Whinarn/UnityMeshSimplifier/tree/v1.0.0
This should fix your issue as well as the issue I described above with bone weights.

@zj831007 Please confirm if this works for you or not.

I will consider this issue as being fixed and will now close this.
@zj831007 Please re-open if you are still having issues with this.