Menubar.Add.js 8.6 KB

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