Menubar.Add.js 12 KB

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