| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- import { UIPanel, UISelect } from './libs/ui.js';
- function ViewportControls( editor ) {
- const signals = editor.signals;
- const container = new UIPanel();
- container.setPosition( 'absolute' );
- container.setRight( '10px' );
- container.setTop( '10px' );
- // camera
- const cameraSelect = new UISelect();
- cameraSelect.setMarginRight( '10px' );
- cameraSelect.onChange( function () {
- editor.setViewportCamera( this.getValue() );
- } );
- container.add( cameraSelect );
- signals.cameraAdded.add( update );
- signals.cameraRemoved.add( update );
- signals.objectChanged.add( function ( object ) {
- if ( object.isCamera ) {
- update( false );
- }
- } );
- // shading
- const shadingSelect = new UISelect();
- shadingSelect.setOptions( { 'realistic': 'realistic', 'solid': 'solid', 'normals': 'normals', 'wireframe': 'wireframe' } );
- shadingSelect.setValue( 'solid' );
- shadingSelect.onChange( function () {
- editor.setViewportShading( this.getValue() );
- } );
- container.add( shadingSelect );
- signals.editorCleared.add( function () {
- editor.setViewportCamera( editor.camera.uuid );
- shadingSelect.setValue( 'solid' );
- editor.setViewportShading( shadingSelect.getValue() );
- } );
- signals.cameraResetted.add( update );
- update();
- //
- function update( effect = true ) {
- const options = {};
- const cameras = editor.cameras;
- for ( const key in cameras ) {
- const camera = cameras[ key ];
- options[ camera.uuid ] = camera.name;
- }
- cameraSelect.setOptions( options );
- const selectedCamera = ( editor.viewportCamera.uuid in options )
- ? editor.viewportCamera
- : editor.camera;
- cameraSelect.setValue( selectedCamera.uuid );
- if ( effect ) editor.setViewportCamera( selectedCamera.uuid );
- }
- return container;
- }
- export { ViewportControls };
|