SideBar.Properties.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. var Properties = function ( signals ) {
  2. var selected = null;
  3. var container = new UI.Panel();
  4. container.setDisplay( 'none' );
  5. container.setPadding( '8px' );
  6. container.setBorderTop( '1px solid #ccc' );
  7. container.add( new UI.Text().setText( 'PROPERTIES' ).setColor( '#666' ) );
  8. container.add( new UI.Break(), new UI.Break() );
  9. container.add( new UI.Text().setText( 'position' ).setColor( '#666' ) );
  10. var positionX = new UI.FloatNumber( 'absolute' ).setLeft( '90px' ).onChanged( update );
  11. var positionY = new UI.FloatNumber( 'absolute' ).setLeft( '160px' ).onChanged( update );
  12. var positionZ = new UI.FloatNumber( 'absolute' ).setLeft( '230px' ).onChanged( update );
  13. container.add( positionX, positionY, positionZ );
  14. container.add( new UI.HorizontalRule() );
  15. container.add( new UI.Text().setText( 'rotation' ).setColor( '#666' ) );
  16. var rotationX = new UI.FloatNumber( 'absolute' ).setLeft( '90px' ).onChanged( update );
  17. var rotationY = new UI.FloatNumber( 'absolute' ).setLeft( '160px' ).onChanged( update );
  18. var rotationZ = new UI.FloatNumber( 'absolute' ).setLeft( '230px' ).onChanged( update );
  19. container.add( rotationX, rotationY, rotationZ );
  20. container.add( new UI.HorizontalRule() );
  21. container.add( new UI.Text().setText( 'scale' ).setColor( '#666' ) );
  22. var scaleX = new UI.FloatNumber( 'absolute' ).setValue( 1 ).setLeft( '90px' ).onChanged( update );
  23. var scaleY = new UI.FloatNumber( 'absolute' ).setValue( 1 ).setLeft( '160px' ).onChanged( update );
  24. var scaleZ = new UI.FloatNumber( 'absolute' ).setValue( 1 ).setLeft( '230px' ).onChanged( update );
  25. container.add( scaleX, scaleY, scaleZ );
  26. container.add( new UI.Break(), new UI.Break(), new UI.Break() );
  27. // Geometry
  28. container.add( new UI.Text().setText( 'GEOMETRY' ).setColor( '#666' ) );
  29. container.add( new UI.Break(), new UI.Break() );
  30. container.add( new UI.Text().setText( 'class' ).setColor( '#666' ) );
  31. var geometryClass = new UI.Text( 'absolute' ).setLeft( '90px' ).setColor( '#444' ).setFontSize( '12px' );
  32. container.add( geometryClass );
  33. container.add( new UI.HorizontalRule() );
  34. container.add( new UI.Text().setText( 'vertices' ).setColor( '#666' ) );
  35. var verticesCount = new UI.Text( 'absolute' ).setLeft( '90px' ).setColor( '#444' ).setFontSize( '12px' );
  36. container.add( verticesCount );
  37. container.add( new UI.HorizontalRule() );
  38. container.add( new UI.Text().setText( 'faces' ).setColor( '#666' ) );
  39. var facesCount = new UI.Text( 'absolute' ).setLeft( '90px' ).setColor( '#444' ).setFontSize( '12px' );
  40. container.add( facesCount );
  41. container.add( new UI.HorizontalRule() );
  42. container.add( new UI.Text().setText( 'colors' ).setColor( '#666' ) );
  43. var colorsCount = new UI.Text( 'absolute' ).setLeft( '90px' ).setColor( '#444' ).setFontSize( '12px' );
  44. container.add( colorsCount );
  45. container.add( new UI.Break(), new UI.Break(), new UI.Break() );
  46. // Material
  47. container.add( new UI.Text().setText( 'MATERIAL' ).setColor( '#666' ) );
  48. container.add( new UI.Break(), new UI.Break(), new UI.Break() );
  49. // Events
  50. function update() {
  51. if ( selected ) {
  52. selected.position.x = positionX.getValue();
  53. selected.position.y = positionY.getValue();
  54. selected.position.z = positionZ.getValue();
  55. selected.rotation.x = rotationX.getValue();
  56. selected.rotation.y = rotationY.getValue();
  57. selected.rotation.z = rotationZ.getValue();
  58. selected.scale.x = scaleX.getValue();
  59. selected.scale.y = scaleY.getValue();
  60. selected.scale.z = scaleZ.getValue();
  61. signals.objectChanged.dispatch( selected );
  62. }
  63. }
  64. signals.objectSelected.add( function ( object ) {
  65. selected = object;
  66. if ( object ) {
  67. container.setDisplay( 'block' );
  68. positionX.setValue( object.position.x );
  69. positionY.setValue( object.position.y );
  70. positionZ.setValue( object.position.z );
  71. rotationX.setValue( object.rotation.x );
  72. rotationY.setValue( object.rotation.y );
  73. rotationZ.setValue( object.rotation.z );
  74. scaleX.setValue( object.scale.x );
  75. scaleY.setValue( object.scale.y );
  76. scaleZ.setValue( object.scale.z );
  77. geometryClass.setText( getGeometryInstanceName( object.geometry ) );
  78. verticesCount.setText( object.geometry.vertices.length );
  79. facesCount.setText( object.geometry.faces.length );
  80. colorsCount.setText( object.geometry.colors.length );
  81. } else {
  82. container.setDisplay( 'none' );
  83. }
  84. } );
  85. function getGeometryInstanceName( object ) {
  86. // TODO: Is there a way of doing this automatically?
  87. if ( object instanceof THREE.ConvexGeometry ) return "ConvexGeometry";
  88. if ( object instanceof THREE.CubeGeometry ) return "CubeGeometry";
  89. if ( object instanceof THREE.CylinderGeometry ) return "CylinderGeometry";
  90. if ( object instanceof THREE.ExtrudeGeometry ) return "ExtrudeGeometry";
  91. if ( object instanceof THREE.IcosahedronGeometry ) return "IcosahedronGeometry";
  92. if ( object instanceof THREE.LatheGeometry ) return "LatheGeometry";
  93. if ( object instanceof THREE.OctahedronGeometry ) return "OctahedronGeometry";
  94. if ( object instanceof THREE.ParametricGeometry ) return "ParametricGeometry";
  95. if ( object instanceof THREE.PlaneGeometry ) return "PlaneGeometry";
  96. if ( object instanceof THREE.PolyhedronGeometry ) return "PolyhedronGeometry";
  97. if ( object instanceof THREE.SphereGeometry ) return "SphereGeometry";
  98. if ( object instanceof THREE.TetrahedronGeometry ) return "TetrahedronGeometry";
  99. if ( object instanceof THREE.TextGeometry ) return "TextGeometry";
  100. if ( object instanceof THREE.TorusGeometry ) return "TorusGeometry";
  101. if ( object instanceof THREE.TorusKnotGeometry ) return "TorusKnotGeometry";
  102. if ( object instanceof THREE.TubeGeometry ) return "TubeGeometry";
  103. if ( object instanceof THREE.Geometry ) return "Geometry";
  104. }
  105. return container;
  106. }