Sidebar.Project.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. */
  4. Sidebar.Project = function ( editor ) {
  5. var config = editor.config;
  6. var signals = editor.signals;
  7. var strings = editor.strings;
  8. var rendererTypes = {
  9. 'WebGLRenderer': THREE.WebGLRenderer,
  10. 'SVGRenderer': THREE.SVGRenderer,
  11. 'SoftwareRenderer': THREE.SoftwareRenderer,
  12. 'RaytracingRenderer': THREE.RaytracingRenderer
  13. };
  14. var container = new UI.Span();
  15. var projectsettings = new UI.Panel();
  16. projectsettings.setBorderTop( '0' );
  17. projectsettings.setPaddingTop( '20px' );
  18. container.add( projectsettings );
  19. // Title
  20. var titleRow = new UI.Row();
  21. var title = new UI.Input( config.getKey( 'project/title' ) ).setLeft( '100px' ).onChange( function () {
  22. config.setKey( 'project/title', this.getValue() );
  23. } );
  24. titleRow.add( new UI.Text( strings.getKey( 'sidebar/project/title' ) ).setWidth( '90px' ) );
  25. titleRow.add( title );
  26. projectsettings.add( titleRow );
  27. // Editable
  28. var editableRow = new UI.Row();
  29. var editable = new UI.Checkbox( config.getKey( 'project/editable' ) ).setLeft( '100px' ).onChange( function () {
  30. config.setKey( 'project/editable', this.getValue() );
  31. } );
  32. editableRow.add( new UI.Text( strings.getKey( 'sidebar/project/editable' ) ).setWidth( '90px' ) );
  33. editableRow.add( editable );
  34. projectsettings.add( editableRow );
  35. // VR
  36. var vrRow = new UI.Row();
  37. var vr = new UI.Checkbox( config.getKey( 'project/vr' ) ).setLeft( '100px' ).onChange( function () {
  38. config.setKey( 'project/vr', this.getValue() );
  39. } );
  40. vrRow.add( new UI.Text( strings.getKey( 'sidebar/project/vr' ) ).setWidth( '90px' ) );
  41. vrRow.add( vr );
  42. projectsettings.add( vrRow );
  43. // Renderer
  44. var options = {};
  45. for ( var key in rendererTypes ) {
  46. if ( key.indexOf( 'WebGL' ) >= 0 && System.support.webgl === false ) continue;
  47. options[ key ] = key;
  48. }
  49. var rendererTypeRow = new UI.Row();
  50. var rendererType = new UI.Select().setOptions( options ).setWidth( '150px' ).onChange( function () {
  51. var value = this.getValue();
  52. config.setKey( 'project/renderer', value );
  53. updateRenderer();
  54. } );
  55. rendererTypeRow.add( new UI.Text( strings.getKey( 'sidebar/project/renderer' ) ).setWidth( '90px' ) );
  56. rendererTypeRow.add( rendererType );
  57. projectsettings.add( rendererTypeRow );
  58. if ( config.getKey( 'project/renderer' ) !== undefined ) {
  59. rendererType.setValue( config.getKey( 'project/renderer' ) );
  60. }
  61. // Renderer / Antialias
  62. var rendererPropertiesRow = new UI.Row().setMarginLeft( '90px' );
  63. var rendererAntialias = new UI.THREE.Boolean( config.getKey( 'project/renderer/antialias' ), strings.getKey( 'sidebar/project/antialias' ) ).onChange( function () {
  64. config.setKey( 'project/renderer/antialias', this.getValue() );
  65. updateRenderer();
  66. } );
  67. rendererPropertiesRow.add( rendererAntialias );
  68. // Renderer / Shadows
  69. var rendererShadows = new UI.THREE.Boolean( config.getKey( 'project/renderer/shadows' ), strings.getKey( 'sidebar/project/shadows' ) ).onChange( function () {
  70. config.setKey( 'project/renderer/shadows', this.getValue() );
  71. updateRenderer();
  72. } );
  73. rendererPropertiesRow.add( rendererShadows );
  74. projectsettings.add( rendererPropertiesRow );
  75. //
  76. function updateRenderer() {
  77. createRenderer( rendererType.getValue(), rendererAntialias.getValue() );
  78. }
  79. function createRenderer( type, antialias, shadows ) {
  80. rendererPropertiesRow.setDisplay( type === 'WebGLRenderer' ? '' : 'none' );
  81. var parameters = {};
  82. switch ( type ) {
  83. case 'WebGLRenderer':
  84. parameters.antialias = antialias;
  85. break;
  86. case 'RaytracingRenderer':
  87. parameters.workers = navigator.hardwareConcurrency || 4;
  88. parameters.workerPath = '../examples/js/renderers/RaytracingWorker.js';
  89. parameters.randomize = true;
  90. parameters.blockSize = 64;
  91. break;
  92. }
  93. var renderer = new rendererTypes[ type ]( parameters );
  94. if ( shadows && renderer.shadowMap ) {
  95. renderer.shadowMap.enabled = true;
  96. // renderer.shadowMap.type = THREE.PCFSoftShadowMap;
  97. }
  98. signals.rendererChanged.dispatch( renderer );
  99. }
  100. createRenderer( config.getKey( 'project/renderer' ), config.getKey( 'project/renderer/antialias' ), config.getKey( 'project/renderer/shadows' ) );
  101. // Materials
  102. var materials = new UI.Panel();
  103. var headerRow = new UI.Row();
  104. headerRow.add( new UI.Text( strings.getKey( 'sidebar/project/materials' ).toUpperCase() ) );
  105. materials.add( headerRow );
  106. var listbox = new UI.Listbox();
  107. signals.materialAdded.add( function () {
  108. listbox.setItems( Object.values( editor.materials ) );
  109. } );
  110. materials.add( listbox );
  111. var buttonsRow = new UI.Row();
  112. buttonsRow.setPadding( '10px 0px' );
  113. materials.add( buttonsRow );
  114. /*
  115. var addButton = new UI.Button().setLabel( 'Add' ).setMarginRight( '5px' );
  116. addButton.onClick( function () {
  117. editor.addMaterial( new THREE.MeshStandardMaterial() );
  118. } );
  119. buttonsRow.add( addButton );
  120. */
  121. var assignMaterial = new UI.Button().setLabel( 'Assign' ).setMargin( '0px 5px' );
  122. assignMaterial.onClick( function () {
  123. if ( editor.selected !== null ) {
  124. var material = editor.getMaterialById( parseInt( listbox.getValue() ) );
  125. if ( material !== undefined ) {
  126. editor.execute( new SetMaterialCommand( editor, editor.selected, material ) );
  127. }
  128. }
  129. } );
  130. buttonsRow.add( assignMaterial );
  131. container.add( materials );
  132. // events
  133. signals.objectSelected.add( function ( object ) {
  134. if ( object !== null ) {
  135. var index = Object.values( editor.materials ).indexOf( object.material );
  136. listbox.selectIndex( index );
  137. }
  138. } );
  139. return container;
  140. };