Skip to content

本地模型无法换肤、隐藏时仍消耗性能等问题 #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
qtqz opened this issue Feb 12, 2025 · 0 comments
Open

本地模型无法换肤、隐藏时仍消耗性能等问题 #3

qtqz opened this issue Feb 12, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@qtqz
Copy link

qtqz commented Feb 12, 2025

咱使用项目时发现它还不太成熟,并且遇到了一些比较要紧的问题,就在这里说一下。由于项目比较复杂,代码比较规范,咱也无暇了解 pixi 等依赖,就先不 PR 了,只提交问题。

1.使用单个本地模型时,无法换肤

      live2DCollection: {
         Pio: {
          message: 'Pio ~',
          models: '/Pio/model.json',
        }, 
      }

模型文件:

{
    "version":"1.0.0",
    "model":"model.moc",
    "textures":[
        "textures/Halloween Costume.png",
        "textures/Night Witch Costume Black.png",
        "textures/Dress Costume Brown.png",
        "textures/Santa Costume.png"
    ]
}

自己的缓解办法

//client/composable.ts
async function getSequentialSkin() {
//////
    if (typeof live2D.models === 'string') {
      // HACK: The step of using `convertJsdelivrUrlToGithubApiUrl` should be avoided
      //const skins = await getFilenamesFromGitHub(convertJsdelivrUrlToGithubApiUrl(live2D.models))
      const skinslength=live2D.num //在配置中多定义一个皮肤数量
      const newSkinIndex = getNewSkinIndex(skinslength)
      return getModelJson(live2D.models, newSkinIndex)
    }
//////
  }
//utils/model.ts
export async function getModelJson(model: string, newSkinIndex: number) {
//const url = convertJsdelivrUrlToGithubApiUrl(model)
  try {
    /* const filenames = await getFilenamesFromGitHub(url)
    const json = await urlToJson(model)

    json.url = model
    json.textures[0] = `textures/${filenames[newSkinIndex]}` */

    const json = await urlToJson(model)
    const filenames = json.textures

    json.url = model
    json.textures[0] = filenames[newSkinIndex]
    setLive2DModelKeys(null, newSkinIndex)
    return json
  }
  catch (error) {
    console.error(error)
  }
}

2.隐藏时仍然持续消耗性能

点击隐藏后未停止 live2d,未删除定时器和事件监听器,持续消耗性能(另一个库 oh-my-live2d 也有这个问题)

自己的缓解办法

//client/composable.ts

  function hideLive2D() {
///////////
    setTimeout(() => {
      live2DApp.value?.hideModel()
    }, 2000)
///////////
  }

  function showLive2D() {
/////////////
      live2DApp.value?.showModel()
/////////////
  }
//app/Live2DApp.js

    static async showModel() {
        this.loadModel(window.current_model_source)
    }
    static async hideModel() {
        this.clearAppStage();
        this.model.destroy()
        this.model = {}
    }
    static async loadModel(source) {
        try {
//////////
            window.current_model_source = source
//////////

3.其他

增加更多可配置项:

  • 自定义位置(页面左、右)
  • 允许初始隐藏
  • 允许自定义按钮

修改掉按钮内意义不明的文字

@WRXinYue WRXinYue added the enhancement New feature or request label Feb 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants