veeti512 / wadblender

13 stars 4 forks source link

No command is extracted from an object #17

Closed TokyoSU closed 3 years ago

TokyoSU commented 3 years ago

Ive spotted this when doing a small rewrite by changing the int to a command enum for the GenerateLaraAnimations script: Command instruction = (Command)com[0].AsInt;

public enum Command : int
{
    None,
    SetPosition,
    GrabPosition,
    FreeHands,
    Die,
    PlaySound,
    PlayEffect
}
AnimationEvent evt;
switch (instruction)
{
    case Command.FreeHands:
        evt = new AnimationEvent
        {
            functionName = "EmptyHands"
        };
        animationClipClone.AddEvent(evt);
        break;
    case Command.Die:
        evt = new AnimationEvent
        {
            functionName = "Die",
            time = animationClipClone.length
        };
        animationClipClone.AddEvent(evt);
        break;
    case Command.PlaySound: // com[1] = frame, com[2] = id
        evt = new AnimationEvent
        {
            functionName = "PlaySound",
            time = (com[1] - start) * duration / 30f,
            intParameter = com[2]
        };
        animationClipClone.AddEvent(evt);
        break;
    case Command.PlayEffect: // com[1] = frame, com[2] = CommandEffect
        evt = new AnimationEvent
        {
            functionName = "PlayEffect",
            time = (com[1] - start) * duration / 30f,
            intParameter = com[2]
        };
        animationClipClone.AddEvent(evt);
        break;
    case Command.SetPosition: // com[1] = X, com[2] = Y, com[3] = Z
        evt = new AnimationEvent
        {
            functionName = "SetPositionX",
            floatParameter = com[1] / 512f,
            time = animationClipClone.length
        };
        animationClipClone.AddEvent(evt);

        evt = new AnimationEvent
        {
            functionName = "SetPositionY",
            floatParameter = com[2] / 512f,
            time = animationClipClone.length
        };
        animationClipClone.AddEvent(evt);

        evt = new AnimationEvent
        {
            functionName = "SetPositionZ",
            floatParameter = com[3] / 512f,
            time = animationClipClone.length
        };
        animationClipClone.AddEvent(evt);
        break;
    case Command.GrabPosition: // com[1] = Y, com[2] = Z
        evt = new AnimationEvent
        {
            functionName = "JumpVelocityUpward",
            floatParameter = com[1] / 512f,
            time = animationClipClone.length
        };
        animationClipClone.AddEvent(evt);

        evt = new AnimationEvent
        {
            functionName = "JumpVelocityForward",
            floatParameter = com[2] / 512f,
            time = animationClipClone.length
        };
        animationClipClone.AddEvent(evt);
        break;
}

The Debug.Log() returned 0 command found for each animation, it's what caused me to check it on the json. The extracted json dont have any command writed only that: "commands": [], It's pretty wreid that nothing is extracted, my lara object (from TR1) have actually command like PlaySound or SetPosition. can you check whats going on :)

PS: the json is unreadable when its only one line :x

veeti512 commented 3 years ago

If you use TR1 Lara the c# code does not work. I think that the commands are also different with respect to TR4. Anyway commands should be preserved in the json, can you send me the wad so I can check?

For the json I reformatted using vscode when I needed it :D

TokyoSU commented 3 years ago

https://www.mediafire.com/file/ow4hpubdowd3zqy/TR1_LARA.zip/file there the file. i could try TR3 maybe ?

veeti512 commented 3 years ago

Sorry, I can't check today, anyway the problem is that TR1 Lara doesn't crouch so it will raise errors when unity executes crouch related code. Maybe TR3 Lara will work if the state/animation ids are the same as TR4 otherwise you need to change the code.

TokyoSU commented 3 years ago

Does the CurrentAnimFrame can have negative value ? Because it's what i have, some check like if (CurrentAnimFrame > -0.0147) o.o' EDIT: it was caused by me, when refactoring GenerateLaraAnimation script, i messed up and changed Frame by CurrentState:

transition.AddCondition(AnimatorConditionMode.Greater, startm1, CurAnimFrameName);
transition.AddCondition(AnimatorConditionMode.Less, end, CurAnimFrameName); // <--- there !

but it not fix the problem of negative value for box collider being invalid. since box collider not support negative value.

TokyoSU commented 3 years ago

Im using a new project, so the state are not setup with TR4 lara code, so it work fine with TR1 one :) Also i have the leaked code of TR1, so i will code it with TR1 code :D And upgrade it when necessary. It not solve the command being not extracted through :x

veeti512 commented 3 years ago

It should be fixed now, I also formatted the json!

veeti512 commented 3 years ago

Does the CurrentAnimFrame can have negative value ? Because it's what i have, some check like if (CurrentAnimFrame > -0.0147) o.o' EDIT: it was caused by me, when refactoring GenerateLaraAnimation script, i messed up and changed Frame by CurrentState:

transition.AddCondition(AnimatorConditionMode.Greater, startm1, CurAnimFrameName);
transition.AddCondition(AnimatorConditionMode.Less, end, CurAnimFrameName); // <--- there !

but it not fix the problem of negative value for box collider being invalid. since box collider not support negative value.

The current animation frame is used to check whether an animation transition can happen. For instance when Lara runs, she can jump only in the frames where one of her feet is close to the ground. The frame > -0.0147 just means that the animation switch can also happen at frame 0.

TokyoSU commented 3 years ago

Just one more question before closing :) I get some Infinity or -Infinity in the frame condition, it cause many error ❌ Do you have an idea how to fix ? EDIT: the json not contains any command after the update :x but the formatting is great :) Maybe the original tr1 lara cause that, i will try with TR3 one. EDIT2: Command work with TR3 one, but not TR1, wreid... EDIT3: The Infinity is not here when using TR3 one, dont know if TR2 one is working too :x

veeti512 commented 3 years ago

I tested with your wad and the json included the commands, did you try keeping the tr4 object names?

For the infinity, maybe you are dividing by zero somewhere? Maybe it is not loading the animation correctly and gives you 0 frames in total.

TokyoSU commented 3 years ago

Im trying to load with TR4 object name yes, since it's the only one with Lara Full Model Mode.

veeti512 commented 3 years ago

Its working on my end with your TR1 wad, that's strange. Some animations have no commands but others do have them such as walk forward. Maybe some issue overwriting the json file.. did you delete it? I've no idea :o

TokyoSU commented 3 years ago

Dont know, maybe using the WadMerger with TRNG fix cause that ?

veeti512 commented 3 years ago

I would have asked to try emptying the addon pycache folders but if it is working for TR3.. it should also work for TR1. That TRNG fix I think that just changes the wad version number.

veeti512 commented 3 years ago

This is the file I get from your TR1 wad:

https://mega.nz/file/tdYwiLxQ#95uUFVNM5UKzKkfhJ5mEe5Rmr-90S9s2Vcqkwbcb8A0

TokyoSU commented 3 years ago

It's wreid i dont get this at all (command), for me it's empty. i could try another time, but it will give me 0 command :x

EDIT: wreid i retested it with tr1 lara to get the json file with command, after updating to the flip update and it worked this time :x

veeti512 commented 3 years ago

I see, sometimes Blender is weird. Being a modal editor, it can behave differently depending on a lot of stuff, and it is difficult to take account of everything.