unreal.MLDeformerTrainingModel

class unreal.MLDeformerTrainingModel(outer: Object | None = None, name: Name | str = 'None')

Bases: Object

The 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)

  • sample_bone_rotations (Array[float]): [Read-Write] The bone rotations in bone (local) space for this sample. This is updated after SetCurrentSampleIndex 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 SetCurrentSampleIndex is called.

  • sample_deltas (Array[float]): [Read-Write] The delta values per vertex for this sample. This is updated after SetCurrentSampleIndex is called. Contains an xyz (3 floats) for each vertex.

get_model() MLDeformerModel

Get the runtime ML Deformer model object.

Return type:

MLDeformerModel

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:

bool

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

next_sample() bool

Take the next sample. This will return false when there is something wrong or we sampled more times than NumSamples() returns.

Return type:

bool

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 SetCurrentSampleIndex is called and is 6 floats per bone (2 columns of 3x3 rotation matrix).

Type:

(Array[float])

property sample_curve_values: None

[Read-Write] The curve weights. This is updated after SetCurrentSampleIndex is called.

Type:

(Array[float])

property sample_deltas: None

[Read-Write] The delta values per vertex for this sample. This is updated after SetCurrentSampleIndex is called. Contains an xyz (3 floats) for each vertex.

Type:

(Array[float])

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) –

set_num_floats_per_curve(num_floats_per_curve) None

Set the number of floats per curve. On default this is one.

Parameters:

num_floats_per_curve (int32) –