Cubism SDK‎ > ‎Live2D Library‎ > ‎

Operate the Motion Parameter

Make settings of Motion Parameters
You usually make settings of Motion Parameters from the motion, and you can also specify its value directly.
In this case, you can choose one of three ways as below;

1. Overwrite the value
The setParamFloat function is used.
Set Motion Parameter's ID for the first parameter, set the value for the second parameter, and set the influence for the third parameter.
You can omit to set the influence, which will be "1".
For example, if you set "0.5" for the influence, it will be set with 50% influence of the previous value remained.

Example
live2DModel->setParamFloat( "PARAM_ANGLE_X", 30 ,1 );//Set PARAM_ANGLE_X as 30 

2. Add to the present value
The addToParamFloat function is used.
The parameter is the same as of setParamFloat.
The difference from setParamFloat is that the set value will be added.

Example
live2DModel->addToParamFloat( "PARAM_ANGLE_X", 1, 1);//Add 1 to PARAM_ANGLE_X value


3. Multiply to the present value
The multParamFloat function is used.
The parameter is the same as of setParamFloat.
The difference from setParamFloat is that the set value will be multiplied


Example
live2DModel->multParamFloat( "PARAM_ANGLE_X", 2, 1);//The value of PARAM_ANGLE_X is multiplied by 2


The getParamFloat function is used to get the present Motion Parameter value.

Specify with the index of the Motion Parameter

There are two ways to specify the Motion Parameter's ID, one is to specify it with the text strings like "PARAM_ANGLE_X", and the other is to specify it with the index.
Using index is quicker, so it is recommended to use the index if you want to invoke frequently.
You can get the index of the Motion Parameter with the getParamIndex function.

Example
//When initializing
int paramAngleX;
paramAngleX = live2DModel->getParamIndex( "PARAM_ANGLE_X" );

//When setting Motion Parameters
live2DModel->setParamFloat( paramAngleX, 30 , 1);


Save Motion Parameters

The saveParam function is used to save the present Motion Parameter value of the model temporarily.
If you execute it, all Motion Parameter's values are saved temporarily and restored when the 
loadParam function is loaded next time.

Example

// Set the Motion Parameter as 30
live2DModel->setParamFloat( "PARAM_ANGLE_X", 30 ,1 );

//Save all the present Motion Parameter's values temporarily
live2DModel->saveParam();

// Set the value as 0
live2DModel->setParamFloat( "PARAM_ANGLE_X", 0 ,1 );

//output: value = 0
printf("value = %f",live2DModel->getParamFloat( "PARAM_ANGLE_X" ) );

//Restore the value of previous saveParam
live2DModel->loadParam();

//output: value = 30
printf("value = %f",live2DModel->getParamFloat( "PARAM_ANGLE_X" ) );

Set the transparency of the part

The setPartsOpacity function and the getPartsOpacity function are used to set and get the transparency of the part.

Example
// Set the transparency of face parts as 0.5
live2DModel->setPartsOpacity( "PARTS_01_FACE_001",0.5 );


When to apply the Motion Parameter and its cost

When the Motion Parameter settings are executed, only the Motion Parameter's value is rewritten and the point is not calculated.
The point is calculated by the update function after changing the Motion Parameter, and the draw function afterwards will draw the model with the applied Motion Parameter.

Comments