Sidebar.Properties.Material.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. Sidebar.Properties.Material = function ( signals ) {
  2. var container = new UI.Panel();
  3. container.setDisplay( 'none' );
  4. container.add( new UI.Text().setText( 'MATERIAL' ).setColor( '#666' ) );
  5. container.add( new UI.Break(), new UI.Break() );
  6. container.add( new UI.Text().setText( 'Name' ).setColor( '#666' ) );
  7. var materialName = new UI.Text( 'absolute' ).setLeft( '90px' ).setColor( '#444' ).setFontSize( '12px' );
  8. container.add( materialName );
  9. container.add( new UI.HorizontalRule() );
  10. container.add( new UI.Text().setText( 'Class' ).setColor( '#666' ) );
  11. var materialClass = new UI.Text( 'absolute' ).setLeft( '90px' ).setColor( '#444' ).setFontSize( '12px' );
  12. container.add( materialClass );
  13. container.add( new UI.HorizontalRule() );
  14. container.add( new UI.Text().setText( 'Color' ).setColor( '#666' ) );
  15. var materialColor = new UI.Text( 'absolute' ).setLeft( '90px' ).setColor( '#444' ).setFontSize( '12px' );
  16. container.add( materialColor );
  17. //
  18. signals.objectSelected.add( function ( object ) {
  19. if ( object && object.material ) {
  20. container.setDisplay( 'block' );
  21. materialName.setText( object.material.name );
  22. materialClass.setText( getMaterialInstanceName( object.material ) );
  23. materialColor.setText( '#' + object.material.color.getHex().toString(16) );
  24. } else {
  25. container.setDisplay( 'none' );
  26. }
  27. } );
  28. function getMaterialInstanceName( material ) {
  29. // TODO: Is there a way of doing this automatically?
  30. if ( material instanceof THREE.LineBasicMaterial ) return "LineBasicMaterial";
  31. if ( material instanceof THREE.MeshBasicMaterial ) return "MeshBasicMaterial";
  32. if ( material instanceof THREE.MeshDepthMaterial ) return "MeshDepthMaterial";
  33. if ( material instanceof THREE.MeshFaceMaterial ) return "MeshFaceMaterial";
  34. if ( material instanceof THREE.MeshLambertMaterial ) return "MeshLambertMaterial";
  35. if ( material instanceof THREE.MeshNormalMaterial ) return "MeshNormalMaterial";
  36. if ( material instanceof THREE.MeshPhongMaterial ) return "MeshPhongMaterial";
  37. if ( material instanceof THREE.ParticleBasicMaterial ) return "ParticleBasicMaterial";
  38. if ( material instanceof THREE.ParticleCanvasMaterial ) return "ParticleCanvasMaterial";
  39. if ( material instanceof THREE.ParticleDOMMaterial ) return "ParticleDOMMaterial";
  40. if ( material instanceof THREE.ShaderMaterial ) return "ShaderMaterial";
  41. if ( material instanceof THREE.Material ) return "Material";
  42. }
  43. return container;
  44. }