Menubar.Add.js 10.8 KB
Newer Older
M
Mr.doob 已提交
1 2 3 4
/**
 * @author mrdoob / http://mrdoob.com/
 */

5
Menubar.Add = function ( editor ) {
6

M
Mr.doob 已提交
7 8
	var strings = editor.strings;

9 10 11 12 13
	var container = new UI.Panel();
	container.setClass( 'menu' );

	var title = new UI.Panel();
	title.setClass( 'title' );
M
Mr.doob 已提交
14
	title.setTextContent( strings.getKey( 'menubar/add' ) );
15 16 17 18 19 20 21
	container.add( title );

	var options = new UI.Panel();
	options.setClass( 'options' );
	container.add( options );

	// Group
M
Mr.doob 已提交
22

M
Mr.doob 已提交
23
	var option = new UI.Row();
24
	option.setClass( 'option' );
M
Mr.doob 已提交
25
	option.setTextContent( strings.getKey( 'menubar/add/group' ) );
26
	option.onClick( function () {
M
Mr.doob 已提交
27

M
Mr.doob 已提交
28
		var mesh = new THREE.Group();
M
Mr.doob 已提交
29
		mesh.name = 'Group';
M
Mr.doob 已提交
30

31
		editor.execute( new AddObjectCommand( mesh ) );
M
Mr.doob 已提交
32

33 34
	} );
	options.add( option );
M
Mr.doob 已提交
35

36 37 38 39
	//

	options.add( new UI.HorizontalRule() );

40
	// Box
41

M
Mr.doob 已提交
42
	var option = new UI.Row();
43
	option.setClass( 'option' );
44
	option.setTextContent( strings.getKey( 'menubar/add/box' ) );
45
	option.onClick( function () {
46

47 48 49
		var geometry = new THREE.BoxBufferGeometry( 1, 1, 1, 1, 1, 1 );
		var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
		mesh.name = 'Box';
M
Mr.doob 已提交
50

51
		editor.execute( new AddObjectCommand( mesh ) );
52

53 54 55
	} );
	options.add( option );

56
	// Circle
M
Mr.doob 已提交
57

M
Mr.doob 已提交
58
	var option = new UI.Row();
59
	option.setClass( 'option' );
60
	option.setTextContent( strings.getKey( 'menubar/add/circle' ) );
61
	option.onClick( function () {
62

63
		var geometry = new THREE.CircleBufferGeometry( 1, 8, 0, Math.PI * 2 );
M
Mr.doob 已提交
64
		var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
65
		mesh.name = 'Circle';
M
Mr.doob 已提交
66

67
		editor.execute( new AddObjectCommand( mesh ) );
68

69 70 71
	} );
	options.add( option );

72
	// Cylinder
73

M
Mr.doob 已提交
74
	var option = new UI.Row();
75
	option.setClass( 'option' );
76
	option.setTextContent( strings.getKey( 'menubar/add/cylinder' ) );
77
	option.onClick( function () {
M
Mr.doob 已提交
78

79
		var geometry = new THREE.CylinderBufferGeometry( 1, 1, 1, 8, 1, false, 0, Math.PI * 2 );
M
Mr.doob 已提交
80
		var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
81
		mesh.name = 'Cylinder';
M
Mr.doob 已提交
82

83
		editor.execute( new AddObjectCommand( mesh ) );
M
Mr.doob 已提交
84

85 86
	} );
	options.add( option );
87

88
	// Icosahedron
T
Temdog007 已提交
89 90 91

	var option = new UI.Row();
	option.setClass( 'option' );
92
	option.setTextContent( strings.getKey( 'menubar/add/icosahedron' ) );
T
Temdog007 已提交
93 94
	option.onClick( function () {

95
		var geometry = new THREE.IcosahedronBufferGeometry( 1, 0 );
T
Temdog007 已提交
96
		var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
97
		mesh.name = 'Icosahedron';
T
Temdog007 已提交
98 99 100 101 102 103

		editor.execute( new AddObjectCommand( mesh ) );

	} );
	options.add( option );

104
	// Lathe
105

M
Mr.doob 已提交
106
	var option = new UI.Row();
107
	option.setClass( 'option' );
108
	option.setTextContent( strings.getKey( 'menubar/add/lathe' ) );
109
	option.onClick( function () {
110

111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
		var points = [
			new THREE.Vector2( 0, 0 ),
			new THREE.Vector2( 0.4, 0 ),
			new THREE.Vector2( 0.35, 0.05 ),
			new THREE.Vector2( 0.1, 0.075 ),
			new THREE.Vector2( 0.08, 0.1 ),
			new THREE.Vector2( 0.08, 0.4 ),
			new THREE.Vector2( 0.1, 0.42 ),
			new THREE.Vector2( 0.14, 0.48 ),
			new THREE.Vector2( 0.2, 0.5 ),
			new THREE.Vector2( 0.25, 0.54 ),
			new THREE.Vector2( 0.3, 1.2 )
		];

		var geometry = new THREE.LatheBufferGeometry( points, 12, 0, Math.PI * 2 );
		var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial( { side: THREE.DoubleSide } ) );
		mesh.name = 'Lathe';
M
Mr.doob 已提交
128

129
		editor.execute( new AddObjectCommand( mesh ) );
M
Mr.doob 已提交
130

131 132 133
	} );
	options.add( option );

134
	// Octahedron
M
Mr.doob 已提交
135

M
Mr.doob 已提交
136
	var option = new UI.Row();
137
	option.setClass( 'option' );
138
	option.setTextContent( strings.getKey( 'menubar/add/octahedron' ) );
139
	option.onClick( function () {
M
Mr.doob 已提交
140

141
		var geometry = new THREE.OctahedronBufferGeometry( 1, 0 );
M
Mr.doob 已提交
142
		var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
143
		mesh.name = 'Octahedron';
M
Mr.doob 已提交
144

145
		editor.execute( new AddObjectCommand( mesh ) );
146

147 148
	} );
	options.add( option );
149

150
	// Plane
151

M
Mr.doob 已提交
152
	var option = new UI.Row();
153
	option.setClass( 'option' );
154
	option.setTextContent( strings.getKey( 'menubar/add/plane' ) );
155
	option.onClick( function () {
156

157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
		var geometry = new THREE.PlaneBufferGeometry( 1, 1, 1, 1 );
		var material = new THREE.MeshStandardMaterial();
		var mesh = new THREE.Mesh( geometry, material );
		mesh.name = 'Plane';

		editor.execute( new AddObjectCommand( mesh ) );

	} );
	options.add( option )

	// Ring

	var option = new UI.Row();
	option.setClass( 'option' );
	option.setTextContent( strings.getKey( 'menubar/add/ring' ) );
	option.onClick( function () {

		var geometry = new THREE.RingBufferGeometry( 0.5, 1, 8, 1, 0, Math.PI * 2 );
M
Mr.doob 已提交
175
		var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
176
		mesh.name = 'Ring';
M
Mr.doob 已提交
177

178
		editor.execute( new AddObjectCommand( mesh ) );
M
Mr.doob 已提交
179

180 181
	} );
	options.add( option );
T
Temdog007 已提交
182

183
	// Sphere
T
Temdog007 已提交
184 185 186

	var option = new UI.Row();
	option.setClass( 'option' );
187
	option.setTextContent( strings.getKey( 'menubar/add/sphere' ) );
T
Temdog007 已提交
188 189
	option.onClick( function () {

190
		var geometry = new THREE.SphereBufferGeometry( 1, 8, 6, 0, Math.PI * 2, 0, Math.PI );
T
Temdog007 已提交
191
		var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
192
		mesh.name = 'Sphere';
T
Temdog007 已提交
193 194 195 196 197

		editor.execute( new AddObjectCommand( mesh ) );

	} );
	options.add( option );
198

199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
	// Sprite

	var option = new UI.Row();
	option.setClass( 'option' );
	option.setTextContent( strings.getKey( 'menubar/add/sprite' ) );
	option.onClick( function () {

		var sprite = new THREE.Sprite( new THREE.SpriteMaterial() );
		sprite.name = 'Sprite';

		editor.execute( new AddObjectCommand( sprite ) );

	} );
	options.add( option );

T
Temdog007 已提交
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
	// Tetrahedron

	var option = new UI.Row();
	option.setClass( 'option' );
	option.setTextContent( strings.getKey( 'menubar/add/tetrahedron' ) );
	option.onClick( function () {

		var geometry = new THREE.TetrahedronBufferGeometry( 1, 0 );
		var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
		mesh.name = 'Tetrahedron';

		editor.execute( new AddObjectCommand( mesh ) );

	} );
	options.add( option );
229 230

	// Torus
M
Mr.doob 已提交
231

M
Mr.doob 已提交
232
	var option = new UI.Row();
233
	option.setClass( 'option' );
T
Temdog007 已提交
234
	option.setTextContent( strings.getKey( 'menubar/add/torus' ) );
235
	option.onClick( function () {
236

237
		var geometry = new THREE.TorusBufferGeometry( 1, 0.4, 8, 6, Math.PI * 2 );
M
Mr.doob 已提交
238
		var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
M
Mr.doob 已提交
239
		mesh.name = 'Torus';
M
Mr.doob 已提交
240

241
		editor.execute( new AddObjectCommand( mesh ) );
242

243 244
	} );
	options.add( option );
M
Mr.doob 已提交
245

246 247
	// TorusKnot

M
Mr.doob 已提交
248
	var option = new UI.Row();
249
	option.setClass( 'option' );
T
Temdog007 已提交
250
	option.setTextContent( strings.getKey( 'menubar/add/torusknot' ) );
251
	option.onClick( function () {
M
Mr.doob 已提交
252

253
		var geometry = new THREE.TorusKnotBufferGeometry( 1, 0.4, 64, 8, 2, 3 );
M
Mr.doob 已提交
254
		var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
M
Mr.doob 已提交
255
		mesh.name = 'TorusKnot';
M
Mr.doob 已提交
256

257
		editor.execute( new AddObjectCommand( mesh ) );
258

259 260 261
	} );
	options.add( option );

T
Temdog007 已提交
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
	// Tube

	var option = new UI.Row();
	option.setClass( 'option' );
	option.setTextContent( strings.getKey( 'menubar/add/tube' ) );
	option.onClick( function () {

		var path = new THREE.CatmullRomCurve3( [
			new THREE.Vector3( 2, 2, - 2 ),
			new THREE.Vector3( 2, - 2, - 0.6666666666666667 ),
			new THREE.Vector3( - 2, - 2, 0.6666666666666667 ),
			new THREE.Vector3( - 2, 2, 2 )
		] );

		var geometry = new THREE.TubeBufferGeometry( path, 64, 1, 8, false );
		var mesh = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial() );
		mesh.name = 'Tube';

		editor.execute( new AddObjectCommand( mesh ) );

	} );
	options.add( option );

285
	/*
T
tschw 已提交
286 287
	// Teapot

M
Mr.doob 已提交
288
	var option = new UI.Row();
T
tschw 已提交
289 290 291 292 293 294 295 296 297 298 299 300
	option.setClass( 'option' );
	option.setTextContent( 'Teapot' );
	option.onClick( function () {

		var size = 50;
		var segments = 10;
		var bottom = true;
		var lid = true;
		var body = true;
		var fitLid = false;
		var blinnScale = true;

M
Mr.doob 已提交
301
		var material = new THREE.MeshStandardMaterial();
T
tschw 已提交
302 303 304

		var geometry = new THREE.TeapotBufferGeometry( size, segments, bottom, lid, body, fitLid, blinnScale );
		var mesh = new THREE.Mesh( geometry, material );
M
Mr.doob 已提交
305
		mesh.name = 'Teapot';
T
tschw 已提交
306 307 308 309 310 311

		editor.addObject( mesh );
		editor.select( mesh );

	} );
	options.add( option );
312
	*/
T
tschw 已提交
313

314 315 316
	//

	options.add( new UI.HorizontalRule() );
M
Mr.doob 已提交
317

318
	// AmbientLight
319

M
Mr.doob 已提交
320
	var option = new UI.Row();
321
	option.setClass( 'option' );
322
	option.setTextContent( strings.getKey( 'menubar/add/ambientlight' ) );
323
	option.onClick( function () {
324

325
		var color = 0x222222;
M
Mr.doob 已提交
326

327 328
		var light = new THREE.AmbientLight( color );
		light.name = 'AmbientLight';
M
Mr.doob 已提交
329

330
		editor.execute( new AddObjectCommand( light ) );
331

332 333 334
	} );
	options.add( option );

335
	// DirectionalLight
336

M
Mr.doob 已提交
337
	var option = new UI.Row();
338
	option.setClass( 'option' );
339
	option.setTextContent( strings.getKey( 'menubar/add/directionallight' ) );
340
	option.onClick( function () {
M
Mr.doob 已提交
341

M
Mr.doob 已提交
342 343
		var color = 0xffffff;
		var intensity = 1;
M
Mr.doob 已提交
344

345 346 347
		var light = new THREE.DirectionalLight( color, intensity );
		light.name = 'DirectionalLight';
		light.target.name = 'DirectionalLight Target';
M
Mr.doob 已提交
348

349
		light.position.set( 5, 10, 7.5 );
M
Mr.doob 已提交
350

351
		editor.execute( new AddObjectCommand( light ) );
M
Mr.doob 已提交
352

353 354
	} );
	options.add( option );
M
Mr.doob 已提交
355

356
	// HemisphereLight
357

M
Mr.doob 已提交
358
	var option = new UI.Row();
359
	option.setClass( 'option' );
360
	option.setTextContent( strings.getKey( 'menubar/add/hemispherelight' ) );
361
	option.onClick( function () {
362

363 364
		var skyColor = 0x00aaff;
		var groundColor = 0xffaa00;
M
Mr.doob 已提交
365
		var intensity = 1;
366

367 368
		var light = new THREE.HemisphereLight( skyColor, groundColor, intensity );
		light.name = 'HemisphereLight';
369

370
		light.position.set( 0, 10, 0 );
371

372
		editor.execute( new AddObjectCommand( light ) );
373

374 375 376
	} );
	options.add( option );

377
	// PointLight
378

M
Mr.doob 已提交
379
	var option = new UI.Row();
380
	option.setClass( 'option' );
381
	option.setTextContent( strings.getKey( 'menubar/add/pointlight' ) );
382
	option.onClick( function () {
383

384
		var color = 0xffffff;
M
Mr.doob 已提交
385
		var intensity = 1;
386
		var distance = 0;
387

388 389
		var light = new THREE.PointLight( color, intensity, distance );
		light.name = 'PointLight';
390

391
		editor.execute( new AddObjectCommand( light ) );
392

393 394
	} );
	options.add( option );
395

396
	// SpotLight
397

M
Mr.doob 已提交
398
	var option = new UI.Row();
399
	option.setClass( 'option' );
400
	option.setTextContent( strings.getKey( 'menubar/add/spotlight' ) );
T
Temdog007 已提交
401
	option.onClick( function () {
402

403 404 405 406 407
		var color = 0xffffff;
		var intensity = 1;
		var distance = 0;
		var angle = Math.PI * 0.1;
		var penumbra = 0;
408

409 410 411 412 413
		var light = new THREE.SpotLight( color, intensity, distance, angle, penumbra );
		light.name = 'SpotLight';
		light.target.name = 'SpotLight Target';

		light.position.set( 5, 10, 7.5 );
414

415
		editor.execute( new AddObjectCommand( light ) );
416

417 418
	} );
	options.add( option );
419

420 421 422 423
	//

	options.add( new UI.HorizontalRule() );

424
	// OrthographicCamera
425

M
Mr.doob 已提交
426
	var option = new UI.Row();
427
	option.setClass( 'option' );
428
	option.setTextContent( strings.getKey( 'menubar/add/orthographiccamera' ) );
T
Temdog007 已提交
429
	option.onClick( function () {
430

431 432
		var camera = new THREE.OrthographicCamera();
		camera.name = 'OrthographicCamera';
433

434
		editor.execute( new AddObjectCommand( camera ) );
435 436 437 438

	} );
	options.add( option );

439
	// PerspectiveCamera
T
Temdog007 已提交
440 441

	var option = new UI.Row();
T
Temdog007 已提交
442
	option.setClass( 'option' );
443
	option.setTextContent( strings.getKey( 'menubar/add/perspectivecamera' ) );
T
Temdog007 已提交
444 445
	option.onClick( function () {

446 447
		var camera = new THREE.PerspectiveCamera();
		camera.name = 'PerspectiveCamera';
T
Temdog007 已提交
448

T
Temdog007 已提交
449 450 451 452
		editor.execute( new AddObjectCommand( camera ) );

	} );
	options.add( option );
T
Temdog007 已提交
453

454
	return container;
M
Mr.doob 已提交
455

T
Tristan VALCKE 已提交
456
};