Sidebar.Properties.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. Sidebar.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( 'Name' ).setColor( '#666' ) );
  10. var objectName = new UI.Text( 'absolute' ).setLeft( '90px' ).setColor( '#444' ).setFontSize( '12px' );
  11. container.add( objectName );
  12. container.add( new UI.HorizontalRule() );
  13. container.add( new UI.Text().setText( 'Position' ).setColor( '#666' ) );
  14. var positionX = new UI.FloatNumber( 'absolute' ).setLeft( '90px' ).onChanged( update );
  15. var positionY = new UI.FloatNumber( 'absolute' ).setLeft( '160px' ).onChanged( update );
  16. var positionZ = new UI.FloatNumber( 'absolute' ).setLeft( '230px' ).onChanged( update );
  17. container.add( positionX, positionY, positionZ );
  18. container.add( new UI.HorizontalRule() );
  19. container.add( new UI.Text().setText( 'Rotation' ).setColor( '#666' ) );
  20. var rotationX = new UI.FloatNumber( 'absolute' ).setLeft( '90px' ).onChanged( update );
  21. var rotationY = new UI.FloatNumber( 'absolute' ).setLeft( '160px' ).onChanged( update );
  22. var rotationZ = new UI.FloatNumber( 'absolute' ).setLeft( '230px' ).onChanged( update );
  23. container.add( rotationX, rotationY, rotationZ );
  24. container.add( new UI.HorizontalRule() );
  25. container.add( new UI.Text().setText( 'Scale' ).setColor( '#666' ) );
  26. var scaleX = new UI.FloatNumber( 'absolute' ).setValue( 1 ).setLeft( '90px' ).onChanged( update );
  27. var scaleY = new UI.FloatNumber( 'absolute' ).setValue( 1 ).setLeft( '160px' ).onChanged( update );
  28. var scaleZ = new UI.FloatNumber( 'absolute' ).setValue( 1 ).setLeft( '230px' ).onChanged( update );
  29. container.add( scaleX, scaleY, scaleZ );
  30. container.add( new UI.Break(), new UI.Break(), new UI.Break() );
  31. // Geometry
  32. container.add( new UI.Text().setText( 'GEOMETRY' ).setColor( '#666' ) );
  33. container.add( new UI.Break(), new UI.Break() );
  34. container.add( new UI.Text().setText( 'Name' ).setColor( '#666' ) );
  35. var geometryName = new UI.Text( 'absolute' ).setLeft( '90px' ).setColor( '#444' ).setFontSize( '12px' );
  36. container.add( geometryName );
  37. container.add( new UI.HorizontalRule() );
  38. container.add( new UI.Text().setText( 'Class' ).setColor( '#666' ) );
  39. var geometryClass = new UI.Text( 'absolute' ).setLeft( '90px' ).setColor( '#444' ).setFontSize( '12px' );
  40. container.add( geometryClass );
  41. container.add( new UI.HorizontalRule() );
  42. container.add( new UI.Text().setText( 'Vertices' ).setColor( '#666' ) );
  43. var verticesCount = new UI.Text( 'absolute' ).setLeft( '90px' ).setColor( '#444' ).setFontSize( '12px' );
  44. container.add( verticesCount );
  45. container.add( new UI.HorizontalRule() );
  46. container.add( new UI.Text().setText( 'Faces' ).setColor( '#666' ) );
  47. var facesCount = new UI.Text( 'absolute' ).setLeft( '90px' ).setColor( '#444' ).setFontSize( '12px' );
  48. container.add( facesCount );
  49. container.add( new UI.HorizontalRule() );
  50. container.add( new UI.Text().setText( 'Colors' ).setColor( '#666' ) );
  51. var colorsCount = new UI.Text( 'absolute' ).setLeft( '90px' ).setColor( '#444' ).setFontSize( '12px' );
  52. container.add( colorsCount );
  53. container.add( new UI.Break(), new UI.Break(), new UI.Break() );
  54. // Material
  55. container.add( new UI.Text().setText( 'MATERIAL' ).setColor( '#666' ) );
  56. container.add( new UI.Break(), new UI.Break() );
  57. container.add( new UI.Text().setText( 'Name' ).setColor( '#666' ) );
  58. var materialName = new UI.Text( 'absolute' ).setLeft( '90px' ).setColor( '#444' ).setFontSize( '12px' );
  59. container.add( materialName );
  60. container.add( new UI.HorizontalRule() );
  61. container.add( new UI.Text().setText( 'Class' ).setColor( '#666' ) );
  62. var materialClass = new UI.Text( 'absolute' ).setLeft( '90px' ).setColor( '#444' ).setFontSize( '12px' );
  63. container.add( materialClass );
  64. container.add( new UI.HorizontalRule() );
  65. container.add( new UI.Text().setText( 'Color' ).setColor( '#666' ) );
  66. var materialColor = new UI.Text( 'absolute' ).setLeft( '90px' ).setColor( '#444' ).setFontSize( '12px' );
  67. container.add( materialColor );
  68. // Events
  69. function update() {
  70. if ( selected ) {
  71. selected.position.x = positionX.getValue();
  72. selected.position.y = positionY.getValue();
  73. selected.position.z = positionZ.getValue();
  74. selected.rotation.x = rotationX.getValue();
  75. selected.rotation.y = rotationY.getValue();
  76. selected.rotation.z = rotationZ.getValue();
  77. selected.scale.x = scaleX.getValue();
  78. selected.scale.y = scaleY.getValue();
  79. selected.scale.z = scaleZ.getValue();
  80. signals.objectChanged.dispatch( selected );
  81. }
  82. }
  83. signals.objectSelected.add( function ( object ) {
  84. selected = object;
  85. if ( object ) {
  86. container.setDisplay( 'block' );
  87. objectName.setText( object.name );
  88. positionX.setValue( object.position.x );
  89. positionY.setValue( object.position.y );
  90. positionZ.setValue( object.position.z );
  91. rotationX.setValue( object.rotation.x );
  92. rotationY.setValue( object.rotation.y );
  93. rotationZ.setValue( object.rotation.z );
  94. scaleX.setValue( object.scale.x );
  95. scaleY.setValue( object.scale.y );
  96. scaleZ.setValue( object.scale.z );
  97. if ( object.geometry ) {
  98. geometryName.setText( object.geometry.name );
  99. geometryClass.setText( getGeometryInstanceName( object.geometry ) );
  100. verticesCount.setText( object.geometry.vertices.length );
  101. facesCount.setText( object.geometry.faces.length );
  102. colorsCount.setText( object.geometry.colors.length );
  103. }
  104. if ( object.material ) {
  105. materialName.setText( object.material.name );
  106. materialClass.setText( getMaterialInstanceName( object.material ) );
  107. materialColor.setText( '#' + object.material.color.getHex().toString(16) );
  108. }
  109. } else {
  110. container.setDisplay( 'none' );
  111. }
  112. } );
  113. function getGeometryInstanceName( geometry ) {
  114. // TODO: Is there a way of doing this automatically?
  115. if ( geometry instanceof THREE.ConvexGeometry ) return "ConvexGeometry";
  116. if ( geometry instanceof THREE.CubeGeometry ) return "CubeGeometry";
  117. if ( geometry instanceof THREE.CylinderGeometry ) return "CylinderGeometry";
  118. if ( geometry instanceof THREE.ExtrudeGeometry ) return "ExtrudeGeometry";
  119. if ( geometry instanceof THREE.IcosahedronGeometry ) return "IcosahedronGeometry";
  120. if ( geometry instanceof THREE.LatheGeometry ) return "LatheGeometry";
  121. if ( geometry instanceof THREE.OctahedronGeometry ) return "OctahedronGeometry";
  122. if ( geometry instanceof THREE.ParametricGeometry ) return "ParametricGeometry";
  123. if ( geometry instanceof THREE.PlaneGeometry ) return "PlaneGeometry";
  124. if ( geometry instanceof THREE.PolyhedronGeometry ) return "PolyhedronGeometry";
  125. if ( geometry instanceof THREE.SphereGeometry ) return "SphereGeometry";
  126. if ( geometry instanceof THREE.TetrahedronGeometry ) return "TetrahedronGeometry";
  127. if ( geometry instanceof THREE.TextGeometry ) return "TextGeometry";
  128. if ( geometry instanceof THREE.TorusGeometry ) return "TorusGeometry";
  129. if ( geometry instanceof THREE.TorusKnotGeometry ) return "TorusKnotGeometry";
  130. if ( geometry instanceof THREE.TubeGeometry ) return "TubeGeometry";
  131. if ( geometry instanceof THREE.Geometry ) return "Geometry";
  132. }
  133. function getMaterialInstanceName( material ) {
  134. // TODO: Is there a way of doing this automatically?
  135. if ( material instanceof THREE.LineBasicMaterial ) return "LineBasicMaterial";
  136. if ( material instanceof THREE.MeshBasicMaterial ) return "MeshBasicMaterial";
  137. if ( material instanceof THREE.MeshDepthMaterial ) return "MeshDepthMaterial";
  138. if ( material instanceof THREE.MeshFaceMaterial ) return "MeshFaceMaterial";
  139. if ( material instanceof THREE.MeshLambertMaterial ) return "MeshLambertMaterial";
  140. if ( material instanceof THREE.MeshNormalMaterial ) return "MeshNormalMaterial";
  141. if ( material instanceof THREE.MeshPhongMaterial ) return "MeshPhongMaterial";
  142. if ( material instanceof THREE.ParticleBasicMaterial ) return "ParticleBasicMaterial";
  143. if ( material instanceof THREE.ParticleCanvasMaterial ) return "ParticleCanvasMaterial";
  144. if ( material instanceof THREE.ParticleDOMMaterial ) return "ParticleDOMMaterial";
  145. if ( material instanceof THREE.ShaderMaterial ) return "ShaderMaterial";
  146. if ( material instanceof THREE.Material ) return "Material";
  147. }
  148. return container;
  149. }