提交 49a44b1c 编写于 作者: M Mr.doob

Editor: Multi material code clean up.

上级 e6260569
......@@ -351,7 +351,11 @@ Editor.prototype = {
var material = object.material;
if( Array.isArray( material ) == true) material = material[ slot ];
if ( Array.isArray( material ) ) {
material = material[ slot ];
}
return material;
......@@ -359,10 +363,16 @@ Editor.prototype = {
setObjectMaterial: function ( object, slot, newMaterial ) {
var material = object.material;
if ( Array.isArray( object.material ) ) {
object.material[ slot ] = newMaterial;
} else {
object.material = newMaterial;
}
if( Array.isArray( material ) == true) material[ slot ] = newMaterial;
else object.material = newMaterial;
},
//
......
......@@ -24,7 +24,7 @@ Sidebar.Material = function ( editor ) {
var materialSlotRow = new UI.Row();
materialSlotRow.add( new UI.Text( 'Material Slot' ).setWidth( '90px' ) );
materialSlotRow.add( new UI.Text( 'Slot' ).setWidth( '90px' ) );
var materialSlotSelect = new UI.Select().setWidth( '170px' ).setFontSize( '12px' ).onChange( update );
......@@ -46,11 +46,12 @@ Sidebar.Material = function ( editor ) {
copiedMaterial = currentObject.material;
if( Array.isArray( copiedMaterial ) == true){
if ( Array.isArray( copiedMaterial ) ) {
if( copiedMaterial.length == 0 ) return;
if ( copiedMaterial.length === 0 ) return;
copiedMaterial = copiedMaterial[ currentMaterialSlot ];
copiedMaterial = copiedMaterial[ currentMaterialSlot ]
}
} ) );
......@@ -515,8 +516,7 @@ Sidebar.Material = function ( editor ) {
currentMaterialSlot = parseInt( materialSlotSelect.getValue() );
if( currentMaterialSlot != previousSelectedSlot )
refreshUI(true);
if ( currentMaterialSlot !== previousSelectedSlot ) refreshUI( true );
material = editor.getObjectMaterial( currentObject, currentMaterialSlot )
......@@ -1005,11 +1005,18 @@ Sidebar.Material = function ( editor ) {
var material = currentObject.material;
if( Array.isArray( material ) == true){
if ( Array.isArray( material ) ) {
materialSlotRow.setDisplay( '' );
if( material.length == 0 ) return;
if ( material.length === 0 ) return;
material = material[ 0 ];
} else {
materialSlotRow.setDisplay( 'none' );
material = material[0]
}
for ( var property in properties ) {
......@@ -1027,46 +1034,24 @@ Sidebar.Material = function ( editor ) {
var material = currentObject.material;
var materialArray = []
if( Array.isArray( material ) == true){
if ( Array.isArray( material ) ) {
if( material.length == 0 ){
currentMaterialSlot = 0;
materialArray = [undefined];
}else{
materialArray = material;
var slotOptions = {};
}
currentMaterialSlot = Math.max( 0, Math.min( material.length, currentMaterialSlot ) );
} else {
for ( var i = 0; i < material.length; i ++ ) {
materialArray = [material];
slotOptions[ i ] = String( i + 1 ) + ': ' + material[ i ].name;
}
var slotOptions = {};
if( ( currentMaterialSlot < 0 ) || ( currentMaterialSlot >= materialArray.length ) ) currentMaterialSlot = 0;
for( var i=0; i < materialArray.length; i++){
var material = materialArray[ i ];
materialSlotSelect.setOptions( slotOptions ).setValue( currentMaterialSlot );
var label = material ? ( material.name == '' ? '[Unnamed]' : material.name ) : '[No Material]';
slotOptions[i] = '' + (i+1) + ':' + materialArray.length + ' ' + label;
}
materialSlotSelect.setOptions(slotOptions).setValue( currentMaterialSlot )
material = editor.getObjectMaterial( currentObject, currentMaterialSlot );
if ( material.uuid !== undefined ) {
materialUUID.setValue( material.uuid );
......@@ -1352,14 +1337,22 @@ Sidebar.Material = function ( editor ) {
// events
signals.objectSelected.add( function ( object ) {
var hasMaterial = false
var hasMaterial = false;
if ( object && object.material ) {
if( ( Array.isArray( object.material ) === false ) || ( object.material.length > 0 ) )
hasMaterial = true;
if ( Array.isArray( object.material ) && object.material.length === 0 ) {
hasMaterial = false;
}
}
if( hasMaterial ){
if ( hasMaterial ) {
var objectChanged = object !== currentObject;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册