1. Explore Live2D API again

Last time I looked at loading the Live2D model from a file, the Cubism SDK does a lot of work and it is very easy to use. Different from pictures, Live2D does not end when it is displayed on the screen. There are two interactive operations with users in the Demo project:

  1. The view direction of the Live2D model changes with finger dragging
  2. Click the model to trigger the action randomly

The drag event must be triggered in the ACTION_MOVE of onTouchEvent. Demo listens for the onTouchEvent of the Activity. We can do the same in the View. Events through JNI to native layer, through LAppDelegate: : OnTouchMoved, LAppView: : OnTouchesMoved, LAppLive2DManager: : OnDrag, Final CubismUserModel in execution to the SDK: : SetDragging implementation effect.

The Demo does not listen for click events, but does a click decision in ACTION_UP. Different clicking positions of the model can achieve different clicking effects (I did not find that in the test Demo). The clicking area is set by the Live2D model itself, and there are only two clicking processing areas in the Demo: random expressions are changed when clicking the head area, and random actions are started when clicking the body area.

If (_models[I]->HitTest(HitAreaNameHead, x, y)) {_models[I]->SetRandomExpression(); } else if (_models[i]->HitTest(HitAreaNameBody, x, y)) { _models[i]->StartRandomMotion(MotionGroupTapBody, PriorityNormal, FinishedMotion); }Copy the code

SetRandomExpression ultimately is CubismMotionManager: : StartMotionPriority, SDK is probably no random expression method, expression of random selection or in business writing, So let’s take one of the expressions and pass it in.

StartRandomMotion the implementation of the slightly more complicated, and ultimately realize or CubismMotionManager: : StartMotionPriority, but action is more complicated than the expression a lot, In addition to an ID, you also need to read the corresponding file by ID (and possibly audio). Take a look at a complicated action with 50 cents of special effects:

Live2DView package plan

The operations in the Demo are still very limited, so the code is not very difficult to read, and you won’t understand the difficulty until you write it yourself. The next plan is to encapsulate a Live2DView in order to put it into practice. The function of Live2DView is very simple, without considering the details, just need to provide a setModelPath function to pass in the file path and display it, and implement basic user operations.

Most of the display of Live2D can refer to the implementation of Demo, the project has been created, cmakelists. TXT needs to modify the path configuration to access the project. Note that the Framework’s cmakelist.txt also includes an include. Missing this configuration wasted me over an hour.

)


Today I wrote some code of Live2DView, the biggest difficulty should be in OpenGL. Last time I contacted it was when I finished my graduation project, I have been working for three years in a blink of an eye, and my youth and hair are gradually leaving me.

It’s not easy to work on Saturday, tomorrow is finally a day off… 【 Lack of attention 】