Menubar.Add.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. Menubar.Add = function ( editor ) {
  2. var container = new UI.Panel();
  3. container.setClass( 'menu' );
  4. container.onMouseOver( function () { options.setDisplay( 'block' ) } );
  5. container.onMouseOut( function () { options.setDisplay( 'none' ) } );
  6. container.onClick( function () { options.setDisplay( 'block' ) } );
  7. var title = new UI.Panel();
  8. title.setTextContent( 'Add' ).setColor( '#666' );
  9. title.setMargin( '0px' );
  10. title.setPadding( '8px' );
  11. container.add( title );
  12. //
  13. var options = new UI.Panel();
  14. options.setClass( 'options' );
  15. options.setDisplay( 'none' );
  16. container.add( options );
  17. var meshCount = 0;
  18. var lightCount = 0;
  19. // add plane
  20. var option = new UI.Panel();
  21. option.setClass( 'option' );
  22. option.setTextContent( 'Plane' );
  23. option.onClick( function () {
  24. var width = 200;
  25. var height = 200;
  26. var widthSegments = 1;
  27. var heightSegments = 1;
  28. var geometry = new THREE.PlaneGeometry( width, height, widthSegments, heightSegments );
  29. var material = new THREE.MeshLambertMaterial();
  30. var mesh = new THREE.Mesh( geometry, material );
  31. mesh.name = 'Plane ' + ( ++ meshCount );
  32. mesh.rotation.x = - Math.PI/2;
  33. editor.addObject( mesh );
  34. editor.select( mesh );
  35. } );
  36. options.add( option );
  37. // add cube
  38. var option = new UI.Panel();
  39. option.setClass( 'option' );
  40. option.setTextContent( 'Cube' );
  41. option.onClick( function () {
  42. var width = 100;
  43. var height = 100;
  44. var depth = 100;
  45. var widthSegments = 1;
  46. var heightSegments = 1;
  47. var depthSegments = 1;
  48. var geometry = new THREE.CubeGeometry( width, height, depth, widthSegments, heightSegments, depthSegments );
  49. var mesh = new THREE.Mesh( geometry, new THREE.MeshLambertMaterial() );
  50. mesh.name = 'Cube ' + ( ++ meshCount );
  51. editor.addObject( mesh );
  52. editor.select( mesh );
  53. } );
  54. options.add( option );
  55. // add cylinder
  56. var option = new UI.Panel();
  57. option.setClass( 'option' );
  58. option.setTextContent( 'Cylinder' );
  59. option.onClick( function () {
  60. var radiusTop = 20;
  61. var radiusBottom = 20;
  62. var height = 100;
  63. var radiusSegments = 8;
  64. var heightSegments = 1;
  65. var openEnded = false;
  66. var geometry = new THREE.CylinderGeometry( radiusTop, radiusBottom, height, radiusSegments, heightSegments, openEnded );
  67. var mesh = new THREE.Mesh( geometry, new THREE.MeshLambertMaterial() );
  68. mesh.name = 'Cylinder ' + ( ++ meshCount );
  69. editor.addObject( mesh );
  70. editor.select( mesh );
  71. } );
  72. options.add( option );
  73. // add sphere
  74. var option = new UI.Panel();
  75. option.setClass( 'option' );
  76. option.setTextContent( 'Sphere' );
  77. option.onClick( function () {
  78. var radius = 75;
  79. var widthSegments = 32;
  80. var heightSegments = 16;
  81. var geometry = new THREE.SphereGeometry( radius, widthSegments, heightSegments );
  82. var mesh = new THREE.Mesh( geometry, new THREE.MeshLambertMaterial() );
  83. mesh.name = 'Sphere ' + ( ++ meshCount );
  84. editor.addObject( mesh );
  85. editor.select( mesh );
  86. } );
  87. options.add( option );
  88. // add icosahedron
  89. var option = new UI.Panel();
  90. option.setClass( 'option' );
  91. option.setTextContent( 'Icosahedron' );
  92. option.onClick( function () {
  93. var radius = 75;
  94. var detail = 2;
  95. var geometry = new THREE.IcosahedronGeometry ( radius, detail );
  96. var mesh = new THREE.Mesh( geometry, new THREE.MeshLambertMaterial() );
  97. mesh.name = 'Icosahedron ' + ( ++ meshCount );
  98. editor.addObject( mesh );
  99. editor.select( mesh );
  100. } );
  101. options.add( option );
  102. // add torus
  103. var option = new UI.Panel();
  104. option.setClass( 'option' );
  105. option.setTextContent( 'Torus' );
  106. option.onClick( function () {
  107. var radius = 100;
  108. var tube = 40;
  109. var radialSegments = 8;
  110. var tubularSegments = 6;
  111. var arc = Math.PI * 2;
  112. var geometry = new THREE.TorusGeometry( radius, tube, radialSegments, tubularSegments, arc );
  113. var mesh = new THREE.Mesh( geometry, new THREE.MeshLambertMaterial() );
  114. mesh.name = 'Torus ' + ( ++ meshCount );
  115. editor.addObject( mesh );
  116. editor.select( mesh );
  117. } );
  118. options.add( option );
  119. // add torus knot
  120. var option = new UI.Panel();
  121. option.setClass( 'option' );
  122. option.setTextContent( 'TorusKnot' );
  123. option.onClick( function () {
  124. var radius = 100;
  125. var tube = 40;
  126. var radialSegments = 64;
  127. var tubularSegments = 8;
  128. var p = 2;
  129. var q = 3;
  130. var heightScale = 1;
  131. var geometry = new THREE.TorusKnotGeometry( radius, tube, radialSegments, tubularSegments, p, q, heightScale );
  132. var mesh = new THREE.Mesh( geometry, new THREE.MeshLambertMaterial() );
  133. mesh.name = 'TorusKnot ' + ( ++ meshCount );
  134. editor.addObject( mesh );
  135. editor.select( mesh );
  136. } );
  137. options.add( option );
  138. // divider
  139. options.add( new UI.HorizontalRule() );
  140. // add point light
  141. var option = new UI.Panel();
  142. option.setClass( 'option' );
  143. option.setTextContent( 'Point light' );
  144. option.onClick( function () {
  145. var color = 0xffffff;
  146. var intensity = 1;
  147. var distance = 0;
  148. var light = new THREE.PointLight( color, intensity, distance );
  149. light.name = 'PointLight ' + ( ++ lightCount );
  150. editor.addObject( light );
  151. editor.select( light );
  152. } );
  153. options.add( option );
  154. // add spot light
  155. var option = new UI.Panel();
  156. option.setClass( 'option' );
  157. option.setTextContent( 'Spot light' );
  158. option.onClick( function () {
  159. var color = 0xffffff;
  160. var intensity = 1;
  161. var distance = 0;
  162. var angle = Math.PI * 0.1;
  163. var exponent = 10;
  164. var light = new THREE.SpotLight( color, intensity, distance, angle, exponent );
  165. light.name = 'SpotLight ' + ( ++ lightCount );
  166. light.target.name = 'SpotLight ' + ( lightCount ) + ' Target';
  167. light.position.set( 0, 1, 0 ).multiplyScalar( 200 );
  168. editor.addObject( light );
  169. editor.select( light );
  170. } );
  171. options.add( option );
  172. // add directional light
  173. var option = new UI.Panel();
  174. option.setClass( 'option' );
  175. option.setTextContent( 'Directional light' );
  176. option.onClick( function () {
  177. var color = 0xffffff;
  178. var intensity = 1;
  179. var light = new THREE.DirectionalLight( color, intensity );
  180. light.name = 'DirectionalLight ' + ( ++ lightCount );
  181. light.target.name = 'DirectionalLight ' + ( lightCount ) + ' Target';
  182. light.position.set( 1, 1, 1 ).multiplyScalar( 200 );
  183. editor.addObject( light );
  184. editor.select( light );
  185. } );
  186. options.add( option );
  187. // add hemisphere light
  188. var option = new UI.Panel();
  189. option.setClass( 'option' );
  190. option.setTextContent( 'Hemisphere light' );
  191. option.onClick( function () {
  192. var skyColor = 0x00aaff;
  193. var groundColor = 0xffaa00;
  194. var intensity = 1;
  195. var light = new THREE.HemisphereLight( skyColor, groundColor, intensity );
  196. light.name = 'HemisphereLight ' + ( ++ lightCount );
  197. light.position.set( 1, 1, 1 ).multiplyScalar( 200 );
  198. editor.addObject( light );
  199. editor.select( light );
  200. } );
  201. options.add( option );
  202. // add ambient light
  203. var option = new UI.Panel();
  204. option.setClass( 'option' );
  205. option.setTextContent( 'Ambient light' );
  206. option.onClick( function () {
  207. var color = 0x222222;
  208. var light = new THREE.AmbientLight( color );
  209. light.name = 'AmbientLight ' + ( ++ lightCount );
  210. editor.addObject( light );
  211. editor.select( light );
  212. } );
  213. options.add( option );
  214. //
  215. return container;
  216. }