1
0

Sidebar.Outliner.Materials.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. if ( material.name == '') material.name = 'Material' + material.id;
  13. options[ i ] = material.name;
  14. }
  15. outliner.setOptions( options );
  16. getSelected();
  17. }
  18. function getSelected() {
  19. var selectedIds = [];
  20. for ( var id in editor.selected ) {
  21. if ( editor.materials[ id ] ) selectedIds.push( id );
  22. }
  23. // TODO: implement multiple selection
  24. outliner.setValue( selectedIds.length ? selectedIds[0] : null );
  25. }
  26. function selectFromOutliner() {
  27. var id = outliner.getValue();
  28. editor.select( editor.materials[ id ] );
  29. }
  30. // events
  31. var timeout;
  32. signals.sceneChanged.add( function () {
  33. clearTimeout( timeout );
  34. timeout = setTimeout( function () {
  35. getMaterials();
  36. }, 100 );
  37. } );
  38. signals.selected.add( getSelected );
  39. return container;
  40. }
粤ICP备19079148号