Class Model
Model asset that contains model object made of meshes which can rendered on the GPU.
Inherited Members
Assembly: FlaxEngine.dll
File: Engine/Content/Assets/Model.h
Syntax
public class Model : public ModelBaseFields
LODs
Model level of details. The first entry is the highest quality LOD0 followed by more optimized versions.
Declaration
public Array<ModelLOD, FixedAllocation<MODEL_MAX_LODS>> LODsField Value
| Array<ModelLOD, FixedAllocation<MODEL_MAX_LODS>> 
 | 
SDF
The generated Sign Distant Field (SDF) for this model (merged all meshes). Use GenerateSDF to update it.
Declaration
public SDFData SDFField Value
| SDFData 
 | 
Methods
Draw(const RenderContext& renderContext, const Mesh::DrawInfo& info)
Draws the model.
Declaration
public void Draw(const RenderContext& renderContext, const Mesh::DrawInfo& info)Parameters
| RenderContext
        renderContext The rendering context. | 
| Mesh::DrawInfo
        info The packed drawing info data. | 
Draw(const RenderContext& renderContext, MaterialBase* material, const Matrix& world, StaticFlags flags=StaticFlags::None, bool receiveDecals=true, int8 sortOrder = 0)
Draws the model.
Declaration
public void Draw(const RenderContext& renderContext, MaterialBase* material, const Matrix& world, StaticFlags flags=StaticFlags::None, bool receiveDecals=true, int8 sortOrder = 0) constParameters
| RenderContext
        renderContext The rendering context. | 
| MaterialBase
        material The material to use for rendering. | 
| Matrix
        world The world transformation of the model. | 
| StaticFlags
        flags The object static flags. | 
| bool
        receiveDecals True if rendered geometry can receive decals, otherwise false. | 
| int8
        sortOrder Object sorting key. | 
Draw(const RenderContextBatch& renderContextBatch, const Mesh::DrawInfo& info)
Draws the model.
Declaration
public void Draw(const RenderContextBatch& renderContextBatch, const Mesh::DrawInfo& info)Parameters
| RenderContextBatch
        renderContextBatch The rendering context batch. | 
| Mesh::DrawInfo
        info The packed drawing info data. | 
GenerateSDF(float resolutionScale=1.0f, int32 lodIndex=6, bool cacheData=true, float backfacesThreshold = 0.6f, bool useGPU=true)
Generates the Sign Distant Field for this model.
Can be called in async in case of SDF generation on a CPU (assuming model is not during rendering).
Declaration
public bool GenerateSDF(float resolutionScale=1.0f, int32 lodIndex=6, bool cacheData=true, float backfacesThreshold = 0.6f, bool useGPU=true)Parameters
| float
        resolutionScale The SDF texture resolution scale. Use higher values for more precise data but with significant performance and memory overhead. | 
| int32
        lodIndex The index of the LOD to use for the SDF building. | 
| bool
        cacheData If true, the generated SDF texture data will be cached on CPU (in asset chunk storage) to allow saving it later, otherwise it will be runtime for GPU-only. Ignored for virtual assets or in build. | 
| float
        backfacesThreshold Custom threshold (in range 0-1) for adjusting mesh internals detection based on the percentage of test rays hit triangle backfaces. Use lower value for more dense mesh. | 
| bool
        useGPU Enables using GPU for SDF generation, otherwise CPU will be used (async via Job System). | 
Returns
| bool True if failed, otherwise false. | 
GetAllocatedResidency()
Gets resource allocated residency level.
Declaration
public virtual int32 GetAllocatedResidency() const overrideReturns
| int32 
 | 
Overrides
GetBox(const Matrix& world, int32 lodIndex = 0)
Gets the model bounding box in custom matrix world space.
Declaration
public BoundingBox GetBox(const Matrix& world, int32 lodIndex = 0) constParameters
| Matrix
        world The transformation matrix. | 
| int32
        lodIndex The Level Of Detail index. | 
Returns
| BoundingBox The bounding box. | 
GetBox(const Transform& transform, int32 lodIndex = 0)
Gets the model bounding box in custom transformation.
Declaration
public BoundingBox GetBox(const Transform& transform, int32 lodIndex = 0) constParameters
| Transform
        transform The instance transformation. | 
| int32
        lodIndex The Level Of Detail index. | 
Returns
| BoundingBox The bounding box. | 
GetBox(int32 lodIndex = 0)
Gets the model bounding box in local space.
Declaration
public BoundingBox GetBox(int32 lodIndex = 0) constParameters
| int32
        lodIndex The Level Of Detail index. | 
Returns
| BoundingBox The bounding box. | 
getChunksToPreload()
Gets packed chunks indices to preload before asset loading action
Declaration
protected virtual AssetChunksFlag getChunksToPreload() const overrideReturns
| AssetChunksFlag Chunks to load flags | 
Overrides
GetLOD(int32 lodIndex)
Gets the mesh for a particular LOD index.
Declaration
public virtual ModelLODBase* GetLOD(int32 lodIndex) const overrideParameters
| int32
        lodIndex 
 | 
Returns
| ModelLODBase 
 | 
Overrides
GetLODsCount()
Gets amount of the level of details in the model.
Declaration
public virtual int32 GetLODsCount() const overrideReturns
| int32 
 | 
Overrides
GetMaxResidency()
Gets resource maximum residency level.
Declaration
public virtual int32 GetMaxResidency() const overrideReturns
| int32 
 | 
Overrides
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 overrideParameters
| int32
        meshIndex 
 | 
| int32
        lodIndex 
 | 
Returns
| MeshBase 
 | 
Overrides
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 overrideParameters
| Array<MeshBase >
        meshes 
 | 
| int32
        lodIndex 
 | 
Overrides
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) overrideParameters
| Array<MeshBase >
        meshes 
 | 
| int32
        lodIndex 
 | 
Overrides
HasAnyLODInitialized()
Determines whether any LOD has been initialized.
Declaration
public bool HasAnyLODInitialized() constReturns
| bool 
 | 
InitAsVirtual()
Initializes asset data as virtual asset.
Declaration
public virtual void InitAsVirtual() overrideOverrides
Intersects(const Ray& ray, const Matrix& world, Real& distance, Vector3& normal, Mesh* *mesh, int32 lodIndex = 0)
Determines if there is an intersection between the Model and a Ray in given world using given instance.
Declaration
public bool Intersects(const Ray& ray, const Matrix& world, Real& distance, Vector3& normal, Mesh* *mesh, int32 lodIndex = 0)Parameters
| Ray
        ray The ray to test | 
| Matrix
        world World to test | 
| Real
        distance When the method completes, contains the distance of the intersection (if any valid). | 
| Vector3
        normal When the method completes, contains the intersection surface normal vector (if any valid). | 
| Mesh
        mesh Mesh, or null | 
| int32
        lodIndex Level Of Detail index | 
Returns
| bool True whether the two objects intersected | 
Intersects(const Ray& ray, const Transform& transform, Real& distance, Vector3& normal, Mesh* *mesh, int32 lodIndex = 0)
Determines if there is an intersection between the Model and a Ray in given world using given instance.
Declaration
public bool Intersects(const Ray& ray, const Transform& transform, Real& distance, Vector3& normal, Mesh* *mesh, int32 lodIndex = 0)Parameters
| Ray
        ray The ray to test | 
| Transform
        transform The instance transformation. | 
| Real
        distance When the method completes, contains the distance of the intersection (if any valid). | 
| Vector3
        normal When the method completes, contains the intersection surface normal vector (if any valid). | 
| Mesh
        mesh Mesh, or null | 
| int32
        lodIndex Level Of Detail index | 
Returns
| bool True whether the two objects intersected | 
load()
Load data from the chunks
Declaration
protected virtual LoadResult load() overrideReturns
| LoadResult Loading result | 
Overrides
Render(GPUContext* context, int32 lodIndex = 0)
Draws the meshes. Binds vertex and index buffers and invokes the draw calls.
Declaration
public void Render(GPUContext* context, int32 lodIndex = 0)Parameters
| GPUContext
        context GPU context to draw with. | 
| int32
        lodIndex The Level Of Detail index. | 
SetSDF(const SDFData& sdf)
Sets set SDF data (releases the current one).
Declaration
public void SetSDF(const SDFData& sdf)Parameters
| SDFData
        sdf 
 | 
SetupLODs(const Span<int32>& meshesCountPerLod)
Setups the model LODs collection including meshes creation.
Declaration
public bool SetupLODs(const Span<int32>& meshesCountPerLod)Parameters
| Span<int32>
        meshesCountPerLod The meshes count per lod array (amount of meshes per LOD). | 
Returns
| bool True if failed, otherwise false. | 
SetupMaterialSlots(int32 slotsCount)
Resizes the material slots collection. Updates meshes that were using removed slots.
Declaration
public virtual void SetupMaterialSlots(int32 slotsCount) overrideParameters
| int32
        slotsCount 
 | 
Overrides
unload(bool isReloading)
Unloads asset data
Declaration
protected virtual void unload(bool isReloading) overrideParameters
| bool
        isReloading True if asset is reloading data, otherwise false. |