// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved.
#pragma once
#include "Engine/Content/AssetReference.h"
#include "Engine/Content/Assets/MaterialBase.h"
#include "Engine/Serialization/ISerializable.h"
#include "Types.h"
///
/// The model instance entry that describes how to draw it.
///
API_STRUCT() struct FLAXENGINE_API ModelInstanceEntry : ISerializable
{
API_AUTO_SERIALIZATION();
DECLARE_SCRIPTING_TYPE_MINIMAL(ModelInstanceEntry);
///
/// The mesh surface material used for the rendering. If not assigned the default value will be used from the model asset.
///
API_FIELD() AssetReference Material;
///
/// The shadows casting mode.
///
API_FIELD() ShadowsCastingMode ShadowsMode = ShadowsCastingMode::All;
///
/// Determines whenever this mesh is visible.
///
API_FIELD() bool Visible = true;
///
/// Determines whenever this mesh can receive decals.
///
API_FIELD() bool ReceiveDecals = true;
public:
bool operator==(const ModelInstanceEntry& other) const;
FORCE_INLINE bool operator!=(const ModelInstanceEntry& other) const
{
return !operator==(other);
}
};
///
/// Collection of model instance entries.
///
class FLAXENGINE_API ModelInstanceEntries : public Array, public ISerializable
{
public:
///
/// Determines whether buffer is valid for the given model.
///
/// The model.
/// True if this buffer is valid for the specified model object.
bool IsValidFor(const Model* model) const;
///
/// Determines whether buffer is valid ofr the given skinned model.
///
/// The skinned model.
/// True if this buffer is valid for the specified skinned model object.
bool IsValidFor(const SkinnedModel* model) const;
public:
///
/// Setup buffer for given model
///
/// Model to setup for
void Setup(const Model* model);
///
/// Setup buffer for given skinned model
///
/// Model to setup for
void Setup(const SkinnedModel* model);
///
/// Setup buffer for given amount of material slots
///
/// Amount of material slots
void Setup(int32 slotsCount);
///
/// Setups the buffer if is invalid (has different amount of entries).
///
/// The model.
void SetupIfInvalid(const Model* model);
///
/// Setups the buffer if is invalid (has different amount of entries).
///
/// The skinned model.
void SetupIfInvalid(const SkinnedModel* model);
///
/// Clones the other buffer data
///
/// The other buffer to clone.
void Clone(const ModelInstanceEntries* other)
{
*this = *other;
}
///
/// Releases the buffer data.
///
void Release()
{
Resize(0);
}
bool HasContentLoaded() const;
public:
// [ISerializable]
void Serialize(SerializeStream& stream, const void* otherObj) override;
void Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) override;
};