Menubar.Add.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. */
  4. Menubar.Add = function ( editor ) {
  5. var container = new UI.Panel();
  6. container.setClass( 'menu' );
  7. var title = new UI.Panel();
  8. title.setClass( 'title' );
  9. title.setTextContent( 'Add' );
  10. container.add( title );
  11. var options = new UI.Panel();
  12. options.setClass( 'options' );
  13. container.add( options );
  14. // Group
  15. var option = new UI.Row();
  16. option.setClass( 'option' );
  17. option.setTextContent( 'Group' );
  18. option.onClick( function () {
  19. var mesh = new THREE.Group();
  20. mesh.name = 'Group';
  21. editor.execute( new AddObjectCommand( mesh ) );
  22. } );
  23. options.add( option );
  24. //
  25. options.add( new UI.HorizontalRule() );
  26. // Plane
  27. var option = new UI.Row();
  28. option.setClass( 'option' );
  29. option.setTextContent( 'Plane' );
  30. option.onClick( function () {
  31. var geometry = new THREE.PlaneBufferGeometry( 1, 1, 1, 1 );
  32. var material = new THREE.MeshStandardMaterial();
  33. var mesh = new THREE.Mesh( geometry, material );
  34. mesh.name = 'Plane';
  35. editor.execute( new AddObjectCommand( mesh ) );
  36. } );
  37. options.add( option );
  38. // Box
  39. var option = new UI.Row();
  40. option.setClass( 'option' );
  41. option.setTextContent( 'Box' );
  42. option.onClick( function () {
  43. var geometry = new THREE.BoxBufferGeometry( 1, 1, 1, 1, 1, 1 );
  44. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
  45. mesh.name = 'Box';
  46. editor.execute( new AddObjectCommand( mesh ) );
  47. } );
  48. options.add( option );
  49. // Circle
  50. var option = new UI.Row();
  51. option.setClass( 'option' );
  52. option.setTextContent( 'Circle' );
  53. option.onClick( function () {
  54. var geometry = new THREE.CircleBufferGeometry( 1, 8, 0, Math.PI * 2 );
  55. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
  56. mesh.name = 'Circle';
  57. editor.execute( new AddObjectCommand( mesh ) );
  58. } );
  59. options.add( option );
  60. // Cylinder
  61. var option = new UI.Row();
  62. option.setClass( 'option' );
  63. option.setTextContent( 'Cylinder' );
  64. option.onClick( function () {
  65. var geometry = new THREE.CylinderBufferGeometry( 1, 1, 1, 8, 1, false, 0, Math.PI * 2 );
  66. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
  67. mesh.name = 'Cylinder';
  68. editor.execute( new AddObjectCommand( mesh ) );
  69. } );
  70. options.add( option );
  71. // Sphere
  72. var option = new UI.Row();
  73. option.setClass( 'option' );
  74. option.setTextContent( 'Sphere' );
  75. option.onClick( function () {
  76. var geometry = new THREE.SphereBufferGeometry( 1, 8, 6, 0, Math.PI * 2, 0, Math.PI );
  77. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
  78. mesh.name = 'Sphere';
  79. editor.execute( new AddObjectCommand( mesh ) );
  80. } );
  81. options.add( option );
  82. // Icosahedron
  83. var option = new UI.Row();
  84. option.setClass( 'option' );
  85. option.setTextContent( 'Icosahedron' );
  86. option.onClick( function () {
  87. var geometry = new THREE.IcosahedronGeometry( 1, 0 );
  88. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
  89. mesh.name = 'Icosahedron';
  90. editor.execute( new AddObjectCommand( mesh ) );
  91. } );
  92. options.add( option );
  93. // Torus
  94. var option = new UI.Row();
  95. option.setClass( 'option' );
  96. option.setTextContent( 'Torus' );
  97. option.onClick( function () {
  98. var geometry = new THREE.TorusBufferGeometry( 1, 0.4, 8, 6, Math.PI * 2 );
  99. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
  100. mesh.name = 'Torus';
  101. editor.execute( new AddObjectCommand( mesh ) );
  102. } );
  103. options.add( option );
  104. // TorusKnot
  105. var option = new UI.Row();
  106. option.setClass( 'option' );
  107. option.setTextContent( 'TorusKnot' );
  108. option.onClick( function () {
  109. var geometry = new THREE.TorusKnotBufferGeometry( 1, 0.4, 64, 8, 2, 3 );
  110. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
  111. mesh.name = 'TorusKnot';
  112. editor.execute( new AddObjectCommand( mesh ) );
  113. } );
  114. options.add( option );
  115. /*
  116. // Teapot
  117. var option = new UI.Row();
  118. option.setClass( 'option' );
  119. option.setTextContent( 'Teapot' );
  120. option.onClick( function () {
  121. var size = 50;
  122. var segments = 10;
  123. var bottom = true;
  124. var lid = true;
  125. var body = true;
  126. var fitLid = false;
  127. var blinnScale = true;
  128. var material = new THREE.MeshStandardMaterial();
  129. var geometry = new THREE.TeapotBufferGeometry( size, segments, bottom, lid, body, fitLid, blinnScale );
  130. var mesh = new THREE.Mesh( geometry, material );
  131. mesh.name = 'Teapot';
  132. editor.addObject( mesh );
  133. editor.select( mesh );
  134. } );
  135. options.add( option );
  136. */
  137. // Lathe
  138. var option = new UI.Row();
  139. option.setClass( 'option' );
  140. option.setTextContent( 'Lathe' );
  141. option.onClick( function() {
  142. var points = [
  143. new THREE.Vector2( 0, 0 ),
  144. new THREE.Vector2( 0.4, 0 ),
  145. new THREE.Vector2( 0.35, 0.05 ),
  146. new THREE.Vector2( 0.1, 0.075 ),
  147. new THREE.Vector2( 0.08, 0.1 ),
  148. new THREE.Vector2( 0.08, 0.4 ),
  149. new THREE.Vector2( 0.1, 0.42 ),
  150. new THREE.Vector2( 0.14, 0.48 ),
  151. new THREE.Vector2( 0.2, 0.5 ),
  152. new THREE.Vector2( 0.25, 0.54 ),
  153. new THREE.Vector2( 0.3, 1.2 )
  154. ];
  155. var geometry = new THREE.LatheBufferGeometry( points, 12, 0, Math.PI * 2 );
  156. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial( { side: THREE.DoubleSide } ) );
  157. mesh.name = 'Lathe';
  158. editor.execute( new AddObjectCommand( mesh ) );
  159. } );
  160. options.add( option );
  161. // Sprite
  162. var option = new UI.Row();
  163. option.setClass( 'option' );
  164. option.setTextContent( 'Sprite' );
  165. option.onClick( function () {
  166. var sprite = new THREE.Sprite( new THREE.SpriteMaterial() );
  167. sprite.name = 'Sprite';
  168. editor.execute( new AddObjectCommand( sprite ) );
  169. } );
  170. options.add( option );
  171. //
  172. options.add( new UI.HorizontalRule() );
  173. // PointLight
  174. var option = new UI.Row();
  175. option.setClass( 'option' );
  176. option.setTextContent( 'PointLight' );
  177. option.onClick( function () {
  178. var color = 0xffffff;
  179. var intensity = 1;
  180. var distance = 0;
  181. var light = new THREE.PointLight( color, intensity, distance );
  182. light.name = 'PointLight';
  183. editor.execute( new AddObjectCommand( light ) );
  184. } );
  185. options.add( option );
  186. // SpotLight
  187. var option = new UI.Row();
  188. option.setClass( 'option' );
  189. option.setTextContent( 'SpotLight' );
  190. option.onClick( function () {
  191. var color = 0xffffff;
  192. var intensity = 1;
  193. var distance = 0;
  194. var angle = Math.PI * 0.1;
  195. var penumbra = 0;
  196. var light = new THREE.SpotLight( color, intensity, distance, angle, penumbra );
  197. light.name = 'SpotLight';
  198. light.target.name = 'SpotLight Target';
  199. light.position.set( 5, 10, 7.5 );
  200. editor.execute( new AddObjectCommand( light ) );
  201. } );
  202. options.add( option );
  203. // DirectionalLight
  204. var option = new UI.Row();
  205. option.setClass( 'option' );
  206. option.setTextContent( 'DirectionalLight' );
  207. option.onClick( function () {
  208. var color = 0xffffff;
  209. var intensity = 1;
  210. var light = new THREE.DirectionalLight( color, intensity );
  211. light.name = 'DirectionalLight';
  212. light.target.name = 'DirectionalLight Target';
  213. light.position.set( 5, 10, 7.5 );
  214. editor.execute( new AddObjectCommand( light ) );
  215. } );
  216. options.add( option );
  217. // HemisphereLight
  218. var option = new UI.Row();
  219. option.setClass( 'option' );
  220. option.setTextContent( 'HemisphereLight' );
  221. option.onClick( function () {
  222. var skyColor = 0x00aaff;
  223. var groundColor = 0xffaa00;
  224. var intensity = 1;
  225. var light = new THREE.HemisphereLight( skyColor, groundColor, intensity );
  226. light.name = 'HemisphereLight';
  227. light.position.set( 0, 10, 0 );
  228. editor.execute( new AddObjectCommand( light ) );
  229. } );
  230. options.add( option );
  231. // AmbientLight
  232. var option = new UI.Row();
  233. option.setClass( 'option' );
  234. option.setTextContent( 'AmbientLight' );
  235. option.onClick( function() {
  236. var color = 0x222222;
  237. var light = new THREE.AmbientLight( color );
  238. light.name = 'AmbientLight';
  239. editor.execute( new AddObjectCommand( light ) );
  240. } );
  241. options.add( option );
  242. //
  243. options.add( new UI.HorizontalRule() );
  244. // PerspectiveCamera
  245. var option = new UI.Row();
  246. option.setClass( 'option' );
  247. option.setTextContent( 'PerspectiveCamera' );
  248. option.onClick( function() {
  249. var camera = new THREE.PerspectiveCamera( 50, 1, 1, 10000 );
  250. camera.name = 'PerspectiveCamera';
  251. editor.execute( new AddObjectCommand( camera ) );
  252. } );
  253. options.add( option );
  254. return container;
  255. };