All Projects → markaren → three-kt-wrapper

markaren / three-kt-wrapper

Licence: MIT license
Kotlin wrappers for Three.js

Programming Languages

kotlin
9241 projects
javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to three-kt-wrapper

lvr
👓 Augmented Reality for everyone - Out of the world experiences
Stars: ✭ 92 (+100%)
Mutual labels:  threejs, three-js
ng-three-examples
three.js examples in Angular 2
Stars: ✭ 24 (-47.83%)
Mutual labels:  threejs, three-js
three-csg-ts
CSG library for use with THREE.js
Stars: ✭ 312 (+578.26%)
Mutual labels:  threejs, three-js
WebGL-Billiards
ThreeJS based 8-ball pool
Stars: ✭ 28 (-39.13%)
Mutual labels:  threejs, three-js
EduSmart
It utilizes 3D, Augmented reality to give real-life simulations or feels of various models and make the learning process more impactful and fascinating. With an interactive live feature, students can ask the teacher their doubts instantly and also discuss.
Stars: ✭ 23 (-50%)
Mutual labels:  threejs, three-js
Threejs Sandbox
Set of experiments and extensions to THREE.js.
Stars: ✭ 163 (+254.35%)
Mutual labels:  threejs, three-js
gamedex
👾 The code for my game dev + computer graphics experiments on YouTube.
Stars: ✭ 165 (+258.7%)
Mutual labels:  threejs, three-js
A Mmd
A-Frame MMD component
Stars: ✭ 74 (+60.87%)
Mutual labels:  threejs, three-js
revit-family-web-viewer
Revit Web Viewer is a Three.js-based project viewer. Revit projects / families must be exported using RvtVa3cExporter (https://github.com/va3c/RvtVa3c)
Stars: ✭ 48 (+4.35%)
Mutual labels:  threejs, three-js
THREE.InfiniteGridHelper
Infinite anti-aliased grid.
Stars: ✭ 101 (+119.57%)
Mutual labels:  threejs, three-js
Patches
Patches is a visual programming editor for building WebVR and WebGL experiences.
Stars: ✭ 164 (+256.52%)
Mutual labels:  threejs, three-js
react-with-threejs-example
An example project integrating React with three.js
Stars: ✭ 27 (-41.3%)
Mutual labels:  threejs, three-js
Three Ui
UI solution for Three.js
Stars: ✭ 149 (+223.91%)
Mutual labels:  threejs, three-js
Pipes
💿 Classic 3D Pipes screensaver remake (web-based)
Stars: ✭ 176 (+282.61%)
Mutual labels:  threejs, three-js
Three Csgmesh
Conversion of a CSG library for use with modern THREE.js
Stars: ✭ 101 (+119.57%)
Mutual labels:  threejs, three-js
generative-art
🌈🎨 Generative Art is the idea realized as genetic code of artificial events, as construction of dynamic complex systems able to generate endless variations. This is also a nuxt-module (@luxdamore/nuxt-canvas-sketch) - [three.js, tensorflow.js and gsap are not included].
Stars: ✭ 41 (-10.87%)
Mutual labels:  threejs, three-js
Solarsys
Realistic Solar System simulation with three.js
Stars: ✭ 49 (+6.52%)
Mutual labels:  threejs, three-js
Vanta
Animated 3D backgrounds for your website
Stars: ✭ 1,162 (+2426.09%)
Mutual labels:  threejs, three-js
three-js-fundamentals-r3f
Examples from the Three.js Fundamentals website recreated in react-three-fiber renderer.
Stars: ✭ 84 (+82.61%)
Mutual labels:  threejs, three-js
Manim.three.js
A web compatible html5 canvas based mathematical rendering engine like the manim by 3b1b
Stars: ✭ 14 (-69.57%)
Mutual labels:  threejs, three-js

three-kt-wrapper

Kotlin wrappers for Three.js (r88)

Allows you to write Three.js apps using Kotlin

For a full on Kotlin/JVM port, check out https://github.com/markaren/three.kt

Awesome Kotlin Badge

License: MIT contributions welcome

HelloWorld

result

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Kotlin + three.js</title>
    <style>
        body {
            margin: 0;
            overflow: hidden;
        }
    </style>
</head>
    <body>

    <div id="container"></div>

        <script type="text/javascript" src="js/libs/stats.min.js"></script>
        <script type="text/javascript" src="js/libs/dat.gui.min.js"></script>

        <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/three.js/88/three.min.js"></script>
        <script type="text/javascript" src="js/OrbitControls.js"></script>

        <script type="text/javascript" src="js/kt2js/kotlin.js"></script>
        <script type="text/javascript" src="js/kt2js/threejs-wrapper.js"></script>

        <script type="text/javascript" src="js/kt2js/example.js"></script>

        <script type="text/javascript">
            new example.HelloWorld().animate()
        </script>

    </body>
</html>
class HelloWorld {

    private val renderer: WebGLRenderer
    private val scene: Scene = Scene()
    private val camera: PerspectiveCamera
    private val controls: OrbitControls
    private val cube: Mesh
    private val stats: Stats = Stats()

    init {

        scene.add(AmbientLight())

        camera = PerspectiveCamera(75, window.innerWidth.toDouble() / window.innerHeight, 0.1, 1000)
        camera.position.setZ(5)

        renderer = WebGLRenderer(WebGLRendererParams(
                antialias = true
        )).apply {
            setClearColor(ColorConstants.skyblue, 1)
            setSize(window.innerWidth, window.innerHeight)
        }

        document.getElementById("container")?.apply {
            appendChild(renderer.domElement)
            appendChild(stats.dom)
        }

        controls = OrbitControls(camera, renderer.domElement)

        cube = Mesh(BoxBufferGeometry(1, 1, 1),
                MeshPhongMaterial().apply {
                    this.color.set(ColorConstants.darkgreen)
                }).also ( scene::add )

        Mesh(cube.geometry as BufferGeometry,
                MeshBasicMaterial().apply {
                    this.wireframe = true
                    this.color.set(ColorConstants.black)
                }).also ( cube::add )

        val points = CatmullRomCurve3(
                arrayOf(Vector3(-10, 0, 10),
                        Vector3(-5, 5, 5),
                        Vector3(0, 0, 0),
                        Vector3(5, -5, 5),
                        Vector3(10, 0, 10))
        ).getPoints(50)

        val geometry = BufferGeometry().setFromPoints(points)

        val material = LineBasicMaterial().apply {
            color.set(0xff0000)
        }

        // Create the final object to add to the scene
        Line(geometry, material).apply ( scene::add )

        window.addEventListener("resize", {
            camera.aspect = window.innerWidth.toDouble() / window.innerHeight;
            camera.updateProjectionMatrix();

            renderer.setSize( window.innerWidth, window.innerHeight )
        }, false)

    }

    fun animate() {
        window.requestAnimationFrame {
            cube.rotation.x += 0.01
            cube.rotation.y += 0.01
            animate()
        }
        renderer.render(scene, camera)
        stats.update()
    }

}

Loaders

result

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Kotlin + three.js</title>
    <style>
        body {
            margin: 0;
            overflow: hidden;
        }
    </style>
</head>
    <body>

        <div id="container"></div>

        <script type="text/javascript" src="js/libs/stats.min.js"></script>
        <script type="text/javascript" src="js/libs/dat.gui.min.js"></script>

        <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/three.js/88/three.min.js"></script>
        <script type="text/javascript" src="js/OrbitControls.js"></script>

        <script type="text/javascript" src="js/STLLoader.js"></script>
        <script type="text/javascript" src="js/OBJLoader.js"></script>
        <script type="text/javascript" src="js/LoaderSupport.js"></script>
        <script type="text/javascript" src="js/OBJLoader2.js"></script>


        <script type="text/javascript" src="js/kt2js/kotlin.js"></script>
        <script type="text/javascript" src="js/kt2js/threejs-wrapper.js"></script>

        <script type="text/javascript" src="js/kt2js/example.js"></script>

        <script type="text/javascript">
            new example.LoaderTest().animate()
        </script>

    </body>
</html>
class LoaderTest {

    val stats: Stats = Stats()
    val renderer: WebGLRenderer
    val scene: Scene = Scene()
    val camera: PerspectiveCamera
    val controls: OrbitControls
    val models: MutableList<Mesh> = ArrayList()
    var speed: Double = 1.0
    val clock: Clock = Clock(autoStart = true)

    init {

        val light = DirectionalLight(color = 0xffffff, intensity =  0.5)
        light.position.set(0, 0, -1)
        scene.add(light)

        camera = PerspectiveCamera(75, window.innerWidth.toDouble() / window.innerHeight, 0.1, 1000)
        camera.position.set(0, 5, -5)

        renderer = WebGLRenderer(WebGLRendererParams(
                antialias = true
        )).apply {
            setClearColor(ColorConstants.skyblue, alpha = 1)
            setSize(window.innerWidth, window.innerHeight)
        }

        dat.GUI(GUIParams(
                closed = false
        )).also {
            (it.add(this, "speed") as NumberController).apply {
                min(0).max(10).step(0.1)
            }
        }

        document.getElementById("container")?.apply {
            appendChild(renderer.domElement)
            appendChild(stats.dom)
        }

        controls = OrbitControls(camera, renderer.domElement)

        STLLoader().apply {
            load("models/suzanne.stl", {
                Mesh(it, MeshPhongMaterial().apply {
                    color.set(0xff5533)
                    specular.set(0x111111)
                    shininess = 200.0
                }).also {
                    models.add(it)
                    scene.add(it)
                }
            })
        }

        OBJLoader().apply {
            load("models/suzanne.obj", {

                it.position.setX(-5)
                models.add(it)
                scene.add(it)

            })
        }

        OBJLoader2().apply {
            load("models/suzanne.obj", {

                it.detail.loaderRootNode.let {

                    it.position.setX(5)
                    it.traverse {
                        if (it is Mesh) {
                            it.material.asDynamic().color.set(0x00ff00)
                        }
                    }

                    models.add(it)
                    scene.add(it)

                }

            })
        }
        
        window.addEventListener("resize", {
            camera.aspect = window.innerWidth.toDouble() / window.innerHeight;
            camera.updateProjectionMatrix();
            renderer.setSize( window.innerWidth, window.innerHeight )
        }, false)

    }

    fun animate() {
        window.requestAnimationFrame {

            val dt = clock.getDelta()
            models.forEach {
                it.rotation.apply {
                    y += speed * dt
                }
            }
            animate()
        }
        renderer.render(scene, camera)
        stats.update()
    }

}

How to get it

Use JitPack. See below for how this works using Gradle. Check the link for other builds systems.

repositories {
    maven { url 'https://jitpack.io' }
}

dependencies {
    implementation 'com.github.markaren:three-kt-wrapper:v0.88-ALPHA-7'
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].