<commit_before>import { Box3Helper, Group, MeshBasicMaterial } from 'three';
import { TilesRenderer } from './TilesRenderer.js';
import { SphereHelper } from './SphereHelper.js';

const ORIGINAL_MATERIAL = Symbol( 'ORIGINAL_MATERIAL' );

const NONE = 0;
const SCREEN_ERROR = 1;
const GEOMETRIC_ERROR = 2;
const DISTANCE = 3;
const DEPTH = 4;
const RELATIVE_DEPTH = 5;
const IS_LEAF = 6;
const RANDOM_COLOR = 7;

function emptyRaycast() {}

export class DebugTilesRenderer extends TilesRenderer {

	constructor( ...args ) {

		super( ...args );

		const tilesGroup = this.group;
		const boxGroup = new Group();
		tilesGroup.add( boxGroup );

		const sphereGroup = new Group();
		tilesGroup.add( sphereGroup );

		this.displayBoxBounds = false;
		this.displaySphereBounds = false;
		this.colorMode = NONE;
		this.boxGroup = boxGroup;
		this.sphereGroup = sphereGroup;
		this.maxDepth = - 1;
		this.maxDistance = - 1;
		this.maxError = - 1;

		this.extremeDepth = - 1;
		this.extremeError = - 1;

	}

	initExtremes() {

		let maxDepth = - 1;
		this.traverse( tile => {

			maxDepth = Math.max( maxDepth, tile.__depth );

		} );

		let maxError = - 1;
		this.traverse( tile => {

			maxError = Math.max( maxError, tile.geometricError );

		} );

		this.extremeDepth = maxDepth;
		this.extremeError = maxError;

	}

	loadTileSet( ...args ) {

		const pr = super.loadTileSet( ...args );
		pr.then( () => this.initExtremes() );

		return pr;

	}

	getTileInformationFromActiveObject( object ) {

		let targetTile = null;
		const activeTiles = this.activeTiles;
		activeTiles.forEach( tile => {

			if ( targetTile ) {

				return true;

			}

			const scene = tile.cached.scene;
			if ( scene ) {

				scene.traverse( c => {

					if ( c === object ) {

						targetTile = tile;

					}

				} );

			}

		} );

		if ( targetTile ) {

			return {

				distanceToCamera: targetTile.cached.distance,
				geometricError: targetTile.geometricError,
				screenSpaceError: targetTile.__error,
				depth: targetTile.__depth,
				isLeaf: targetTile.__isLeaf

			};

		} else {

			return null;

		}

	}

	update() {

		super.update();

		if ( ! this.root ) {

			return;

		}

		this.boxGroup.visible = this.displayBoxBounds;
		this.sphereGroup.visible = this.displaySphereBounds;

		let maxDepth = - 1;
		if ( this.maxDepth === - 1 ) {

			maxDepth = this.extremeDepth;

		} else {

			maxDepth = this.maxDepth;

		}

		let maxError = - 1;
		if ( this.maxError === - 1 ) {

			maxError = this.extremeError;

		} else {

			maxError = this.maxError;

		}

		let maxDistance = - 1;
		if ( this.maxDistance === - 1 ) {

			maxDistance = this.root.cached.sphere.radius;

		} else {

			maxDistance = this.maxDistance;

		}

		// TODO: Support i3dm, pnts, cmpt here
		const errorTarget = this.errorTarget;
		const colorMode = this.colorMode;
		const visibleTiles = this.visibleTiles;
		visibleTiles.forEach( tile => {

			const scene = tile.cached.scene;
			scene.traverse( c => {

				const currMaterial = c.material;
				if ( currMaterial ) {

					const originalMaterial = c[ ORIGINAL_MATERIAL ];
					if ( colorMode === NONE && currMaterial !== originalMaterial ) {

						c.material.dispose();
						c.material = c[ ORIGINAL_MATERIAL ];

					} else if ( colorMode !== NONE && currMaterial === originalMaterial ) {

						c.material = new MeshBasicMaterial();

					}

					if ( colorMode !== RANDOM_COLOR ) {

						delete c.material.__randomColor;

					}

					switch ( colorMode ) {

						case DEPTH: {

							const val = tile.__depth / maxDepth;
							c.material.color.setRGB( val, val, val );
							break;

						}
						case RELATIVE_DEPTH: {5

							const val = tile.__depthFromRenderedParent / maxDepth;
							c.material.color.setRGB( val, val, val );
							break;

						}
						case SCREEN_ERROR: {

							const val = tile.__error / errorTarget;
							if ( val > 1.0 ) {

								c.material.color.setRGB( 1.0, 0.0, 0.0 );
<commit_msg>remove extraneous 5<commit_after>import { Box3Helper, Group, MeshBasicMaterial } from 'three';
import { TilesRenderer } from './TilesRenderer.js';
import { SphereHelper } from './SphereHelper.js';

const ORIGINAL_MATERIAL = Symbol( 'ORIGINAL_MATERIAL' );

const NONE = 0;
const SCREEN_ERROR = 1;
const GEOMETRIC_ERROR = 2;
const DISTANCE = 3;
const DEPTH = 4;
const RELATIVE_DEPTH = 5;
const IS_LEAF = 6;
const RANDOM_COLOR = 7;

function emptyRaycast() {}

export class DebugTilesRenderer extends TilesRenderer {

	constructor( ...args ) {

		super( ...args );

		const tilesGroup = this.group;
		const boxGroup = new Group();
		tilesGroup.add( boxGroup );

		const sphereGroup = new Group();
		tilesGroup.add( sphereGroup );

		this.displayBoxBounds = false;
		this.displaySphereBounds = false;
		this.colorMode = NONE;
		this.boxGroup = boxGroup;
		this.sphereGroup = sphereGroup;
		this.maxDepth = - 1;
		this.maxDistance = - 1;
		this.maxError = - 1;

		this.extremeDepth = - 1;
		this.extremeError = - 1;

	}

	initExtremes() {

		let maxDepth = - 1;
		this.traverse( tile => {

			maxDepth = Math.max( maxDepth, tile.__depth );

		} );

		let maxError = - 1;
		this.traverse( tile => {

			maxError = Math.max( maxError, tile.geometricError );

		} );

		this.extremeDepth = maxDepth;
		this.extremeError = maxError;

	}

	loadTileSet( ...args ) {

		const pr = super.loadTileSet( ...args );
		pr.then( () => this.initExtremes() );

		return pr;

	}

	getTileInformationFromActiveObject( object ) {

		let targetTile = null;
		const activeTiles = this.activeTiles;
		activeTiles.forEach( tile => {

			if ( targetTile ) {

				return true;

			}

			const scene = tile.cached.scene;
			if ( scene ) {

				scene.traverse( c => {

					if ( c === object ) {

						targetTile = tile;

					}

				} );

			}

		} );

		if ( targetTile ) {

			return {

				distanceToCamera: targetTile.cached.distance,
				geometricError: targetTile.geometricError,
				screenSpaceError: targetTile.__error,
				depth: targetTile.__depth,
				isLeaf: targetTile.__isLeaf

			};

		} else {

			return null;

		}

	}

	update() {

		super.update();

		if ( ! this.root ) {

			return;

		}

		this.boxGroup.visible = this.displayBoxBounds;
		this.sphereGroup.visible = this.displaySphereBounds;

		let maxDepth = - 1;
		if ( this.maxDepth === - 1 ) {

			maxDepth = this.extremeDepth;

		} else {

			maxDepth = this.maxDepth;

		}

		let maxError = - 1;
		if ( this.maxError === - 1 ) {

			maxError = this.extremeError;

		} else {

			maxError = this.maxError;

		}

		let maxDistance = - 1;
		if ( this.maxDistance === - 1 ) {

			maxDistance = this.root.cached.sphere.radius;

		} else {

			maxDistance = this.maxDistance;

		}

		// TODO: Support i3dm, pnts, cmpt here
		const errorTarget = this.errorTarget;
		const colorMode = this.colorMode;
		const visibleTiles = this.visibleTiles;
		visibleTiles.forEach( tile => {

			const scene = tile.cached.scene;
			scene.traverse( c => {

				const currMaterial = c.material;
				if ( currMaterial ) {

					const originalMaterial = c[ ORIGINAL_MATERIAL ];
					if ( colorMode === NONE && currMaterial !== originalMaterial ) {

						c.material.dispose();
						c.material = c[ ORIGINAL_MATERIAL ];

					} else if ( colorMode !== NONE && currMaterial === originalMaterial ) {

						c.material = new MeshBasicMaterial();

					}

					if ( colorMode !== RANDOM_COLOR ) {

						delete c.material.__randomColor;

					}

					switch ( colorMode ) {

						case DEPTH: {

							const val = tile.__depth / maxDepth;
							c.material.color.setRGB( val, val, val );
							break;

						}
						case RELATIVE_DEPTH: {

							const val = tile.__depthFromRenderedParent / maxDepth;
							c.material.color.setRGB( val, val, val );
							break;

						}
						case SCREEN_ERROR: {

							const val = tile.__error / errorTarget;
							if ( val > 1.0 ) {

								c.material.color.setRGB( 1.0, 0.0, 0.0 );

{'fraction_non_alphanumeric': 0.12580849714648065, 'fraction_numerical': 0.008116677235256817, 'mean_word_length': 2.5894401456531635, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '103069', 'n_tokens_mistral': 3392, 'n_tokens_neox': 2648, 'n_words': 595}