Live2D SDK https://live2dsdk.mist.so Cubism SDK Research Sun, 16 Feb 2014 14:28:27 +0000 zh-CN hourly 1 https://wordpress.org/?v=4.9.5 快速调用live2d.dll制作桌宠 https://live2dsdk.mist.so/posts/29.html https://live2dsdk.mist.so/posts/29.html#comments Sun, 16 Feb 2014 13:56:17 +0000 http://sdk.live2d.cn/?p=29 看到标题有没一种“怎么又是快速”的感觉。但是事实上确实很快速,有人为你铺好路你点个鼠标当然快。
一.准备
先去下载开源项目 ytx1991/Azusa-Live2D
会得到一个DLL,live2d.dll。
IDE随便什么都行。

二.创建工程
我就以vs2012控制台程序为例。
显式调用dll。

#include <windows.h>
#include <process.h>

int _tmain(int argc, _TCHAR* argv[])
{
	HINSTANCE dll;
	typedef int( * dllmain)();
	typedef bool( * dllstart)(int);
	dllmain CreateWin;
	dllstart	Live2DStart;
	dll=LoadLibraryA("Live2D.dll");
	if(dll)
	{
		CreateWin=(dllmain)GetProcAddress(dll,"CreateWin");
		Live2DStart=(dllstart)GetProcAddress(dll,"Live2DStart");
		if(CreateWin)
		{
			CreateWin();
		}
		if(Live2DStart)
		{
			int pid = (int)_getpid();
			Live2DStart(pid);
		}

	}
	system("pause");
	return 0;
}

几句搞定。运行一下就会看到桌宠了。

三.其他接口

[DllImport("Live2D.dll")]
public static extern bool Live2DStart(int tid);
[DllImport("Live2D.dll")]
public static extern bool Live2DAbort(int hinst);
[DllImport("Live2D.dll")]
public static extern bool SetExpression(int hinst, string expid, int index);
[DllImport("Live2D.dll")]
public static extern bool StartMotion(int hinst, string motiontype, int motionindex, int priority, int index);
[DllImport("Live2D.dll")]
public static extern int AddModel(int hinst, string path);
[DllImport("Live2D.dll", EntryPoint = "RemoveModels")]
public static extern bool RemoveModel(int hinst);
[DllImport("Live2D.dll")]
public static extern bool GetModelInfo(int hinst, int index, StringBuilder info);
[DllImport("Live2D.dll")]
public static extern bool SetEyeBallDirection(int hinst, float x, float y, int index);
[DllImport("Live2D.dll")]
public static extern bool SetFaceDirection(int hinst, float x, float y, float z, int index);
[DllImport("Live2D.dll")]
public static extern bool SetBodyDirection(int hinst, float x, int index);
[DllImport("Live2D.dll")]
public static extern bool SetViewDepth(int hinst, int x, int y, int depth);
[DllImport("Live2D.dll", CharSet = CharSet.Unicode)]
public static extern bool ShowMessage(int hinst, int x, int y, int width, int height, string text, int fontHeight, int fontWidth, int fontWeight, bool italic, string family, uint color);

参照上面的就能完成大部分功能了。

四。最后
我挖出这些接口只是为了学习,如果无意冒犯了原作者想隐藏的某些,可以说一下我马上删掉,毕竟原作者没给出DLL源码

]]>
https://live2dsdk.mist.so/posts/29.html/feed 3
快速搭建 DirectX 平台的 Live2D 开发环境 https://live2dsdk.mist.so/posts/21.html https://live2dsdk.mist.so/posts/21.html#respond Sat, 15 Feb 2014 15:40:58 +0000 http://sdk.live2d.cn/?p=21 对于习惯各种开发的大牛可以绕道了,这种看一眼就能明白的东西为何要写出来?
官方就给的 SDK 就能用为何要搭?请看第二点
一方面为了备忘,另一方面给新手看,还有就是练习写文章的能力。

一. 准备

  1. Live2D 官方的 SDK
  2. DirectX 9 的 SDK
  3. 良好的 C++ 开发环境,顺手的 IDE。

二. 实现目的

能够在自己的工程中加入 Live2D。

三. 配置

以 Visual Studio 2012 配置为例:

  1. 将官方 SDK 附带的文件夹 includelibframework 以及 SampleApp1/src。复制到自己工程根目录。
  2. 修改解决方案属性:
    • 附加包含目录:$(DXSDK_DIR)Include;..\src;..\include;..\framework;%(AdditionalIncludeDirectories)
    • 附加库目录:..\lib;%(AdditionalLibraryDirectories)
    • 附加依赖项:live2d_directX_md.lib;%(AdditionalDependencies)
    • 预处理定义:WIN32;NDEBUG;_WINDOWS;_USRDLL;MAIN_EXPORTS;L2D_TARGET_D3D;%(PreprocessorDefinitions)
  3. 引入文件。

文件头,lib 库,定义宏,参照 SampleApp1 复制黏贴就行,不列举,cpp 同样对照引入就行。
配置就基本完成了,好简单的样子。为何我要如此废话。

四. 注意

发现把 SDK 引入 MFC 框架时候发现,莫名多了一个蓝色的窗体。这个窗体实际上是在引入的 live2d_directX_md.lib 中。形成的原因就因为 MFC 自身入口点封装很深。导致程序先进入引入的 live2d_directX_md.lib 里面的另一个入口点。解决方法就是拿连接器 lib.exe -EXTRACT,然后再把包含入口点的 live2d_directX.obj 删掉。重编就可以了。

还有就是官方 SDK 例子用 Debug 配置编译会出问题,不止我一个人碰到了。

还有就是 MT/MD 什么的要对应 lib,这些常识就不啰嗦了。

就以上这些,3 分钟就能完成,谈不上搭建(笑)

]]>
https://live2dsdk.mist.so/posts/21.html/feed 0
解析 model.json 实现自动处理点击事件 https://live2dsdk.mist.so/posts/8.html https://live2dsdk.mist.so/posts/8.html#respond Thu, 13 Feb 2014 17:14:31 +0000 http://sdk.live2d.cn/?p=8 如果你阅读过 Android、iOS 或 Flash 版本的 SDK 中附带的 SampleApp1,你一定会发现,点击和滑动事件不但要写好 JSON,还要在 Define 和 Live2DManager 中添加判定和处理代码。
这绝对是件让人很厌烦的事情。
于是我简单的实现了一下解析 model.json 来自动处理点击和滑动事件。
源码是 Android 版本,如果你在使用其他版本 SDK 请自己翻译一下,很简单的。

以下请加在 LAppLive2DManager.javatapEvent(float x, float y) 里面。

int hitAreas = models.get(i).modelSetting.getHitAreasNum();
for (int h = 0; h < hitAreas; h++)
{
	if(models.get(i).hitTest(models.get(i).modelSetting.getHitAreaName(h), x, y))
	{
		String motionGroup = "tap_" + models.get(i).modelSetting.getHitAreaName(h);
		int exist = models.get(i).modelSetting.getMotionNum(motionGroup);
		if (exist != 0)
		{
			models.get(i).startRandomMotion(motionGroup, LAppDefine.PRIORITY_NORMAL);
			break;
		}
	}
}

至于 flickEvent,只要把以上代码中的 tap_ 修改成 flick_ 就可以了。

]]>
https://live2dsdk.mist.so/posts/8.html/feed 0