-
-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
340 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
Packages/src/Runtime/Internal/Extensions/MeshExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using UnityEngine; | ||
|
||
namespace Coffee.UISoftMaskInternal | ||
{ | ||
internal static class MeshExtensions | ||
{ | ||
internal static readonly ObjectPool<Mesh> s_MeshPool = new ObjectPool<Mesh>( | ||
() => | ||
{ | ||
var mesh = new Mesh | ||
{ | ||
hideFlags = HideFlags.DontSave | HideFlags.NotEditable | ||
}; | ||
mesh.MarkDynamic(); | ||
return mesh; | ||
}, | ||
mesh => mesh, | ||
mesh => | ||
{ | ||
if (mesh) | ||
{ | ||
mesh.Clear(); | ||
} | ||
}); | ||
|
||
public static Mesh Rent() | ||
{ | ||
return s_MeshPool.Rent(); | ||
} | ||
|
||
public static void Return(ref Mesh mesh) | ||
{ | ||
s_MeshPool.Return(ref mesh); | ||
} | ||
|
||
public static void CopyTo(this Mesh self, Mesh dst) | ||
{ | ||
if (!self || !dst) return; | ||
|
||
var vector3List = ListPool<Vector3>.Rent(); | ||
var vector4List = ListPool<Vector4>.Rent(); | ||
var color32List = ListPool<Color32>.Rent(); | ||
var intList = ListPool<int>.Rent(); | ||
|
||
dst.Clear(false); | ||
|
||
self.GetVertices(vector3List); | ||
dst.SetVertices(vector3List); | ||
|
||
self.GetTriangles(intList, 0); | ||
dst.SetTriangles(intList, 0); | ||
|
||
self.GetNormals(vector3List); | ||
dst.SetNormals(vector3List); | ||
|
||
self.GetTangents(vector4List); | ||
dst.SetTangents(vector4List); | ||
|
||
self.GetColors(color32List); | ||
dst.SetColors(color32List); | ||
|
||
self.GetUVs(0, vector4List); | ||
dst.SetUVs(0, vector4List); | ||
|
||
self.GetUVs(1, vector4List); | ||
dst.SetUVs(1, vector4List); | ||
|
||
self.GetUVs(2, vector4List); | ||
dst.SetUVs(2, vector4List); | ||
|
||
self.GetUVs(3, vector4List); | ||
dst.SetUVs(3, vector4List); | ||
|
||
dst.RecalculateBounds(); | ||
ListPool<Vector3>.Return(ref vector3List); | ||
ListPool<Vector4>.Return(ref vector4List); | ||
ListPool<Color32>.Return(ref color32List); | ||
ListPool<int>.Return(ref intList); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Packages/src/Runtime/Internal/Extensions/MeshExtensions.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.