-
Notifications
You must be signed in to change notification settings - Fork 13
/
displayable.py
49 lines (34 loc) · 1.65 KB
/
displayable.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import renpy.exports as renpy
from live2d.wrapper import PyCubismUserModel, PyCubismModelSettingJson, PyLAppModel, PyLAppDelegate, PyLAppScene
import json
import os
import pygame
from renpy.display.core import Interface
# TODO: Do not forget to call 'PyCubismFramework.dispose()'.
PyLAppDelegate.initialize()
class Live2DDisplayable(renpy.Displayable):
def __init__(self, **kwargs):
super(Live2DDisplayable, self).__init__(**kwargs)
self.scene = PyLAppScene()
self.scene_initialized = False
self.render_width = 1024
self.render_height = 512
interface_set_mode_old = Interface.set_mode
self_displayable = self
def interface_set_mode_new(self, physical_size=None):
interface_set_mode_old(self, physical_size)
self_displayable.initialize()
Interface.set_mode = interface_set_mode_new
def initialize(self):
self.scene.initialize(self.render_width, self.render_height)
def render(self, width, height, st, at):
self.scene.update()
result = renpy.Render(self.render_width, self.render_height)
surface = result.canvas().get_surface()
surface.lock()
self.scene.draw(surface.get_pitch() // surface.get_bytesize(), surface._pixels_address)
surface.unlock()
renpy.display.render.redraw(self, 0.06)
return result
def create_model(self, model_dir, model_file):
return self.scene.create_model(model_dir, model_file)