123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302 |
- Sidebar.Attributes = function ( signals ) {
- var scope = this;
- var object;
- var param = {};
- var primaryParams = [
- 'name',
- 'parent',
- 'geometry',
- 'material',
- 'position',
- 'rotation',
- 'scale',
- 'width',
- 'height',
- 'depth',
- 'widthSegments',
- 'heightSegments',
- 'depthSegments',
- 'radialSegments',
- 'tubularSegments',
- 'radius',
- 'radiusTop',
- 'radiusBottom',
- 'phiStart',
- 'phiLength',
- 'thetaStart',
- 'thetaLength',
- 'tube',
- 'arc',
- 'detail',
- 'p',
- 'q',
- 'heightScale',
- 'openEnded',
- 'color',
- 'groundColor',
- 'ambient',
- 'emissive',
- 'specular',
- 'reflectivity',
- 'shininess',
- 'intensity',
- 'opacity',
- 'transparent',
- 'metal',
- 'wireframe',
- 'visible',
- 'userData'
- ];
-
- var secondaryParams = [
- 'castShadow',
- 'receiveShadow',
- 'useQuaternion',
- 'fog',
- 'depthTest',
- 'depthWrite',
- 'dynamic'
- ];
- var integerParams = [
- 'widthSegments',
- 'heightSegments',
- 'depthSegments',
- 'radialSegments',
- 'tubularSegments'
- ];
- var container = new UI.Panel();
- var group1 = new UI.Panel().setBorderTop( '1px solid #ccc' ).setPadding( '10px' );
- var group2 = new UI.Panel().setBorderTop( '1px solid #ccc' ).setPadding( '10px' ).setOpacity( 0.5 );
- var group3 = new UI.Panel().setBorderTop( '1px solid #ccc' ).setPadding( '10px' ).setOpacity( 0.25 );//.setDisplay( 'none' );
- container.add( group1, group2, group3 );
- signals.objectChanged.add( function ( changed ) {
-
- if ( object === changed ) updateUI();
- } );
- signals.selected.add( function ( selected ) {
-
- var selected = editor.listSelected();
- object = ( selected.length ) ? selected[0] : null;
- createUI();
- updateUI();
- } );
- function createUI() {
- param = {};
- while ( group1.dom.hasChildNodes() ) group1.dom.removeChild( group1.dom.lastChild );
- while ( group2.dom.hasChildNodes() ) group2.dom.removeChild( group2.dom.lastChild );
- while ( group3.dom.hasChildNodes() ) group3.dom.removeChild( group3.dom.lastChild );
- if ( object ) {
- for ( var i in primaryParams ) addElement( primaryParams[i], group1 );
- for ( var i in secondaryParams ) addElement( secondaryParams[i], group2 );
- for ( var key in object ) addElement( key, group3 );
- }
- }
- function addElement( key, parent ) {
- if ( object[ key ] !== undefined && param[ key ] === undefined ) {
- if ( typeof object[ key ] === 'string' ) {
- param[ key ] = new UI.ParamString( key ).onChange( updateParam );
- parent.add( param[ key ] );
- } else if ( typeof object[ key ] === 'boolean' ) {
- param[ key ] = new UI.ParamBool( key ).onChange( updateParam );
- parent.add( param[ key ] );
- } else if ( typeof object[ key ] === 'number' ) {
- if ( integerParams.indexOf( key ) != -1 )
- param[ key ] = new UI.ParamInteger( key ).onChange( updateParam );
- else
- param[ key ] = new UI.ParamFloat( key ).onChange( updateParam );
-
- parent.add( param[ key ] );
- } else if ( object[ key ] instanceof THREE.Vector3 ) {
- var hasLock = ( key === 'scale' ) ? true : false;
- param[ key ] = new UI.ParamVector3( key, hasLock ).onChange( updateParam );
- parent.add( param[ key ] );
- } else if ( object[ key ] instanceof THREE.Color ) {
- param[ key ] = new UI.ParamColor( key ).onChange( updateParam );
- parent.add( param[ key ] );
- } else if ( key === 'parent' ) {
- param[ key ] = new UI.ParamSelect( key ).onChange( updateParam );
- param[ key ].name.setColor( '#0080f0' ).onClick( function(){ editor.select( editor.objects[ param[ key ].getValue() ] ) } );
- parent.add( param[ key ] );
- } else if ( key === 'geometry' ) {
- param[ key ] = new UI.ParamSelect( key ).onChange( updateParam );
- param[ key ].name.setColor( '#0080f0' ).onClick( function(){ editor.select( editor.geometries[ param[ key ].getValue() ] ) } );
- parent.add( param[ key ] );
- } else if ( key == 'material' ) {
- param[ key ] = new UI.ParamSelect( key ).onChange( updateParam );
- param[ key ].name.setColor( '#0080f0' ).onClick( function(){ editor.select( editor.materials[ param[ key ].getValue() ] ) } );
- parent.add( param[ key ] );
- } else if ( key == 'userData' ) {
- param[ key ] = new UI.ParamJson( key ).onChange( updateParam );
- parent.add( param[ key ] );
- }
- }
-
- }
- function updateUI() {
- if ( object ) {
- for ( var key in object ) {
- if ( typeof object[ key ] === 'string' ) param[ key ].setValue( object[ key ] );
- else if ( typeof object[ key ] === 'boolean' ) param[ key ].setValue( object[ key ] );
- else if ( typeof object[ key ] === 'number' ) param[ key ].setValue( object[ key ] );
- else if ( object[ key ] instanceof THREE.Vector3 ) param[ key ].setValue( object[ key ] );
- else if ( object[ key ] instanceof THREE.Color ) param[ key ].setValue( object[ key ] );
- else if ( object[ key ] && key === 'parent' ) {
- var options = {};
- for ( var uuid in editor.objects ) if ( object.uuid != uuid ) options[ uuid ] = editor.objects[ uuid ].name;
- param[ key ].setOptions( options );
- if ( object.parent !== undefined ) param[ key ].setValue( object.parent.uuid );
- } else if ( object[ key ] && key === 'geometry' ) {
- var options = {};
- for ( var uuid in editor.geometries ) if ( object.uuid != uuid ) options[ uuid ] = editor.geometries[ uuid ].name;
- param[ key ].setOptions( options );
- if ( object.geometry !== undefined ) param[ key ].setValue( object.geometry.uuid );
- } else if ( object[ key ] && key === 'material' ) {
- var options = {};
- for ( var uuid in editor.materials ) if ( object.uuid != uuid ) options[ uuid ] = editor.materials[ uuid ].name;
- param[ key ].setOptions( options );
- if ( object.material !== undefined ) param[ key ].setValue( object.material.uuid );
- } else if ( key == 'userData' ) {
- try {
- param[ key ].setValue( JSON.stringify( object.userData, null, ' ' ) );
- } catch ( error ) {
- console.log( error );
- }
- }
- }
- }
- }
- function updateParam( event ) {
- var key = event.srcElement.name;
- if ( typeof object[ key ] === 'string' ) object[ key ] = param[ key ].getValue();
- else if ( typeof object[ key ] === 'boolean' ) object[ key ] = param[ key ].getValue();
- else if ( typeof object[ key ] === 'number' ) object[ key ] = param[ key ].getValue();
- else if ( object[ key ] instanceof THREE.Color ) object[ key ].setHex( param[ key ].getValue() );
- else if ( object[ key ] instanceof THREE.Vector3 ) object[ key ].copy( param[ key ].getValue() );
- else if ( key === 'parent' ) {
- if ( param[ key ].getValue() != object.uuid )
- editor.parent( object, editor.objects[ param[ key ].getValue() ] );
- } else if ( key === 'geometry' ) {
- if ( param[ key ].getValue() != object.geometry.uuid )
- object.geometry = editor.geometries[ param[ key ].getValue() ];
- } else if ( key === 'material' ) {
- if ( param[ key ].getValue() != object.material.uuid )
- object.material = editor.materials[ param[ key ].getValue() ];
- } else if ( key === 'userData' ) {
- try {
- object.userData = JSON.parse( param[ key ].getValue() );
- } catch ( error ) {
- console.log( error );
- }
- }
- if ( object instanceof THREE.Object3D ) {
- signals.objectChanged.dispatch( object );
- } else if ( object instanceof THREE.Geometry ) {
- var geoParams = {};
- for ( var i in param ) geoParams[ i ] = param[ i ].getValue();
- editor.updateGeometry( object, geoParams );
- } else if ( object instanceof THREE.Material ) {
- signals.materialChanged.dispatch( object );
- }
- signals.sceneChanged.dispatch( editor.scene );
- }
- return container;
- }
|