Whinarn / UnityMeshSimplifier

Mesh simplification for Unity.
MIT License
1.75k stars 275 forks source link

Meshsimply error #4

Closed zj831007 closed 6 years ago

zj831007 commented 6 years ago

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

Whinarn commented 6 years ago

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.

Whinarn commented 6 years ago

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.

Whinarn commented 6 years ago

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.