// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved. #pragma once #include "MeshBase.h" #include "BlendShape.h" /// /// Represents part of the skinned model that is made of vertices and can be rendered using custom material, transformation and skeleton bones hierarchy. /// API_CLASS(NoSpawn) class FLAXENGINE_API SkinnedMesh : public MeshBase { DECLARE_SCRIPTING_TYPE_WITH_CONSTRUCTOR_IMPL(SkinnedMesh, MeshBase); public: SkinnedMesh(const SkinnedMesh& other) : SkinnedMesh() { #if !BUILD_RELEASE CRASH; // Not used #endif } public: /// /// Gets the skinned model owning this mesh. /// FORCE_INLINE SkinnedModel* GetSkinnedModel() const { return (SkinnedModel*)_model; } /// /// Blend shapes used by this mesh. /// Array BlendShapes; public: /// /// Load mesh data and Initialize GPU buffers /// [Deprecated in v1.10] /// /// Amount of vertices in the vertex buffer /// Amount of triangles in the index buffer /// Vertex buffer data /// Index buffer data /// True if use 16 bit indices for the index buffer (true: uint16, false: uint32). /// True if cannot load data, otherwise false. DEPRECATED("Use Init intead.") bool Load(uint32 vertices, uint32 triangles, const void* vb0, const void* ib, bool use16BitIndexBuffer); public: /// /// Updates the model mesh (used by the virtual models created with Init rather than Load). /// /// The amount of vertices in the vertex buffer. /// The amount of triangles in the index buffer. /// The vertex buffer data. /// The index buffer in clockwise order. /// True if failed, otherwise false. FORCE_INLINE bool UpdateMesh(uint32 vertexCount, uint32 triangleCount, const VB0SkinnedElementType* vb, const int32* ib) { return UpdateMesh(vertexCount, triangleCount, vb, ib, false); } /// /// Updates the model mesh (used by the virtual models created with Init rather than Load). /// /// The amount of vertices in the vertex buffer. /// The amount of triangles in the index buffer. /// The vertex buffer data. /// The index buffer in clockwise order. /// True if failed, otherwise false. FORCE_INLINE bool UpdateMesh(uint32 vertexCount, uint32 triangleCount, const VB0SkinnedElementType* vb, const uint32* ib) { return UpdateMesh(vertexCount, triangleCount, vb, ib, false); } /// /// Updates the model mesh (used by the virtual models created with Init rather than Load). /// /// The amount of vertices in the vertex buffer. /// The amount of triangles in the index buffer. /// The vertex buffer data. /// The index buffer, clockwise order. /// True if failed, otherwise false. FORCE_INLINE bool UpdateMesh(uint32 vertexCount, uint32 triangleCount, const VB0SkinnedElementType* vb, const uint16* ib) { return UpdateMesh(vertexCount, triangleCount, vb, ib, true); } /// /// Updates the model mesh (used by the virtual models created with Init rather than Load). /// /// The amount of vertices in the vertex buffer. /// The amount of triangles in the index buffer. /// The vertex buffer data. /// The index buffer in clockwise order. /// True if index buffer uses 16-bit index buffer, otherwise 32-bit. /// True if failed, otherwise false. bool UpdateMesh(uint32 vertexCount, uint32 triangleCount, const VB0SkinnedElementType* vb, const void* ib, bool use16BitIndices); public: /// /// Draws the mesh. /// /// The rendering context. /// The packed drawing info data. /// The LOD transition dither factor. void Draw(const RenderContext& renderContext, const DrawInfo& info, float lodDitherFactor) const; /// /// Draws the mesh. /// /// The rendering context batch. /// The packed drawing info data. /// The LOD transition dither factor. void Draw(const RenderContextBatch& renderContextBatch, const DrawInfo& info, float lodDitherFactor) const; public: // [MeshBase] void Release() override; bool DownloadDataCPU(MeshBufferType type, BytesContainer& result, int32& count) const override; private: // Internal bindings #if !COMPILE_WITHOUT_CSHARP API_FUNCTION(NoProxy) bool UpdateMeshUInt(const MArray* verticesObj, const MArray* trianglesObj, const MArray* blendIndicesObj, const MArray* blendWeightsObj, const MArray* normalsObj, const MArray* tangentsObj, const MArray* uvObj); API_FUNCTION(NoProxy) bool UpdateMeshUShort(const MArray* verticesObj, const MArray* trianglesObj, const MArray* blendIndicesObj, const MArray* blendWeightsObj, const MArray* normalsObj, const MArray* tangentsObj, const MArray* uvObj); API_FUNCTION(NoProxy) MArray* DownloadBuffer(bool forceGpu, MTypeObject* resultType, int32 typeI); #endif };