Refactor models and meshes to share more code in a base class
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "../BinaryAsset.h"
|
||||
#include "Engine/Core/Collections/Array.h"
|
||||
#include "Engine/Graphics/Models/Config.h"
|
||||
#include "Engine/Graphics/Models/MaterialSlot.h"
|
||||
#include "Engine/Streaming/StreamableResource.h"
|
||||
|
||||
@@ -26,6 +27,14 @@ struct RenderContextBatch;
|
||||
API_CLASS(Abstract, NoSpawn) class FLAXENGINE_API ModelBase : public BinaryAsset, public StreamableResource
|
||||
{
|
||||
DECLARE_ASSET_HEADER(ModelBase);
|
||||
friend MeshBase;
|
||||
friend class StreamModelLODTask;
|
||||
|
||||
protected:
|
||||
bool _initialized = false;
|
||||
int32 _loadedLODs = 0;
|
||||
StreamModelLODTask* _streamingTask = nullptr;
|
||||
|
||||
public:
|
||||
/// <summary>
|
||||
/// The Sign Distant Field (SDF) data for the model.
|
||||
@@ -106,6 +115,48 @@ public:
|
||||
return MaterialSlots.Count();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this instance is initialized.
|
||||
/// </summary>
|
||||
FORCE_INLINE bool IsInitialized() const
|
||||
{
|
||||
return _initialized;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clamps the index of the LOD to be valid for rendering (only loaded LODs).
|
||||
/// </summary>
|
||||
/// <param name="index">The index.</param>
|
||||
/// <returns>The resident LOD index.</returns>
|
||||
FORCE_INLINE int32 ClampLODIndex(int32 index) const
|
||||
{
|
||||
return Math::Clamp(index, HighestResidentLODIndex(), GetLODsCount() - 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets index of the highest resident LOD (it may be equal to LODs.Count if no LOD has been uploaded). Note: LOD=0 is the highest (top quality)
|
||||
/// </summary>
|
||||
FORCE_INLINE int32 HighestResidentLODIndex() const
|
||||
{
|
||||
return GetLODsCount() - _loadedLODs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the amount of loaded model LODs.
|
||||
/// </summary>
|
||||
API_PROPERTY() FORCE_INLINE int32 GetLoadedLODs() const
|
||||
{
|
||||
return _loadedLODs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this model can be rendered.
|
||||
/// </summary>
|
||||
FORCE_INLINE bool CanBeRendered() const
|
||||
{
|
||||
return _loadedLODs > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resizes the material slots collection. Updates meshes that were using removed slots.
|
||||
/// </summary>
|
||||
@@ -127,4 +178,37 @@ public:
|
||||
/// Gets the meshes for a particular LOD index.
|
||||
/// </summary>
|
||||
virtual void GetMeshes(Array<MeshBase*>& meshes, int32 lodIndex = 0) = 0;
|
||||
|
||||
public:
|
||||
/// <summary>
|
||||
/// Requests the LOD data asynchronously (creates task that will gather chunk data or null if already here).
|
||||
/// </summary>
|
||||
/// <param name="lodIndex">Index of the LOD.</param>
|
||||
/// <returns>Task that will gather chunk data or null if already here.</returns>
|
||||
ContentLoadTask* RequestLODDataAsync(int32 lodIndex);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the model LOD data (links bytes).
|
||||
/// </summary>
|
||||
/// <param name="lodIndex">Index of the LOD.</param>
|
||||
/// <param name="data">The data (it may be missing if failed to get it).</param>
|
||||
void GetLODData(int32 lodIndex, BytesContainer& data) const;
|
||||
|
||||
public:
|
||||
// [BinaryAsset]
|
||||
void CancelStreaming() override;
|
||||
#if USE_EDITOR
|
||||
void GetReferences(Array<Guid>& assets, Array<String>& files) const override;
|
||||
#endif
|
||||
|
||||
// [StreamableResource]
|
||||
int32 GetCurrentResidency() const override;
|
||||
bool CanBeUpdated() const override;
|
||||
Task* UpdateAllocation(int32 residency) override;
|
||||
Task* CreateStreamingTask(int32 residency) override;
|
||||
void CancelStreamingTasks() override;
|
||||
|
||||
protected:
|
||||
// [BinaryAsset]
|
||||
void unload(bool isReloading) override;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user