浏览代码

add conditional support for MeshUpdateFlags

/main
Lasse Jon Fuglsang Pedersen 5 年前
当前提交
1869a6f9
共有 4 个文件被更改,包括 73 次插入20 次删除
  1. 65
      Runtime/MeshTools/MeshEx.cs
  2. 12
      Runtime/SkinAttachment.cs
  3. 6
      Runtime/SkinAttachmentTarget.cs
  4. 10
      Runtime/SkinDeformationRenderer.cs

65
Runtime/MeshTools/MeshEx.cs


using UnityEngine;
using UnityEngine.Rendering;
public static class MeshEx
public static class MeshEx
#if UNITY_2020_1_OR_NEWER
const MeshUpdateFlags UPDATE_FLAGS_SILENT =
MeshUpdateFlags.DontNotifyMeshUsers |
MeshUpdateFlags.DontRecalculateBounds |
MeshUpdateFlags.DontResetBoneBounds;
#endif
#endif
}
public static void SilentlySetVertices(this Mesh mesh, Vector3[] positions)
{
#if UNITY_2020_1_OR_NEWER
mesh.SetVertices(positions, 0, positions.Length, UPDATE_FLAGS_SILENT);
#else
mesh.EnableSilentWrites(true);
mesh.SetVertices(positions, 0, positions.Length);
mesh.EnableSilentWrites(false);
#endif
}
public static void SilentlySetNormals(this Mesh mesh, Vector3[] normals)
{
#if UNITY_2020_1_OR_NEWER
mesh.SetNormals(normals, 0, normals.Length, UPDATE_FLAGS_SILENT);
#else
mesh.EnableSilentWrites(true);
mesh.SetNormals(normals, 0, normals.Length);
mesh.EnableSilentWrites(false);
#endif
}
public static void SilentlyRecalculateTangents(this Mesh mesh)
{
#if UNITY_2020_1_OR_NEWER
mesh.RecalculateTangents(UPDATE_FLAGS_SILENT);
#else
mesh.EnableSilentWrites(true);
mesh.RecalculateTangents();
mesh.EnableSilentWrites(false);
#endif
}
public static void SilentlyRecalculateNormals(this Mesh mesh)
{
#if UNITY_2020_1_OR_NEWER
mesh.RecalculateNormals(UPDATE_FLAGS_SILENT);
#else
mesh.EnableSilentWrites(true);
mesh.RecalculateNormals();
mesh.EnableSilentWrites(false);
#endif
}
public static void SilentlyRecalculateBounds(this Mesh mesh)
{
#if UNITY_2020_1_OR_NEWER
mesh.RecalculateBounds(UPDATE_FLAGS_SILENT);
#else
mesh.EnableSilentWrites(true);
mesh.RecalculateBounds();
mesh.EnableSilentWrites(false);
#endif
}
}

12
Runtime/SkinAttachment.cs


var forceRecalculateAny = forceRecalculateBounds || forceRecalculateNormals || forceRecalculateTangents;
if (forceRecalculateAny && meshInstance != null)
{
meshInstance.EnableSilentWrites(true);
if (forceRecalculateNormals)
meshInstance.RecalculateNormals();
meshInstance.RecalculateTangents();
meshInstance.SilentlyRecalculateTangents();
if (forceRecalculateNormals)
meshInstance.SilentlyRecalculateNormals();
meshInstance.RecalculateBounds();
meshInstance.EnableSilentWrites(false);
meshInstance.SilentlyRecalculateBounds();
}
}

6
Runtime/SkinAttachmentTarget.cs


break;
}
subject.meshInstance.EnableSilentWrites(true);
subject.meshInstance.vertices = stagingData[indexPos];
subject.meshInstance.normals = stagingData[indexNrm];
subject.meshInstance.EnableSilentWrites(false);
subject.meshInstance.SilentlySetVertices(stagingData[indexPos]);
subject.meshInstance.SilentlySetNormals(stagingData[indexPos]);
//Profiler.BeginSample("recalc-bounds");
//subject.meshInstance.RecalculateBounds();

10
Runtime/SkinDeformationRenderer.cs


smr.SetPropertyBlock(smrProps);
}
meshInstance.EnableSilentWrites(true);
meshInstance.vertices = blendedPositions;
meshInstance.normals = blendedNormals;
meshInstance.EnableSilentWrites(false);
meshInstance.SilentlySetVertices(blendedPositions);
meshInstance.SilentlySetNormals(blendedNormals);
meshInstance.EnableSilentWrites(true);
meshInstance.RecalculateTangents();
meshInstance.EnableSilentWrites(false);
meshInstance.SilentlyRecalculateTangents();
}
if (renderFittedWeights)

正在加载...
取消
保存