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 {
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;
}
};
}