新しいLive2D公式コミュニティ(日本向け)が公開されました!
ぜひご利用ください!
Live2D公式コミュニティ
■このコミュニティの今後について
このコミュニティ(forum.live2d.com)につきましては、しばらくの間新コミュニティと並行して運営しますが、2023年夏ごろを目処に方針を決定する予定です。
(2022/12/27追記 2022年内を目処に閉鎖 から変更しております)
内容については決定次第お知らせいたします。
海外向けコミュニティについては変更ございません。
ぜひご利用ください!
Live2D公式コミュニティ
■このコミュニティの今後について
このコミュニティ(forum.live2d.com)につきましては、しばらくの間新コミュニティと並行して運営しますが、2023年夏ごろを目処に方針を決定する予定です。
(2022/12/27追記 2022年内を目処に閉鎖 から変更しております)
内容については決定次第お知らせいたします。
海外向けコミュニティについては変更ございません。
Live2Dに関するユーザーのみなさま同士の交流・ご質問・不具合の報告・提案・要望などについて是非お寄せください。
※Live2D公式スタッフからの発言や回答については確約できないことを予めご了承ください。
Live2D ヘルプ
Cubism Editorダウンロード / 動作環境
Cubism SDKダウンロード / 対応表
Cubism 製品利用ライセンス(SDK含)
Cubism 製品のライセンスについてのお問い合わせはこちら
nizima 及び nizima 製品についてのお問い合わせはこちら
※Live2D公式スタッフからの発言や回答については確約できないことを予めご了承ください。
Live2D ヘルプ
Cubism Editorダウンロード / 動作環境
Cubism SDKダウンロード / 対応表
Cubism 製品利用ライセンス(SDK含)
Cubism 製品のライセンスについてのお問い合わせはこちら
nizima 及び nizima 製品についてのお問い合わせはこちら
【各最新OSの対応状況について】
Cubism Editorは 4.1.02 正式版以降でWindows 11 及び macOS Monterey に対応しております。ぜひ最新版をご利用ください。
※macOSをお使いの方でOSアップデートする際は必ずCubism Editorのライセンスを解除してください。
Cubism EditorをインストールしているmacOSをアップグレードしたい
Cubism SDKについては各SDKのREADMEまたはNOTICEをご確認ください。
【Mac各機種への対応状況について】
現在、Cubism EditorはApple M1チップ搭載機種には対応しておりません。
詳細は 動作環境 をご参照ください。
関連するお問い合わせへの対応はこの文章をもって代えさせていただきます。
Cubism Editorは 4.1.02 正式版以降でWindows 11 及び macOS Monterey に対応しております。ぜひ最新版をご利用ください。
※macOSをお使いの方でOSアップデートする際は必ずCubism Editorのライセンスを解除してください。
Cubism EditorをインストールしているmacOSをアップグレードしたい
Cubism SDKについては各SDKのREADMEまたはNOTICEをご確認ください。
【Mac各機種への対応状況について】
現在、Cubism EditorはApple M1チップ搭載機種には対応しておりません。
詳細は 動作環境 をご参照ください。
関連するお問い合わせへの対応はこの文章をもって代えさせていただきます。
cocos2dx 3.9 mtnファイルの読み込みでエラー「file open error」
初めて投稿させて頂きます
==========================================
制作環境:mac OSX El Capitan
cocos2dxバージョン:3.9
live2dSDKバージョン:Live2D_SDK_OpenGL_2.0.08_2_jp
==========================================
任意のモーションを再生させようと、mtnファイルを読み込んで再生させようとしています。
素材は「Epsilon」を使用し、Resouce直下に「live2d」ディレクトリを作り、その中にファイルが存在しています。
参考サイトを元に下記のように記述しました。
Live2DMotion* motion = Live2DMotion::loadMotion("live2d/epsilon/motions/Epsilon_m_05.mtn");
MotionQueueManager* motionManager = new MotionQueueManager();//モーション管理クラスの作成
motionManager->startMotion( motion, false );//モーションの再生
motionManager->updateParam( live2DModel );//モーションの更新
ところが
file open error live2d/epsilon/motions/Epsilon_m_05.mtn!!
とエラーが出てしまいます。
cocos2dx初心者、live2dも初心者で、至らないところだらけなのですが
同じようなエラーを検索出来なかった為に投稿させて頂きます。
ご教示頂ければ幸いです。
==========================================
制作環境:mac OSX El Capitan
cocos2dxバージョン:3.9
live2dSDKバージョン:Live2D_SDK_OpenGL_2.0.08_2_jp
==========================================
任意のモーションを再生させようと、mtnファイルを読み込んで再生させようとしています。
素材は「Epsilon」を使用し、Resouce直下に「live2d」ディレクトリを作り、その中にファイルが存在しています。
参考サイトを元に下記のように記述しました。
Live2DMotion* motion = Live2DMotion::loadMotion("live2d/epsilon/motions/Epsilon_m_05.mtn");
MotionQueueManager* motionManager = new MotionQueueManager();//モーション管理クラスの作成
motionManager->startMotion( motion, false );//モーションの再生
motionManager->updateParam( live2DModel );//モーションの更新
ところが
file open error live2d/epsilon/motions/Epsilon_m_05.mtn!!
とエラーが出てしまいます。
cocos2dx初心者、live2dも初心者で、至らないところだらけなのですが
同じようなエラーを検索出来なかった為に投稿させて頂きます。
ご教示頂ければ幸いです。
コメント
loadMotionの引数はファイルパスではなく、FileUtils::getInstance()->getFileDataの返り値かと思います。
以下にソースをつけたので参考にしてみて下さい。
SampleLive2DSprite.h
#define __sampleCocos2dx__SampleLive2DSprite__
#include "cocos2d.h"
#include "2d/CCSprite.h"
#include
#include "Live2DModelOpenGL.h"
#include "motion/Live2DMotion.h"
#include "motion/MotionQueueManager.h"
class SampleLive2DSprite :public cocos2d::DrawNode {
live2d::Live2DModelOpenGL* live2DModel ;
live2d::MotionQueueManager* motionManager; // モーションマネジャー
std::vector textures ;
public:
SampleLive2DSprite();
virtual ~SampleLive2DSprite();
virtual void draw(cocos2d::Renderer *renderer, const cocos2d::Mat4 &transform, uint32_t flags) override;
void onDraw(const cocos2d::Mat4 &transform, uint32_t flags);
static SampleLive2DSprite* createDrawNode();
protected:
cocos2d::CustomCommand _customCommand;
};
#endif /* defined(__sampleCocos2dx__SampleLive2DSprite__) */
SampleLive2DSprite.cpp
#include "base/CCDirector.h"
#include "util/UtSystem.h"
#include "graphics/DrawProfileCocos2D.h"
#include "platform/CCFileUtils.h"
using namespace live2d;
USING_NS_CC;
const char* TEXTURES[] ={
"haru/haru_02.1024/texture_00.png" ,
"haru/haru_02.1024/texture_01.png" ,
"haru/haru_02.1024/texture_02.png" ,
NULL
};
AMotion* motion; // モーション
SampleLive2DSprite::SampleLive2DSprite()
{
//Live2D Sample
const char* MODEL = "haru/haru_02.moc" ;
unsigned char* buf;
ssize_t bufSize;
buf = FileUtils::getInstance()->getFileData(MODEL,"rb", &bufSize);
// mocロード
live2DModel = Live2DModelOpenGL::loadModel( buf,bufSize ) ;
free(buf);
// Textureロード
for( int i = 0 ; TEXTURES[i] != NULL ; i++ ){
auto texture =Director::getInstance()->getTextureCache()->addImage(std::string(TEXTURES[i]));
Texture2D::TexParams texParams = { GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE };
texture->setTexParameters(texParams);
texture->generateMipmap();
int glTexNo = texture->getName() ;
live2DModel->setTexture( i , glTexNo ) ;// テクスチャとモデルを結びつける
textures.push_back( texture ) ;
}
// Motionロード
const char* MOTION = "haru/motions/tapBody_00.mtn";
unsigned char* motionbuf;
ssize_t MotionSize;
motionbuf = FileUtils::getInstance()->getFileData(MOTION,"rb", &MotionSize);
motion=Live2DMotion::loadMotion(motionbuf,(int)MotionSize);
motionManager = new MotionQueueManager();
// Live2Dモデルはローカル座標で左上を原点にして(CanvasWidth、CanvasWidth)
// のサイズになるため、以下のようにして調整してください。
float w = Director::getInstance()->getWinSize().width;
float h = Director::getInstance()->getWinSize().height;
float scx = 2.0 / live2DModel->getCanvasWidth() ;
float scy = -2.0 / live2DModel->getCanvasWidth() * (w/h);
float x = -1 ;
float y = 1 ;
float matrix []= {
scx , 0 , 0 , 0 ,
0 , scy ,0 , 0 ,
0 , 0 , 1 , 0 ,
x , y , 0 , 1
} ;
live2DModel->setMatrix(matrix) ;// 位置を設定
}
SampleLive2DSprite::~SampleLive2DSprite()
{
delete live2DModel;
// テクスチャを解放
Director::getInstance()->getTextureCache()->removeTextureForKey(std::string(TEXTURES[0]));
Director::getInstance()->getTextureCache()->removeTextureForKey(std::string(TEXTURES[1]));
Director::getInstance()->getTextureCache()->removeTextureForKey(std::string(TEXTURES[2]));
}
void SampleLive2DSprite::draw(cocos2d::Renderer *renderer, const cocos2d::Mat4 &transform, uint32_t flags)
{
DrawNode::draw(renderer, transform, flags);
_customCommand.init(_globalZOrder);
_customCommand.func = CC_CALLBACK_0(SampleLive2DSprite::onDraw, this, transform, flags);
renderer->addCommand(&_customCommand);
}
void SampleLive2DSprite::onDraw(const cocos2d::Mat4 &transform, uint32_t flags)
{
kmGLPushMatrix();
kmGLLoadMatrix(&transform);
// モーションが終了した場合
if(motionManager->isFinished())
{
// モーションをスタート
motionManager->startMotion(motion, false);
}
// モーションのパラメーターを更新
motionManager->updateParam(live2DModel);
// Live2Dの描画前と描画後に以下の関数を呼んでください
// live2d::DrawProfileCocos2D::preDraw() ;
// live2d::DrawProfileCocos2D::postDraw() ;
// これはOpenGLの状態をもとに戻すための処理です。
// これを行わない場合、Cocos2DかLive2Dどちらかで状態の不整合が起こります。
live2d::DrawProfileCocos2D::preDraw();
live2DModel->update() ;
live2DModel->draw() ;
live2d::DrawProfileCocos2D::postDraw() ;
kmGLPopMatrix();
}
SampleLive2DSprite* SampleLive2DSprite::createDrawNode()
{
SampleLive2DSprite *ret = new SampleLive2DSprite();
if (ret && ret->init())
{
ret->autorelease();
return ret;
}
else
{
CC_SAFE_DELETE(ret);
return nullptr;
}
}
cocos2dxのver3.5で確認していますが、3.9でもほぼ同様に動くかと思います。
これで解決しない場合は過去に類似したスレッドがあったので、こちらの設定を確認してみて下さい。
・Cocos2d-xのサンプルコードのモデル表示について
返信ありがとうございます
添付して頂いたソースを元に試してみます。
今日中に返信出来ないかもしれませんが、
動作確認をして、またコメントさせて頂きます。
先ほど添付して頂いたソースを元にテストしてみたところ、正常に動作いたしました。
startMotionもupdateParamも「onDraw」の内部でやるのですね、、、
恥ずかしいソースを失礼いたしました。。
また投稿させて頂くこともあると思いますが、
その時はまたよろしくお願いします。
もう少しまともな質問が出来るようがんばります。
ありがとうございました。
またなんなりと質問して頂けたらと思います