Delsin-Yu / CSharp-Wrapper-Generator-for-GDExtension

This editor plugin generates C# wrappers for classes from the GDExtension plugins.
MIT License
11 stars 2 forks source link

Fail to get MediaPipeNormalizedLandmarks from MediaPipeFaceLandmarkerResult => face_landmarks #20

Closed GeorgeS2019 closed 1 month ago

GeorgeS2019 commented 2 months ago

https://github.com/j20001970/GDMP-demo/blob/3474994c3a844d935551c9793c8b642868105d2e/project/vision/face_landmarker/FaceLandmarker.gd#L37

The FaceLandMarks should returns Godot.Collections.Array<MediaPipeNormalizedLandmarks>

The casting of Godot.Variant to MediaPipeNormalizedLandmarks does not work

func show_result(image: Image, result: MediaPipeFaceLandmarkerResult) -> void:
    for landmarks in result.face_landmarks:
        draw_landmarks(image, landmarks)

func draw_landmarks(image: Image, landmarks: MediaPipeNormalizedLandmarks) 

    public Godot.Collections.Array FaceLandmarks
    {
        get => (Godot.Collections.Array)Get("face_landmarks");
        set => Set("face_landmarks", Variant.From(value));
    }

//=========================
using System;
using Godot;

namespace GDExtension.Wrappers;

public partial class MediaPipeFaceLandmarkerResult : RefCounted
{
    public static readonly StringName GDExtensionName = "MediaPipeFaceLandmarkerResult";

    [Obsolete("Wrapper classes cannot be constructed with Ctor (it only instantiate the underlying RefCounted), please use the Instantiate() method instead.")]
    protected MediaPipeFaceLandmarkerResult() { }

    /// <summary>
    /// Creates an instance of the GDExtension <see cref="MediaPipeFaceLandmarkerResult"/> type, and attaches the wrapper script to it.
    /// </summary>
    /// <returns>The wrapper instance linked to the underlying GDExtension type.</returns>
    public static MediaPipeFaceLandmarkerResult Instantiate()
    {
        return GDExtensionHelper.Instantiate<MediaPipeFaceLandmarkerResult>(GDExtensionName);
    }

    /// <summary>
    /// Try to cast the script on the supplied <paramref name="godotObject"/> to the <see cref="MediaPipeFaceLandmarkerResult"/> wrapper type,
    /// if no script has attached to the type, or the script attached to the type does not inherit the <see cref="MediaPipeFaceLandmarkerResult"/> wrapper type,
    /// a new instance of the <see cref="MediaPipeFaceLandmarkerResult"/> wrapper script will get attaches to the <paramref name="godotObject"/>.
    /// </summary>
    /// <remarks>The developer should only supply the <paramref name="godotObject"/> that represents the correct underlying GDExtension type.</remarks>
    /// <param name="godotObject">The <paramref name="godotObject"/> that represents the correct underlying GDExtension type.</param>
    /// <returns>The existing or a new instance of the <see cref="MediaPipeFaceLandmarkerResult"/> wrapper script attached to the supplied <paramref name="godotObject"/>.</returns>
    public static MediaPipeFaceLandmarkerResult Bind(GodotObject godotObject)
    {
        return GDExtensionHelper.Bind<MediaPipeFaceLandmarkerResult>(godotObject);
    }
#region Properties

    public Godot.Collections.Array FaceLandmarks
    {
        get => (Godot.Collections.Array)Get("face_landmarks");
        set => Set("face_landmarks", Variant.From(value));
    }

    public Godot.Collections.Array FaceBlendshapes
    {
        get => (Godot.Collections.Array)Get("face_blendshapes");
        set => Set("face_blendshapes", Variant.From(value));
    }

    public Godot.Collections.Array FacialTransformationMatrixes
    {
        get => (Godot.Collections.Array)Get("facial_transformation_matrixes");
        set => Set("facial_transformation_matrixes", Variant.From(value));
    }

#endregion

#region Methods

    public bool HasFaceBlendshapes() => Call("has_face_blendshapes").As<bool>();

    public bool HasFacialTransformationMatrixes() => Call("has_facial_transformation_matrixes").As<bool>();

#endregion

}
Delsin-Yu commented 2 months ago

Please provide a demo for this issue.

GeorgeS2019 commented 2 months ago

@Delsin-Yu @ZerxZ

protected void ShowResult(Image image, MediaPipeFaceLandmarkerResult result)
{

    foreach (var tmplandmarks in result.FaceLandmarks)
    {
                //This step SLOW down the performance significantly <============
        var landmarks = GDExtensionHelper.Bind<MediaPipeNormalizedLandmarks>(tmplandmarks.AsGodotObject());

        DrawLandmarks(image, landmarks);
    }
}

func show_result(image: Image, result: MediaPipeFaceLandmarkerResult) -> void:
    for landmarks in result.face_landmarks:
        draw_landmarks(image, landmarks)

func draw_landmarks(image: Image, landmarks: MediaPipeNormalizedLandmarks) 
GeorgeS2019 commented 2 months ago

Review => the wrapper work. but performance is as PREVIOUSLY feedback => slow

https://github.com/Delsin-Yu/CSharp-Wrapper-Generator-for-GDExtension/issues/21

Delsin-Yu commented 2 months ago

Please open a separate issue if you are mentioning another topic.

GeorgeS2019 commented 2 months ago

@Delsin-Yu

Do you have suggestion how to Bind with better performance to get Godot.Collections.Array<MediaPipeNormalizedLandmarks> => in ONE STEP, so iteration can be avoided?

//This step SLOW down the performance significantly <============ var landmarks = GDExtensionHelper.Bind(tmplandmarks.AsGodotObject());

public Godot.Collections.Array FaceLandmarks
{
        get => (Godot.Collections.Array)Get("face_landmarks");
        set => Set("face_landmarks", Variant.From(value));
}
ZerxZ commented 2 months ago

@GeorgeS2019 Could you try this PR and see how it performs? https://github.com/Delsin-Yu/CSharp-Wrapper-Generator-for-GDExtension/pull/22#issue-2267635621

Delsin-Yu commented 2 months ago

@Delsin-Yu

Do you have suggestion how to Bind with better performance to get Godot.Collections.Array<MediaPipeNormalizedLandmarks> => in ONE STEP, so iteration can be avoided?

//This step SLOW down the performance significantly <============ var landmarks = GDExtensionHelper.Bind(tmplandmarks.AsGodotObject());

public Godot.Collections.Array FaceLandmarks
{
        get => (Godot.Collections.Array)Get("face_landmarks");
        set => Set("face_landmarks", Variant.From(value));
}

Let's move the discussion to the correct issue (#21) and continue it there.