|
@@ -1,51 +1,68 @@
|
|
Sidebar.Properties.Material = function ( signals ) {
|
|
Sidebar.Properties.Material = function ( signals ) {
|
|
|
|
|
|
|
|
+ var materials = {
|
|
|
|
+
|
|
|
|
+ 'LineBasicMaterial': THREE.LineBasicMaterial,
|
|
|
|
+ 'MeshBasicMaterial': THREE.MeshBasicMaterial,
|
|
|
|
+ 'MeshDepthMaterial': THREE.MeshDepthMaterial,
|
|
|
|
+ 'MeshFaceMaterial': THREE.MeshFaceMaterial,
|
|
|
|
+ 'MeshLambertMaterial': THREE.MeshLambertMaterial,
|
|
|
|
+ 'MeshNormalMaterial': THREE.MeshNormalMaterial,
|
|
|
|
+ 'MeshPhongMaterial': THREE.MeshPhongMaterial,
|
|
|
|
+ 'ParticleBasicMaterial': THREE.ParticleBasicMaterial,
|
|
|
|
+ 'ParticleCanvasMaterial': THREE.ParticleCanvasMaterial,
|
|
|
|
+ 'ParticleDOMMaterial': THREE.ParticleDOMMaterial,
|
|
|
|
+ 'ShaderMaterial': THREE.ShaderMaterial,
|
|
|
|
+ 'Material': THREE.Material
|
|
|
|
+
|
|
|
|
+ };
|
|
|
|
+
|
|
var container = new UI.Panel();
|
|
var container = new UI.Panel();
|
|
container.setDisplay( 'none' );
|
|
container.setDisplay( 'none' );
|
|
|
|
|
|
- container.add( new UI.Text().setText( 'MATERIAL' ).setColor( '#666' ) );
|
|
|
|
|
|
+ container.add( new UI.Text().setValue( 'MATERIAL' ).setColor( '#666' ) );
|
|
container.add( new UI.Break(), new UI.Break() );
|
|
container.add( new UI.Break(), new UI.Break() );
|
|
|
|
|
|
- container.add( new UI.Text().setText( 'Name' ).setColor( '#666' ) );
|
|
|
|
|
|
+ container.add( new UI.Text().setValue( 'Name' ).setColor( '#666' ) );
|
|
var materialName = new UI.Text( 'absolute' ).setLeft( '90px' ).setColor( '#444' ).setFontSize( '12px' );
|
|
var materialName = new UI.Text( 'absolute' ).setLeft( '90px' ).setColor( '#444' ).setFontSize( '12px' );
|
|
container.add( materialName );
|
|
container.add( materialName );
|
|
container.add( new UI.HorizontalRule() );
|
|
container.add( new UI.HorizontalRule() );
|
|
|
|
|
|
- container.add( new UI.Text().setText( 'Class' ).setColor( '#666' ) );
|
|
|
|
- var materialClass = new UI.Text( 'absolute' ).setLeft( '90px' ).setColor( '#444' ).setFontSize( '12px' );
|
|
|
|
|
|
+ container.add( new UI.Text().setValue( 'Class' ).setColor( '#666' ) );
|
|
|
|
+ var materialClass = new UI.Select( 'absolute' ).setOptions( [ 'LineBasicMaterial', 'MeshBasicMaterial', 'MeshDepthMaterial', 'MeshFaceMaterial', 'MeshLambertMaterial', 'MeshNormalMaterial', 'MeshPhongMaterial', 'ParticleBasicMaterial', 'ParticleCanvasMaterial', 'ParticleDOMMaterial', 'ShaderMaterial' ] ).setLeft( '90px' ).setWidth( '180px' ).setColor( '#444' ).setFontSize( '12px' ).onChange( update );
|
|
container.add( materialClass );
|
|
container.add( materialClass );
|
|
container.add( new UI.HorizontalRule() );
|
|
container.add( new UI.HorizontalRule() );
|
|
|
|
|
|
- container.add( new UI.Text().setText( 'Color' ).setColor( '#666' ) );
|
|
|
|
-
|
|
|
|
|
|
+ container.add( new UI.Text().setValue( 'Color' ).setColor( '#666' ) );
|
|
|
|
+
|
|
var materialColor = new UI.Color( 'absolute' ).setLeft( '90px' ).onChange( update );
|
|
var materialColor = new UI.Color( 'absolute' ).setLeft( '90px' ).onChange( update );
|
|
container.add( materialColor );
|
|
container.add( materialColor );
|
|
container.add( new UI.HorizontalRule() );
|
|
container.add( new UI.HorizontalRule() );
|
|
|
|
|
|
- container.add( new UI.Text().setText( 'Ambient' ).setColor( '#666' ) );
|
|
|
|
-
|
|
|
|
|
|
+ container.add( new UI.Text().setValue( 'Ambient' ).setColor( '#666' ) );
|
|
|
|
+
|
|
var materialAmbient = new UI.Color( 'absolute' ).setLeft( '90px' ).onChange( update );
|
|
var materialAmbient = new UI.Color( 'absolute' ).setLeft( '90px' ).onChange( update );
|
|
container.add( materialAmbient );
|
|
container.add( materialAmbient );
|
|
container.add( new UI.HorizontalRule() );
|
|
container.add( new UI.HorizontalRule() );
|
|
|
|
|
|
- container.add( new UI.Text().setText( 'Specular' ).setColor( '#666' ) );
|
|
|
|
-
|
|
|
|
|
|
+ container.add( new UI.Text().setValue( 'Specular' ).setColor( '#666' ) );
|
|
|
|
+
|
|
var materialSpecular = new UI.Color( 'absolute' ).setLeft( '90px' ).onChange( update );
|
|
var materialSpecular = new UI.Color( 'absolute' ).setLeft( '90px' ).onChange( update );
|
|
container.add( materialSpecular );
|
|
container.add( materialSpecular );
|
|
container.add( new UI.HorizontalRule() );
|
|
container.add( new UI.HorizontalRule() );
|
|
|
|
|
|
- container.add( new UI.Text().setText( 'Map' ).setColor( '#666' ) );
|
|
|
|
|
|
+ container.add( new UI.Text().setValue( 'Map' ).setColor( '#666' ) );
|
|
var materialMap = new UI.Text( 'absolute' ).setLeft( '90px' ).setColor( '#444' ).setFontSize( '12px' );
|
|
var materialMap = new UI.Text( 'absolute' ).setLeft( '90px' ).setColor( '#444' ).setFontSize( '12px' );
|
|
container.add( materialMap );
|
|
container.add( materialMap );
|
|
container.add( new UI.HorizontalRule() );
|
|
container.add( new UI.HorizontalRule() );
|
|
|
|
|
|
- container.add( new UI.Text().setText( 'Opacity' ).setColor( '#666' ) );
|
|
|
|
|
|
+ container.add( new UI.Text().setValue( 'Opacity' ).setColor( '#666' ) );
|
|
var materialOpacity = new UI.Number( 'absolute' ).setLeft( '90px' ).setWidth( '60px' ).setMin( 0 ).setMax( 1 ).onChange( update );
|
|
var materialOpacity = new UI.Number( 'absolute' ).setLeft( '90px' ).setWidth( '60px' ).setMin( 0 ).setMax( 1 ).onChange( update );
|
|
container.add( materialOpacity );
|
|
container.add( materialOpacity );
|
|
container.add( new UI.HorizontalRule() );
|
|
container.add( new UI.HorizontalRule() );
|
|
|
|
|
|
- container.add( new UI.Text().setText( 'Transparent' ).setColor( '#666' ) );
|
|
|
|
- var materialTransparent = new UI.Text( 'absolute' ).setLeft( '90px' ).setColor( '#444' ).setFontSize( '12px' );
|
|
|
|
|
|
+ container.add( new UI.Text().setValue( 'Transparent' ).setColor( '#666' ) );
|
|
|
|
+ var materialTransparent = new UI.Boolean( 'absolute' ).setLeft( '90px' ).onChange( update );
|
|
container.add( materialTransparent );
|
|
container.add( materialTransparent );
|
|
|
|
|
|
//
|
|
//
|
|
@@ -54,25 +71,39 @@ Sidebar.Properties.Material = function ( signals ) {
|
|
|
|
|
|
function update() {
|
|
function update() {
|
|
|
|
|
|
- if ( selected ) {
|
|
|
|
|
|
+ var material = selected.material;
|
|
|
|
+
|
|
|
|
+ if ( material ) {
|
|
|
|
+
|
|
|
|
+ if ( material instanceof materials[ materialClass.getValue() ] == false ) {
|
|
|
|
+
|
|
|
|
+ material = new materials[ materialClass.getValue() ];
|
|
|
|
+ selected.material = material;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if ( material.color ) {
|
|
|
|
+
|
|
|
|
+ material.color.setHex( parseInt( materialColor.getValue().substr( 1 ), 16 ) );
|
|
|
|
|
|
- selected.color.setHex( parseInt( materialColor.getValue().substr( 1 ), 16 ) );
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- if ( selected.ambient ) {
|
|
|
|
|
|
+ if ( material.ambient ) {
|
|
|
|
|
|
- selected.ambient.setHex( parseInt( materialAmbient.getValue().substr( 1 ), 16 ) );
|
|
|
|
|
|
+ material.ambient.setHex( parseInt( materialAmbient.getValue().substr( 1 ), 16 ) );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- if ( selected.specular ) {
|
|
|
|
|
|
+ if ( material.specular ) {
|
|
|
|
|
|
- selected.specular.setHex( parseInt( materialSpecular.getValue().substr( 1 ), 16 ) );
|
|
|
|
|
|
+ material.specular.setHex( parseInt( materialSpecular.getValue().substr( 1 ), 16 ) );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- selected.opacity = materialOpacity.getValue();
|
|
|
|
|
|
+ material.opacity = materialOpacity.getValue();
|
|
|
|
+ material.transparent = materialTransparent.getValue();
|
|
|
|
|
|
- signals.materialChanged.dispatch( selected );
|
|
|
|
|
|
+ signals.materialChanged.dispatch( material );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -82,18 +113,22 @@ Sidebar.Properties.Material = function ( signals ) {
|
|
|
|
|
|
if ( object && object.material ) {
|
|
if ( object && object.material ) {
|
|
|
|
|
|
- selected = object.material;
|
|
|
|
|
|
+ selected = object;
|
|
|
|
|
|
container.setDisplay( 'block' );
|
|
container.setDisplay( 'block' );
|
|
|
|
|
|
- materialName.setText( object.material.name );
|
|
|
|
- materialClass.setText( getMaterialInstanceName( object.material ) );
|
|
|
|
- materialColor.setValue( '#' + object.material.color.getHex().toString( 16 ) );
|
|
|
|
- if ( object.material.ambient ) materialAmbient.setValue( '#' + object.material.ambient.getHex().toString( 16 ) );
|
|
|
|
- if ( object.material.specular ) materialSpecular.setValue( '#' + object.material.specular.getHex().toString( 16 ) );
|
|
|
|
- materialMap.setText( object.material.map );
|
|
|
|
- materialOpacity.setValue( object.material.opacity );
|
|
|
|
- materialTransparent.setText( object.material.transparent );
|
|
|
|
|
|
+ var material = object.material;
|
|
|
|
+
|
|
|
|
+ materialName.setValue( material.name );
|
|
|
|
+ materialClass.setValue( getMaterialInstanceName( material ) );
|
|
|
|
+
|
|
|
|
+ if ( material.color ) materialColor.setValue( '#' + material.color.getHex().toString( 16 ) );
|
|
|
|
+ if ( material.ambient ) materialAmbient.setValue( '#' + material.ambient.getHex().toString( 16 ) );
|
|
|
|
+ if ( material.specular ) materialSpecular.setValue( '#' + material.specular.getHex().toString( 16 ) );
|
|
|
|
+ if ( material.map ) materialMap.setValue( material.map );
|
|
|
|
+
|
|
|
|
+ materialOpacity.setValue( material.opacity );
|
|
|
|
+ materialTransparent.setValue( material.transparent );
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
@@ -107,20 +142,11 @@ Sidebar.Properties.Material = function ( signals ) {
|
|
|
|
|
|
function getMaterialInstanceName( material ) {
|
|
function getMaterialInstanceName( material ) {
|
|
|
|
|
|
- // TODO: Is there a way of doing this automatically?
|
|
|
|
-
|
|
|
|
- if ( material instanceof THREE.LineBasicMaterial ) return "LineBasicMaterial";
|
|
|
|
- if ( material instanceof THREE.MeshBasicMaterial ) return "MeshBasicMaterial";
|
|
|
|
- if ( material instanceof THREE.MeshDepthMaterial ) return "MeshDepthMaterial";
|
|
|
|
- if ( material instanceof THREE.MeshFaceMaterial ) return "MeshFaceMaterial";
|
|
|
|
- if ( material instanceof THREE.MeshLambertMaterial ) return "MeshLambertMaterial";
|
|
|
|
- if ( material instanceof THREE.MeshNormalMaterial ) return "MeshNormalMaterial";
|
|
|
|
- if ( material instanceof THREE.MeshPhongMaterial ) return "MeshPhongMaterial";
|
|
|
|
- if ( material instanceof THREE.ParticleBasicMaterial ) return "ParticleBasicMaterial";
|
|
|
|
- if ( material instanceof THREE.ParticleCanvasMaterial ) return "ParticleCanvasMaterial";
|
|
|
|
- if ( material instanceof THREE.ParticleDOMMaterial ) return "ParticleDOMMaterial";
|
|
|
|
- if ( material instanceof THREE.ShaderMaterial ) return "ShaderMaterial";
|
|
|
|
- if ( material instanceof THREE.Material ) return "Material";
|
|
|
|
|
|
+ for ( var key in materials ) {
|
|
|
|
+
|
|
|
|
+ if ( material instanceof materials[ key ] ) return key;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|