|
@@ -42,7 +42,7 @@ Sidebar.Material = function ( editor ) {
|
|
|
var materialNameRow = new UI.Panel();
|
|
|
var materialName = new UI.Input().setWidth( '150px' ).setFontSize( '12px' ).onChange( function () {
|
|
|
|
|
|
- editor.setMaterialName( editor.selected.material, materialName.getValue() );
|
|
|
+ editor.execute( new CmdSetMaterialValue( editor.selected, 'name', materialName.getValue() ) );
|
|
|
|
|
|
} );
|
|
|
|
|
@@ -82,7 +82,7 @@ Sidebar.Material = function ( editor ) {
|
|
|
materialProgramInfo.setMarginLeft( '4px' );
|
|
|
materialProgramInfo.onClick( function () {
|
|
|
|
|
|
- signals.editScript.dispatch( currentObject.material, 'programInfo' );
|
|
|
+ signals.editScript.dispatch( currentObject, 'programInfo' );
|
|
|
|
|
|
} );
|
|
|
materialProgramRow.add( materialProgramInfo );
|
|
@@ -91,7 +91,7 @@ Sidebar.Material = function ( editor ) {
|
|
|
materialProgramVertex.setMarginLeft( '4px' );
|
|
|
materialProgramVertex.onClick( function () {
|
|
|
|
|
|
- signals.editScript.dispatch( currentObject.material, 'vertexShader' );
|
|
|
+ signals.editScript.dispatch( currentObject, 'vertexShader' );
|
|
|
|
|
|
} );
|
|
|
materialProgramRow.add( materialProgramVertex );
|
|
@@ -100,7 +100,7 @@ Sidebar.Material = function ( editor ) {
|
|
|
materialProgramFragment.setMarginLeft( '4px' );
|
|
|
materialProgramFragment.onClick( function () {
|
|
|
|
|
|
- signals.editScript.dispatch( currentObject.material, 'fragmentShader' );
|
|
|
+ signals.editScript.dispatch( currentObject, 'fragmentShader' );
|
|
|
|
|
|
} );
|
|
|
materialProgramRow.add( materialProgramFragment );
|
|
@@ -400,9 +400,9 @@ Sidebar.Material = function ( editor ) {
|
|
|
|
|
|
if ( material ) {
|
|
|
|
|
|
- if ( material.uuid !== undefined ) {
|
|
|
+ if ( material.uuid !== undefined && material.uuid !== materialUUID.getValue() ) {
|
|
|
|
|
|
- material.uuid = materialUUID.getValue();
|
|
|
+ editor.execute( new CmdSetMaterialValue( currentObject, 'uuid', materialUUID.getValue() ) );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -410,7 +410,7 @@ Sidebar.Material = function ( editor ) {
|
|
|
|
|
|
material = new THREE[ materialClass.getValue() ]();
|
|
|
|
|
|
- object.material = material;
|
|
|
+ editor.execute( new CmdSetMaterial( currentObject, material ), 'New Material: ' + materialClass.getValue() );
|
|
|
// TODO Copy other references in the scene graph
|
|
|
// keeping name and UUID then.
|
|
|
// Also there should be means to create a unique
|
|
@@ -419,27 +419,27 @@ Sidebar.Material = function ( editor ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- if ( material.color !== undefined ) {
|
|
|
+ if ( material.color !== undefined && material.color.getHex() !== materialColor.getHexValue() ) {
|
|
|
|
|
|
- material.color.setHex( materialColor.getHexValue() );
|
|
|
+ editor.execute( new CmdSetMaterialColor( currentObject, 'color', materialColor.getHexValue() ) );
|
|
|
|
|
|
}
|
|
|
|
|
|
- if ( material.emissive !== undefined ) {
|
|
|
+ if ( material.emissive !== undefined && material.emissive.getHex() !== materialEmissive.getHexValue() ) {
|
|
|
|
|
|
- material.emissive.setHex( materialEmissive.getHexValue() );
|
|
|
+ editor.execute( new CmdSetMaterialColor( currentObject, 'emissive', materialEmissive.getHexValue() ) );
|
|
|
|
|
|
}
|
|
|
|
|
|
- if ( material.specular !== undefined ) {
|
|
|
+ if ( material.specular !== undefined && material.specular.getHex() !== materialSpecular.getHexValue() ) {
|
|
|
|
|
|
- material.specular.setHex( materialSpecular.getHexValue() );
|
|
|
+ editor.execute( new CmdSetMaterialColor( currentObject, 'specular', materialSpecular.getHexValue() ) );
|
|
|
|
|
|
}
|
|
|
|
|
|
- if ( material.shininess !== undefined ) {
|
|
|
+ if ( material.shininess !== undefined && Math.abs( material.shininess - materialShininess.getValue() ) >= 0.01 ) {
|
|
|
|
|
|
- material.shininess = materialShininess.getValue();
|
|
|
+ editor.execute( new CmdSetMaterialValue( currentObject, 'shininess', materialShininess.getValue() ) );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -449,16 +449,15 @@ Sidebar.Material = function ( editor ) {
|
|
|
|
|
|
if ( material.vertexColors !== vertexColors ) {
|
|
|
|
|
|
- material.vertexColors = vertexColors;
|
|
|
- material.needsUpdate = true;
|
|
|
+ editor.execute( new CmdSetMaterialValue( currentObject, 'vertexColors', vertexColors ) );
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
- if ( material.skinning !== undefined ) {
|
|
|
+ if ( material.skinning !== undefined && material.skinning !== materialSkinning.getValue() ) {
|
|
|
|
|
|
- material.skinning = materialSkinning.getValue();
|
|
|
+ editor.execute( new CmdSetMaterialValue( currentObject, 'skinning', materialSkinning.getValue() ) );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -468,8 +467,12 @@ Sidebar.Material = function ( editor ) {
|
|
|
|
|
|
if ( objectHasUvs ) {
|
|
|
|
|
|
- material.map = mapEnabled ? materialMap.getValue() : null;
|
|
|
- material.needsUpdate = true;
|
|
|
+ var map = mapEnabled ? materialMap.getValue() : null;
|
|
|
+ if ( material.map !== map ) {
|
|
|
+
|
|
|
+ editor.execute( new CmdSetMaterialMap( currentObject, 'map', map ) );
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
} else {
|
|
|
|
|
@@ -485,8 +488,12 @@ Sidebar.Material = function ( editor ) {
|
|
|
|
|
|
if ( objectHasUvs ) {
|
|
|
|
|
|
- material.alphaMap = mapEnabled ? materialAlphaMap.getValue() : null;
|
|
|
- material.needsUpdate = true;
|
|
|
+ var alphaMap = mapEnabled ? materialAlphaMap.getValue() : null;
|
|
|
+ if ( material.alphaMap !== alphaMap ) {
|
|
|
+
|
|
|
+ editor.execute( new CmdSetMaterialMap( currentObject, 'alphaMap', alphaMap ) );
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
} else {
|
|
|
|
|
@@ -502,9 +509,18 @@ Sidebar.Material = function ( editor ) {
|
|
|
|
|
|
if ( objectHasUvs ) {
|
|
|
|
|
|
- material.bumpMap = bumpMapEnabled ? materialBumpMap.getValue() : null;
|
|
|
- material.bumpScale = materialBumpScale.getValue();
|
|
|
- material.needsUpdate = true;
|
|
|
+ var bumpMap = bumpMapEnabled ? materialBumpMap.getValue() : null;
|
|
|
+ if ( material.bumpMap !== bumpMap ) {
|
|
|
+
|
|
|
+ editor.execute( new CmdSetMaterialMap( currentObject, 'bumpMap', bumpMap ) );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( material.bumpScale !== materialBumpScale.getValue() ) {
|
|
|
+
|
|
|
+ editor.execute( new CmdSetMaterialValue( currentObject, 'bumpScale', materialBumpScale.getValue() ) );
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
} else {
|
|
|
|
|
@@ -520,8 +536,12 @@ Sidebar.Material = function ( editor ) {
|
|
|
|
|
|
if ( objectHasUvs ) {
|
|
|
|
|
|
- material.normalMap = normalMapEnabled ? materialNormalMap.getValue() : null;
|
|
|
- material.needsUpdate = true;
|
|
|
+ var normalMap = normalMapEnabled ? materialNormalMap.getValue() : null;
|
|
|
+ if ( material.normalMap !== normalMap ) {
|
|
|
+
|
|
|
+ editor.execute( new CmdSetMaterialMap( currentObject, 'normalMap', normalMap ) );
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
} else {
|
|
|
|
|
@@ -537,9 +557,18 @@ Sidebar.Material = function ( editor ) {
|
|
|
|
|
|
if ( objectHasUvs ) {
|
|
|
|
|
|
- material.displacementMap = displacementMapEnabled ? materialDisplacementMap.getValue() : null;
|
|
|
- material.displacementScale = materialDisplacementScale.getValue();
|
|
|
- material.needsUpdate = true;
|
|
|
+ var displacementMap = displacementMapEnabled ? materialDisplacementMap.getValue() : null;
|
|
|
+ if ( material.displacementMap !== displacementMap ) {
|
|
|
+
|
|
|
+ editor.execute( new CmdSetMaterialMap( currentObject, 'displacementMap', displacementMap ) );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( material.displacementScale !== materialDisplacementScale.getValue() ) {
|
|
|
+
|
|
|
+ editor.execute( new CmdSetMaterialValue( currentObject, 'displacementScale', materialDisplacementScale.getValue() ) );
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
} else {
|
|
|
|
|
@@ -555,8 +584,12 @@ Sidebar.Material = function ( editor ) {
|
|
|
|
|
|
if ( objectHasUvs ) {
|
|
|
|
|
|
- material.specularMap = specularMapEnabled ? materialSpecularMap.getValue() : null;
|
|
|
- material.needsUpdate = true;
|
|
|
+ var specularMap = specularMapEnabled ? materialSpecularMap.getValue() : null;
|
|
|
+ if ( material.specularMap !== specularMap ) {
|
|
|
+
|
|
|
+ editor.execute( new CmdSetMaterialMap( currentObject, 'specularMap', specularMap ) );
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
} else {
|
|
|
|
|
@@ -570,12 +603,21 @@ Sidebar.Material = function ( editor ) {
|
|
|
|
|
|
var envMapEnabled = materialEnvMapEnabled.getValue() === true;
|
|
|
|
|
|
- material.envMap = envMapEnabled ? materialEnvMap.getValue() : null;
|
|
|
- material.reflectivity = materialReflectivity.getValue();
|
|
|
- material.needsUpdate = true;
|
|
|
+ var envMap = envMapEnabled ? materialEnvMap.getValue() : null;
|
|
|
|
|
|
- }
|
|
|
+ if ( material.envMap !== envMap ) {
|
|
|
+
|
|
|
+ editor.execute( new CmdSetMaterialMap( currentObject, 'envMap', envMap ) );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( material.reflectivity !== materialReflectivity.getValue() ) {
|
|
|
|
|
|
+ editor.execute( new CmdSetMaterialValue( currentObject, 'reflectivity', materialReflectivity.getValue() ) );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
if ( material.lightMap !== undefined ) {
|
|
|
|
|
@@ -583,8 +625,12 @@ Sidebar.Material = function ( editor ) {
|
|
|
|
|
|
if ( objectHasUvs ) {
|
|
|
|
|
|
- material.lightMap = lightMapEnabled ? materialLightMap.getValue() : null;
|
|
|
- material.needsUpdate = true;
|
|
|
+ var lightMap = lightMapEnabled ? materialLightMap.getValue() : null;
|
|
|
+ if ( material.lightMap !== lightMap ) {
|
|
|
+
|
|
|
+ editor.execute( new CmdSetMaterialMap( currentObject, 'lightMap', lightMap ) );
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
} else {
|
|
|
|
|
@@ -600,9 +646,18 @@ Sidebar.Material = function ( editor ) {
|
|
|
|
|
|
if ( objectHasUvs ) {
|
|
|
|
|
|
- material.aoMap = aoMapEnabled ? materialAOMap.getValue() : null;
|
|
|
- material.aoMapIntensity = materialAOScale.getValue();
|
|
|
- material.needsUpdate = true;
|
|
|
+ var aoMap = aoMapEnabled ? materialAOMap.getValue() : null;
|
|
|
+ if ( material.aoMap !== aoMap ) {
|
|
|
+
|
|
|
+ editor.execute( new CmdSetMaterialMap( currentObject, 'aoMap', aoMap ) );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( material.aoMapIntensity !== materialAOScale.getValue() ) {
|
|
|
+
|
|
|
+ editor.execute( new CmdSetMaterialValue( currentObject, 'aoMapIntensity', materialAOScale.getValue() ) );
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
} else {
|
|
|
|
|
@@ -614,49 +669,65 @@ Sidebar.Material = function ( editor ) {
|
|
|
|
|
|
if ( material.side !== undefined ) {
|
|
|
|
|
|
- material.side = parseInt( materialSide.getValue() );
|
|
|
+ var side = parseInt( materialSide.getValue() );
|
|
|
+ if ( material.side !== side ) {
|
|
|
+
|
|
|
+ editor.execute( new CmdSetMaterialValue( currentObject, 'side', side ) );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|
|
|
|
|
|
if ( material.shading !== undefined ) {
|
|
|
|
|
|
- material.shading = parseInt( materialShading.getValue() );
|
|
|
+ var shading = parseInt( materialShading.getValue() );
|
|
|
+ if ( material.shading !== shading ) {
|
|
|
+
|
|
|
+ editor.execute( new CmdSetMaterialValue( currentObject, 'shading', shading ) );
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
if ( material.blending !== undefined ) {
|
|
|
|
|
|
- material.blending = parseInt( materialBlending.getValue() );
|
|
|
+ var blending = parseInt( materialBlending.getValue() );
|
|
|
+ if ( material.blending !== blending ) {
|
|
|
+
|
|
|
+ editor.execute( new CmdSetMaterialValue( currentObject, 'blending', blending ) );
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
- if ( material.opacity !== undefined ) {
|
|
|
+ if ( material.opacity !== undefined && Math.abs( material.opacity - materialOpacity.getValue() ) >= 0.01 ) {
|
|
|
|
|
|
- material.opacity = materialOpacity.getValue();
|
|
|
+ editor.execute( new CmdSetMaterialValue( currentObject, 'opacity', materialOpacity.getValue() ) );
|
|
|
|
|
|
}
|
|
|
|
|
|
- if ( material.transparent !== undefined ) {
|
|
|
+ if ( material.transparent !== undefined && material.transparent !== materialTransparent.getValue() ) {
|
|
|
|
|
|
- material.transparent = materialTransparent.getValue();
|
|
|
+ editor.execute( new CmdSetMaterialValue( currentObject, 'transparent', materialTransparent.getValue() ) );
|
|
|
|
|
|
}
|
|
|
|
|
|
- if ( material.alphaTest !== undefined ) {
|
|
|
+ if ( material.alphaTest !== undefined && Math.abs( material.alphaTest - materialAlphaTest.getValue() ) >= 0.01 ) {
|
|
|
|
|
|
- material.alphaTest = materialAlphaTest.getValue();
|
|
|
+ editor.execute( new CmdSetMaterialValue( currentObject, 'alphaTest', materialAlphaTest.getValue() ) );
|
|
|
|
|
|
}
|
|
|
|
|
|
- if ( material.wireframe !== undefined ) {
|
|
|
+ if ( material.wireframe !== undefined && material.wireframe !== materialWireframe.getValue() ) {
|
|
|
|
|
|
- material.wireframe = materialWireframe.getValue();
|
|
|
+ editor.execute( new CmdSetMaterialValue( currentObject, 'wireframe', materialWireframe.getValue() ) );
|
|
|
|
|
|
}
|
|
|
|
|
|
- if ( material.wireframeLinewidth !== undefined ) {
|
|
|
+ if ( material.wireframeLinewidth !== undefined && Math.abs( material.wireframeLinewidth - materialWireframeLinewidth.getValue() ) >= 0.01 ) {
|
|
|
|
|
|
- material.wireframeLinewidth = materialWireframeLinewidth.getValue();
|
|
|
+ editor.execute( new CmdSetMaterialValue( currentObject, 'wireframeLinewidth', materialWireframeLinewidth.getValue() ) );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -718,6 +789,8 @@ Sidebar.Material = function ( editor ) {
|
|
|
|
|
|
function refreshUi( resetTextureSelectors ) {
|
|
|
|
|
|
+ if ( !currentObject ) return;
|
|
|
+
|
|
|
var material = currentObject.material;
|
|
|
|
|
|
if ( material.uuid !== undefined ) {
|
|
@@ -959,6 +1032,7 @@ Sidebar.Material = function ( editor ) {
|
|
|
|
|
|
} );
|
|
|
|
|
|
+ signals.materialChanged.add( function () { refreshUi() } );
|
|
|
return container;
|
|
|
|
|
|
}
|