// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved. using System; using System.Collections.Generic; namespace FlaxEngine { partial class MeshBase { /// /// Gets the material slot used by this mesh during rendering. /// public MaterialSlot MaterialSlot => ModelBase.MaterialSlots[MaterialSlotIndex]; /// /// Gets a format of the mesh index buffer. /// public PixelFormat IndexBufferFormat => Use16BitIndexBuffer ? PixelFormat.R16_UInt : PixelFormat.R32_UInt; /// /// Updates the model mesh index buffer data. /// Can be used only for virtual assets (see and ). /// Mesh data will be cached and uploaded to the GPU with a delay. /// /// The mesh index buffer (triangles). Uses 32-bit stride buffer. Cannot be null. public void UpdateTriangles(int[] triangles) { if (!ModelBase.IsVirtual) throw new InvalidOperationException("Only virtual models can be updated at runtime."); if (triangles == null) throw new ArgumentNullException(nameof(triangles)); if (triangles.Length == 0 || triangles.Length % 3 != 0) throw new ArgumentOutOfRangeException(nameof(triangles)); if (Internal_UpdateTrianglesUInt(__unmanagedPtr, triangles.Length / 3, triangles)) throw new Exception("Failed to update mesh data."); } /// /// Updates the model mesh index buffer data. /// Can be used only for virtual assets (see and ). /// Mesh data will be cached and uploaded to the GPU with a delay. /// /// The mesh index buffer (triangles). Uses 32-bit stride buffer. Cannot be null. public void UpdateTriangles(List triangles) { if (!ModelBase.IsVirtual) throw new InvalidOperationException("Only virtual models can be updated at runtime."); if (triangles == null) throw new ArgumentNullException(nameof(triangles)); if (triangles.Count == 0 || triangles.Count % 3 != 0) throw new ArgumentOutOfRangeException(nameof(triangles)); if (Internal_UpdateTrianglesUInt(__unmanagedPtr, triangles.Count / 3, Utils.ExtractArrayFromList(triangles))) throw new Exception("Failed to update mesh data."); } /// /// Updates the model mesh index buffer data. /// Can be used only for virtual assets (see and ). /// Mesh data will be cached and uploaded to the GPU with a delay. /// /// The mesh index buffer (triangles). Uses 16-bit stride buffer. Cannot be null. public void UpdateTriangles(ushort[] triangles) { if (!ModelBase.IsVirtual) throw new InvalidOperationException("Only virtual models can be updated at runtime."); if (triangles == null) throw new ArgumentNullException(nameof(triangles)); if (triangles.Length == 0 || triangles.Length % 3 != 0) throw new ArgumentOutOfRangeException(nameof(triangles)); if (Internal_UpdateTrianglesUShort(__unmanagedPtr, triangles.Length / 3, triangles)) throw new Exception("Failed to update mesh data."); } /// /// Updates the model mesh index buffer data. /// Can be used only for virtual assets (see and ). /// Mesh data will be cached and uploaded to the GPU with a delay. /// /// The mesh index buffer (triangles). Uses 16-bit stride buffer. Cannot be null. public void UpdateTriangles(List triangles) { if (!ModelBase.IsVirtual) throw new InvalidOperationException("Only virtual models can be updated at runtime."); if (triangles == null) throw new ArgumentNullException(nameof(triangles)); if (triangles.Count == 0 || triangles.Count % 3 != 0) throw new ArgumentOutOfRangeException(nameof(triangles)); if (Internal_UpdateTrianglesUShort(__unmanagedPtr, triangles.Count / 3, Utils.ExtractArrayFromList(triangles))) throw new Exception("Failed to update mesh data."); } } }