Class Model
Model asset that contains model object made of meshes which can rendered on the GPU.
Namespace: FlaxEngine
Assembly: FlaxEngine.CSharp.dll
Syntax
[Unmanaged]
public class Model : ModelBase
Constructors
Model()
Fields
MaxLODs
The maximum amount of levels of detail for the model.
Declaration
public const int MaxLODs = 6
Field Value
System.Int32
|
MaxMaterialSlots
The maximum allowed amount of material slots per model resource
Declaration
public const int MaxMaterialSlots = 4096
Field Value
System.Int32
|
MaxMeshes
The maximum amount of meshes per model LOD.
Declaration
public const int MaxMeshes = 4096
Field Value
System.Int32
|
Properties
LoadedLODs
Gets the amount of loaded model LODs.
Declaration
[Unmanaged]
public int LoadedLODs { get; }
Property Value
System.Int32
|
LODs
Model level of details. The first entry is the highest quality LOD0 followed by more optimized versions.
Declaration
[Unmanaged]
public ModelLOD[] LODs { get; }
Property Value
ModelLOD[]
|
SDF
The generated Sign Distant Field (SDF) for this model (merged all meshes). Use GenerateSDF to update it.
Declaration
[Unmanaged]
public ModelBase.SDFData SDF { get; }
Property Value
ModelBase.SDFData
|
Methods
Draw(ref RenderContext, MaterialBase, ref Matrix, StaticFlags, Boolean, SByte)
Draws the model.
Declaration
[Unmanaged]
public void Draw(ref RenderContext renderContext, MaterialBase material, ref Matrix world, StaticFlags flags, bool receiveDecals = true, sbyte sortOrder = 0)
Parameters
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. |
System.Boolean
receiveDecals
True if rendered geometry can receive decals, otherwise false. |
System.SByte
sortOrder
Object sorting key. |
GenerateSDF(Single, Int32, Boolean, Single, Boolean)
Generates the Sign Distant Field for this model.
Declaration
[Unmanaged]
public bool GenerateSDF(float resolutionScale = 1F, int lodIndex = 6, bool cacheData = true, float backfacesThreshold = 0.6F, bool useGPU = true)
Parameters
System.Single
resolutionScale
The SDF texture resolution scale. Use higher values for more precise data but with significant performance and memory overhead. |
System.Int32
lodIndex
The index of the LOD to use for the SDF building. |
System.Boolean
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. |
System.Single
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. |
System.Boolean
useGPU
Enables using GPU for SDF generation, otherwise CPU will be used (async via Job System). |
Returns
System.Boolean
True if failed, otherwise false. |
Remarks
Can be called in async in case of SDF generation on a CPU (assuming model is not during rendering).
GetBox(Matrix, Int32)
Gets the model bounding box in custom matrix world space.
Declaration
[Unmanaged]
public BoundingBox GetBox(Matrix world, int lodIndex = 0)
Parameters
Matrix
world
The transformation matrix. |
System.Int32
lodIndex
The Level Of Detail index. |
Returns
BoundingBox
The bounding box. |
GetBox(Transform, Int32)
Gets the model bounding box in custom transformation.
Declaration
[Unmanaged]
public BoundingBox GetBox(Transform transform, int lodIndex = 0)
Parameters
Transform
transform
The instance transformation. |
System.Int32
lodIndex
The Level Of Detail index. |
Returns
BoundingBox
The bounding box. |
GetBox(Int32)
Gets the model bounding box in local space.
Declaration
[Unmanaged]
public BoundingBox GetBox(int lodIndex = 0)
Parameters
System.Int32
lodIndex
The Level Of Detail index. |
Returns
BoundingBox
The bounding box. |
Save(Boolean, String)
Saves this asset to the file. Supported only in Editor.
Declaration
[Unmanaged]
public bool Save(bool withMeshDataFromGpu = false, string path = null)
Parameters
System.Boolean
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. |
System.String
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
System.Boolean
True if cannot save data, otherwise false. |
Remarks
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.
SetSDF(ModelBase.SDFData)
Sets set SDF data (releases the current one).
Declaration
[Unmanaged]
public void SetSDF(ModelBase.SDFData sdf)
Parameters
ModelBase.SDFData
sdf
|
SetupLODs(Int32[])
Setups the model LODs collection including meshes creation.
Declaration
[Unmanaged]
public bool SetupLODs(int[] meshesCountPerLod)
Parameters
System.Int32[]
meshesCountPerLod
The meshes count per lod array (amount of meshes per LOD). |
Returns
System.Boolean
True if failed, otherwise false. |