diff --git a/js/Cube.js b/js/Cube.js new file mode 100644 index 0000000..665d3d9 --- /dev/null +++ b/js/Cube.js @@ -0,0 +1,12 @@ +import { Element } from "./Element.js"; + +export class Cube extends Element { + constructor() { + super(); + + this.data = new THREE.Mesh( + new THREE.BoxGeometry(1, 1, 1), + new THREE.MeshBasicMaterial({ color: 0x00ff00 }) + ); + } +} diff --git a/js/Element.js b/js/Element.js index 60b67d4..50b4ca6 100644 --- a/js/Element.js +++ b/js/Element.js @@ -1,16 +1,15 @@ export class Element { constructor() { - this.data = new THREE.Mesh( - new THREE.BoxGeometry(1, 1, 1), - new THREE.MeshBasicMaterial({ color: 0x00ff00 }) - ); + this.data = undefined; } /** * Rotate the element */ rotate = () => { - this.data.rotation.x += 0.01; - this.data.rotation.y += 0.01; + if (this.data) { + this.data.rotation.x += 0.01; + this.data.rotation.y += 0.01; + } }; }