123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276 |
- Menubar.Add = function ( editor ) {
- var menuConfig,
- optionsPanel,
- createOption,
- createDivider;
- var meshCount = 0;
- var lightCount = 0;
- // event handlers
- function onObject3DOptionClick () {
- var mesh = new THREE.Object3D();
- mesh.name = 'Object3D ' + ( ++ meshCount );
- editor.addObject( mesh );
- editor.select( mesh );
- }
- function onPlaneOptionClick () {
- var width = 200;
- var height = 200;
- var widthSegments = 1;
- var heightSegments = 1;
- var geometry = new THREE.PlaneGeometry( width, height, widthSegments, heightSegments );
- var material = new THREE.MeshPhongMaterial();
- var mesh = new THREE.Mesh( geometry, material );
- mesh.name = 'Plane ' + ( ++ meshCount );
- editor.addObject( mesh );
- editor.select( mesh );
- };
- function onBoxOptionClick () {
- var width = 100;
- var height = 100;
- var depth = 100;
- var widthSegments = 1;
- var heightSegments = 1;
- var depthSegments = 1;
- var geometry = new THREE.BoxGeometry( width, height, depth, widthSegments, heightSegments, depthSegments );
- var mesh = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial() );
- mesh.name = 'Box ' + ( ++ meshCount );
- editor.addObject( mesh );
- editor.select( mesh );
- }
-
- function onCircleOptionClick () {
- var radius = 20;
- var segments = 8;
- var geometry = new THREE.CircleGeometry( radius, segments );
- var mesh = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial() );
- mesh.name = 'Circle ' + ( ++ meshCount );
- editor.addObject( mesh );
- editor.select( mesh );
- }
- function onCylinderOptionClick () {
- var radiusTop = 20;
- var radiusBottom = 20;
- var height = 100;
- var radiusSegments = 8;
- var heightSegments = 1;
- var openEnded = false;
- var geometry = new THREE.CylinderGeometry( radiusTop, radiusBottom, height, radiusSegments, heightSegments, openEnded );
- var mesh = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial() );
- mesh.name = 'Cylinder ' + ( ++ meshCount );
- editor.addObject( mesh );
- editor.select( mesh );
- }
- function onSphereOptionClick () {
- var radius = 75;
- var widthSegments = 32;
- var heightSegments = 16;
- var geometry = new THREE.SphereGeometry( radius, widthSegments, heightSegments );
- var mesh = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial() );
- mesh.name = 'Sphere ' + ( ++ meshCount );
- editor.addObject( mesh );
- editor.select( mesh );
- }
- function onIcosahedronOptionClick () {
- var radius = 75;
- var detail = 2;
- var geometry = new THREE.IcosahedronGeometry ( radius, detail );
- var mesh = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial() );
- mesh.name = 'Icosahedron ' + ( ++ meshCount );
- editor.addObject( mesh );
- editor.select( mesh );
- }
- function onTorusOptionClick () {
- var radius = 100;
- var tube = 40;
- var radialSegments = 8;
- var tubularSegments = 6;
- var arc = Math.PI * 2;
- var geometry = new THREE.TorusGeometry( radius, tube, radialSegments, tubularSegments, arc );
- var mesh = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial() );
- mesh.name = 'Torus ' + ( ++ meshCount );
- editor.addObject( mesh );
- editor.select( mesh );
- }
- function onTorusKnotOptionClick () {
- var radius = 100;
- var tube = 40;
- var radialSegments = 64;
- var tubularSegments = 8;
- var p = 2;
- var q = 3;
- var heightScale = 1;
- var geometry = new THREE.TorusKnotGeometry( radius, tube, radialSegments, tubularSegments, p, q, heightScale );
- var mesh = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial() );
- mesh.name = 'TorusKnot ' + ( ++ meshCount );
- editor.addObject( mesh );
- editor.select( mesh );
- }
- function onSpriteOptionClick () {
- var sprite = new THREE.Sprite( new THREE.SpriteMaterial() );
- sprite.name = 'Sprite ' + ( ++ meshCount );
- editor.addObject( sprite );
- editor.select( sprite );
- }
- function onPointLightOptionClick () {
- var color = 0xffffff;
- var intensity = 1;
- var distance = 0;
- var light = new THREE.PointLight( color, intensity, distance );
- light.name = 'PointLight ' + ( ++ lightCount );
- editor.addObject( light );
- editor.select( light );
- }
- function onSpotLightOptionClick () {
- var color = 0xffffff;
- var intensity = 1;
- var distance = 0;
- var angle = Math.PI * 0.1;
- var exponent = 10;
- var light = new THREE.SpotLight( color, intensity, distance, angle, exponent );
- light.name = 'SpotLight ' + ( ++ lightCount );
- light.target.name = 'SpotLight ' + ( lightCount ) + ' Target';
- light.position.set( 0, 1, 0 ).multiplyScalar( 200 );
- editor.addObject( light );
- editor.select( light );
- }
- function onDirectionalLightOptionClick () {
- var color = 0xffffff;
- var intensity = 1;
- var light = new THREE.DirectionalLight( color, intensity );
- light.name = 'DirectionalLight ' + ( ++ lightCount );
- light.target.name = 'DirectionalLight ' + ( lightCount ) + ' Target';
- light.position.set( 1, 1, 1 ).multiplyScalar( 200 );
- editor.addObject( light );
- editor.select( light );
- }
- function onHemisphereLightOptionClick () {
- var skyColor = 0x00aaff;
- var groundColor = 0xffaa00;
- var intensity = 1;
- var light = new THREE.HemisphereLight( skyColor, groundColor, intensity );
- light.name = 'HemisphereLight ' + ( ++ lightCount );
- light.position.set( 1, 1, 1 ).multiplyScalar( 200 );
- editor.addObject( light );
- editor.select( light );
- }
- function onAmbientLightOptionClick() {
- var color = 0x222222;
- var light = new THREE.AmbientLight( color );
- light.name = 'AmbientLight ' + ( ++ lightCount );
- editor.addObject( light );
- editor.select( light );
- }
- // configure menu contents
- createOption = UI.MenubarHelper.createOption;
- createDivider = UI.MenubarHelper.createDivider;
- menuConfig = [
- createOption( 'Object3D', onObject3DOptionClick ),
- createDivider(),
- createOption( 'Plane', onPlaneOptionClick ),
- createOption( 'Box', onBoxOptionClick ),
- createOption( 'Circle', onCircleOptionClick ),
- createOption( 'Cylinder', onCylinderOptionClick ),
- createOption( 'Sphere', onSphereOptionClick ),
- createOption( 'Icosahedron', onIcosahedronOptionClick ),
- createOption( 'Torus', onTorusOptionClick ),
- createOption( 'Torus Knot', onTorusKnotOptionClick ),
- createDivider(),
- createOption( 'Sprite', onSpriteOptionClick ),
- createDivider(),
- createOption( 'Point light', onPointLightOptionClick ),
- createOption( 'Spot light', onSpotLightOptionClick ),
- createOption( 'Directional light', onDirectionalLightOptionClick ),
- createOption( 'Hemisphere light', onHemisphereLightOptionClick ),
- createOption( 'Ambient light', onAmbientLightOptionClick )
- ];
- optionsPanel = UI.MenubarHelper.createOptionsPanel( menuConfig );
- return UI.MenubarHelper.createMenuContainer( 'Add', optionsPanel );
- }
|