Sidebar.Script.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. Sidebar.Script = function ( editor ) {
  2. var signals = editor.signals;
  3. var container = new UI.CollapsiblePanel();
  4. container.setCollapsed( editor.config.getKey( 'ui/sidebar/script/collapsed' ) );
  5. container.onCollapsedChange( function ( boolean ) {
  6. editor.config.setKey( 'ui/sidebar/script/collapsed', boolean );
  7. } );
  8. container.setDisplay( 'none' );
  9. container.addStatic( new UI.Text( 'Script' ).setTextTransform( 'uppercase' ) );
  10. container.add( new UI.Break() );
  11. var scriptsRow = new UI.Panel();
  12. container.add( scriptsRow );
  13. // source
  14. var scriptSourceRow = new UI.Panel();
  15. var scriptSource = new UI.TextArea().setWidth( '240px' ).setHeight( '180px' ).setColor( '#444' ).setFontSize( '12px' );
  16. scriptSource.onChange( function () {
  17. var object = editor.selected;
  18. object.script = new THREE.Script( scriptSource.getValue() );
  19. editor.signals.objectChanged.dispatch( object );
  20. } );
  21. scriptSourceRow.add( scriptSource );
  22. container.add( scriptSourceRow );
  23. //
  24. signals.objectSelected.add( function ( object ) {
  25. if ( object !== null ) {
  26. container.setDisplay( 'block' );
  27. if ( object.script !== undefined ) {
  28. scriptSource.setValue( object.script.source );
  29. } else {
  30. scriptSource.setValue( '' );
  31. }
  32. } else {
  33. container.setDisplay( 'none' );
  34. }
  35. } );
  36. return container;
  37. }