PHP 7.4.33
Preview: ClippingContext.js Size: 5.46 KB
/var/www/uibuilder.cmshelp.dk/httpdocs/node_modules/three/src/renderers/common/ClippingContext.js
import { Matrix3 } from '../../math/Matrix3.js';
import { Plane } from '../../math/Plane.js';
import { Vector4 } from '../../math/Vector4.js';

const _plane = /*@__PURE__*/ new Plane();

/**
 * Represents the state that is used to perform clipping via clipping planes.
 * There is a default clipping context for each render context. When the
 * scene holds instances of `ClippingGroup`, there will be a context for each
 * group.
 *
 * @private
 */
class ClippingContext {

	/**
	 * Constructs a new clipping context.
	 *
	 * @param {?ClippingContext} [parentContext=null] - A reference to the parent clipping context.
	 */
	constructor( parentContext = null ) {

		/**
		 * The clipping context's version.
		 *
		 * @type {number}
		 * @readonly
		 */
		this.version = 0;

		/**
		 * Whether the intersection of the clipping planes is used to clip objects, rather than their union.
		 *
		 * @type {?boolean}
		 * @default null
		 */
		this.clipIntersection = null;

		/**
		 * The clipping context's cache key.
		 *
		 * @type {string}
		 */
		this.cacheKey = '';

		/**
		 * Whether the shadow pass is active or not.
		 *
		 * @type {boolean}
		 * @default false
		 */
		this.shadowPass = false;

		/**
		 * The view normal matrix.
		 *
		 * @type {Matrix3}
		 */
		this.viewNormalMatrix = new Matrix3();

		/**
		 * Internal cache for maintaining clipping contexts.
		 *
		 * @type {WeakMap<ClippingGroup,ClippingContext>}
		 */
		this.clippingGroupContexts = new WeakMap();

		/**
		 * The intersection planes.
		 *
		 * @type {Array<Vector4>}
		 */
		this.intersectionPlanes = [];

		/**
		 * The intersection planes.
		 *
		 * @type {Array<Vector4>}
		 */
		this.unionPlanes = [];

		/**
		 * The version of the clipping context's parent context.
		 *
		 * @type {?number}
		 * @readonly
		 */
		this.parentVersion = null;

		if ( parentContext !== null ) {

			this.viewNormalMatrix = parentContext.viewNormalMatrix;
			this.clippingGroupContexts = parentContext.clippingGroupContexts;

			this.shadowPass = parentContext.shadowPass;
			this.viewMatrix = parentContext.viewMatrix;

		}

	}

	/**
	 * Projects the given source clipping planes and writes the result into the
	 * destination array.
	 *
	 * @param {Array<Plane>} source - The source clipping planes.
	 * @param {Array<Vector4>} destination - The destination.
	 * @param {number} offset - The offset.
	 */
	projectPlanes( source, destination, offset ) {

		const l = source.length;

		for ( let i = 0; i < l; i ++ ) {

			_plane.copy( source[ i ] ).applyMatrix4( this.viewMatrix, this.viewNormalMatrix );

			const v = destination[ offset + i ];
			const normal = _plane.normal;

			v.x = - normal.x;
			v.y = - normal.y;
			v.z = - normal.z;
			v.w = _plane.constant;

		}

	}

	/**
	 * Updates the root clipping context of a scene.
	 *
	 * @param {Scene} scene - The scene.
	 * @param {Camera} camera - The camera that is used to render the scene.
	 */
	updateGlobal( scene, camera ) {

		this.shadowPass = ( scene.overrideMaterial !== null && scene.overrideMaterial.isShadowPassMaterial );
		this.viewMatrix = camera.matrixWorldInverse;

		this.viewNormalMatrix.getNormalMatrix( this.viewMatrix );

	}

	/**
	 * Updates the clipping context.
	 *
	 * @param {ClippingContext} parentContext - The parent context.
	 * @param {ClippingGroup} clippingGroup - The clipping group this context belongs to.
	 */
	update( parentContext, clippingGroup ) {

		let update = false;

		if ( parentContext.version !== this.parentVersion ) {

			this.intersectionPlanes = Array.from( parentContext.intersectionPlanes );
			this.unionPlanes = Array.from( parentContext.unionPlanes );
			this.parentVersion = parentContext.version;

		}

		if ( this.clipIntersection !== clippingGroup.clipIntersection ) {

			this.clipIntersection = clippingGroup.clipIntersection;

			if ( this.clipIntersection ) {

				this.unionPlanes.length = parentContext.unionPlanes.length;

			} else {

				this.intersectionPlanes.length = parentContext.intersectionPlanes.length;

			}

		}

		const srcClippingPlanes = clippingGroup.clippingPlanes;
		const l = srcClippingPlanes.length;

		let dstClippingPlanes;
		let offset;

		if ( this.clipIntersection ) {

			dstClippingPlanes = this.intersectionPlanes;
			offset = parentContext.intersectionPlanes.length;

		} else {

			dstClippingPlanes = this.unionPlanes;
			offset = parentContext.unionPlanes.length;

		}

		if ( dstClippingPlanes.length !== offset + l ) {

			dstClippingPlanes.length = offset + l;

			for ( let i = 0; i < l; i ++ ) {

				dstClippingPlanes[ offset + i ] = new Vector4();

			}

			update = true;

		}

		this.projectPlanes( srcClippingPlanes, dstClippingPlanes, offset );

		if ( update ) {

			this.version ++;
			this.cacheKey = `${ this.intersectionPlanes.length }:${ this.unionPlanes.length }`;

		}

	}

	/**
	 * Returns a clipping context for the given clipping group.
	 *
	 * @param {ClippingGroup} clippingGroup - The clipping group.
	 * @return {ClippingContext} The clipping context.
	 */
	getGroupContext( clippingGroup ) {

		if ( this.shadowPass && ! clippingGroup.clipShadows ) return this;

		let context = this.clippingGroupContexts.get( clippingGroup );

		if ( context === undefined ) {

			context = new ClippingContext( this );
			this.clippingGroupContexts.set( clippingGroup, context );

		}

		context.update( this, clippingGroup );

		return context;

	}

	/**
	 * The count of union clipping planes.
	 *
	 * @type {number}
	 * @readonly
	 */
	get unionClippingCount() {

		return this.unionPlanes.length;

	}

}

export default ClippingContext;

Directory Contents

Dirs: 2 × Files: 50
Name Size Perms Modified Actions
extras DIR
- drwxr-xr-x 2025-03-28 11:04:39
Edit Download
nodes DIR
- drwxr-xr-x 2025-03-28 11:04:38
Edit Download
2.48 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
2.39 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
15.92 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
5.20 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
1.11 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
1.01 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
6.81 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
1.26 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
1.50 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
1.71 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
1.74 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
5.46 KB lrw-r--r-- 2025-03-28 11:04:38
Edit Download
1.53 KB lrw-r--r-- 2025-03-28 11:04:38
Edit Download
740 B lrw-r--r-- 2025-03-28 11:04:38
Edit Download
283 B lrw-r--r-- 2025-03-28 11:04:38
Edit Download
2.61 KB lrw-r--r-- 2025-03-28 11:04:38
Edit Download
1.28 KB lrw-r--r-- 2025-03-28 11:04:38
Edit Download
7.19 KB lrw-r--r-- 2025-03-28 11:04:38
Edit Download
998 B lrw-r--r-- 2025-03-28 11:04:38
Edit Download
3.73 KB lrw-r--r-- 2025-03-28 11:04:38
Edit Download
1.34 KB lrw-r--r-- 2025-03-28 11:04:38
Edit Download
484 B lrw-r--r-- 2025-03-28 11:04:38
Edit Download
11.50 KB lrw-r--r-- 2025-03-28 11:04:38
Edit Download
4.27 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
1.72 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
2.33 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
458 B lrw-r--r-- 2025-03-28 11:04:39
Edit Download
1.13 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
4.86 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
2.53 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
74.32 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
5.37 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
10.09 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
1.27 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
17.04 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
5.19 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
806 B lrw-r--r-- 2025-03-28 11:04:39
Edit Download
3.65 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
769 B lrw-r--r-- 2025-03-28 11:04:39
Edit Download
718 B lrw-r--r-- 2025-03-28 11:04:39
Edit Download
1.44 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
1.52 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
1.26 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
10.13 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
1.61 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
5.83 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
561 B lrw-r--r-- 2025-03-28 11:04:39
Edit Download
10.22 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
27.59 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
1.72 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).