Menubar.Add.js 9.2 KB

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