|
@@ -35,6 +35,7 @@
|
|
|
|
|
|
import { TrackballControls } from 'three/addons/controls/TrackballControls.js';
|
|
|
import { CSS3DRenderer, CSS3DObject } from 'three/addons/renderers/CSS3DRenderer.js';
|
|
|
+ import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
|
|
|
|
|
|
let camera, scene, renderer;
|
|
|
|
|
@@ -103,6 +104,7 @@
|
|
|
controls = new TrackballControls( camera, renderer2.domElement );
|
|
|
|
|
|
window.addEventListener( 'resize', onWindowResize );
|
|
|
+ createPanel();
|
|
|
|
|
|
}
|
|
|
|
|
@@ -129,6 +131,70 @@
|
|
|
|
|
|
}
|
|
|
|
|
|
+ function createPanel() {
|
|
|
+
|
|
|
+ const panel = new GUI();
|
|
|
+ const folder1 = panel.addFolder( 'camera setViewOffset' ).close();
|
|
|
+
|
|
|
+ const settings = {
|
|
|
+ 'setViewOffset'() {
|
|
|
+
|
|
|
+ folder1.children[ 1 ].enable().setValue( window.innerWidth );
|
|
|
+ folder1.children[ 2 ].enable().setValue( window.innerHeight );
|
|
|
+ folder1.children[ 3 ].enable().setValue( 0 );
|
|
|
+ folder1.children[ 4 ].enable().setValue( 0 );
|
|
|
+ folder1.children[ 5 ].enable().setValue( window.innerWidth );
|
|
|
+ folder1.children[ 6 ].enable().setValue( window.innerHeight );
|
|
|
+
|
|
|
+ },
|
|
|
+ 'fullWidth': 0,
|
|
|
+ 'fullHeight': 0,
|
|
|
+ 'offsetX': 0,
|
|
|
+ 'offsetY': 0,
|
|
|
+ 'width': 0,
|
|
|
+ 'height': 0,
|
|
|
+ 'clearViewOffset'() {
|
|
|
+
|
|
|
+ folder1.children[ 1 ].setValue( 0 ).disable();
|
|
|
+ folder1.children[ 2 ].setValue( 0 ).disable();
|
|
|
+ folder1.children[ 3 ].setValue( 0 ).disable();
|
|
|
+ folder1.children[ 4 ].setValue( 0 ).disable();
|
|
|
+ folder1.children[ 5 ].setValue( 0 ).disable();
|
|
|
+ folder1.children[ 6 ].setValue( 0 ).disable();
|
|
|
+ camera.clearViewOffset();
|
|
|
+
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ folder1.add( settings, 'setViewOffset' );
|
|
|
+ folder1.add( settings, 'fullWidth', window.screen.width / 4, window.screen.width * 2, 1 ).onChange( ( val ) => updateCameraViewOffset( { fullWidth: val } ) ).disable();
|
|
|
+ folder1.add( settings, 'fullHeight', window.screen.height / 4, window.screen.height * 2, 1 ).onChange( ( val ) => updateCameraViewOffset( { fullHeight: val } ) ).disable();
|
|
|
+ folder1.add( settings, 'offsetX', 0, 256, 1 ).onChange( ( val ) => updateCameraViewOffset( { x: val } ) ).disable();
|
|
|
+ folder1.add( settings, 'offsetY', 0, 256, 1 ).onChange( ( val ) => updateCameraViewOffset( { y: val } ) ).disable();
|
|
|
+ folder1.add( settings, 'width', window.screen.width / 4, window.screen.width * 2, 1 ).onChange( ( val ) => updateCameraViewOffset( { width: val } ) ).disable();
|
|
|
+ folder1.add( settings, 'height', window.screen.height / 4, window.screen.height * 2, 1 ).onChange( ( val ) => updateCameraViewOffset( { height: val } ) ).disable();
|
|
|
+ folder1.add( settings, 'clearViewOffset' );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ function updateCameraViewOffset( { fullWidth, fullHeight, x, y, width, height } ) {
|
|
|
+
|
|
|
+ if ( ! camera.view ) {
|
|
|
+
|
|
|
+ camera.setViewOffset( fullWidth || window.innerWidth, fullHeight || window.innerHeight, x || 0, y || 0, width || window.innerWidth, height || window.innerHeight );
|
|
|
+ camera.aspect = window.innerWidth / window.innerHeight;
|
|
|
+ camera.updateProjectionMatrix();
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ camera.setViewOffset( fullWidth || camera.view.fullWidth, fullHeight || camera.view.fullHeight, x || camera.view.offsetX, y || camera.view.offsetY, width || camera.view.width, height || camera.view.height );
|
|
|
+ camera.aspect = window.innerWidth / window.innerHeight;
|
|
|
+ camera.updateProjectionMatrix();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
</script>
|
|
|
</body>
|
|
|
</html>
|