PHP 7.4.33
Preview: RendererUtils.js Size: 5.37 KB
/var/www/uibuilder.cmshelp.dk/httpdocs/node_modules/three/src/renderers/common/RendererUtils.js
import { Color } from '../../math/Color.js';

/**
 * Saves the state of the given renderer and stores it into the given state object.
 *
 * If not state object is provided, the function creates one.
 *
 * @function
 * @param {Renderer} renderer - The renderer.
 * @param {Object} [state={}] - The state.
 * @return {Object} The state.
 */
export function saveRendererState( renderer, state = {} ) {

	state.toneMapping = renderer.toneMapping;
	state.toneMappingExposure = renderer.toneMappingExposure;
	state.outputColorSpace = renderer.outputColorSpace;
	state.renderTarget = renderer.getRenderTarget();
	state.activeCubeFace = renderer.getActiveCubeFace();
	state.activeMipmapLevel = renderer.getActiveMipmapLevel();
	state.renderObjectFunction = renderer.getRenderObjectFunction();
	state.pixelRatio = renderer.getPixelRatio();
	state.mrt = renderer.getMRT();
	state.clearColor = renderer.getClearColor( state.clearColor || new Color() );
	state.clearAlpha = renderer.getClearAlpha();
	state.autoClear = renderer.autoClear;
	state.scissorTest = renderer.getScissorTest();

	return state;

}

/**
 * Saves the state of the given renderer and stores it into the given state object.
 * Besides, the function also resets the state of the renderer to its default values.
 *
 * If not state object is provided, the function creates one.
 *
 * @function
 * @param {Renderer} renderer - The renderer.
 * @param {Object} [state={}] - The state.
 * @return {Object} The state.
 */
export function resetRendererState( renderer, state ) {

	state = saveRendererState( renderer, state );

	renderer.setMRT( null );
	renderer.setRenderObjectFunction( null );
	renderer.setClearColor( 0x000000, 1 );
	renderer.autoClear = true;

	return state;

}

/**
 * Restores the state of the given renderer from the given state object.
 *
 * @function
 * @param {Renderer} renderer - The renderer.
 * @param {Object} state - The state to restore.
 */
export function restoreRendererState( renderer, state ) {

	renderer.toneMapping = state.toneMapping;
	renderer.toneMappingExposure = state.toneMappingExposure;
	renderer.outputColorSpace = state.outputColorSpace;
	renderer.setRenderTarget( state.renderTarget, state.activeCubeFace, state.activeMipmapLevel );
	renderer.setRenderObjectFunction( state.renderObjectFunction );
	renderer.setPixelRatio( state.pixelRatio );
	renderer.setMRT( state.mrt );
	renderer.setClearColor( state.clearColor, state.clearAlpha );
	renderer.autoClear = state.autoClear;
	renderer.setScissorTest( state.scissorTest );

}

/**
 * Saves the state of the given scene and stores it into the given state object.
 *
 * If not state object is provided, the function creates one.
 *
 * @function
 * @param {Scene} scene - The scene.
 * @param {Object} [state={}] - The state.
 * @return {Object} The state.
 */
export function saveSceneState( scene, state = {} ) {

	state.background = scene.background;
	state.backgroundNode = scene.backgroundNode;
	state.overrideMaterial = scene.overrideMaterial;

	return state;

}

/**
 * Saves the state of the given scene and stores it into the given state object.
 * Besides, the function also resets the state of the scene to its default values.
 *
 * If not state object is provided, the function creates one.
 *
 * @function
 * @param {Scene} scene - The scene.
 * @param {Object} [state={}] - The state.
 * @return {Object} The state.
 */
export function resetSceneState( scene, state ) {

	state = saveSceneState( scene, state );

	scene.background = null;
	scene.backgroundNode = null;
	scene.overrideMaterial = null;

	return state;

}

/**
 * Restores the state of the given scene from the given state object.
 *
 * @function
 * @param {Scene} scene - The scene.
 * @param {Object} state - The state to restore.
 */
export function restoreSceneState( scene, state ) {

	scene.background = state.background;
	scene.backgroundNode = state.backgroundNode;
	scene.overrideMaterial = state.overrideMaterial;

}

/**
 * Saves the state of the given renderer and scene and stores it into the given state object.
 *
 * If not state object is provided, the function creates one.
 *
 * @function
 * @param {Renderer} renderer - The renderer.
 * @param {Scene} scene - The scene.
 * @param {Object} [state={}] - The state.
 * @return {Object} The state.
 */
export function saveRendererAndSceneState( renderer, scene, state = {} ) {

	state = saveRendererState( renderer, state );
	state = saveSceneState( scene, state );

	return state;

}

/**
 * Saves the state of the given renderer and scene and stores it into the given state object.
 * Besides, the function also resets the state of the renderer and scene to its default values.
 *
 * If not state object is provided, the function creates one.
 *
 * @function
 * @param {Renderer} renderer - The renderer.
 * @param {Scene} scene - The scene.
 * @param {Object} [state={}] - The state.
 * @return {Object} The state.
 */
export function resetRendererAndSceneState( renderer, scene, state ) {

	state = resetRendererState( renderer, state );
	state = resetSceneState( scene, state );

	return state;

}

/**
 * Restores the state of the given renderer and scene from the given state object.
 *
 * @function
 * @param {Renderer} renderer - The renderer.
 * @param {Scene} scene - The scene.
 * @param {Object} state - The state to restore.
 */
export function restoreRendererAndSceneState( renderer, scene, state ) {

	restoreRendererState( renderer, state );
	restoreSceneState( scene, state );

}

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).