Sidebar.Script.Editor.js 921 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. */
  4. Sidebar.Script.Editor = function ( editor ) {
  5. var timeout;
  6. var scriptSource = new UI.TextArea( 'javascript' ).setWidth( '240px' ).setHeight( '180px' ).setFontSize( '12px' );
  7. scriptSource.onKeyUp( function () {
  8. clearTimeout( timeout );
  9. timeout = setTimeout( function () {
  10. var object = editor.selected;
  11. var source = scriptSource.getValue();
  12. try {
  13. var script = new Function( 'scene', 'time', source ).bind( object.clone() );
  14. script( new THREE.Scene(), 0 );
  15. scriptSource.dom.classList.add( 'success' );
  16. scriptSource.dom.classList.remove( 'fail' );
  17. } catch ( error ) {
  18. scriptSource.dom.classList.remove( 'success' );
  19. scriptSource.dom.classList.add( 'fail' );
  20. return;
  21. }
  22. editor.scripts[ object.uuid ] = [ source ];
  23. editor.signals.objectChanged.dispatch( object );
  24. }, 500 );
  25. } );
  26. return scriptSource;
  27. }