Menubar.Add.js 10 KB

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