godot icon indicating copy to clipboard operation
godot copied to clipboard

Implement add custom animation nodes.

Open Daylily-Zeleen opened this issue 3 years ago • 1 comments

The document descripte that allow us to create custom AnimationNode.

Animation Tree Editors allow to load a animation node's resource, but it is quite inconvenient.

I found that the AnimationNodeBlendTreeEditor has methods add_custom_type() and remove_custom_type() to handle custom AnimationNode which be implemented by script, but they are never used. And I found that AnimationNodeBlendSpace1DEditor, AnimationNodeBlendSpace2DEditor and AnimationNodeStateMachineEditor are get avaliable AnimationRootNode by ClassDB.

So, I let AnimationNodeBlendTreeEditor to get AnimationNodes by ClassDB, too. And allow using EditorPlugin.add_custom_type() to add custom AnimationNode which be implemented by script.

Now, we can add custom AnimationNode by using GDExtension or EditorPlugin.

image image

Daylily-Zeleen avatar Dec 06 '22 08:12 Daylily-Zeleen

I think this merits a proposal first?

Zireael07 avatar Dec 06 '22 13:12 Zireael07

I think only this PR is not meaningful, since it is not enough to implement for extending. It may be possible to create the custom AnimationNode as class, but I suspect that we could not actually override the process.

virtual double process(double p_time, bool p_seek, bool p_is_external_seeking) override;

Each AnimationNode does its own processing by overriding this function, ~~but since it is not bound to GDVIRTUAL, it is not possible to add processing here in GDScript/GDExtension.~~ It seems to be bound.

But, even if it were bound to GDVIRTUAL, it would be processed in-game, but it would not be processed correctly in the editor. I am not too familiar with this, but due to this limitation, I had to implement the realtime retarget module as a custom module and do a virutual override on the cpp.

TokageItLab avatar Dec 06 '22 18:12 TokageItLab

So, it would be nice if these animation features could be extended as GDExtention like a custom physics engine, but a proposal would need to be made first.

TokageItLab avatar Dec 06 '22 18:12 TokageItLab

I'll test them again later in more detail. Perhaps we should send it to 4.1, but I hope we can accommodate this PR in some way.

TokageItLab avatar Dec 06 '22 18:12 TokageItLab

I have interest in this, but we have to design the feature first.

fire avatar Dec 06 '22 19:12 fire

If we extend only the base class AnimationNode, then this PR is fine, but if we extend a class like AnimationNodeAdd2, then it is not enough. For example, if you have a functionality similar to AnimationNodeAdd2, but want to change the functionality a little bit, you need to duplicate most of the methods from AnimationNodeAdd2 with extending AnimationNode, since you can't extend AnimationNodeAdd2 (AnimationNodeAdd2::process() doesn't call GDVIRTUAL_CALL currently).

So I think the following implementation is necessary, but there is a performance concern.

double AnimationNodeAdd2::process(double p_time, bool p_seek, bool p_is_external_seeking) {
    double ret = -1;
    GDVIRTUAL_CALL(_process, p_time, p_seek, p_is_external_seeking, ret);
    if (ret != -1) {
        return ret; // Virtual process is existing.
    }

    // Fallback built-in process.
    double amount = get_parameter(add_amount);
    double rem0 = blend_input(0, p_time, p_seek, p_is_external_seeking, 1.0, FILTER_IGNORE, sync);
    blend_input(1, p_time, p_seek, p_is_external_seeking, amount, FILTER_PASS, sync);

    return rem0;
}

The fundamental problem is that the GDVIRTUAL fallback method cannot be placed in the Godot core without hackey way like above. In any case, I feel that a proposal is needed that would make it easier to extend the Animation features.

TokageItLab avatar Dec 06 '22 20:12 TokageItLab

I think this PR just provide an ability to collect AnimationNode for AnimationNodeBlendTreeEditor by using ClassDB and EditorPlugin::add_custom_type(). In othe word, it focus on "how to add" instead of "how to implement" a custom AnimationNode.

I think we need a proposal to discussion how to implement a custom AnimationNode, too. But I have not idea for this topic.

Daylily-Zeleen avatar Dec 07 '22 03:12 Daylily-Zeleen

I have sent #69802, which in combination with this PR should allow us to extend AnimationNode as we want.

TokageItLab avatar Dec 09 '22 09:12 TokageItLab

It seems that registration to the state machine editor is not working. Is any commit missing?

image image

custom_anim_node.zip

TokageItLab avatar Jan 19 '23 12:01 TokageItLab

It seems that registration to the state machine editor is not working. Is any commit missing?

image image

custom_anim_node.zip

Add custom animation nodes from Editor plugin only implement for AnimationNodeBlendTreeEditor currently.

But can add them from GDExtension.

~~If it is nessary, I will implement add from Editor Plugin for all AnimationTreeNodeEditorPlugin.~~

Now, I implement add custom animation nodes by using EditorPlugin for all AnimationTreeNodeEditorPlugin.

Daylily-Zeleen avatar Jan 20 '23 05:01 Daylily-Zeleen