void updateModel() { view.update(Input.acceleration); if (live2DModel == null) { if (LAppDefine.DEBUG_LOG) { Debug.Log("Can not update there is no model data"); } return; } long timeMSec = UtSystem.getUserTimeMSec() - startTimeMSec; double timeSec = timeMSec / 1000.0; double t = timeSec * 2 * Math.PI; if (mainMotionManager.isFinished()) { //startRandomMotion(LAppDefine.MOTION_GROUP_IDLE, LAppDefine.PRIORITY_IDLE); turnOnMouseTracking(); } //----------------------------------------------------------------- live2DModel.loadParam(); bool update = mainMotionManager.updateParam(live2DModel); if (!update) { eyeBlink.updateParam(live2DModel); } live2DModel.saveParam(); //----------------------------------------------------------------- if (expressionManager != null) { expressionManager.updateParam(live2DModel); } live2DModel.addToParamFloat(PARAM_ANGLE_X, dragX * 30, 1); live2DModel.addToParamFloat(PARAM_ANGLE_Y, dragY * 30, 1); live2DModel.addToParamFloat(PARAM_ANGLE_Z, (dragX * dragY) * -30, 1); live2DModel.addToParamFloat(PARAM_BODY_X, dragX, 10); live2DModel.addToParamFloat(PARAM_EYE_BALL_X, dragX, 1); live2DModel.addToParamFloat(PARAM_EYE_BALL_Y, dragY, 1); live2DModel.addToParamFloat(PARAM_ANGLE_X, (float)(15 * Math.Sin(t / 6.5345)), 0.5f); live2DModel.addToParamFloat(PARAM_ANGLE_Y, (float)(8 * Math.Sin(t / 3.5345)), 0.5f); live2DModel.addToParamFloat(PARAM_ANGLE_Z, (float)(10 * Math.Sin(t / 5.5345)), 0.5f); live2DModel.addToParamFloat(PARAM_BODY_X, (float)(4 * Math.Sin(t / 15.5345)), 0.5f); live2DModel.setParamFloat(PARAM_BREATH, (float)(0.5f + 0.5f * Math.Sin(t / 3.2345)), 1); live2DModel.addToParamFloat(PARAM_ANGLE_X, 90 * accelX, 0.5f); live2DModel.addToParamFloat(PARAM_ANGLE_Z, 10 * accelX, 0.5f); if (physics != null) { physics.updateParam(live2DModel); } if (lipSync) { live2DModel.setParamFloat(PARAM_MOUTH_OPEN_Y, lipSyncValue, 0.8f); } if (pose != null) { pose.updateParam(live2DModel); } if (source.isPlaying) { live2DModel.setParamFloat(PARAM_MOUTH_OPEN_Y, source.volume); } live2DModel.update(); }
/* * 更新 */ public void Update() { if (!isInitialized() || isUpdating()) { return; } view.update(Input.acceleration); if (live2DModel == null) { if (LAppDefine.DEBUG_LOG) { Debug.Log("Can not update there is no model data"); } return; } if (!Application.isPlaying) { live2DModel.update(); return; } long timeMSec = UtSystem.getUserTimeMSec() - startTimeMSec; double timeSec = timeMSec / 1000.0; double t = timeSec * 2 * Math.PI;// 2πt // 待機モーション判定 if (mainMotionManager.isFinished()) { // モーションの再生がない場合、待機モーションの中からランダムで再生する StartRandomMotion(LAppDefine.MOTION_GROUP_IDLE, LAppDefine.PRIORITY_IDLE); } //----------------------------------------------------------------- live2DModel.loadParam(); // 前回セーブされた状態をロード bool update = mainMotionManager.updateParam(live2DModel); // モーションを更新 if (!update) { // メインモーションの更新がないとき eyeBlink.updateParam(live2DModel);// 目パチ } live2DModel.saveParam();// 状態を保存 //----------------------------------------------------------------- if (expressionManager != null) { expressionManager.updateParam(live2DModel); // 表情でパラメータ更新(相対変化) } // ドラッグによる変化 // ドラッグによる顔の向きの調整 live2DModel.addToParamFloat(L2DStandardID.PARAM_ANGLE_X, dragX * 30, 1);// -30から30の値を加える live2DModel.addToParamFloat(L2DStandardID.PARAM_ANGLE_Y, dragY * 30, 1); live2DModel.addToParamFloat(L2DStandardID.PARAM_ANGLE_Z, (dragX * dragY) * -30, 1); // ドラッグによる体の向きの調整 live2DModel.addToParamFloat(L2DStandardID.PARAM_BODY_ANGLE_X, dragX, 10);// -10から10の値を加える // ドラッグによる目の向きの調整 live2DModel.addToParamFloat(L2DStandardID.PARAM_EYE_BALL_X, dragX, 1);// -1から1の値を加える live2DModel.addToParamFloat(L2DStandardID.PARAM_EYE_BALL_Y, dragY, 1); // 呼吸など live2DModel.addToParamFloat(L2DStandardID.PARAM_ANGLE_X, (float)(15 * Math.Sin(t / 6.5345)), 0.5f); live2DModel.addToParamFloat(L2DStandardID.PARAM_ANGLE_Y, (float)(8 * Math.Sin(t / 3.5345)), 0.5f); live2DModel.addToParamFloat(L2DStandardID.PARAM_ANGLE_Z, (float)(10 * Math.Sin(t / 5.5345)), 0.5f); live2DModel.addToParamFloat(L2DStandardID.PARAM_BODY_ANGLE_X, (float)(4 * Math.Sin(t / 15.5345)), 0.5f); live2DModel.setParamFloat(L2DStandardID.PARAM_BREATH, (float)(0.5f + 0.5f * Math.Sin(t / 3.2345)), 1); // 加速度による変化 live2DModel.addToParamFloat(L2DStandardID.PARAM_ANGLE_X, 90 * accelX, 0.5f); live2DModel.addToParamFloat(L2DStandardID.PARAM_ANGLE_Z, 10 * accelX, 0.5f); if (physics != null) { physics.updateParam(live2DModel); // 物理演算でパラメータ更新 } // リップシンクの設定 if (lipSync) { live2DModel.setParamFloat(L2DStandardID.PARAM_MOUTH_OPEN_Y, lipSyncValue, 0.8f); } // ポーズの設定 if (pose != null) { pose.updateParam(live2DModel); } live2DModel.update(); }