How do I duplicate a mesh asset from fbx(the fbx has meshs) by use editor script?

I want peel the mesh from fbx,But Copy Mesh with this

static private Mesh CopyMesh(Mesh original)
{
    Mesh newMesh = new Mesh();
    newMesh.name = original.name;

    newMesh.vertices = original.vertices;
    newMesh.triangles = original.triangles;
    newMesh.uv = original.uv;
    newMesh.normals = original.normals;
    newMesh.tangents = original.tangents;
    return newMesh;
}

Save Use

AssetDatabase.CreateAsset(newMesh, newAssetPath);

The bindposes,bonesAABB … are not saved;Who know the [Ctrl+D] origin code?

To copy a mesh you can simply use Instantiate. Though keep in mind that with skinned mesh renderers you also have a “bones” array in the SkinnedMeshRenderer and the order of those bones are directly linked to the bind poses of the mesh. So the skinning information is kinda split into the bindposes and boneweights on the mesh side and the bones array on the SkinnedMeshRenderer side. Those have to fit together.

1 Like

Also the mesh is a sub-object of the fbx asset, so you could simply extract that asset and save it under a new name.

1 Like

Sounds interesting. However this part in the documentation may be an issue or the documentation is outdated:

I make more tests. CombineInstance makes new mesh bigger.

Solution by The code like this:

Mesh newMesh = new Mesh();
// Prefect Solution
EditorUtility.CopySerialized(originalMesh, newMesh);
AssetDatabase.CreateAsset(newMesh, newAssetPath);

Thank’s Everyone!!!