Add support for uint as triangle indices for mesh updates API
This commit is contained in:
@@ -144,7 +144,7 @@ namespace FlaxEngine
|
||||
if (colors != null && colors.Length != vertices.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(colors));
|
||||
|
||||
if (Internal_UpdateMeshInt(
|
||||
if (Internal_UpdateMeshUInt(
|
||||
__unmanagedPtr,
|
||||
vertices.Length,
|
||||
triangles.Length / 3,
|
||||
@@ -190,7 +190,100 @@ namespace FlaxEngine
|
||||
if (colors != null && colors.Count != vertices.Count)
|
||||
throw new ArgumentOutOfRangeException(nameof(colors));
|
||||
|
||||
if (Internal_UpdateMeshInt(
|
||||
if (Internal_UpdateMeshUInt(
|
||||
__unmanagedPtr,
|
||||
vertices.Count,
|
||||
triangles.Count / 3,
|
||||
Utils.ExtractArrayFromList(vertices),
|
||||
Utils.ExtractArrayFromList(triangles),
|
||||
Utils.ExtractArrayFromList(normals),
|
||||
Utils.ExtractArrayFromList(tangents),
|
||||
Utils.ExtractArrayFromList(uv),
|
||||
Utils.ExtractArrayFromList(colors)
|
||||
))
|
||||
throw new FlaxException("Failed to update mesh data.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the model mesh vertex and index buffer data.
|
||||
/// Can be used only for virtual assets (see <see cref="Asset.IsVirtual"/> and <see cref="Content.CreateVirtualAsset{T}"/>).
|
||||
/// Mesh data will be cached and uploaded to the GPU with a delay.
|
||||
/// </summary>
|
||||
/// <param name="vertices">The mesh vertices positions. Cannot be null.</param>
|
||||
/// <param name="triangles">The mesh index buffer (clockwise triangles). Uses 32-bit stride buffer. Cannot be null.</param>
|
||||
/// <param name="normals">The normal vectors (per vertex).</param>
|
||||
/// <param name="tangents">The normal vectors (per vertex). Use null to compute them from normal vectors.</param>
|
||||
/// <param name="uv">The texture coordinates (per vertex).</param>
|
||||
/// <param name="colors">The vertex colors (per vertex).</param>
|
||||
public void UpdateMesh(Vector3[] vertices, uint[] triangles, Vector3[] normals = null, Vector3[] tangents = null, Vector2[] uv = null, Color32[] colors = null)
|
||||
{
|
||||
// Validate state and input
|
||||
if (!ParentModel.IsVirtual)
|
||||
throw new InvalidOperationException("Only virtual models can be updated at runtime.");
|
||||
if (vertices == null)
|
||||
throw new ArgumentNullException(nameof(vertices));
|
||||
if (triangles == null)
|
||||
throw new ArgumentNullException(nameof(triangles));
|
||||
if (triangles.Length == 0 || triangles.Length % 3 != 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(triangles));
|
||||
if (normals != null && normals.Length != vertices.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(normals));
|
||||
if (tangents != null && tangents.Length != vertices.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(tangents));
|
||||
if (tangents != null && normals == null)
|
||||
throw new ArgumentException("If you specify tangents then you need to also provide normals for the mesh.");
|
||||
if (uv != null && uv.Length != vertices.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(uv));
|
||||
if (colors != null && colors.Length != vertices.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(colors));
|
||||
|
||||
if (Internal_UpdateMeshUInt(
|
||||
__unmanagedPtr,
|
||||
vertices.Length,
|
||||
triangles.Length / 3,
|
||||
vertices, triangles,
|
||||
normals,
|
||||
tangents,
|
||||
uv,
|
||||
colors
|
||||
))
|
||||
throw new FlaxException("Failed to update mesh data.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the model mesh vertex and index buffer data.
|
||||
/// Can be used only for virtual assets (see <see cref="Asset.IsVirtual"/> and <see cref="Content.CreateVirtualAsset{T}"/>).
|
||||
/// Mesh data will be cached and uploaded to the GPU with a delay.
|
||||
/// </summary>
|
||||
/// <param name="vertices">The mesh vertices positions. Cannot be null.</param>
|
||||
/// <param name="triangles">The mesh index buffer (clockwise triangles). Uses 32-bit stride buffer. Cannot be null.</param>
|
||||
/// <param name="normals">The normal vectors (per vertex).</param>
|
||||
/// <param name="tangents">The normal vectors (per vertex). Use null to compute them from normal vectors.</param>
|
||||
/// <param name="uv">The texture coordinates (per vertex).</param>
|
||||
/// <param name="colors">The vertex colors (per vertex).</param>
|
||||
public void UpdateMesh(List<Vector3> vertices, List<uint> triangles, List<Vector3> normals = null, List<Vector3> tangents = null, List<Vector2> uv = null, List<Color32> colors = null)
|
||||
{
|
||||
// Validate state and input
|
||||
if (!ParentModel.IsVirtual)
|
||||
throw new InvalidOperationException("Only virtual models can be updated at runtime.");
|
||||
if (vertices == null)
|
||||
throw new ArgumentNullException(nameof(vertices));
|
||||
if (triangles == null)
|
||||
throw new ArgumentNullException(nameof(triangles));
|
||||
if (triangles.Count == 0 || triangles.Count % 3 != 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(triangles));
|
||||
if (normals != null && normals.Count != vertices.Count)
|
||||
throw new ArgumentOutOfRangeException(nameof(normals));
|
||||
if (tangents != null && tangents.Count != vertices.Count)
|
||||
throw new ArgumentOutOfRangeException(nameof(tangents));
|
||||
if (tangents != null && normals == null)
|
||||
throw new ArgumentException("If you specify tangents then you need to also provide normals for the mesh.");
|
||||
if (uv != null && uv.Count != vertices.Count)
|
||||
throw new ArgumentOutOfRangeException(nameof(uv));
|
||||
if (colors != null && colors.Count != vertices.Count)
|
||||
throw new ArgumentOutOfRangeException(nameof(colors));
|
||||
|
||||
if (Internal_UpdateMeshUInt(
|
||||
__unmanagedPtr,
|
||||
vertices.Count,
|
||||
triangles.Count / 3,
|
||||
@@ -314,7 +407,7 @@ namespace FlaxEngine
|
||||
if (triangles.Length == 0 || triangles.Length % 3 != 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(triangles));
|
||||
|
||||
if (Internal_UpdateTrianglesInt(
|
||||
if (Internal_UpdateTrianglesUInt(
|
||||
__unmanagedPtr,
|
||||
triangles.Length / 3,
|
||||
triangles
|
||||
@@ -338,7 +431,7 @@ namespace FlaxEngine
|
||||
if (triangles.Count == 0 || triangles.Count % 3 != 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(triangles));
|
||||
|
||||
if (Internal_UpdateTrianglesInt(
|
||||
if (Internal_UpdateTrianglesUInt(
|
||||
__unmanagedPtr,
|
||||
triangles.Count / 3,
|
||||
Utils.ExtractArrayFromList(triangles)
|
||||
|
||||
Reference in New Issue
Block a user