unreal.MLDeformerTrainingModel¶
- class unreal.MLDeformerTrainingModel(outer: Object | None = None, name: Name | str = 'None')¶
Bases:
ObjectThe training model base class. This class is used to interface with Python by providing some methods you can call inside your python training code. For example it allows you to get all the sampled data, such as the deltas, bones and curve values. When you create a new model you need to create a class inherited from this base class, and define a Train method inside it as follows: code{.cpp}: // Doesn’t need an implementation inside cpp, just a declaration in the header file. UFUNCTION(BlueprintImplementableEvent, Category = “Training Model”) int32 Train() const; endcode: Now inside your Python class you do something like: code{.py}: unreal.uclass(): class YourModelPythonTrainingModel(unreal.YourTrainingModel): unreal.ufunction(override=True): def train(self): # …do training here… return 0 # A value of 0 is success, 1 means aborted, see ETrainingResult. endcode: The editor will execute the Train method, which will trigger the “train” method in your Python class to be executed. Keep in mind that in Unreal Engine all python code is lower case. So a “Train” method inside c++ will need to be called “train” inside the python code. Or if you have something called “PerformMyTraining” it will need to be called “perform_my_training” inside Python.
C++ Source:
Plugin: MLDeformerFramework
Module: MLDeformerFrameworkEditor
File: MLDeformerTrainingModel.h
Editor Properties: (see get_editor_property/set_editor_property)
mask_index_per_sample(Array[int32]): [Read-Write] The mask index for each sample. See GetTrainingInputAnimMasks() and GetTrainingInputAnimMaskData().sample_bone_rotations(Array[float]): [Read-Write] The bone rotations in bone (local) space for this sample. This is updated after NextSample is called and is 6 floats per bone (2 columns of 3x3 rotation matrix).sample_curve_values(Array[float]): [Read-Write] The curve weights. This is updated after NextSample is called.sample_deltas(Array[float]): [Read-Write] The delta values per vertex for this sample. This is updated after NextSample is called. Contains an xyz (3 floats) for each vertex.
- get_mask_index_per_sample_array() Array[int32]¶
For each sample we took, this contains the index inside the mask as returned by the GetTrainingInputAnimMasks() array.
- Return type:
Array[int32]
- get_model() MLDeformerModel¶
Get the runtime ML Deformer model object.
- Return type:
- get_needs_resampling() bool¶
Check whether we need to resample the inputs and outputs, or if we can use a cached version. This will return true if any inputs changed, that indicate that we should regenerate any cached data.
- Returns:
Returns true when we need to regenerate any cached data, otherwise false is returned.
- Return type:
- get_number_sample_curves() int32¶
Get number of input curves.
- Return type:
int32
- get_number_sample_deltas() int32¶
Get the number of vertex deltas.
- Return type:
int32
- get_number_sample_transforms() int32¶
Get the number of input transforms. This is the number of bones.
- Return type:
int32
- get_training_input_anim_mask_data(mask_name) Array[float]¶
Get the per vertex data for a given mask name. The mask name must be one that is present in the array returned by GetTrainingInputAnimMasks.
- get_training_input_anim_masks() Array[Name]¶
Get the names of all valid training animation masks. They are valid when they are used, the anim is enabled, and the attribute exists on the skeletal mesh.
- property mask_index_per_sample: None¶
[Read-Write] The mask index for each sample. See GetTrainingInputAnimMasks() and GetTrainingInputAnimMaskData().
- Type:
(Array[int32])
- next_sample() bool¶
Take the next sample. This will update the deltas, curve values and bone rotation arrays with values sampled at the next frame. This will return false when there is something wrong or we sampled more times than NumSamples() returns.
- Return type:
- num_samples() int32¶
Get the number of samples in this data set. This is the number of sample frames we want to train on.
- Return type:
int32
- reset_sampling() None¶
This will make the sampling start again from the beginning. This can be used if you have to iterate multiple times over the data set.
- property sample_bone_rotations: None¶
[Read-Write] The bone rotations in bone (local) space for this sample. This is updated after NextSample is called and is 6 floats per bone (2 columns of 3x3 rotation matrix).
- property sample_curve_values: None¶
[Read-Write] The curve weights. This is updated after NextSample is called.
- property sample_deltas: None¶
[Read-Write] The delta values per vertex for this sample. This is updated after NextSample is called. Contains an xyz (3 floats) for each vertex.
- set_device_list(device_names, preferred_device_index) None¶
Set the list of possible training devices.
- set_needs_resampling(needs_resampling) None¶
Specify whether we need to resample any cached data or not, because our input assets, or any other relevant settings changed that would invalidate the cached data.
- Parameters:
needs_resampling (bool)