extend Element for a Cube class

This commit is contained in:
Mylloon 2022-11-22 10:40:13 +01:00
parent 9a352e7789
commit 819c89e92f
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 17 additions and 6 deletions

12
js/Cube.js Normal file
View file

@ -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 })
);
}
}

View file

@ -1,16 +1,15 @@
export class Element { export class Element {
constructor() { constructor() {
this.data = new THREE.Mesh( this.data = undefined;
new THREE.BoxGeometry(1, 1, 1),
new THREE.MeshBasicMaterial({ color: 0x00ff00 })
);
} }
/** /**
* Rotate the element * Rotate the element
*/ */
rotate = () => { rotate = () => {
this.data.rotation.x += 0.01; if (this.data) {
this.data.rotation.y += 0.01; this.data.rotation.x += 0.01;
this.data.rotation.y += 0.01;
}
}; };
} }