From 819c89e92f7509a1e381089506e425e1eb1227a5 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 22 Nov 2022 10:40:13 +0100 Subject: [PATCH] extend Element for a Cube class --- js/Cube.js | 12 ++++++++++++ js/Element.js | 11 +++++------ 2 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 js/Cube.js 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; + } }; }