Skip to content

GeorgeAdamon/FastMeshCopy

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
img
 
 
 
 
 
 

FastMeshCopy

Zero-allocation copying of Meshes using the new MeshData functionality in Unity 2020.1+.

The code comes in the form of the static class FastMeshCopy with the

public static void CopyTo(this Mesh inMesh, ref Mesh outMesh){...}

and

public static Mesh CopyReplicate(this Mesh mesh, NativeArray<float4x4> matrices) {...}

extension methods.
Simply call this method on a Mesh instance to perform either a Single Copy, or a Multi-Copy based on an array of transformations + Merge.

Add as a Unity Package

Add this line to your Packages/manifest.json file

"ulc-tools-fastmeshcopy": "https://github.com/GeorgeAdamon/FastMeshCopy.git?path=/UnityProject/Assets/FastMeshCopy#master",

Usage of the Single Copy example

  • Attach the MeshCopyExample.cs to a GameObject, and reference a Mesh in the inMesh field.
  • Run the game, and press the Spacebar to perform the mesh copy.

Limitations

Accessing BlendShapes and BoneWeights without GC allocations is not supported by Unity's API, so this zero-allocation effort ignores them for the time being. See the discussion

Performance Example

Copying of a 98 MB mesh, creating only 80 Bytes of allocations for the Garbage Collector to clean-up.

About

Zero-allocation copying of Meshes using the new MeshData functionality in Unity 2020.1+ .

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages