Using Kotlin/JS to write THREE programs

Did anyone had luck in using Kotlin/JS with recent three.js releases? It would be great if he can share an example project.
I was able to run r88 with the help of kotlin wrappers provided here three-kt-wrapper,
But I wonder if anyone played with it lately as they are constantly improving the JS interop and the automatic processes to help setting up the projects.

I tried also using Dukat to convert the .d.ts files and could get it to compile eventually, but I still can’t to configure this puzzle properly.

For whoever is not familiar with Kotiln, it’s a JVM based statically typed language with multiple targets (i.e javascript).

1 Like

Did you try Nativescript.org for native apps both iOS/Android - you can code vanilla JS or Vue/TS even Angular or React. It’s really good.

Thanks for the offer, looks like an interesting project.
But my purpose (hopefully) is to target the browser using Kotlin.

Yes, I’ve been working with it quite a lot lately and I absolutely love it!
Check out the following:

A starter project that you can use as baseline for your own project:
https://github.com/liorgonnen/kotlin-three-js-starter

A 3D Boids simulation:
https://github.com/liorgonnen/boids.kt

A 3D PacMan implementation
https://github.com/liorgonnen/pacman3d

I also created a modified version of Dukat (that you can find here) that worked around the issues Dukat had for generating the three.js externals.

I’ve also opened issues for the original project so that those could be addressed by JetBrains.

2 Likes

That’s more than awesome, thanks! Glad to hear someone had the same wish and made it happen. it works well.

I’m not sure if you are working with “–continuous” mode, but it gave me an error until I implemented some workaround offered here - https://youtrack.jetbrains.com/issue/KT-32273
in short, take this file, remove first 5 lines, and put it into a .js file under a folder named webpack.config.d in your project root.

Cheers

Thanks, I’ll check it out.

I haven’t been using --continuous directly. I’m running the browserDevelopmentRun gradle task from inside IntelliJ

Thank you for sharing this :slight_smile:

Sorry about posting this to the “wrong forum”, but I can’t find anyone else discussing this in other forums: by any chance, have you made pixi.js work with Kotlin? I tried but failed.

At what part you stuck?
if you are still stuck on the lib.dom.kt files that doesn’t compile (from the other post), I think you can omit them as they are probably included by the kotlin/js stdlib.
Generally, the “generateExternals = true” flag did not work very well for me before, so I did it manually with the dukat CLI tool, and then just included the files I needed (also saves some compilation time I think). You can basically have only the declarations for the functions/properties that you are actually using in your app, and not all the library API.

It was all very confusing for me at the first time, but it worth it. so feel free to ask on whatever is not clear from what I said.

This is awesome!
I’ve been playing around with it for a while now, trying to port some things I made with Libgdx/Java. I’m having some trouble handing over a texture to ShaderMaterial. What I came up with is something like this:

myShaderMaterial.uniforms[“uTexture”] = {}
myShaderMaterial.uniforms[“uTexture”]?.value = myTexture

This works, but there must be an easier / cleaner solution. Sorry for asking this here, I’m very new to Kotlin.