找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 961|回复: 0

[原创] Live2d 实验一则,有演示,附代码

[复制链接]
发表于 2022-10-7 02:51:05 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×




live2d大家可以先去官方网站下载一个模型用来测试。下载的网站是:

https://www.live2d.com/zh-CHS/download/sample-data/

当然要在Renpy中使用live2d,是需要先安装的。安装的办法,在官方文档里写的很清楚:

使用Live2D之前,你需要下载和安装原声的Cubism SDK,下载链接为 Live2D 页面 。 请注意,如果你的商业项目年收入达到了某个下限,将需要购买一个Live2D使用许可证。

下载完Live2D后,把CubismSdkForNative-4-r.1.zip文件放入Ren’Py的SDK目录中,接着可以在Ren’Py启动器中安装。 在启动器中进入“设置”项,选择“操作”标签下的“安装库”,点击“安装 Live2D Cubism SDK for Native”。等待一段时间后,Live2D就安装成功了

https://doc.renpy.cn/zh-CN/live2d.html



如果上不了Live2D官方网站,或者下载比较慢,可以站内搜live2d,里面有个国内云盘下载链接。

Live2D Cubism 相关资料网址与下载
https://www.renpy.cn/forum.php?m ... mp;highlight=live2d

下载完模型之后,要在game下面建立一个文件夹,然后我这里叫natori_pro_t06。然后把下载的模型给粘到这个文件夹里。并把runtime文件里的东西都粘贴到natori_pro_t06里,并且删掉这个文件夹否则会报错。

放完是这样的

Screen Shot 2022-10-06 at 11.48.19 AM.png


不过我对live2d不熟悉,不清楚是不是这里有的文件是不需要的,评论可以指正。

这些都做好后可以开始写代码。

我这里写了一个python读取文件夹,然后获得了表情和动作的名字,之后把他们作为按钮,来修改live2d的参数。


[RenPy] 纯文本查看 复制代码
init:
    define config.gl2 = True

define cp = CharacterPreprocessor('natori_pro_t06')

image natori close = Live2D("natori_pro_t06", loop=True, base=.6)
image natori far = Live2D("natori_pro_t06", base=.9)

default exp_s = "angry"
default motion_s = "mtn_01"


label start:

    scene street day
    jump live2d

    return

label live2d():
    $ img = "natori close {:s} {:s}".format(exp_s, motion_s)
    $ renpy.show(img)
    show screen live2d
    pause
    jump live2d
    return

screen live2d():
    style_prefix "live2d"
    hbox:
        xpos 50
        ypos 30
        spacing 50
        vbox:
            spacing 15
            for exp in cp.exps:
                button:
                    background Solid("#eb6679")
                    selected_background Solid("#e7ba15")
                    text exp
                    selected exp == exp_s
                    action [SetVariable('exp_s', exp),
                        Function(renpy.show, "natori close {:s} {:s}".format(exp_s, motion_s))]

        vbox:
            spacing 15
            for motion in cp.motions:
                button:
                    background Solid("#4dbbac")
                    selected_background Solid("#e7ba15")
                    text motion
                    selected motion == motion_s
                    action [SetVariable('motion_s', motion),
                        Function(renpy.show, "natori close {:s} {:s}".format(exp_s, motion_s))]

style live2d_text:
    size 30
    color "#fff"
 



用来获取标签的代码

[RenPy] 纯文本查看 复制代码
init -1 python:
    import os
    from collections import defaultdict

    class CharacterPreprocessor:
        def __init__(self, character_name):
            ## exp
            self.exps = sorted(self.__parse_file(character_name, 'exp'))

            ## motions
            self.motions = sorted(self.__parse_file(character_name, 'motions'))

        def __parse_file(self, character_name, tag):
            directory_path = os.path.join(config.gamedir, character_name, tag)

            result = []

            for dirpath, dirnames, filenames in os.walk(directory_path):
                for file in filenames:
                    file = file.split('.')[0]
                    file = file.lower()
                    result.append(file)

            return result

评分

参与人数 1活力 +300 干货 +3 收起 理由
被诅咒的章鱼 + 300 + 3 感谢分享!

查看全部评分

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|RenPy中文空间 ( 苏ICP备17067825号|苏公网安备 32092302000068号 )

GMT+8, 2024-4-27 06:26 , Processed in 0.066468 second(s), 16 queries , File On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表