Menubar.Add.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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.MeshPhongMaterial();
  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.MeshPhongMaterial() );
  50. mesh.name = 'Cube ' + ( ++ meshCount );
  51. editor.addObject( mesh );
  52. editor.select( mesh );
  53. } );
  54. options.add( option );
  55. // add circle
  56. var option = new UI.Panel();
  57. option.setClass( 'option' );
  58. option.setTextContent( 'Circle' );
  59. option.onClick( function () {
  60. var radius = 20;
  61. var segments = 8;
  62. var geometry = new THREE.CircleGeometry( radius, segments );
  63. var mesh = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial() );
  64. mesh.name = 'Circle ' + ( ++ meshCount );
  65. editor.addObject( mesh );
  66. editor.select( mesh );
  67. } );
  68. options.add( option );
  69. // add cylinder
  70. var option = new UI.Panel();
  71. option.setClass( 'option' );
  72. option.setTextContent( 'Cylinder' );
  73. option.onClick( function () {
  74. var radiusTop = 20;
  75. var radiusBottom = 20;
  76. var height = 100;
  77. var radiusSegments = 8;
  78. var heightSegments = 1;
  79. var openEnded = false;
  80. var geometry = new THREE.CylinderGeometry( radiusTop, radiusBottom, height, radiusSegments, heightSegments, openEnded );
  81. var mesh = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial() );
  82. mesh.name = 'Cylinder ' + ( ++ meshCount );
  83. editor.addObject( mesh );
  84. editor.select( mesh );
  85. } );
  86. options.add( option );
  87. // add sphere
  88. var option = new UI.Panel();
  89. option.setClass( 'option' );
  90. option.setTextContent( 'Sphere' );
  91. option.onClick( function () {
  92. var radius = 75;
  93. var widthSegments = 32;
  94. var heightSegments = 16;
  95. var geometry = new THREE.SphereGeometry( radius, widthSegments, heightSegments );
  96. var mesh = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial() );
  97. mesh.name = 'Sphere ' + ( ++ meshCount );
  98. editor.addObject( mesh );
  99. editor.select( mesh );
  100. } );
  101. options.add( option );
  102. // add icosahedron
  103. var option = new UI.Panel();
  104. option.setClass( 'option' );
  105. option.setTextContent( 'Icosahedron' );
  106. option.onClick( function () {
  107. var radius = 75;
  108. var detail = 2;
  109. var geometry = new THREE.IcosahedronGeometry ( radius, detail );
  110. var mesh = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial() );
  111. mesh.name = 'Icosahedron ' + ( ++ meshCount );
  112. editor.addObject( mesh );
  113. editor.select( mesh );
  114. } );
  115. options.add( option );
  116. // add torus
  117. var option = new UI.Panel();
  118. option.setClass( 'option' );
  119. option.setTextContent( 'Torus' );
  120. option.onClick( function () {
  121. var radius = 100;
  122. var tube = 40;
  123. var radialSegments = 8;
  124. var tubularSegments = 6;
  125. var arc = Math.PI * 2;
  126. var geometry = new THREE.TorusGeometry( radius, tube, radialSegments, tubularSegments, arc );
  127. var mesh = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial() );
  128. mesh.name = 'Torus ' + ( ++ meshCount );
  129. editor.addObject( mesh );
  130. editor.select( mesh );
  131. } );
  132. options.add( option );
  133. // add torus knot
  134. var option = new UI.Panel();
  135. option.setClass( 'option' );
  136. option.setTextContent( 'TorusKnot' );
  137. option.onClick( function () {
  138. var radius = 100;
  139. var tube = 40;
  140. var radialSegments = 64;
  141. var tubularSegments = 8;
  142. var p = 2;
  143. var q = 3;
  144. var heightScale = 1;
  145. var geometry = new THREE.TorusKnotGeometry( radius, tube, radialSegments, tubularSegments, p, q, heightScale );
  146. var mesh = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial() );
  147. mesh.name = 'TorusKnot ' + ( ++ meshCount );
  148. editor.addObject( mesh );
  149. editor.select( mesh );
  150. } );
  151. options.add( option );
  152. // divider
  153. options.add( new UI.HorizontalRule() );
  154. // add point light
  155. var option = new UI.Panel();
  156. option.setClass( 'option' );
  157. option.setTextContent( 'Point light' );
  158. option.onClick( function () {
  159. var color = 0xffffff;
  160. var intensity = 1;
  161. var distance = 0;
  162. var light = new THREE.PointLight( color, intensity, distance );
  163. light.name = 'PointLight ' + ( ++ lightCount );
  164. editor.addObject( light );
  165. editor.select( light );
  166. } );
  167. options.add( option );
  168. // add spot light
  169. var option = new UI.Panel();
  170. option.setClass( 'option' );
  171. option.setTextContent( 'Spot light' );
  172. option.onClick( function () {
  173. var color = 0xffffff;
  174. var intensity = 1;
  175. var distance = 0;
  176. var angle = Math.PI * 0.1;
  177. var exponent = 10;
  178. var light = new THREE.SpotLight( color, intensity, distance, angle, exponent );
  179. light.name = 'SpotLight ' + ( ++ lightCount );
  180. light.target.name = 'SpotLight ' + ( lightCount ) + ' Target';
  181. light.position.set( 0, 1, 0 ).multiplyScalar( 200 );
  182. editor.addObject( light );
  183. editor.select( light );
  184. } );
  185. options.add( option );
  186. // add directional light
  187. var option = new UI.Panel();
  188. option.setClass( 'option' );
  189. option.setTextContent( 'Directional light' );
  190. option.onClick( function () {
  191. var color = 0xffffff;
  192. var intensity = 1;
  193. var light = new THREE.DirectionalLight( color, intensity );
  194. light.name = 'DirectionalLight ' + ( ++ lightCount );
  195. light.target.name = 'DirectionalLight ' + ( lightCount ) + ' Target';
  196. light.position.set( 1, 1, 1 ).multiplyScalar( 200 );
  197. editor.addObject( light );
  198. editor.select( light );
  199. } );
  200. options.add( option );
  201. // add hemisphere light
  202. var option = new UI.Panel();
  203. option.setClass( 'option' );
  204. option.setTextContent( 'Hemisphere light' );
  205. option.onClick( function () {
  206. var skyColor = 0x00aaff;
  207. var groundColor = 0xffaa00;
  208. var intensity = 1;
  209. var light = new THREE.HemisphereLight( skyColor, groundColor, intensity );
  210. light.name = 'HemisphereLight ' + ( ++ lightCount );
  211. light.position.set( 1, 1, 1 ).multiplyScalar( 200 );
  212. editor.addObject( light );
  213. editor.select( light );
  214. } );
  215. options.add( option );
  216. // add ambient light
  217. var option = new UI.Panel();
  218. option.setClass( 'option' );
  219. option.setTextContent( 'Ambient light' );
  220. option.onClick( function () {
  221. var color = 0x222222;
  222. var light = new THREE.AmbientLight( color );
  223. light.name = 'AmbientLight ' + ( ++ lightCount );
  224. editor.addObject( light );
  225. editor.select( light );
  226. } );
  227. options.add( option );
  228. //
  229. return container;
  230. }