I have been trying to get Three.js to work with my JS Kotlin project. so far I'm just trying to get the getting started project to run.
ThreeJS Getting Started = http://threejs.org/docs/index.html#Manual/Introduction/Creating_a_scene
My Project = https://bitbucket.org/ClassicThunder/kotlin_threejs/src
Below is the code that is generate by my project.
(function (Kotlin) {
‘use strict’;
var _ = Kotlin.defineRootPackage(null, /** @lends _ / {
org: Kotlin.definePackage(null, /* @lends _.org / {
sample: Kotlin.definePackage(null, /* @lends _.org.sample */ {
main: function (args) {
var scene = THREE.Scene();
var camera = THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
var renderer = THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
window.document.body.appendChild(renderer.domElement);
var geometry = THREE.BoxGeometry(1, 1, 1);
var material = THREE.MeshBasicMaterial(THREE.Color(‘0x00ff00’));
var cube = THREE.Mesh(geometry, material);
scene.add(cube);
}
})
})
});
Kotlin.defineModule(‘basic’, );
.org.sample.main();
}(Kotlin));’
When I run this it fails on the “var camera = THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);” line.
-
Uncaught TypeError: Cannot redefine property: position three.js:7156
- THREE.Object3Dthree.js:7156
- THREE.Camerathree.js:10566
- THREE.PerspectiveCamerathree.js:10740
- Kotlin.defineRootPackage.org.Kotlin.definePackage.sample.Kotlin.definePackage.mainbasic.js:8
- (anonymous function)basic.js:21
- (anonymous function)
The sample project run fine though. Below seems to be the difference. On the left (or on the top) is the Kotlin project and as you can see this Object3D already exists from when the Scene was created. On the right (or bottom) is the downloaded sample code. Here a new Object3D is being created. I assume this is because of how I set up things in this file; however I have been unable to fix the issue. Any help setting up the interop code would be greatly appreciated.