Menubar.Add.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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. // Cylinder
  62. var option = new UI.Row();
  63. option.setClass( 'option' );
  64. option.setTextContent( strings.getKey( 'menubar/add/cylinder' ) );
  65. option.onClick( function () {
  66. var geometry = new THREE.CylinderBufferGeometry( 1, 1, 1, 8, 1, false, 0, Math.PI * 2 );
  67. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
  68. mesh.name = 'Cylinder';
  69. editor.execute( new AddObjectCommand( mesh ) );
  70. } );
  71. options.add( option );
  72. // Sphere
  73. var option = new UI.Row();
  74. option.setClass( 'option' );
  75. option.setTextContent( strings.getKey( 'menubar/add/sphere' ) );
  76. option.onClick( function () {
  77. var geometry = new THREE.SphereBufferGeometry( 1, 8, 6, 0, Math.PI * 2, 0, Math.PI );
  78. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
  79. mesh.name = 'Sphere';
  80. editor.execute( new AddObjectCommand( mesh ) );
  81. } );
  82. options.add( option );
  83. // Icosahedron
  84. var option = new UI.Row();
  85. option.setClass( 'option' );
  86. option.setTextContent( strings.getKey( 'menubar/add/icosahedron' ) );
  87. option.onClick( function () {
  88. var geometry = new THREE.IcosahedronBufferGeometry( 1, 0 );
  89. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
  90. mesh.name = 'Icosahedron';
  91. editor.execute( new AddObjectCommand( mesh ) );
  92. } );
  93. options.add( option );
  94. // Octahedron
  95. var option = new UI.Row();
  96. option.setClass( 'option' );
  97. option.setTextContent( strings.getKey( 'menubar/add/octahedron' ) );
  98. option.onClick( function () {
  99. var geometry = new THREE.OctahedronBufferGeometry( 1, 0 );
  100. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
  101. mesh.name = 'Octahedron';
  102. editor.execute( new AddObjectCommand( mesh ) );
  103. } );
  104. options.add( option );
  105. // Torus
  106. var option = new UI.Row();
  107. option.setClass( 'option' );
  108. option.setTextContent( strings.getKey( 'menubar/add/torus' ) );
  109. option.onClick( function () {
  110. var geometry = new THREE.TorusBufferGeometry( 1, 0.4, 8, 6, Math.PI * 2 );
  111. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
  112. mesh.name = 'Torus';
  113. editor.execute( new AddObjectCommand( mesh ) );
  114. } );
  115. options.add( option );
  116. // TorusKnot
  117. var option = new UI.Row();
  118. option.setClass( 'option' );
  119. option.setTextContent( strings.getKey( 'menubar/add/torusknot' ) );
  120. option.onClick( function () {
  121. var geometry = new THREE.TorusKnotBufferGeometry( 1, 0.4, 64, 8, 2, 3 );
  122. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
  123. mesh.name = 'TorusKnot';
  124. editor.execute( new AddObjectCommand( mesh ) );
  125. } );
  126. options.add( option );
  127. // Tube
  128. var option = new UI.Row();
  129. option.setClass( 'option' );
  130. option.setTextContent( strings.getKey( 'menubar/add/tube' ) );
  131. option.onClick( function () {
  132. var path = new THREE.CatmullRomCurve3( [
  133. new THREE.Vector3( 2, 2, - 2 ),
  134. new THREE.Vector3( 2, - 2, - 0.6666666666666667 ),
  135. new THREE.Vector3( - 2, - 2, 0.6666666666666667 ),
  136. new THREE.Vector3( - 2, 2, 2 )
  137. ] );
  138. var geometry = new THREE.TubeBufferGeometry( path, 64, 1, 8, false );
  139. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
  140. mesh.name = 'Tube';
  141. editor.execute( new AddObjectCommand( mesh ) );
  142. } );
  143. options.add( option );
  144. /*
  145. // Teapot
  146. var option = new UI.Row();
  147. option.setClass( 'option' );
  148. option.setTextContent( 'Teapot' );
  149. option.onClick( function () {
  150. var size = 50;
  151. var segments = 10;
  152. var bottom = true;
  153. var lid = true;
  154. var body = true;
  155. var fitLid = false;
  156. var blinnScale = true;
  157. var material = new THREE.MeshStandardMaterial();
  158. var geometry = new THREE.TeapotBufferGeometry( size, segments, bottom, lid, body, fitLid, blinnScale );
  159. var mesh = new THREE.Mesh( geometry, material );
  160. mesh.name = 'Teapot';
  161. editor.addObject( mesh );
  162. editor.select( mesh );
  163. } );
  164. options.add( option );
  165. */
  166. // Lathe
  167. var option = new UI.Row();
  168. option.setClass( 'option' );
  169. option.setTextContent( strings.getKey( 'menubar/add/lathe' ) );
  170. option.onClick( function () {
  171. var points = [
  172. new THREE.Vector2( 0, 0 ),
  173. new THREE.Vector2( 0.4, 0 ),
  174. new THREE.Vector2( 0.35, 0.05 ),
  175. new THREE.Vector2( 0.1, 0.075 ),
  176. new THREE.Vector2( 0.08, 0.1 ),
  177. new THREE.Vector2( 0.08, 0.4 ),
  178. new THREE.Vector2( 0.1, 0.42 ),
  179. new THREE.Vector2( 0.14, 0.48 ),
  180. new THREE.Vector2( 0.2, 0.5 ),
  181. new THREE.Vector2( 0.25, 0.54 ),
  182. new THREE.Vector2( 0.3, 1.2 )
  183. ];
  184. var geometry = new THREE.LatheBufferGeometry( points, 12, 0, Math.PI * 2 );
  185. var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial( { side: THREE.DoubleSide } ) );
  186. mesh.name = 'Lathe';
  187. editor.execute( new AddObjectCommand( mesh ) );
  188. } );
  189. options.add( option );
  190. // Sprite
  191. var option = new UI.Row();
  192. option.setClass( 'option' );
  193. option.setTextContent( strings.getKey( 'menubar/add/sprite' ) );
  194. option.onClick( function () {
  195. var sprite = new THREE.Sprite( new THREE.SpriteMaterial() );
  196. sprite.name = 'Sprite';
  197. editor.execute( new AddObjectCommand( sprite ) );
  198. } );
  199. options.add( option );
  200. //
  201. options.add( new UI.HorizontalRule() );
  202. // PointLight
  203. var option = new UI.Row();
  204. option.setClass( 'option' );
  205. option.setTextContent( strings.getKey( 'menubar/add/pointlight' ) );
  206. option.onClick( function () {
  207. var color = 0xffffff;
  208. var intensity = 1;
  209. var distance = 0;
  210. var light = new THREE.PointLight( color, intensity, distance );
  211. light.name = 'PointLight';
  212. editor.execute( new AddObjectCommand( light ) );
  213. } );
  214. options.add( option );
  215. // SpotLight
  216. var option = new UI.Row();
  217. option.setClass( 'option' );
  218. option.setTextContent( strings.getKey( 'menubar/add/spotlight' ) );
  219. option.onClick( function () {
  220. var color = 0xffffff;
  221. var intensity = 1;
  222. var distance = 0;
  223. var angle = Math.PI * 0.1;
  224. var penumbra = 0;
  225. var light = new THREE.SpotLight( color, intensity, distance, angle, penumbra );
  226. light.name = 'SpotLight';
  227. light.target.name = 'SpotLight Target';
  228. light.position.set( 5, 10, 7.5 );
  229. editor.execute( new AddObjectCommand( light ) );
  230. } );
  231. options.add( option );
  232. // DirectionalLight
  233. var option = new UI.Row();
  234. option.setClass( 'option' );
  235. option.setTextContent( strings.getKey( 'menubar/add/directionallight' ) );
  236. option.onClick( function () {
  237. var color = 0xffffff;
  238. var intensity = 1;
  239. var light = new THREE.DirectionalLight( color, intensity );
  240. light.name = 'DirectionalLight';
  241. light.target.name = 'DirectionalLight Target';
  242. light.position.set( 5, 10, 7.5 );
  243. editor.execute( new AddObjectCommand( light ) );
  244. } );
  245. options.add( option );
  246. // HemisphereLight
  247. var option = new UI.Row();
  248. option.setClass( 'option' );
  249. option.setTextContent( strings.getKey( 'menubar/add/hemispherelight' ) );
  250. option.onClick( function () {
  251. var skyColor = 0x00aaff;
  252. var groundColor = 0xffaa00;
  253. var intensity = 1;
  254. var light = new THREE.HemisphereLight( skyColor, groundColor, intensity );
  255. light.name = 'HemisphereLight';
  256. light.position.set( 0, 10, 0 );
  257. editor.execute( new AddObjectCommand( light ) );
  258. } );
  259. options.add( option );
  260. // AmbientLight
  261. var option = new UI.Row();
  262. option.setClass( 'option' );
  263. option.setTextContent( strings.getKey( 'menubar/add/ambientlight' ) );
  264. option.onClick( function () {
  265. var color = 0x222222;
  266. var light = new THREE.AmbientLight( color );
  267. light.name = 'AmbientLight';
  268. editor.execute( new AddObjectCommand( light ) );
  269. } );
  270. options.add( option );
  271. //
  272. options.add( new UI.HorizontalRule() );
  273. // PerspectiveCamera
  274. var option = new UI.Row();
  275. option.setClass( 'option' );
  276. option.setTextContent( strings.getKey( 'menubar/add/perspectivecamera' ) );
  277. option.onClick( function () {
  278. var camera = new THREE.PerspectiveCamera();
  279. camera.name = 'PerspectiveCamera';
  280. editor.execute( new AddObjectCommand( camera ) );
  281. } );
  282. options.add( option );
  283. return container;
  284. };