Sidebar.Outliner.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. Sidebar.Outliner = function ( signals ) {
  2. var objectTypes = {
  3. 'PerspectiveCamera': THREE.PerspectiveCamera,
  4. 'PointLight': THREE.PointLight,
  5. 'DirectionalLight': THREE.DirectionalLight,
  6. 'Mesh': THREE.Mesh,
  7. 'Object3D': THREE.Object3D
  8. };
  9. var selected = null;
  10. var container = new UI.Panel();
  11. container.setPadding( '10px' );
  12. container.setBorderTop( '1px solid #ccc' );
  13. container.add( new UI.Text().setValue( 'SCENE' ).setColor( '#666' ) );
  14. container.add( new UI.Break(), new UI.Break() );
  15. //var sceneGraph = new UI.Select().setMultiple( true ).setWidth( '100%' ).setHeight('140px').setColor( '#444' ).setFontSize( '12px' ).onChange( update );
  16. var sceneGraph = new UI.FancySelect().setWidth( '100%' ).setHeight('140px').setColor( '#444' ).setFontSize( '12px' ).onChange( update );
  17. container.add( sceneGraph );
  18. container.add( new UI.Break() );
  19. var scene = null;
  20. function update() {
  21. var id = parseInt( sceneGraph.getValue() );
  22. scene.traverse( function ( node ) {
  23. if ( node.id === id ) {
  24. signals.objectSelected.dispatch( node );
  25. return;
  26. }
  27. } );
  28. }
  29. function getObjectType( object ) {
  30. for ( var type in objectTypes ) {
  31. if ( object instanceof objectTypes[ type ] ) return type;
  32. }
  33. }
  34. // events
  35. signals.sceneCreated.add( function ( object ) {
  36. scene = object;
  37. } );
  38. signals.sceneChanged.add( function ( object ) {
  39. scene = object;
  40. var options = {};
  41. ( function createList( object, pad ) {
  42. for ( var key in object.children ) {
  43. var child = object.children[ key ];
  44. options[ child.id ] = '<div class="option_item">'+pad + '+ ' + child.name + ' <span class="object_type">[' + getObjectType( child ) + ']</span></div>';
  45. createList( child, pad + '&nbsp;&nbsp;&nbsp;' );
  46. }
  47. } )( scene, '' );
  48. sceneGraph.setOptions( options );
  49. } );
  50. signals.objectSelected.add( function ( object ) {
  51. sceneGraph.setValue( object !== null ? object.id : null );
  52. } );
  53. return container;
  54. }
粤ICP备19079148号