Class ModelBase
Base class for asset types that can contain a model resource.
Inherited Members
Assembly: FlaxEngine.dll
File: Engine/Content/Assets/ModelBase.h
Syntax
public class ModelBase : public BinaryAsset, public StreamableResource
Constructors
~ModelBase()
Declaration
public ~ModelBase()
ModelBase(const SpawnParams& params, const AssetInfo* info, StreamingGroup* group)
Declaration
protected ModelBase(const SpawnParams& params, const AssetInfo* info, StreamingGroup* group)
Parameters
SpawnParams
params
|
AssetInfo
info
|
StreamingGroup
group
|
Fields
_initialized
Declaration
protected bool _initialized = false
Field Value
bool
|
_loadedLODs
Declaration
protected int32 _loadedLODs = 0
Field Value
int32
|
_streamingTask
Declaration
protected StreamModelLODTask* _streamingTask = nullptr
Field Value
StreamModelLODTask
|
MaterialSlots
The list of material slots.
Declaration
public Array<MaterialSlot> MaterialSlots
Field Value
Array<MaterialSlot>
|
MinScreenSize
The minimum screen size to draw this model (the bottom limit). Used to cull small models. Set to 0 to disable this feature.
Declaration
public float MinScreenSize = 0.0f
Field Value
float
|
Methods
CanBeRendered()
Determines whether this model can be rendered.
Declaration
public bool CanBeRendered() const
Returns
bool
|
CanBeUpdated()
Determines whether this instance can be updated. Which means: no async streaming, no pending action in background.
Declaration
public virtual bool CanBeUpdated() const override
Returns
bool
|
Overrides
CancelStreaming()
Cancels any asynchronous content streaming by this asset (eg. mesh data streaming into GPU memory). Will release any locks for asset storage container.
Declaration
public virtual void CancelStreaming() override
Overrides
CancelStreamingTasks()
Cancels any streaming task (or tasks sequence) started for this resource.
Declaration
public virtual void CancelStreamingTasks() override
Overrides
ClampLODIndex(int32 index)
Clamps the index of the LOD to be valid for rendering (only loaded LODs).
Declaration
public int32 ClampLODIndex(int32 index) const
Parameters
int32
index
The index. |
Returns
int32
The resident LOD index. |
CreateStreamingTask(int32 residency)
Creates streaming task (or tasks sequence) to perform resource streaming for the desire residency level.
Declaration
public virtual Task* CreateStreamingTask(int32 residency) override
Parameters
int32
residency
The target residency. |
Returns
Task
Async task or tasks that update resource residency level. Must be preceded with UpdateAllocation call. |
Overrides
GetCurrentResidency()
Gets resource current residency level.
Declaration
public virtual int32 GetCurrentResidency() const override
Returns
int32
|
Overrides
GetLoadedLODs()
Gets the amount of loaded model LODs.
Declaration
public int32 GetLoadedLODs() const
Returns
int32
|
GetLOD(int32 lodIndex)
Gets the mesh for a particular LOD index.
Declaration
public virtual ModelLODBase* GetLOD(int32 lodIndex) const = 0
Parameters
int32
lodIndex
|
Returns
ModelLODBase
|
GetLODData(int32 lodIndex, BytesContainer& data)
Gets the model LOD data (links bytes).
Declaration
public void GetLODData(int32 lodIndex, BytesContainer& data) const
Parameters
int32
lodIndex
Index of the LOD. |
BytesContainer
data
The data (it may be missing if failed to get it). |
GetLODsCount()
Gets amount of the level of details in the model.
Declaration
public virtual int32 GetLODsCount() const = 0
Returns
int32
|
GetMaterialSlotsCount()
Gets the amount of the material slots used by this model asset.
Declaration
public int32 GetMaterialSlotsCount() const
Returns
int32
|
GetMesh(int32 meshIndex, int32 lodIndex = 0)
Gets the mesh for a particular LOD index.
Declaration
public virtual MeshBase* GetMesh(int32 meshIndex, int32 lodIndex = 0) const = 0
Parameters
int32
meshIndex
|
int32
lodIndex
|
Returns
MeshBase
|
GetMeshes(Array<const MeshBase* >& meshes, int32 lodIndex = 0)
Gets the meshes for a particular LOD index.
Declaration
public virtual void GetMeshes(Array<const MeshBase* >& meshes, int32 lodIndex = 0) const = 0
Parameters
Array<MeshBase >
meshes
|
int32
lodIndex
|
GetMeshes(Array<MeshBase* >& meshes, int32 lodIndex = 0)
Gets the meshes for a particular LOD index.
Declaration
public virtual void GetMeshes(Array<MeshBase* >& meshes, int32 lodIndex = 0) = 0
Parameters
Array<MeshBase >
meshes
|
int32
lodIndex
|
GetReferences(Array<Guid>& assets, Array<String>& files)
Declaration
public void GetReferences(Array<Guid>& assets, Array<String>& files) const override
Parameters
Array<Guid>
assets
|
Array<String>
files
|
GetSlot(const StringView& name)
Gets the material slot by the name.
Declaration
public MaterialSlot* GetSlot(const StringView& name)
Parameters
StringView
name
The slot name. |
Returns
MaterialSlot
The material slot with the given name or null if cannot find it (asset may be not loaded yet). |
HighestResidentLODIndex()
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)
Declaration
public int32 HighestResidentLODIndex() const
Returns
int32
|
IsInitialized()
Gets a value indicating whether this instance is initialized.
Declaration
public bool IsInitialized() const
Returns
bool
|
LoadHeader(ReadStream& stream, byte& headerVersion)
Declaration
protected bool LoadHeader(ReadStream& stream, byte& headerVersion)
Parameters
ReadStream
stream
|
byte
headerVersion
|
Returns
bool
|
LoadMesh(class MemoryReadStream& stream, byte meshVersion, MeshBase* mesh, MeshData* dataIfReadOnly=nullptr)
Declaration
protected virtual bool LoadMesh(class MemoryReadStream& stream, byte meshVersion, MeshBase* mesh, MeshData* dataIfReadOnly=nullptr)
Parameters
class MemoryReadStream
stream
|
byte
meshVersion
|
MeshBase
mesh
|
MeshData
dataIfReadOnly
|
Returns
bool
|
RequestLODDataAsync(int32 lodIndex)
Requests the LOD data asynchronously (creates task that will gather chunk data or null if already here).
Declaration
public ContentLoadTask* RequestLODDataAsync(int32 lodIndex)
Parameters
int32
lodIndex
Index of the LOD. |
Returns
ContentLoadTask
Task that will gather chunk data or null if already here. |
Save(bool withMeshDataFromGpu, Function<FlaxChunk* (int32)>& getChunk)
Declaration
protected virtual bool Save(bool withMeshDataFromGpu, Function<FlaxChunk* (int32)>& getChunk) const
Parameters
bool
withMeshDataFromGpu
|
Function<FlaxChunk (int32)>
getChunk
|
Returns
bool
|
Save(bool withMeshDataFromGpu=false, const StringView& path=StringView::Empty)
Saves this asset to the file. Supported only in Editor.
If you use saving with the GPU mesh data then the call has to be provided from the thread other than the main game thread.
Declaration
public bool Save(bool withMeshDataFromGpu=false, const StringView& path=StringView::Empty)
Parameters
bool
withMeshDataFromGpu
True if save also GPU mesh buffers, otherwise will keep data in storage unmodified. Valid only if saving the same asset to the same location, and it's loaded. |
StringView
path
The custom asset path to use for the saving. Use empty value to save this asset to its own storage location. Can be used to duplicate asset. Must be specified when saving virtual asset. |
Returns
bool
True when cannot save data, otherwise false. |
Save(const StringView& path=StringView::Empty)
Saves this asset to the file. Supported only in Editor.
Declaration
public virtual bool Save(const StringView& path=StringView::Empty) override
Parameters
StringView
path
The custom asset path to use for the saving. Use empty value to save this asset to its own storage location. Can be used to duplicate asset. Must be specified when saving virtual asset. |
Returns
bool
True when cannot save data, otherwise false. |
Overrides
SaveHeader(WriteStream& stream)
Declaration
protected virtual bool SaveHeader(WriteStream& stream) const
Parameters
WriteStream
stream
|
Returns
bool
|
SaveHeader(WriteStream& stream, const class ModelData& modelData)
Declaration
protected static bool SaveHeader(WriteStream& stream, const class ModelData& modelData)
Parameters
WriteStream
stream
|
class ModelData
modelData
|
Returns
bool
|
SaveLOD(WriteStream& stream, const ModelData& modelData, int32 lodIndex, bool(saveMesh)(WriteStream& stream, const ModelData& modelData, int32 lodIndex, int32 meshIndex)=nullptr)
Declaration
protected static bool SaveLOD(WriteStream& stream, const ModelData& modelData, int32 lodIndex, bool(saveMesh)(WriteStream& stream, const ModelData& modelData, int32 lodIndex, int32 meshIndex)=nullptr)
Parameters
WriteStream
stream
|
ModelData
modelData
|
int32
lodIndex
|
bool(saveMesh)(WriteStreamstream, ModelDatamodelData, int32 lodIndex, int32 meshIndex)
ModelBase_SaveLOD_WriteStream___const_ModelData___int32_bool_saveMesh__WriteStream__stream__const_ModelData__modelData__int32_lodIndex__int32_meshIndex__
|
Returns
bool
|
SaveLOD(WriteStream& stream, int32 lodIndex)
Declaration
protected bool SaveLOD(WriteStream& stream, int32 lodIndex) const
Parameters
WriteStream
stream
|
int32
lodIndex
|
Returns
bool
|
SaveMesh(WriteStream& stream, const MeshBase* mesh)
Declaration
protected virtual bool SaveMesh(WriteStream& stream, const MeshBase* mesh) const
Parameters
WriteStream
stream
|
MeshBase
mesh
|
Returns
bool
|
SetupMaterialSlots(int32 slotsCount)
Resizes the material slots collection. Updates meshes that were using removed slots.
Declaration
public virtual void SetupMaterialSlots(int32 slotsCount)
Parameters
int32
slotsCount
|
unload(bool isReloading)
Unloads asset data
Declaration
protected virtual void unload(bool isReloading) override
Parameters
bool
isReloading
True if asset is reloading data, otherwise false. |
Overrides
UpdateAllocation(int32 residency)
Updates the resource allocation to the given residency level. May not be updated now but in an async operation.
Declaration
public virtual Task* UpdateAllocation(int32 residency) override
Parameters
int32
residency
The target allocation residency. |
Returns
Task
Async task that updates resource allocation or null if already done it. Warning: need to call task start to perform allocation. |