Sidebar.Material.BooleanProperty.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 ).setClass( 'Label' ) );
  7. const boolean = new UICheckbox().setLeft( '100px' ).onChange( onChange );
  8. container.add( boolean );
  9. let object = null;
  10. let materialSlot = null;
  11. let material = null;
  12. function onChange() {
  13. if ( material[ property ] !== boolean.getValue() ) {
  14. editor.execute( new SetMaterialValueCommand( editor, object, property, boolean.getValue(), materialSlot ) );
  15. }
  16. }
  17. function update( currentObject, currentMaterialSlot = 0 ) {
  18. object = currentObject;
  19. materialSlot = currentMaterialSlot;
  20. if ( object === null ) return;
  21. if ( object.material === undefined ) return;
  22. material = editor.getObjectMaterial( object, materialSlot );
  23. if ( property in material ) {
  24. boolean.setValue( material[ property ] );
  25. container.setDisplay( '' );
  26. } else {
  27. container.setDisplay( 'none' );
  28. }
  29. }
  30. //
  31. signals.objectSelected.add( update );
  32. signals.materialChanged.add( update );
  33. return container;
  34. }
  35. export { SidebarMaterialBooleanProperty };