Sidebar.Outliner.Materials.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. Sidebar.Outliner.Materials = function ( signals ) {
  2. var container = new UI.Panel();
  3. container.name = "MAT";
  4. container.setPadding( '10px' );
  5. var outliner = new UI.FancySelect().setWidth( '100%' ).setHeight('170px').setColor( '#444' ).setFontSize( '12px' ).onChange( selectFromOutliner );
  6. container.add( outliner );
  7. var materials = null;
  8. function getMaterials() {
  9. var options = {};
  10. for ( var i in editor.materials ) {
  11. var material = editor.materials[ i ];
  12. options[ i ] = '- ' + material.name;
  13. }
  14. outliner.setOptions( options );
  15. getSelected();
  16. }
  17. function getSelected() {
  18. var selectedIds = [];
  19. for ( var id in editor.selected ) {
  20. if ( editor.materials[ id ] ) selectedIds.push( id );
  21. }
  22. // TODO: implement multiple selection
  23. outliner.setValue( selectedIds.length ? selectedIds[0] : null );
  24. }
  25. function selectFromOutliner() {
  26. var id = outliner.getValue();
  27. editor.select( editor.materials[ id ] );
  28. }
  29. // events
  30. var timeout;
  31. signals.sceneChanged.add( function () {
  32. clearTimeout( timeout );
  33. timeout = setTimeout( function () {
  34. getMaterials();
  35. }, 100 );
  36. } );
  37. signals.selected.add( getSelected );
  38. return container;
  39. }