<commit_before>import * as THREE from "three";

import {IShaderMaterial} from "../../Component";

export class MeshScene {
    public scene: THREE.Scene;
    public sceneOld: THREE.Scene;

    public imagePlanes: THREE.Mesh[];
    public imagePlanesOld: THREE.Mesh[];

    constructor() {
        this.scene = new THREE.Scene();
        this.sceneOld = new THREE.Scene();

        this.imagePlanes = [];
        this.imagePlanesOld = [];
    }

    public updateImagePlanes(planes: THREE.Mesh[]): void {
        this._dispose(this.imagePlanesOld, this.sceneOld);

        for (let plane of this.imagePlanes) {
            this.scene.remove(plane);
            this.sceneOld.add(plane);
        }

        for (let plane of planes) {
            this.scene.add(plane);
        }

        this.imagePlanesOld = this.imagePlanes;
        this.imagePlanes = planes;
    }

    public addImagePlanes(planes: THREE.Mesh[]): void {
        for (let plane of planes) {
            this.scene.add(plane);
            this.imagePlanes.push(plane);
        }
    }

    public addImagePlanesOld(planes: THREE.Mesh[]): void {
        for (let plane of planes) {
            this.sceneOld.add(plane);
            this.imagePlanesOld.push(plane);
        }
    }

    public setImagePlanes(planes: THREE.Mesh[]): void {
        this._clear();
        this.addImagePlanes(planes);
    }

    public setImagePlanesOld(planes: THREE.Mesh[]): void {
        this._clearOld();
        this.addImagePlanesOld(planes);
    }

    public clear(): void {
        this._clear();
        this._clearOld();
    }

    private _clear(): void {
        this._dispose(this.imagePlanes, this.scene);
        this.imagePlanes.length = 0;
    }

    private _clearOld(): void {
        this._dispose(this.imagePlanesOld, this.sceneOld);
        this.imagePlanesOld.length = 0;
    }

    private _dispose(planes: THREE.Mesh[], scene: THREE.Scene): void {
        for (let plane of planes) {
            scene.remove(plane);
            plane.geometry.dispose();
            (<THREE.Material>plane.material).dispose();
            let texture: THREE.Texture = (<IShaderMaterial>plane.material).uniforms.projectorTex.value;
            if (texture != null) {
                texture.dispose();
            }
        }<commit_msg>feat: add periphery plane array to mesh scene<commit_after>import * as THREE from "three";

import {IShaderMaterial} from "../../Component";

export class MeshScene {
    public scene: THREE.Scene;
    public sceneOld: THREE.Scene;
    public peripheryScene: THREE.Scene;

    public imagePlanes: THREE.Mesh[];
    public imagePlanesOld: THREE.Mesh[];
    public peripheryPlanes: THREE.Mesh[];

    constructor() {
        this.scene = new THREE.Scene();
        this.sceneOld = new THREE.Scene();
        this.peripheryScene = new THREE.Scene();

        this.imagePlanes = [];
        this.imagePlanesOld = [];
        this.peripheryPlanes = [];
    }

    public updateImagePlanes(planes: THREE.Mesh[]): void {
        this._dispose(this.imagePlanesOld, this.sceneOld);

        for (let plane of this.imagePlanes) {
            this.scene.remove(plane);
            this.sceneOld.add(plane);
        }

        for (let plane of planes) {
            this.scene.add(plane);
        }

        this.imagePlanesOld = this.imagePlanes;
        this.imagePlanes = planes;
    }

    public addImagePlanes(planes: THREE.Mesh[]): void {
        for (let plane of planes) {
            this.scene.add(plane);
            this.imagePlanes.push(plane);
        }
    }

    public addImagePlanesOld(planes: THREE.Mesh[]): void {
        for (let plane of planes) {
            this.sceneOld.add(plane);
            this.imagePlanesOld.push(plane);
        }
    }

    public setImagePlanes(planes: THREE.Mesh[]): void {
        this._clear();
        this.addImagePlanes(planes);
    }

    public addPeripheryPlanes(planes: THREE.Mesh[]): void {
        for (let plane of planes) {
            this.peripheryScene.add(plane);
            this.peripheryPlanes.push(plane);
        }
    }

    public setPeripheryPlanes(planes: THREE.Mesh[]): void {
        this._clearPeriphery();
        this.addPeripheryPlanes(planes);
    }

    public setImagePlanesOld(planes: THREE.Mesh[]): void {
        this._clearOld();
        this.addImagePlanesOld(planes);
    }

    public clear(): void {
        this._clear();
        this._clearOld();
    }

    private _clear(): void {
        this._dispose(this.imagePlanes, this.scene);
        this.imagePlanes.length = 0;
    }

    private _clearOld(): void {
        this._dispose(this.imagePlanesOld, this.sceneOld);
        this.imagePlanesOld.length = 0;
    }

    private _clearPeriphery(): void {
        this._dispose(this.peripheryPlanes, this.peripheryScene);
        this.peripheryPlanes.length = 0;
    }

    private _dispose(planes: THREE.Mesh[], scene: THREE.Scene): void {
        for (let plane of planes) {
            scene.remove(plane);
            plane.geometry.dispose();
            (<THREE.Material>plane.material).dispose();
            let texture: THREE.Texture = (<IShaderMaterial>plane.material).uniforms.projectorTex.value;
            if (texture != null) {
                texture.dispose();
            }
        }
{'fraction_non_alphanumeric': 0.12379329926178308, 'fraction_numerical': 0.0009464319515426841, 'mean_word_length': 2.1396316102198454, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5915672', 'n_tokens_mistral': 1640, 'n_tokens_neox': 1546, 'n_words': 303}