Cubism SDK‎ > ‎Introduction‎ > ‎

Cooperate with Other Systems

(*Information written in blue was added in 03 Oct, 2013.)

This is to explain about the first check points to cooperate Live2D with systems of other companies (like game engines).

Followings are about cooperation with other environments except Unity and cocos2d-x that cooperate with SDK. Or you do not need the information in this page if you use Live2D in the standard program environment of each platform.

The possibility of cooperation becomes higher if you can include the following operation or drawing into other system.

Initialize and release of Live2D
You can initialize Live2d with Live2D::init( ). Or you can release the memory you use and make it in a condition to unload the library with Live2D::dispose(). (You do not need to unload the library on the way for normal games.)

Memory management
Define the allocator externally to secure the memory (CPU or GPU) to be used in Live2D, and register it to (Live2D::init()) when initializing Live2D. It may occur the request of memory for blocking more than 4K from the Live2D memory manager.

Load and initialize the model texture
As Live 2D provides the function only for drawing, and is designed on the assumption that the resource does not be managed by Live2D itself but by outer code or game engine side.

  • Concerning the unique data like the modeling load the file outside Live2D and take the bite strings to Live2D library for initializing.
  • Concerning the texture, initialize it outside Live2D as a texture and register it in Live2D.

Start the action motion
You can invoke Live2D animation or the order of face expressions to correspond for clicking and so on. Process in Live2D is not thread-safe, so you need to keep away to be updated or drawn the model data from several threads simultaneously.

Update and draw the model for each frame
You can order following things to each model which you have initialized for each frame;
  • Set each Motion Parameter of the model, and start or stop the animation data.
  • Update() process of the model (mainly CPU calculation).
  • Draw() process of the model (mainly drawing the polygon), which will be explained in later page.

Details about rendering
It is expressed by drawing the flat polygons (texture includes semitransparent parts) blending from the rear in orders in Live2D, which is different from drawing using depth buffer of the ordinal 3D software (It is like to express the layers in Photoshop on the 3D).

Specifically, the settings are as below;
  • Depth testing is generally off. (You can draw it with changing Z value only for the part assigning each polygon.)
  • The Shader performs only alpha blend processing of standard texture.
  • Polygons with texture are drawn by vertex array, UV array, or index array.

Each drawing order is executed by invoking draw() of Live2D model on the way of 3D order of each platform like OpenGL etc,. The drawing order is encapsulated in Live2D library and invoked. The source code of drawing parts is not disclosed, however it is available under special contract. Please contact to our support center for details.

The processing of drawing is differ when drawing the subject directly on the same screen as of 3D, and when drawing it on the off-screen buffer first then draw it again on the screen. If you want to make the Live2D characters semitransparent, you need to take the method of off-screen in no.2.  
    1.When drawing Live2D directly on the screen

Execute the drawing order of Live2D after rendering opaque 3D polygons. You need some technique to do it, since it is difficult for Live2D to create the situation of enclosing it with 3D objects in front and in the rear with ordinal depth buffer system.
It is no problem to use this method for 2D games and you do not need to display Live2D characters in semitransparent.

    2.When drawing Live2D on the off-screen

If  you want to draw Live2D on the screen after drawing it on the off-screen like frame buffer object (FBO), the process is as follows. We explain it with FBO as an example.

2-1 Draw Live2D on the transparent FBO
2-2 Draw FBO on the screen (same like rendering the texture with transparency)
You can make Live2D model semitransparent by drawing Live2D on FBO and make FBO semitransparent to draw on the screen.
(If you make it semitransparent with the method of 1, each layer become transparent and the phenomenon like the face becomes transparent and the back hair is shown appears.)

*In such a environment like the off-screen and the texture are not premultiplied (a format to save the alpha value multiplied RGB colors beforehand), the result tends to be 1. the different color from the original, or 2. that there are a little colors appeared around the character.