/** * @author mrdoob / http://mrdoob.com/ */ Sidebar.Project = function ( editor ) { var config = editor.config; var signals = editor.signals; var strings = editor.strings; var rendererTypes = { 'WebGLRenderer': THREE.WebGLRenderer, 'SVGRenderer': THREE.SVGRenderer, 'SoftwareRenderer': THREE.SoftwareRenderer, 'RaytracingRenderer': THREE.RaytracingRenderer }; var container = new UI.Panel(); container.setBorderTop( '0' ); container.setPadding( '0' ); container.setPaddingTop( '20px' ); var projectsettings = new UI.Panel(); projectsettings.setBorderTop( '0' ); container.add( projectsettings ); // Title var titleRow = new UI.Row(); var title = new UI.Input( config.getKey( 'project/title' ) ).setLeft( '100px' ).onChange( function () { config.setKey( 'project/title', this.getValue() ); } ); titleRow.add( new UI.Text( strings.getKey( 'sidebar/project/title' ) ).setWidth( '90px' ) ); titleRow.add( title ); projectsettings.add( titleRow ); // Editable var editableRow = new UI.Row(); var editable = new UI.Checkbox( config.getKey( 'project/editable' ) ).setLeft( '100px' ).onChange( function () { config.setKey( 'project/editable', this.getValue() ); } ); editableRow.add( new UI.Text( strings.getKey( 'sidebar/project/editable' ) ).setWidth( '90px' ) ); editableRow.add( editable ); projectsettings.add( editableRow ); // VR var vrRow = new UI.Row(); var vr = new UI.Checkbox( config.getKey( 'project/vr' ) ).setLeft( '100px' ).onChange( function () { config.setKey( 'project/vr', this.getValue() ); } ); vrRow.add( new UI.Text( strings.getKey( 'sidebar/project/vr' ) ).setWidth( '90px' ) ); vrRow.add( vr ); projectsettings.add( vrRow ); // Renderer var options = {}; for ( var key in rendererTypes ) { if ( key.indexOf( 'WebGL' ) >= 0 && System.support.webgl === false ) continue; options[ key ] = key; } var rendererTypeRow = new UI.Row(); var rendererType = new UI.Select().setOptions( options ).setWidth( '150px' ).onChange( function () { var value = this.getValue(); config.setKey( 'project/renderer', value ); updateRenderer(); } ); rendererTypeRow.add( new UI.Text( strings.getKey( 'sidebar/project/renderer' ) ).setWidth( '90px' ) ); rendererTypeRow.add( rendererType ); projectsettings.add( rendererTypeRow ); if ( config.getKey( 'project/renderer' ) !== undefined ) { rendererType.setValue( config.getKey( 'project/renderer' ) ); } // Renderer / Antialias var rendererPropertiesRow = new UI.Row().setMarginLeft( '90px' ); var rendererAntialias = new UI.THREE.Boolean( config.getKey( 'project/renderer/antialias' ), strings.getKey( 'sidebar/project/antialias' ) ).onChange( function () { config.setKey( 'project/renderer/antialias', this.getValue() ); updateRenderer(); } ); rendererPropertiesRow.add( rendererAntialias ); // Renderer / Shadows var rendererShadows = new UI.THREE.Boolean( config.getKey( 'project/renderer/shadows' ), strings.getKey( 'sidebar/project/shadows' ) ).onChange( function () { config.setKey( 'project/renderer/shadows', this.getValue() ); updateRenderer(); } ); rendererPropertiesRow.add( rendererShadows ); projectsettings.add( rendererPropertiesRow ); // function updateRenderer() { createRenderer( rendererType.getValue(), rendererAntialias.getValue() ); } function createRenderer( type, antialias, shadows ) { rendererPropertiesRow.setDisplay( type === 'WebGLRenderer' ? '' : 'none' ); var parameters = {}; switch ( type ) { case 'WebGLRenderer': parameters.antialias = antialias; break; case 'RaytracingRenderer': parameters.workers = navigator.hardwareConcurrency || 4; parameters.workerPath = '../examples/js/renderers/RaytracingWorker.js'; parameters.randomize = true; parameters.blockSize = 64; break; } var renderer = new rendererTypes[ type ]( parameters ); if ( shadows && renderer.shadowMap ) { renderer.shadowMap.enabled = true; // renderer.shadowMap.type = THREE.PCFSoftShadowMap; } signals.rendererChanged.dispatch( renderer ); } createRenderer( config.getKey( 'project/renderer' ), config.getKey( 'project/renderer/antialias' ), config.getKey( 'project/renderer/shadows' ) ); var materialbrowserpanel = new UI.Panel(); var headerRow = new UI.Row(); headerRow.add( new UI.Text( strings.getKey( 'sidebar/project/materialbrowser' ) ) ); materialbrowserpanel.add( headerRow ); var listbox = new UI.Listbox( ); signals.materialAdded.add( function () { var materials = Object.values( editor.materials ); listbox.setItems( materials ); } ); materialbrowserpanel.add( listbox ); var buttonsRow = new UI.Row( ); buttonsRow.setPadding( '10px 0px' ); materialbrowserpanel.add( buttonsRow ); var addButton = new UI.Button( ).setLabel( 'Add' ).setMarginRight( '5px' ); addButton.onClick( function ( ) { editor.addMaterial( new THREE.MeshStandardMaterial({ color: 0xffffff }) ); } ); buttonsRow.add( addButton ); var assignMaterial = new UI.Button( ).setLabel( 'Assign' ).setMargin( '0px 5px' ); assignMaterial.onClick( function ( ) { if ( typeof editor.selected !== 'undefined' ) { var material = editor.getMaterialById( parseInt( listbox.getValue( ) ) ); if ( typeof material !== 'undefined' ) { editor.execute( new SetMaterialCommand( editor, editor.selected, material ) ); } } } ); buttonsRow.add( assignMaterial ); container.add( materialbrowserpanel ); return container; };