Veykril / cubism-rs

A rust wrapper around the Live2D Cubism SDK with extra functionality
Apache License 2.0
39 stars 10 forks source link

Add json configuration definitions #8

Closed Veykril closed 4 years ago

Veykril commented 5 years ago

All the(so far) known json files cubism uses:

Some of these are just a simple struct definition, nevertheless each probably deserves its own module in the json module. The json module is solely for the definitions, since those basically only act as configuration. Any proper functionality(aside from maybe validation) should go into their own modules.

Discussion: Regarding structure definitions, which fields should get a default de/serialization instead of Option wrappers? This can probably get resolved once the use case for each field is clearer and whether the field has an appropriate default or not.

3c1u commented 5 years ago

All looks good so far, compared with the JSON parser in Cubism Native Framework. However, some values are treated otherwise in other components of Cubism Framework (which is insane). We can just analyze them and infer default values. For example, fade-in/out time can be given their default time from their usage.

You'll find this in CubismNativeFramework/CubismMotion.cpp:

    if (json->IsExistMotionFadeInTime())
    {
        _fadeInSeconds = (json->GetMotionFadeInTime() < 0.0f)
                             ? 1.0f
                             : json->GetMotionFadeInTime();
    }
    else
    {
        _fadeInSeconds = 1.0f;
    }

If "FadeInTime" ("FadeOutTime") is unset, fade-in time (fade-out time) is set to 1.0 [sec] as a default value while the Cubism JSON parser returns -1.0f.

Also, Layout field seem to be not stabilized and plus not used in anywhere so we can simply ignore that.

#[derive(Copy, Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct Layout {}

Layout fields found in CubismModelSettingJson.cpp:

const csmChar* CenterX = "CenterX";
const csmChar* CenterY = "CenterY";
const csmChar* X = "X";
const csmChar* Y = "Y";
const csmChar* Width = "Width";
const csmChar* Height = "Height";

Layout fields found in CubismModelMatrix.cpp:

void ::SetupFromLayout(csmMap<csmString, csmFloat32>& layout)
{
    const csmChar* KeyWidth = "width";
    const csmChar* KeyHeight = "height";
    const csmChar* KeyX = "x";
    const csmChar* KeyY = "y";
    const csmChar* KeyCenterX = "center_x";
    const csmChar* KeyCenterY = "center_y";
    const csmChar* KeyTop = "top";
    const csmChar* KeyBottom = "bottom";
    const csmChar* KeyLeft = "left";
    const csmChar* KeyRight = "right";
...
Veykril commented 5 years ago

yep, I agree with the default stuffm but those can always be added later if we are unsure or if the original framework doesnt make sense. Regarding Layout, I saw the field names but hadn't seen the what types of them were so far which is why i didnt implement them yet.