Sidebar.Properties.js 7.7 KB

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