Refactor engine to support double-precision vectors

This commit is contained in:
Wojtek Figat
2022-06-13 00:40:32 +02:00
parent f82e370392
commit a881c90b2e
744 changed files with 19062 additions and 12467 deletions

View File

@@ -15,7 +15,7 @@ namespace FlaxEngine
/// <summary>
/// The vertex position.
/// </summary>
public Vector3 Position;
public Float3 Position;
}
/// <summary>
@@ -63,32 +63,32 @@ namespace FlaxEngine
/// <summary>
/// The vertex position.
/// </summary>
public Vector3 Position;
public Float3 Position;
/// <summary>
/// The texture coordinates.
/// </summary>
public Vector2 TexCoord;
public Float2 TexCoord;
/// <summary>
/// The normal vector.
/// </summary>
public Vector3 Normal;
public Float3 Normal;
/// <summary>
/// The tangent vector.
/// </summary>
public Vector3 Tangent;
public Float3 Tangent;
/// <summary>
/// The tangent vector.
/// </summary>
public Vector3 Bitangent;
public Float3 Bitangent;
/// <summary>
/// The lightmap UVs.
/// </summary>
public Vector2 LightmapUVs;
public Float2 LightmapUVs;
/// <summary>
/// The vertex color.
@@ -122,45 +122,234 @@ namespace FlaxEngine
/// <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(Float3[] vertices, int[] triangles, Float3[] normals = null, Float3[] tangents = null, Float2[] uv = null, Color32[] colors = null)
{
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 Exception("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<Float3> vertices, List<int> triangles, List<Float3> normals = null, List<Float3> tangents = null, List<Float2> uv = null, List<Color32> colors = null)
{
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, Utils.ExtractArrayFromList(vertices), Utils.ExtractArrayFromList(triangles), Utils.ExtractArrayFromList(normals), Utils.ExtractArrayFromList(tangents), Utils.ExtractArrayFromList(uv), Utils.ExtractArrayFromList(colors)))
throw new Exception("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(Float3[] vertices, uint[] triangles, Float3[] normals = null, Float3[] tangents = null, Float2[] uv = null, Color32[] colors = null)
{
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 Exception("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<Float3> vertices, List<uint> triangles, List<Float3> normals = null, List<Float3> tangents = null, List<Float2> uv = null, List<Color32> colors = null)
{
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, Utils.ExtractArrayFromList(vertices), Utils.ExtractArrayFromList(triangles), Utils.ExtractArrayFromList(normals), Utils.ExtractArrayFromList(tangents), Utils.ExtractArrayFromList(uv), Utils.ExtractArrayFromList(colors)))
throw new Exception("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 16-bit stride buffer. Cannot be null.</param>
/// <param name="normals">The normal vectors (per vertex).</param>
/// <param name="tangents">The tangent 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(Float3[] vertices, ushort[] triangles, Float3[] normals = null, Float3[] tangents = null, Float2[] uv = null, Color32[] colors = null)
{
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_UpdateMeshUShort(__unmanagedPtr, vertices.Length, triangles.Length / 3, vertices, triangles, normals, tangents, uv, colors))
throw new Exception("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 16-bit stride buffer. Cannot be null.</param>
/// <param name="normals">The normal vectors (per vertex).</param>
/// <param name="tangents">The tangent 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<Float3> vertices, List<ushort> triangles, List<Float3> normals = null, List<Float3> tangents = null, List<Float2> uv = null, List<Color32> colors = null)
{
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_UpdateMeshUShort(__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 Exception("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.
/// [Deprecated on 26.05.2022, expires on 26.05.2024]
/// </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>
[Obsolete("Deprecated in 1.4")]
public void UpdateMesh(Vector3[] vertices, int[] 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 Exception("Failed to update mesh data.");
UpdateMesh(Utils.ConvertCollection(vertices), triangles, Utils.ConvertCollection(normals), Utils.ConvertCollection(tangents), Utils.ConvertCollection(uv), colors);
}
/// <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.
/// [Deprecated on 26.05.2022, expires on 26.05.2024]
/// </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>
@@ -168,46 +357,17 @@ namespace FlaxEngine
/// <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>
[Obsolete("Deprecated in 1.4")]
public void UpdateMesh(List<Vector3> vertices, List<int> 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,
Utils.ExtractArrayFromList(vertices),
Utils.ExtractArrayFromList(triangles),
Utils.ExtractArrayFromList(normals),
Utils.ExtractArrayFromList(tangents),
Utils.ExtractArrayFromList(uv),
Utils.ExtractArrayFromList(colors)
))
throw new Exception("Failed to update mesh data.");
UpdateMesh(Utils.ConvertCollection(vertices), triangles, Utils.ConvertCollection(normals), Utils.ConvertCollection(tangents), Utils.ConvertCollection(uv), colors);
}
/// <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.
/// [Deprecated on 26.05.2022, expires on 26.05.2024]
/// </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>
@@ -215,45 +375,17 @@ namespace FlaxEngine
/// <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>
[Obsolete("Deprecated in 1.4")]
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 Exception("Failed to update mesh data.");
UpdateMesh(Utils.ConvertCollection(vertices), triangles, Utils.ConvertCollection(normals), Utils.ConvertCollection(tangents), Utils.ConvertCollection(uv), colors);
}
/// <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.
/// [Deprecated on 26.05.2022, expires on 26.05.2024]
/// </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>
@@ -261,46 +393,17 @@ namespace FlaxEngine
/// <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>
[Obsolete("Deprecated in 1.4")]
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,
Utils.ExtractArrayFromList(vertices),
Utils.ExtractArrayFromList(triangles),
Utils.ExtractArrayFromList(normals),
Utils.ExtractArrayFromList(tangents),
Utils.ExtractArrayFromList(uv),
Utils.ExtractArrayFromList(colors)
))
throw new Exception("Failed to update mesh data.");
UpdateMesh(Utils.ConvertCollection(vertices), triangles, Utils.ConvertCollection(normals), Utils.ConvertCollection(tangents), Utils.ConvertCollection(uv), colors);
}
/// <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.
/// [Deprecated on 26.05.2022, expires on 26.05.2024]
/// </summary>
/// <param name="vertices">The mesh vertices positions. Cannot be null.</param>
/// <param name="triangles">The mesh index buffer (clockwise triangles). Uses 16-bit stride buffer. Cannot be null.</param>
@@ -308,46 +411,17 @@ namespace FlaxEngine
/// <param name="tangents">The tangent 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>
[Obsolete("Deprecated in 1.4")]
public void UpdateMesh(Vector3[] vertices, ushort[] 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_UpdateMeshUShort(
__unmanagedPtr,
vertices.Length,
triangles.Length / 3,
vertices,
triangles,
normals,
tangents,
uv,
colors
))
throw new Exception("Failed to update mesh data.");
UpdateMesh(Utils.ConvertCollection(vertices), triangles, Utils.ConvertCollection(normals), Utils.ConvertCollection(tangents), Utils.ConvertCollection(uv), colors);
}
/// <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.
/// [Deprecated on 26.05.2022, expires on 26.05.2024]
/// </summary>
/// <param name="vertices">The mesh vertices positions. Cannot be null.</param>
/// <param name="triangles">The mesh index buffer (clockwise triangles). Uses 16-bit stride buffer. Cannot be null.</param>
@@ -355,40 +429,10 @@ namespace FlaxEngine
/// <param name="tangents">The tangent 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>
[Obsolete("Deprecated in 1.4")]
public void UpdateMesh(List<Vector3> vertices, List<ushort> 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_UpdateMeshUShort(
__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 Exception("Failed to update mesh data.");
UpdateMesh(Utils.ConvertCollection(vertices), triangles, Utils.ConvertCollection(normals), Utils.ConvertCollection(tangents), Utils.ConvertCollection(uv), colors);
}
/// <summary>
@@ -399,7 +443,6 @@ namespace FlaxEngine
/// <param name="triangles">The mesh index buffer (triangles). Uses 32-bit stride buffer. Cannot be null.</param>
public void UpdateTriangles(int[] triangles)
{
// Validate state and input
if (!ParentModel.IsVirtual)
throw new InvalidOperationException("Only virtual models can be updated at runtime.");
if (triangles == null)
@@ -407,11 +450,7 @@ namespace FlaxEngine
if (triangles.Length == 0 || triangles.Length % 3 != 0)
throw new ArgumentOutOfRangeException(nameof(triangles));
if (Internal_UpdateTrianglesUInt(
__unmanagedPtr,
triangles.Length / 3,
triangles
))
if (Internal_UpdateTrianglesUInt(__unmanagedPtr, triangles.Length / 3, triangles))
throw new Exception("Failed to update mesh data.");
}
@@ -423,7 +462,6 @@ namespace FlaxEngine
/// <param name="triangles">The mesh index buffer (triangles). Uses 32-bit stride buffer. Cannot be null.</param>
public void UpdateTriangles(List<int> triangles)
{
// Validate state and input
if (!ParentModel.IsVirtual)
throw new InvalidOperationException("Only virtual models can be updated at runtime.");
if (triangles == null)
@@ -431,11 +469,7 @@ namespace FlaxEngine
if (triangles.Count == 0 || triangles.Count % 3 != 0)
throw new ArgumentOutOfRangeException(nameof(triangles));
if (Internal_UpdateTrianglesUInt(
__unmanagedPtr,
triangles.Count / 3,
Utils.ExtractArrayFromList(triangles)
))
if (Internal_UpdateTrianglesUInt(__unmanagedPtr, triangles.Count / 3, Utils.ExtractArrayFromList(triangles)))
throw new Exception("Failed to update mesh data.");
}
@@ -447,7 +481,6 @@ namespace FlaxEngine
/// <param name="triangles">The mesh index buffer (triangles). Uses 16-bit stride buffer. Cannot be null.</param>
public void UpdateTriangles(ushort[] triangles)
{
// Validate state and input
if (!ParentModel.IsVirtual)
throw new InvalidOperationException("Only virtual models can be updated at runtime.");
if (triangles == null)
@@ -455,11 +488,7 @@ namespace FlaxEngine
if (triangles.Length == 0 || triangles.Length % 3 != 0)
throw new ArgumentOutOfRangeException(nameof(triangles));
if (Internal_UpdateTrianglesUShort(
__unmanagedPtr,
triangles.Length / 3,
triangles
))
if (Internal_UpdateTrianglesUShort(__unmanagedPtr, triangles.Length / 3, triangles))
throw new Exception("Failed to update mesh data.");
}
@@ -471,7 +500,6 @@ namespace FlaxEngine
/// <param name="triangles">The mesh index buffer (triangles). Uses 16-bit stride buffer. Cannot be null.</param>
public void UpdateTriangles(List<ushort> triangles)
{
// Validate state and input
if (!ParentModel.IsVirtual)
throw new InvalidOperationException("Only virtual models can be updated at runtime.");
if (triangles == null)
@@ -479,11 +507,7 @@ namespace FlaxEngine
if (triangles.Count == 0 || triangles.Count % 3 != 0)
throw new ArgumentOutOfRangeException(nameof(triangles));
if (Internal_UpdateTrianglesUShort(
__unmanagedPtr,
triangles.Count / 3,
Utils.ExtractArrayFromList(triangles)
))
if (Internal_UpdateTrianglesUShort(__unmanagedPtr, triangles.Count / 3, Utils.ExtractArrayFromList(triangles)))
throw new Exception("Failed to update mesh data.");
}
@@ -567,11 +591,11 @@ namespace FlaxEngine
float bitangentSign = v1.Tangent.A > Mathf.Epsilon ? -1.0f : +1.0f;
result[i].Position = v0.Position;
result[i].TexCoord = (Vector2)v1.TexCoord;
result[i].Normal = v1.Normal.ToVector3() * 2.0f - 1.0f;
result[i].Tangent = v1.Tangent.ToVector3() * 2.0f - 1.0f;
result[i].Bitangent = Vector3.Cross(result[i].Normal, result[i].Tangent) * bitangentSign;
result[i].LightmapUVs = (Vector2)v1.LightmapUVs;
result[i].TexCoord = (Float2)v1.TexCoord;
result[i].Normal = v1.Normal.ToFloat3() * 2.0f - 1.0f;
result[i].Tangent = v1.Tangent.ToFloat3() * 2.0f - 1.0f;
result[i].Bitangent = Float3.Cross(result[i].Normal, result[i].Tangent) * bitangentSign;
result[i].LightmapUVs = (Float2)v1.LightmapUVs;
result[i].Color = Color.Black;
}