LoginSignup
2
1

More than 1 year has passed since last update.

【バ美肉!!】 Live2D Cubism Native Samples for Cocos2d-xのDemoをubuntu18.04で動かしてみた

Posted at

babiniku.gif

1 概要

1.1 Live2dとは

  • ”絵”を立体的に動かすことが可能なアプリケーション(導入例:にじさんじ🌈の配信とかですわ。💯 🦂)

1.2 Cubism SDK for Nativeとは

  • C++で実装されたSDK。様々なアーキテクチャへの移植性が高い
  • 開発環境もwin,Mac,iOS,android,linuxなど
  • OpenGL,Cocos2d-x,DirectX等のフレームワークに対応

1.3 cocos2d-x とは

  • Cocos2d-x は 2D/3D ゲーム開発用のゲームフレームワーク
  • 無料で使用可能
  • 処理速度が速い

2 Cubism SDK for Nativeとcocos2d-xのビルド

開発環境

  • OS: Ubuntu 18.04 LTS
  • CPU: i7-6500U CPU @ 2.50GHz × 4
  • メモリ: 11.4 GiB

live2dのCubism SDK for Nativeは一応ubuntuに対応しているが、ビルドを通すにあたり情報が散らばってて、複雑だったので備忘録としてまとめる。
この記事ではcocos2d-xを使ってDemoを動かす。
OpenGLを使うこともできるらしいが、私がやったところコンパイルは通るものの、
Demo実行時にコアダンプして動かなかった。

以下に私が試した方法を示す。

2.1 Cubism SDK for Nativeのダウンロード

CubismNativeSamplesのダウンロード

Ubuntu18.04に対応しているバージョンは4-r.1である。
ビルドなどの詳細についてはこちらを参照。

cd
wget https://github.com/Live2D/CubismNativeSamples/archive/refs/tags/4-r.1.zip
unzip 4-r.1.zip
rm 4-r.1.zip
wget https://github.com/Live2D/CubismNativeFramework/archive/refs/tags/4-r.1.zip
unzip  4-r.1.zip  -d ~/CubismNativeSamples-4-r.1/Framework
rm 4-r.1.zip
mv ~/CubismNativeSamples-4-r.1/Framework/CubismNativeFramework-4-r.1/*  ~/CubismNativeSamples-4-r.1/Framework
rm -rf ~/CubismNativeSamples-4-r.1/Framework/CubismNativeFramework-4-r.1

Live2D Cubism Coreをコピーペースト

 先にダウンロードしたCubismNativeSamples-4-r.1には、モデルをロードするためのライブラリであるLive2D Cubism Core for Native は同梱されていない。
 ダウンロードするにはLive2DのWebページからLive2D Cubism SDK for Native をダウンロードし、ディレクトリー(CubismNativeSamples/Core)の中にあるフォルダなどを全て ディレクトリー(CubismNativeSamples-4-r.1/core)内にコピーペーストする。

https://www.live2d.com/download/cubism-sdk/download-native/

Install Dependencies

いつもの。

sudo apt update
sudo apt upgrade

以下が後のビルドに必要となるのでインストール

sudo apt-get install build-essential libxmu-dev libxi-dev libgl-dev libosmesa-dev cmake libxrandr-dev libxinerama-dev libxcursor-dev libglu1-mesa-dev curl

2.2 cocos2d-xのビルド

cocos2d-xのダウンロード

以下を参考にした。

まずcocos2dを、ダウンロードする。
以下を実行。

cd ~/CubismNativeSamples-4-r.1/Samples/Cocos2d-x/thirdParty/scripts
./setup_cocos2d

実行すると~/CubismNativeSamples-4-r.1/Samples/Cocos2d-x/thirdParty内にcocos2dというファイルができる。 

Install Dependencies

cocos2d-xをビルドするのに必要なものをインストール。

Install Python

sudo apt-get install python-minimal

以下を実行

cd ~/CubismNativeSamples-4-r.1/Samples/Cocos2d-x/thirdParty/cocos2d
sudo apt-get install python-minimal
./download-deps.py

Install Dependencies

sudo apt-get install g++ libgdk-pixbuf2.0-dev python-pip cmake libx11-dev libxmu-dev libglu1-mesa-dev libgl2ps-dev libxi-dev libzip-dev libpng-dev libcurl4-gnutls-dev libfontconfig1-dev libsqlite3-dev libglew-dev libssl-dev libgtk-3-dev libglfw3 libglfw3-dev xorg-dev binutils

Cmakelists.txt の編集

ぶっちゃけ一番詰まったところ。そのままビルドすると通らなかった。下の記事によると

/CubismNativeSamples-4-r.1/Samples/Cocos2d-x/thirdParty/cocos2dの内の
Cmakelists.txtの中に

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -no-pie -fexceptions -std=c++11 -Wno-deprecated-declarations -Wno-reorder") 

を追加するとビルドできるとのこと。

以下は私が変更したCmakelists.txt

#/****************************************************************************
# Copyright (c) 2013 cocos2d-x.org
# Copyright (c) 2014 martell malone
# Copyright (c) 2015-2017 Chukong Technologies Inc.
#
# http://www.cocos2d-x.org
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
# ****************************************************************************/

# build engine library and all tests

cmake_minimum_required(VERSION 3.6)

project(Cocos2d-x)

# cocos2dx root path
set(COCOS2DX_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
set(CMAKE_MODULE_PATH ${COCOS2DX_ROOT_PATH}/cmake/Modules/)

# prevent in-source-build
include(PreventInSourceBuilds)
AssureOutOfSourceBuilds()

# works before build libcocos2d
include(CocosBuildSet)

# build options
option(BUILD_TESTS "Build tests" ON)

# default tests include lua, js test project, so we set those option on to build libs
set(BUILD_LUA_LIBS ON)
set(BUILD_JS_LIBS ON)

######################ADD###########################
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -no-pie -fexceptions -std=c++11 -Wno-deprecated-declarations -Wno-reorder") 
####################################################

add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos ${ENGINE_BINARY_PATH}/cocos/core)

# prevent tests project to build "cocos2d-x/cocos" again
set(BUILD_ENGINE_DONE ON)
# add engine all tests project
if (BUILD_TESTS)
  add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/cpp-empty-test ${ENGINE_BINARY_PATH}/tests/cpp-empty-test)
  add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/cpp-tests ${ENGINE_BINARY_PATH}/tests/cpp-tests)
  add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/js-tests/project ${ENGINE_BINARY_PATH}/tests/js-tests)
  add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/lua-empty-test/project ${ENGINE_BINARY_PATH}/tests/lua-empty-test)
  add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/lua-tests/project ${ENGINE_BINARY_PATH}/tests/lua-test)
endif()

cocos2dのビルド

以下を実行
結構かかる。

cd ~/CubismNativeSamples-4-r.1/Samples/Cocos2d-x/thirdParty/cocos2d/build
mkdir linux-build
cd linux-build
cmake ../..
make -j 4

2.3 CubismNativeSamplesのビルド

以下を実行
結構かかる。

cd ~/CubismNativeSamples-4-r.1/Samples/Cocos2d-x/Demo/proj.linux/scripts/
./fix_libs
./make_gcc

3 DEMOの実行

ビルドに成功したら
デモの実行をしよう!

cd ~/CubismNativeSamples-4-r.1/Samples/Cocos2d-x/Demo/proj.linux/build/make_gcc/bin/Demo
./Demo

babiniku.gif
かわいい。

4 まとめ

  • ubuntu18.04でCubismNativeSamples for Cocos2d-xのDemoを実行
  • cmakelistsをいじるのがみそ
  • 受肉。
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1