Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nimloth05/threejs-kotlin-binding
Binding for threejs in kotlin
https://github.com/nimloth05/threejs-kotlin-binding
kotlin kotlin-bindings threejs
Last synced: 5 days ago
JSON representation
Binding for threejs in kotlin
- Host: GitHub
- URL: https://github.com/nimloth05/threejs-kotlin-binding
- Owner: nimloth05
- Created: 2018-11-07T13:19:19.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2021-03-14T14:47:07.000Z (over 3 years ago)
- Last Synced: 2024-10-12T22:20:56.290Z (about 1 month ago)
- Topics: kotlin, kotlin-bindings, threejs
- Language: Kotlin
- Homepage:
- Size: 632 KB
- Stars: 3
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# threejs-kotlin-binding
This project provides an update to date binding of three.js. (r101)
This binding was generated out of the threejs doc. This means, that most classes/methods/properties contains documentation.ATTENTION: With version 105 I changed the maven coordinates to "wrapper" instead of "binding".
# Extensions
With release 105 there is also an additional project, "extension" which provides (basic) coroutine support for some loaders.
Maven coordinates: ch.viseon.threejs:extensions:105.0.0## setup
The binding is available at the maven central repository.
Reference this library in your build.gradle file:
dependencies {
implementation "ch.viseon.threejs:wrapper:105.0.0"
}Threejs needs to be loaded via npm (use kotlinFrontend Plugin)
kotlinFrontend {
npm {
dependency("three", "0.105.0")
}
}
## ExampleExample code for rotating cube:
fun main(args: Array) {
// require("three")window.onload = {
CubeExample.init()
CubeExample.animate()
}
}object CubeExample {
lateinit var camera: PerspectiveCamera
lateinit var scene: Scene
lateinit var renderer: WebGLRenderer
lateinit var mesh: Meshfun init() {
camera = PerspectiveCamera(70.0, (window.innerWidth / window.innerHeight).toNumber(), 1.0, 1000.0)
camera.position.z = 400.0
scene = Scene()
val texture = TextureLoader().load("textures/crate.gif")
val geometry = BoxBufferGeometry(200.0, 200.0, 200.0)
val material = MeshBasicMaterial(MeshBasisMaterialParameter().apply { map = texture })
mesh = Mesh(geometry.asDynamic(), material)
scene.add(mesh)
renderer = WebGLRenderer(WebGlRendererParams(true))
renderer.setPixelRatio(window.devicePixelRatio)
renderer.setSize(window.innerWidth, window.innerHeight)document.body?.appendChild(renderer.domElement)
window.addEventListener("resize", ::onWindowResize, false)
}fun onWindowResize(event: Event) {
camera.aspect = (window.innerWidth / window.innerHeight).toNumber()
camera.updateProjectionMatrix()
renderer.setSize(window.innerWidth, window.innerHeight)
}fun animate() {
window.requestAnimationFrame {
animate()
}
mesh.rotation.x += 0.005f
mesh.rotation.y += 0.01f
renderer.render(scene, camera);
}
}
The complete example is in the `example` project.# Future
Next thing I'd like to implement is coroutine based loading of assets. Threejs uses a callback based mechanism.
This would be a separate project.
## threejs-kotlin-parser (details)
A Parser which parses threeJs doc to generate Kotlin bindingsThe process works as follows:
- It downloads a JSON description from the threeJs doc page, which contains all existing API reference links
- Parse every API doc and generate an abstract declaration object
- For each declaration object, a Kotlin file is generated