CubismParameterStore

Updated: 01/17/2020

This page is for Cubism version 4.2 or earlier. Click here for the latest version.

Summary

CubismParameterStore can be used to store/restore CubismModel parameters and part values.

If CubismParameterStore is not used, the results of processing values with Expression or other methods may not be correct.

If a value operation such as Expression is performed between restore and save, the result of the value manipulation is saved, so the value is added/multiplied to the restored post-operation value, and the result is not as expected.
When value manipulation is performed outside of restore-to-save, the state before the value was manipulated is restored, so that subsequent manipulation of the value through addition/multiplication will result in the proper result.

Click here for the corresponding tutorial article.

The following process is used to save/restore CubismModel parameters and part values.

  1. Get reference to parameters and parts to be saved/restored
  2. Save parameter and part values
  3. Restore parameter and part values

Get reference to parameters and parts to be saved/restored

CubismParameterStore.OnEnable caches references to CubismModel parameters and parts.

if(DestinationParameters == null)
{
    DestinationParameters = this.FindCubismModel().Parameters;
}

if(DestinationParts == null)
{
    DestinationParts = this.FindCubismModel().Parts;
}

This is done by `CubismParameterStore.OnEnable().’

Save parameter and part values

Stores the current parameter and part values for the model.
The timing for saving the values is after the animation is applied and before manipulating the values in the various Cubism components.

// Save parameter values
for(var i = 0; i < _parameterValues.Length; ++i)
{
    _parameterValues[i] = DestinationParameters[i].Value;
}

// Save the part opacity
for(var i = 0; i < _partOpacities.Length; ++i)
{
    _partOpacities[i] = DestinationParts[i].Opacity;
}

This is done by `CubismParameterStore.SaveParameters().’

Restore parameter and part values

Restores saved parameter and part values.
The timing for restoring the values is before the animation is applied.

// Set saved parameter values
for(var i = 0; i < _parameterValues.Length; ++i)
{
    DestinationParameters[i].Value = _parameterValues[i];
}

// Set the saved part opacity
for(var i = 0; i < _partOpacities.Length; ++i)
{
    DestinationParts[i].Opacity = _partOpacities[i];
}

This is done by `CubismParameterStore.RestoreParameters().’

Was this article helpful?
YesNo
Please let us know what you think about this article.