Porting THREE to C#

What’d be the easiest way to embed a THREE project into a C# desktop app?

Is there a C# library conceptually similar to in its approach and capacity to THREE?



wow sick. good link ty :slight_smile:

1 Like

Thank you!

Also, considering THREE transition to WebGPU, which is not based on OpenGL, a (future) C# library for porting would probably be Vulkan based?

1 Like

There are two approaches you can take.

1.) Use one of the THREE.JS .NET wrapper libraries and copy your code from JS to C#.

2.) Run your existing THREE.JS (client) Web app in a Windows Form using a web browser control.
In this approach you would use an opensource control like CefSharp, which embeds a chrome web browser in a .NET control. And then add the CefSharp to a WinForms Form or WPF. Then you just set the CefSharp’s Url property to your web client address.

Here are just a few tutorials:

1 Like

I’ll definitely try it out.

What I find unfortunate though is that libraries like THREE that found a very effective level of abstraction are locked in the browser and JS.

It’s easier to port the whole browser into your native app, then to port THREE alone.

It seems that with WebGPU it’s going to be worse: according to wiki, WebGPU is not a port of any native API in particular, so we are going to have a good modern API, but designed only for the Web, with THREE locked to it, all of that alienated from the native world, which is a shame.

no one can say what the future development will be like, maybe the web will replace the native, hahah…

1 Like

Hi I am a beginner, Im currently doing the same approach. I followed the fundamentals tutorial from ThreeJS documentation, so i have node, vite and able to run my project thru local server (vite).

My question is, how can I use it with CefSharp? how can i set up a local server inside cefsharp since CORS blocks local html when it uses ESmodules? I apologize if I was not able to explain my situation properly, but I hope you get the point. Thanks!!

@tfoller I agree. I had the same problem when searching for a 3D framework to use with my C# desktop application. I did not end up finding anything nearly as good as THREE.JS for .NET. I ended up trying to use OpenTK, which is a C# port of OpenGL, but I got stuck pretty early on because of how low level OpenGL is. I had to write my own shaders and I couldn’t even figure out how to make a trackball-style camera. THREEJS’s higher level of abstraction provides implementations of those higher level concepts and I think that is the real value of it.

@AjBernababe In your case you would need to have your vite server running and serving your website. Then you would add CefSharp to a Form or control in a separate .NET app. Then set CefSharpObject.Url to your website’s address.

As an alternative, I think you could run the webserver serving your website in your .NET app (instead of thru vite), using something like C#'s HttpServer, and then set your CefSharp object’s URL property to that.

Regarding CORS, you probably just need to add permission/access in your CORS policy on the server to allow whatever host you are trying to access it from. But I am certainly no CORS expert.

Hi, thanks for the response, is there a way to set up a local server within cefsharp that will work with different clients? Thank you!