Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.

If you have any questions, reports, suggestions, or requests about Live2D, please send them to this forum.
※We cannot guarantee statements or answers from Live2D staff. Thank you for your understanding in advance.
 
Live2D Cubism
Cubism Products and Downloads
Cubism product manuals and tutorials
Cubism Editor Manual    Cubism Editor Tutorial    Cubism SDK Manual    Cubism SDK Tutorial
[About macOS Sequoia] (Updated October 22, 2024)
Live2D Cubism Editor 5.1.02 now supports macOS Sequoia.
Other Live2D Cubism products currently released are not guaranteed to work on macOS Sequoia.
Please refrain from upgrading macOS, as it may not operate properly.

Multiple models when using TranslateRelative()

When selecting only one model and translate it like this:
modelToUse->GetModelMatrix()->TranslateRelative(speed,0);
but when i have multiple models on the scene they move instead of only the selected one
(for example: if model number 1 is selected models 2 and 3 will Translate too).
Tagged:

Best Answer

  • @catCoder

    On investigation, we found that the reason is that the instance of CubismMatrix44 used for drawing is not being reset in every loop process.
    This can be avoided by rewriting a part of LAppLive2DManager::OnUpdate() as follows:
    void LAppLive2DManager::OnUpdate() const
    {
        ...
    
        // CubismMatrix44 projection;
        csmUint32 modelCount = _models.GetSize();
        for (csmUint32 i = 0; i < modelCount; ++i)
        {
            CubismMatrix44 projection;
    
            ...
    This fix will be added in a future update of the SDK.

    Thank you.

Answers

  • Hello @catCoder ,
    Thank you for reaching out.

    Could you tell me how you are implementing the display of multiple models?
    If you are using one ModelMatrix for each model, make sure that you have an instance for each model and see if the same problem occurs.
  • I add new models in the same way done in LAppLive2DManager
    by adding a new instance to _models.

    Example code:
    _models.PushBack(new LAppModel());
    _models[_models.GetSize()-1]->LoadAssets(modelPath1.c_str(), modelJsonName1.c_str());

    is there any way other then this?.

    From what I understand there is a ModelMatrix for each model instance in _models
    what did you mean by "If you are using one ModelMatrix for each model"
    is there a way to use multiple models with one ModelMatrix? what are the benefits
    of doing so?
  • @catCoder

    Thanks for the answer.
    The process you provided is correct.

    I rewrote CubismLAppManager::ChangeScene() in the SDK sample here as follows and confirmed the operation.
    void LAppLive2DManager::ChangeScene(Csm::csmInt32 index)
    {
        ...
    
        ReleaseAllModel();
        _models.PushBack(new LAppModel());
        _models[0]->LoadAssets(modelPath.c_str(), modelJsonName.c_str());
    
        // The second model.
        _models.PushBack(new LAppModel());
        _models[1]->LoadAssets("Resources/Haru/", "Haru.model3.json");
        _models[1]->GetModelMatrix()->TranslateRelative(0.7f, 0.0f);
    
        ...
    }
    When I ran this, only the second model moved its position.(See the attached image)


    Could you please check if the problem still occurs when you perform the same process?
  • 1. The problem still occurs for me when i try to add TranslateRelative(0.7f, 0.0f); to both models the first model translate right but the second model translate by 0.7f from the position of the first model.

    2. I wrote a method for translating the first model when the user click the screen
    it is a simple method with only one line:
    _models[0]->GetModelMatrix()->TranslateRelative(speed, 0.0f);
    but when i start it both models translate and that is my main problem
  • To simplify the problem: in the case you presented when trying to translate the first model after both were created both models translate instead of only the first model.

    for example using this line after both models were created:
    _models[0]->GetModelMatrix()->TranslateRelative(0.7f, 0.0f);
  • @catCoder

    Thank you for your answer.

    I was able to confirm the phenomenon.
    We are going to investigate the cause of the problem, so please wait for a while.
  • Thank you
    I tested the code and everything seems to work fine
    P.S. the last comment with the code disappeared for me can you write it again
    for future reference.
  • @catCoder

    I found out that the reason is that the instance of CubismMatrix44 used for drawing is not being reset after each loop process.
    This can be avoided by rewriting a part of LAppLive2DManager::OnUpdate() as follows

    void LAppLive2DManager::OnUpdate() const
    {
    ...
    // CubismMatrix44 projection;
    csmUint32 modelCount = _models.GetSize();
    for (csmUint32 i = 0; i < modelCount; ++i)
    {
    CubismMatrix44 projection;
    ...

    This fix will be added in a future update of the SDK.
    Thanks for the report.
Sign In or Register to comment.