提交 4fa8fba2 编写于 作者: D Daniel

Script.js adjusted for Materials

上级 abd5aad2
......@@ -7,6 +7,7 @@ CmdSetMaterialValue = function ( object, attributeName, newValue ) {
Cmd.call( this );
this.type = 'CmdSetMaterialValue';
this.updatable = true;
this.object = object;
this.attributeName = attributeName;
......@@ -21,16 +22,22 @@ CmdSetMaterialValue.prototype = {
execute: function () {
this.object.material[ this.attributeName ] = this.newValue;
this.editor.signals.objectChanged.dispatch( this.object );
this.editor.signals.sceneGraphChanged.dispatch();
this.object.material.needsUpdate = true;
this.editor.signals.materialChanged.dispatch( this.object.material );
},
undo: function () {
this.object.material[ this.attributeName ] = this.oldValue;
this.editor.signals.objectChanged.dispatch( this.object );
this.editor.signals.sceneGraphChanged.dispatch();
this.object.material.needsUpdate = true;
this.editor.signals.materialChanged.dispatch( this.object.material );
},
update: function ( cmd ) {
this.newValue = cmd.newValue;
},
......
......@@ -22,6 +22,7 @@ History.prototype = {
var isScriptCmd = lastCmd &&
lastCmd.updatable &&
cmd.updatable &&
lastCmd.script !== undefined &&
lastCmd.object === cmd.object &&
lastCmd.type === cmd.type &&
......@@ -30,6 +31,7 @@ History.prototype = {
var isUpdatableCmd = lastCmd &&
lastCmd.updatable &&
cmd.updatable &&
lastCmd.object === cmd.object &&
lastCmd.type === cmd.type &&
timeDifference < 500;
......
......@@ -91,12 +91,28 @@ var Script = function ( editor ) {
if ( currentScript !== 'programInfo' ) return;
var json = JSON.parse( value );
currentObject.defines = json.defines;
currentObject.uniforms = json.uniforms;
currentObject.attributes = json.attributes;
currentObject.needsUpdate = true;
signals.materialChanged.dispatch( currentObject );
if ( JSON.stringify( currentObject.material.defines ) !== JSON.stringify( json.defines ) ) {
var cmd = new CmdSetMaterialValue( currentObject, 'defines', json.defines );
cmd.updatable = false;
editor.execute( cmd );
}
if ( JSON.stringify( currentObject.material.uniforms ) !== JSON.stringify( json.uniforms ) ) {
var cmd = new CmdSetMaterialValue( currentObject, 'uniforms', json.uniforms );
cmd.updatable = false;
editor.execute( cmd );
}
if ( JSON.stringify( currentObject.material.attributes ) !== JSON.stringify( json.attributes ) ) {
var cmd = new CmdSetMaterialValue( currentObject, 'attributes', json.attributes );
cmd.updatable = false;
editor.execute( cmd );
}
}, 300 );
......@@ -225,9 +241,9 @@ var Script = function ( editor ) {
if ( errors.length !== 0 ) break;
if ( renderer instanceof THREE.WebGLRenderer === false ) break;
currentObject[ currentScript ] = string;
currentObject.needsUpdate = true;
signals.materialChanged.dispatch( currentObject );
currentObject.material[ currentScript ] = string;
currentObject.material.needsUpdate = true;
signals.materialChanged.dispatch( currentObject.material );
var programs = renderer.info.programs;
......@@ -239,7 +255,7 @@ var Script = function ( editor ) {
var diagnostics = programs[i].diagnostics;
if ( diagnostics === undefined ||
diagnostics.material !== currentObject ) continue;
diagnostics.material !== currentObject.material ) continue;
if ( ! diagnostics.runnable ) valid = false;
......@@ -345,6 +361,7 @@ var Script = function ( editor ) {
mode = 'javascript';
name = script.name;
source = script.source;
title.setValue( object.name + ' / ' + name );
} else {
......@@ -354,7 +371,7 @@ var Script = function ( editor ) {
mode = 'glsl';
name = 'Vertex Shader';
source = object.vertexShader || "";
source = object.material.vertexShader || "";
break;
......@@ -362,7 +379,7 @@ var Script = function ( editor ) {
mode = 'glsl';
name = 'Fragment Shader';
source = object.fragmentShader || "";
source = object.material.fragmentShader || "";
break;
......@@ -371,13 +388,14 @@ var Script = function ( editor ) {
mode = 'json';
name = 'Program Properties';
var json = {
defines: object.defines,
uniforms: object.uniforms,
attributes: object.attributes
defines: object.material.defines,
uniforms: object.material.uniforms,
attributes: object.material.attributes
};
source = JSON.stringify( json, null, '\t' );
}
title.setValue( object.material.name + ' / ' + name );
}
......@@ -385,7 +403,6 @@ var Script = function ( editor ) {
currentScript = script;
currentObject = object;
title.setValue( object.name + ' / ' + name );
container.setDisplay( '' );
codemirror.setValue( source );
if (mode === 'json' ) mode = { name: 'javascript', json: true };
......
......@@ -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 );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册