Change mesh writing to prevent duplicate objects.

Mesh reading still needs to be updated.