| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- 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 }
|