I’m trying to set up a simple Template for thee js but I get:
“Cannot use import statement outside a module”
My index.html:
<body>
<div id= "container" ></div>
<script src="app.js"></script>
</body>
And in app.js I do:
import * as THREE from './js/three.module.js';
export default class Sketch{
constructor(){
this.renderer = new THREE.WebGLRenderer( { antialias: true } );
this.renderer.setSize( window.innerWidth, window.innerHeight );
document.getElementById('container').appendChild( this.renderer.domElement );
this.camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.01, 10 );
this.camera.position.z = 1;
this.scene = new THREE.Scene();
this.addMesh();
this.render();
}
addMesh(){
this.geometry = new THREE.PlaneBufferGeometry( 10, 10 );
this.material = new THREE.MeshNormalMaterial({side: THREE.DoubleSide});
this.mesh = new THREE.Mesh( this.geometry, this.material );
this.scene.add( this.mesh );
}
render(){
this.time++;
this.mesh.rotation.x += 0.01;
this.mesh.rotation.y += 0.02;
console.log(this.time);
this.renderer.render( this.scene, this.camera );
window.requestAnimationFrame(this.render.bind);
}
}
new Sketch();
What am I doing wrong?
Thanks in advance.