|
|
@@ -0,0 +1,56 @@
|
|
|
+import * as three from "three-js";
|
|
|
+
|
|
|
+class factor {
|
|
|
+ #mesh;
|
|
|
+
|
|
|
+ constructor(mesh) {
|
|
|
+ if (!(mesh instanceof three.Mesh)) {
|
|
|
+ throw new TypeError("Must initialize with Mesh.");
|
|
|
+ }
|
|
|
+
|
|
|
+ this.#mesh = mesh;
|
|
|
+ }
|
|
|
+
|
|
|
+ get mesh() {
|
|
|
+ if (!(this.#mesh instanceof three.Mesh)) {
|
|
|
+ throw new TypeError("Mesh is not initialized.");
|
|
|
+ }
|
|
|
+
|
|
|
+ return this.#mesh;
|
|
|
+ }
|
|
|
+
|
|
|
+ loop() {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+class functional_factor extends factor {
|
|
|
+ #animation
|
|
|
+
|
|
|
+ constructor (init, animation = null) {
|
|
|
+ if (typeof(init) !== "function") {
|
|
|
+ throw new TypeError("Init must be an function.");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (animation !== null && typeof(animation) !== "function") {
|
|
|
+ throw new TypeError("Animation could only be null or function.");
|
|
|
+ }
|
|
|
+
|
|
|
+ const mesh = init(this);
|
|
|
+
|
|
|
+ if (!(mesh instanceof three.Mesh)) {
|
|
|
+ throw new TypeError("Factor initializer must return mesh.");
|
|
|
+ }
|
|
|
+
|
|
|
+ super(mesh);
|
|
|
+ this.#animation = animation;
|
|
|
+ }
|
|
|
+
|
|
|
+ loop() {
|
|
|
+ if (this.#animation !== null) {
|
|
|
+ this.#animation(this);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+export { factor, functional_factor }
|