functional_factor.js 822 B

123456789101112131415161718192021222324252627282930313233
  1. import * as three from "three-js";
  2. import { factor } from "./factor";
  3. class functional_factor extends factor {
  4. #animation;
  5. constructor(init, animation = null) {
  6. if (typeof (init) !== "function") {
  7. throw new TypeError("Init must be an function.");
  8. }
  9. if (animation !== null && typeof (animation) !== "function") {
  10. throw new TypeError("Animation could only be null or function.");
  11. }
  12. const mesh = init();
  13. if (!(mesh instanceof three.Object3D)) {
  14. throw new TypeError("Factor initializer must return Object3D.");
  15. }
  16. super(mesh);
  17. this.#animation = animation;
  18. }
  19. loop() {
  20. if (this.#animation !== null) {
  21. this.#animation(this.mesh);
  22. }
  23. }
  24. }
  25. export { functional_factor };