Immediately Stabilize Physics Calculations after Model Display
In Cubism 4 SDK R5, the ability to instantly stabilize physics calculations was added.
When a model is displayed in the Cubism SDK, if the parameter values are not the default values, the physics operations may run unstable, and this feature is used to instantly stabilize the physics.
To immediately stabilize the physics operations, call CubismPhysics::Stabilization() in Native, CubismPhysics.stabilization() in Web, or CubismPhysics.Stabilization() in Unity immediately after the model is initialized or placed.
The following is a snippet that uses a sample scene from the Cubism SDK to stabilize physics operations immediately after model initialization.
Native
On only the first frame of the model, the stabilization function is called just before the physics process.
bool isUpdateFirst = true; void LAppModel::Update() { ... // Physics settings if (_physics ! = NULL) { if (isUpdateFirst) { // Stabilize physics immediately after initialization _physics->Stabilization(_model); isUpdateFirst = false; } _physics->Evaluate(_model, deltaTimeSeconds); } ...
Web
On only the first frame of the model, the stabilization function is called just before the physics process.
_isUpdateFirst: boolean = true; public update(): void { ... // Physics settings if (this._physics ! = null) { if (this._isUpdateFirst) { // Stabilize physics immediately after initialization this._physics.stabilization(this._model); this._isUpdateFirst = false; } this._physics.evaluate(this._model, deltaTimeSeconds); } ...
Unity
By attaching the following component to the prefabricated root of the model, the stabilization function is called just before the physics process for only the first frame of the model.
using Live2D.Cubism.Framework; using Live2D.Cubism.Framework.Physics; using UnityEngine; public class PhysicsStabilizer : MonoBehaviour, ICubismUpdatable { private bool _isUpdateFirst = true; public bool HasUpdateController { get; set; } public int ExecutionOrder { get { return CubismUpdateExecutionOrder.CubismPhysicsController - 1; } } public bool NeedsUpdateOnEditing { get { return false; } } public void OnLateUpdate() { if (! _isUpdateFirst) { return; } // Stabilize physics immediately after initialization GetComponent<CubismPhysicsController>().Stabilization(); _isUpdateFirst = false; } public void Start() { HasUpdateController = (GetComponent<CubismUpdateController>() ! = null); } private void LateUpdate() { if (!HasUpdateController) { OnLateUpdate(); } } }