Godot4 c# Support through C# Bindings for GDMP.GDExtension #6
-
I search for GDExtension using c#, it would be interesting to check if this is possible :-) Update 5th June 2023Possible to create C# binding for GDExtension? Given an Addon: Addon1 with Addon1.gdextension with windows binary: addons/Addon1/libs/x86_64/Addon1.dll In this project Addon1 = GDMP
Here are the possible steps => WIP |
Beta Was this translation helpful? Give feedback.
Replies: 10 comments 8 replies
-
According to official Godot's article about C# on 4.0, it would be possible to use API provided by GDExtension in future 4.x releases.
If using GDMP on C# is really a high-demand use case, the best we can do currently is to provide glue code between C# and GDScript AFAIK, which plugin users can easily write one when needed. From my standpoint, I would rather waiting for Godot(heh) to provide some sort of support for using GDExtension API on C#, instead of maintaining such glue. |
Beta Was this translation helpful? Give feedback.
-
@j20001970 I revisit GDExtension C# Binding as for .NET users, your demo is the MOST promising for .NET users open to non-Unity like Mediapipe.NET I have preliminary tested. it is possible to use Classdb to extract all methods, properties exposed by e.g. GDMP.dll to create GDMPSharp.GDExtension.json ==> The next step is to figure out What is the right json format that can be ingested by Godot SourceCodeGenerator. There are a few versions out there, not sure what are the differences with respect to the official one. Then use Godot Csharp SourceCodeGenerator or BindingGenerator to create the wrapper (Native interoperability c# class) Interested your view if my understanding is correct.
@dsnopek <= could you share your latest information for the GDExtension C# Binding? |
Beta Was this translation helpful? Give feedback.
-
Unfortunately, I have no information to share. I'm on the GDExtension team working on GDExtension itself and the godot-cpp binding, but I'm not aware of an active effort to make a C# binding. If someone is working on that, it'd be great for them to come over the #gdextension channel on RocketChat or one of the GDExtension meetings! |
Beta Was this translation helpful? Give feedback.
-
NativeStructs and Pointers in C# Add NativeStructs and Pointers in C# for GDExtension interoperability Please check if the latest PR (involving the use of Global Class) could lead to C# and GDExtension interoperability AudioStreamPlaybackMyToneusing Godot;
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[GlobalClass]
public partial class AudioStreamPlaybackMyTone : AudioStreamPlayback
{
public const int MIX_FRAC_BITS = 13;
public const int MIX_FRAC_LEN = (1 << MIX_FRAC_BITS);
public const int MIX_FRAC_MASK = MIX_FRAC_LEN - 1;
public AudioStreamMyTone parrent;
bool active;
public unsafe override void _Start(double fromPos)
{
_Seek(fromPos);
active = true;
}
public override void _Stop()
{
active = false;
parrent.Reset();
}
public override bool _IsPlaying()
{
return active;
}
public override int _GetLoopCount()
{
return 0;
}
public override double _GetPlaybackPosition()
{
return 0.0;
}
public override void _Seek(double position)
{
if (position < 0)
{
position = 0;
}
parrent.SetPosition((long)(position * parrent.mix_rate) << MIX_FRAC_BITS);
}
public unsafe override int _Mix(ref AudioFrame buffer, float rateScale, int frames)
{
var p_buffer = (AudioFrame*)Unsafe.AsPointer(ref buffer);
if (!active)
{
return 0;
}
for (int i = 0; i < frames; i++)
{
float sample = (float)Math.Sin(2.0 * Math.PI * (((double)(parrent.pos + i)) / (((double)(parrent.mix_rate)) / ((double)(parrent.hz)))));
p_buffer[i] = new AudioFrame { Left = sample, Right = sample };
}
parrent.pos += frames;
return frames;
}
} AudioStreamMyToneusing Godot;
using System;
[GlobalClass]
public partial class AudioStreamMyTone : AudioStream
{
public long pos;
public int mix_rate = 44100;
public bool stereo = false;
[Export]
public double hz = 639;
public void Reset()
{
SetPosition(0);
}
public void SetPosition(long p)
{
pos = p;
}
public override AudioStreamPlayback _InstantiatePlayback()
{
return new AudioStreamPlaybackMyTone() {
parrent = this
};
}
public override string _GetStreamName()
{
return "MyTone";
}
public override double _GetLength()
{
return 0;
}
} |
Beta Was this translation helpful? Give feedback.
-
GDextension for C# Using |
Beta Was this translation helpful? Give feedback.
-
If I understand this correctly, this proposal is for interoperability between C# and GDExtension interface itself. GDMP is a set of classes registered to Godot through GDExtension, in order to use them in C#, some work need to be done on generating C# source code for registered GDExtension classes, that is, interoperability between C# and custom classes registered through GDExtension. Sorry if I didn't clarify in the previous comments, hope this will help you understand the situation better. |
Beta Was this translation helpful? Give feedback.
-
DmitriySalnikov/godot_debug_draw_3d#10 |
Beta Was this translation helpful? Give feedback.
-
Why a coordinated effort between GDextension for c++, rust, and csharp is needed? |
Beta Was this translation helpful? Give feedback.
-
Finally this is Happening!https://github.com/Delsin-Yu/CSharp-Wrapper-Generator-for-GDExtension |
Beta Was this translation helpful? Give feedback.
-
Using this automated c# GDExtension wrapper generator I manage to port the GDscript version of FaceLandmark example to c# The demo works but the performance is yet to be optimized. This branch is no longer neededhttps://github.com/j20001970/GDMP/tree/csharp-bindings Here is the same code of a working .NET wrapper. The performance is almost as good as the GDScript What started almost 11 months ago is NOW DONE Thank you to all supported and contributed |
Beta Was this translation helpful? Give feedback.
@j20001970
@dsnopek
Using this automated c# GDExtension wrapper generator
I manage to port the GDscript version of FaceLandmark example to c#
The demo works but the performance is yet to be optimized.
This branch is no longer needed
https://github.com/j20001970/GDMP/tree/csharp-bindings
Here is the same code of a working .NET wrapper. The performance is almost as good as the GDScript
What started almost 11 months ago is NOW DONE
Thank you to all supported and contributed