// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved.
#pragma once
#include "Engine/Core/Math/BoundingBox.h"
#include "Engine/Core/Math/BoundingSphere.h"
#include "Engine/Core/Types/DataContainer.h"
#include "Engine/Graphics/Models/Types.h"
#include "Engine/Scripting/ScriptingObject.h"
class Task;
class ModelBase;
struct RenderContextBatch;
///
/// Base class for model resources meshes.
///
API_CLASS(Abstract, NoSpawn) class FLAXENGINE_API MeshBase : public ScriptingObject
{
DECLARE_SCRIPTING_TYPE_MINIMAL(MeshBase);
protected:
ModelBase* _model;
BoundingBox _box;
BoundingSphere _sphere;
int32 _index;
int32 _lodIndex;
uint32 _vertices;
uint32 _triangles;
int32 _materialSlotIndex;
bool _use16BitIndexBuffer;
explicit MeshBase(const SpawnParams& params)
: ScriptingObject(params)
{
}
public:
///
/// Gets the model owning this mesh.
///
API_PROPERTY() FORCE_INLINE ModelBase* GetModelBase() const
{
return _model;
}
///
/// Gets the mesh parent LOD index.
///
API_PROPERTY() FORCE_INLINE int32 GetLODIndex() const
{
return _lodIndex;
}
///
/// Gets the mesh index.
///
API_PROPERTY() FORCE_INLINE int32 GetIndex() const
{
return _index;
}
///
/// Gets the triangle count.
///
API_PROPERTY() FORCE_INLINE int32 GetTriangleCount() const
{
return _triangles;
}
///
/// Gets the vertex count.
///
API_PROPERTY() FORCE_INLINE int32 GetVertexCount() const
{
return _vertices;
}
///
/// Gets the box.
///
API_PROPERTY() FORCE_INLINE const BoundingBox& GetBox() const
{
return _box;
}
///
/// Gets the sphere.
///
API_PROPERTY() FORCE_INLINE const BoundingSphere& GetSphere() const
{
return _sphere;
}
///
/// Determines whether this mesh is using 16 bit index buffer, otherwise it's 32 bit.
///
API_PROPERTY() FORCE_INLINE bool Use16BitIndexBuffer() const
{
return _use16BitIndexBuffer;
}
///
/// Gets the index of the material slot to use during this mesh rendering.
///
API_PROPERTY() FORCE_INLINE int32 GetMaterialSlotIndex() const
{
return _materialSlotIndex;
}
///
/// Sets the index of the material slot to use during this mesh rendering.
///
API_PROPERTY() void SetMaterialSlotIndex(int32 value);
///
/// Sets the mesh bounds.
///
/// The bounding box.
void SetBounds(const BoundingBox& box);
public:
///
/// Extract mesh buffer data from GPU. Cannot be called from the main thread.
///
/// Buffer type
/// The result data
/// True if failed, otherwise false
virtual bool DownloadDataGPU(MeshBufferType type, BytesContainer& result) const = 0;
///
/// Extracts mesh buffer data from GPU in the async task.
///
/// Buffer type
/// The result data
/// Created async task used to gather the buffer data.
virtual Task* DownloadDataGPUAsync(MeshBufferType type, BytesContainer& result) const = 0;
///
/// Extract mesh buffer data from CPU. Cached internally.
///
/// Buffer type
/// The result data
/// The amount of items inside the result buffer.
/// True if failed, otherwise false
virtual bool DownloadDataCPU(MeshBufferType type, BytesContainer& result, int32& count) const = 0;
};