Sidebar.Material.BooleanProperty.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { UICheckbox, UIRow, UIText } from './libs/ui.js';
  2. import { SetMaterialValueCommand } from './commands/SetMaterialValueCommand.js';
  3. function SidebarMaterialBooleanProperty( editor, property, name ) {
  4. const signals = editor.signals;
  5. const container = new UIRow();
  6. container.add( new UIText( name ).setWidth( '90px' ) );
  7. const boolean = new UICheckbox().setLeft( '100px' ).onChange( onChange );
  8. container.add( boolean );
  9. let object = null;
  10. let material = null;
  11. function onChange() {
  12. if ( material[ property ] !== boolean.getValue() ) {
  13. editor.execute( new SetMaterialValueCommand( editor, object, property, boolean.getValue(), 0 /* TODO: currentMaterialSlot */ ) );
  14. }
  15. }
  16. function update() {
  17. if ( object === null ) return;
  18. if ( object.material === undefined ) return;
  19. material = object.material;
  20. if ( property in material ) {
  21. boolean.setValue( material[ property ] );
  22. container.setDisplay( '' );
  23. } else {
  24. container.setDisplay( 'none' );
  25. }
  26. }
  27. //
  28. signals.objectSelected.add( function ( selected ) {
  29. object = selected;
  30. update();
  31. } );
  32. signals.materialChanged.add( update );
  33. return container;
  34. }
  35. export { SidebarMaterialBooleanProperty };