Automatic Eye-blinking Settings (SDK for Cocos Creator)
This section explains how to make the model blink automatically.
The following explanation is based on the assumption that the project is the same as the project for which the “Import SDK” was performed.
If the model has the standard parameters, [EyeL open/close (ParamEyeLOpen)] and [EyeR open/close (ParamEyeROpen)], the Prefab of the model generated by the import will automatically be set to blink.
For models that have not been configured as above to blink automatically, you can set them to blink by following the procedure described on this page.
For eye blinking settings, the Cubism SDK uses a component called EyeBlink.
To set up EyeBlink on a Cubism model, do the following three things.
- Attach a Component to Manage Eye Blinking
- Specify Parameters to Make Them Blink
- Set Up a Component to Automatically Manipulate the Value of the Parameter for Eye Blinking
Attach a Component to Manage Eye Blinking
Attach a component called CubismEyeBlinkController that manages eye blinking.
CubismEyeBlinkController has two setting items.
- Blend Mode: Specifies how the Eye Opening value is calculated for the value currently set for the specified parameter.
- Multiply: Multiply the currently set value by the Eye Opening value.
- Additive: Add the Eye Opening value to the currently set value.
- Override: Overwrite the currently set value with the Eye Opening value.
- Eye Opening: The value of eye opening and closing. It is treated as open at 1 and closed at 0. When this value is manipulated from the outside, the value of the specified parameter is also changed accordingly.
For this example, set Blend Mode to [Override].
Specify Parameters to Make Them Blink
Nodes that manage the parameters of the model are located under [Model]/Parameters/.
The name set for this Node is the ID of the parameter.
These are identical to those obtained with CubismModel.parameters().
From among the Nodes for this parameter, attach a component called CubismEyeBlinkParameter to the one with the ID to be treated as an eye blinking.
If a CubismEyeBlinkParameter is attached to the Node for the parameter, the CubismEyeBlinkController will refer to it to set the eye opening and closing during scene execution.
With the above settings, it is now possible to perform blink operations from scripts, etc. However, this is not enough to perform blinking automatically.
To have it blink automatically, you must also set up a component that manipulates the value periodically.
Set Up a Component to Automatically Manipulate the Value of the Parameter for Eye Blinking
As with the CubismEyeBlinkController, attach a component called CubismAutoEyeBlinkInput to the root of the model.
CubismAutoEyeBlinkInput has the following three settings.
– Mean: Sets the time until eye blinking is performed. The unit is seconds. In practice, the time is calculated by adding the error due toMaximum Deviation to this value.
– Maximum Deviation: Sets the maximum value of fluctuation to be added to the time set by Mean. The value to be set is a number greater than or equal to 0.
If you have the character blink at the time you set for Mean above, the cycle will be uniform, which is unnatural for the character’s behavior.
Therefore, random fluctuations are added to the set time period to make the motion appear natural.
The actual calculation is as follows.
Time to next eye blinking = Mean + (random value between -Maximum Deviation and +Maximum Deviation)
– Timescale: Sets the speed at which the eyes open and close. The smaller the value you set, the slower it will be.
For this example, set Mean to 2.5,Maximum Deviation to 2, and Timescale to 10.
This completes the automatic eye-blinking setup.
If you run Scene in this state, you can make the model blink automatically.