123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525 |
- // String
- UI.ParamString = function ( name ) {
- UI.Panel.call( this );
- var scope = this;
- var row = new UI.Panel();
- this.name = new UI.Text( name ).setWidth( '90px' ).setColor( '#666' );
- this.string = new UI.Input().setWidth( '150px' ).setColor( '#444' ).setFontSize( '12px' );
- this.string.dom.name = name;
- row.add( this.name, this.string );
- this.add( row );
- return this;
- };
- UI.ParamString.prototype = Object.create( UI.Panel.prototype );
- UI.ParamString.prototype.setValue = function ( value ) {
- this.string.setValue( value );
- };
- UI.ParamString.prototype.getValue = function ( value ) {
- return this.string.getValue( value );
- };
- // Integer
- UI.ParamInteger = function ( name ) {
- UI.Panel.call( this );
- var scope = this;
- var row = new UI.Panel();
- this.name = new UI.Text( name ).setWidth( '90px' ).setColor( '#666' );
- this.integer = new UI.Integer();
- this.integer.dom.name = name;
-
- row.add( this.name, this.integer );
- this.add( row );
- return this;
- };
- UI.ParamInteger.prototype = Object.create( UI.Panel.prototype );
- UI.ParamInteger.prototype.setValue = function ( value ) {
- this.integer.setValue( value );
- };
- UI.ParamInteger.prototype.getValue = function () {
- return this.integer.getValue();
- };
- // Float
- UI.ParamFloat = function ( name ) {
- UI.Panel.call( this );
- var scope = this;
- var row = new UI.Panel();
- this.name = new UI.Text( name ).setWidth( '90px' ).setColor( '#666' );
- this.float = new UI.Number();
- this.float.dom.name = name;
-
- row.add( this.name, this.float );
- this.add( row );
- return this;
- };
- UI.ParamFloat.prototype = Object.create( UI.Panel.prototype );
- UI.ParamFloat.prototype.setValue = function ( value ) {
- this.float.setValue( value );
- };
- UI.ParamFloat.prototype.getValue = function () {
- return this.float.getValue();
- };
- // Bool
- UI.ParamBool = function ( name ) {
- UI.Panel.call( this );
- var scope = this;
- var row = new UI.Panel();
- this.name = new UI.Text( name ).setWidth( '90px' ).setColor( '#666' ).setPosition( 'relative' ).setLeft( '25px' );
- this.bool = new UI.Checkbox().setPosition( 'absolute' ).setLeft( '10px' );
- this.bool.dom.name = name;
- row.add( this.name, this.bool );
- this.add( row );
- return this;
- };
- UI.ParamBool.prototype = Object.create( UI.Panel.prototype );
- UI.ParamBool.prototype.setValue = function ( value ) {
- this.bool.setValue( value );
- };
- UI.ParamBool.prototype.getValue = function () {
- return this.bool.getValue();
- };
- // Vector3
- UI.ParamVector3 = function ( name, scaleLock ) {
- UI.Panel.call( this );
- scaleLock = scaleLock ? scaleLock : false;
- var scope = this;
- var row = new UI.Panel();
- this.name = new UI.Text( name ).setWidth( '90px' ).setColor( '#666' );
- this.x = new UI.Number().setWidth( '50px' ).onChange( setYZ );
- this.y = new UI.Number().setWidth( '50px' ).onChange( setXZ );
- this.z = new UI.Number().setWidth( '50px' ).onChange( setXY );
- this.x.dom.name = name;
- this.y.dom.name = name;
- this.z.dom.name = name;
-
- row.add( this.name, this.x, this.y, this.z );
- if ( scaleLock ) {
-
- this.scaleLock = new UI.Checkbox().setPosition( 'absolute' ).setLeft( '75px' );
- row.add( this.scaleLock );
- }
- this.add( row );
- function setYZ( event ) {
- if ( scope.scaleLock && scope.scaleLock.getValue() && event.srcElement.oldValue ) {
- var scale = event.srcElement.value / event.srcElement.oldValue;
- scope.y.setValue( parseFloat(scope.y.getValue()) * scale );
- scope.z.setValue( parseFloat(scope.z.getValue()) * scale );
- }
- }
- function setXZ( event ) {
- if ( scope.scaleLock && scope.scaleLock.getValue() && event.srcElement.oldValue ) {
- var scale = event.srcElement.value / event.srcElement.oldValue;
- scope.x.setValue( parseFloat(scope.x.getValue()) * scale );
- scope.z.setValue( parseFloat(scope.z.getValue()) * scale );
- }
- }
- function setXY( event ) {
- if ( scope.scaleLock && scope.scaleLock.getValue() && event.srcElement.oldValue ) {
- var scale = event.srcElement.value / event.srcElement.oldValue;
- scope.x.setValue( parseFloat(scope.x.getValue()) * scale );
- scope.y.setValue( parseFloat(scope.y.getValue()) * scale );
- }
- }
- return this;
- };
- UI.ParamVector3.prototype = Object.create( UI.Panel.prototype );
- UI.ParamVector3.prototype.setValue = function ( value ) {
- this.x.setValue( value.x );
- this.y.setValue( value.y );
- this.z.setValue( value.z );
- };
- UI.ParamVector3.prototype.getValue = function () {
- return new THREE.Vector3( this.x.getValue(), this.y.getValue(), this.z.getValue() );
- };
- // Color
- UI.ParamColor = function ( name ) {
- UI.Panel.call( this );
- var scope = this;
- var row = new UI.Panel();
- this.name = new UI.Text( name ).setWidth( '90px' ).setColor( '#666' );
- this.color = new UI.Color();
- this.color.dom.name = name;
-
- row.add( this.name, this.color );
- this.add( row );
- return this;
- };
- UI.ParamColor.prototype = Object.create( UI.Panel.prototype );
- UI.ParamColor.prototype.setValue = function ( color ) {
- this.color.setValue( '#' + color.getHexString() );
- };
- UI.ParamColor.prototype.getValue = function () {
- return this.color.getHexValue();
- };
- // Select
- UI.ParamSelect = function ( name ) {
- UI.Panel.call( this );
- var scope = this;
- this.onChangeCallback;
- var row = new UI.Panel();
- this.name = new UI.Text( name ).setWidth( '90px' ).setColor( '#666' );
- this.select = new UI.Select().setWidth( '150px' ).setColor( '#444' ).setFontSize( '12px' );
- this.select.dom.name = name;
- row.add( this.name, this.select );
- this.add( row );
- return this;
- };
- UI.ParamSelect.prototype = Object.create( UI.Panel.prototype );
- UI.ParamSelect.prototype.setValue = function ( value ) {
- this.select.setValue( value );
- };
- UI.ParamSelect.prototype.getValue = function ( value ) {
- return this.select.getValue( value );
- };
- UI.ParamSelect.prototype.setOptions = function ( value ) {
- this.select.setOptions( value );
- };
- // Texture
- UI.Texture = function ( position ) {
- UI.Element.call( this );
- var scope = this;
- var image = new Image();
- this.texture = null;
- this.dom = document.createElement( 'input' );
- this.dom.type = 'file';
- this.dom.style.position = position || 'relative';
- this.onChangeCallback = null;
- this.dom.addEventListener( 'change', function ( event ) {
- var file = event.target.files[ 0 ];
- if ( file.type.match( 'image.*' ) ) {
- var reader = new FileReader();
- reader.addEventListener( 'load', function ( event ) {
- var image = document.createElement( 'img' );
- image.addEventListener( 'load', function( event ) {
- scope.texture = new THREE.Texture( this );
- scope.texture.needsUpdate = true;
- // remember the original filename (including extension)
- // this is used for url field in the scene export
- scope.texture.sourceFile = file.name;
- // generate unique name per texture
- // based on source file name
- var chunks = file.name.split( '.' );
- var extension = chunks.pop().toLowerCase();
- var filename = chunks.join( '.' );
- if ( ! ( filename in scope.textureNameMap ) ) {
- scope.textureNameMap[ filename ] = true;
- scope.texture.name = filename;
- } else {
- scope.texture.name = filename + "_" + scope.texture.id;
- }
- if ( scope.onChangeCallback ) scope.onChangeCallback();
- }, false );
- image.src = event.target.result;
- }, false );
- reader.readAsDataURL( file );
- }
- }, false );
- return this;
- };
- UI.Texture.prototype = Object.create( UI.Element.prototype );
- UI.Texture.prototype.textureNameMap = {};
- UI.Texture.prototype.getValue = function () {
- return this.texture;
- };
- UI.Texture.prototype.setValue = function ( value ) {
- this.texture = value;
- };
- UI.Texture.prototype.onChange = function ( callback ) {
- this.onChangeCallback = callback;
- return this;
- };
- // CubeTexture
- UI.CubeTexture = function ( position ) {
- UI.Element.call( this );
- var scope = this;
- this.texture = new THREE.Texture( [], new THREE.CubeReflectionMapping() );
- this.dom = document.createElement( 'input' );
- this.dom.type = 'file';
- this.dom.style.position = position || 'relative';
- this.onChangeCallback = null;
- this.dom.addEventListener( 'change', function ( event ) {
- var file = event.target.files[ 0 ];
- if ( file.type.match( 'image.*' ) ) {
- var reader = new FileReader();
- reader.addEventListener( 'load', function ( event ) {
- var image = document.createElement( 'img' );
- image.addEventListener( 'load', function( event ) {
- scope.texture.image = [ this, this, this, this, this, this ];
- scope.texture.needsUpdate = true;
- if ( scope.onChangeCallback ) scope.onChangeCallback();
- }, false );
- image.src = event.target.result;
- }, false );
- reader.readAsDataURL( file );
- }
- }, false );
- return this;
- };
- UI.CubeTexture.prototype = Object.create( UI.Element.prototype );
- UI.CubeTexture.prototype.getValue = function () {
- return this.texture;
- };
- UI.CubeTexture.prototype.setValue = function ( value ) {
- this.texture = value;
- };
- UI.CubeTexture.prototype.onChange = function ( callback ) {
- this.onChangeCallback = callback;
- return this;
- };
- // Json
- UI.ParamJson = function ( name ) {
- UI.Panel.call( this );
- var scope = this;
- var row = new UI.Panel();
- this.name = new UI.Text( name ).setWidth( '90px' ).setColor( '#666' );
- this.json = new UI.TextArea().setWidth( '150px' ).setHeight( '40px' ).setColor( '#444' ).setFontSize( '12px' );
- this.json.dom.name = name;
- this.json.onKeyUp( function () {
- try {
- JSON.parse( scope.json.getValue() );
- scope.json.setBorderColor( '#ccc' );
- scope.json.setBackgroundColor( '' );
- } catch ( error ) {
- scope.json.setBorderColor( '#f00' );
- scope.json.setBackgroundColor( 'rgba(255,0,0,0.25)' );
- }
- } );
-
- row.add( this.name, this.json );
- this.add( row );
- return this;
- };
- UI.ParamJson.prototype = Object.create( UI.Panel.prototype );
- UI.ParamJson.prototype.setValue = function ( value ) {
- this.json.setValue( value );
- };
- UI.ParamJson.prototype.getValue = function () {
- return this.json.getValue();
- };
|