Sfoglia il codice sorgente

Editor: Introduce `SetShadowValueCommand`. (#28608)

Michael Herzog 1 anno fa
parent
commit
5db0f4fb14

+ 5 - 4
editor/js/Sidebar.Object.js

@@ -9,6 +9,7 @@ import { SetPositionCommand } from './commands/SetPositionCommand.js';
 import { SetRotationCommand } from './commands/SetRotationCommand.js';
 import { SetScaleCommand } from './commands/SetScaleCommand.js';
 import { SetColorCommand } from './commands/SetColorCommand.js';
+import { SetShadowValueCommand } from './commands/SetShadowValueCommand.js';
 
 import { SidebarObjectAnimation } from './Sidebar.Object.Animation.js';
 
@@ -593,25 +594,25 @@ function SidebarObject( editor ) {
 
 				if ( object.shadow.intensity !== objectShadowIntensity.getValue() ) {
 
-					editor.execute( new SetValueCommand( editor, object.shadow, 'intensity', objectShadowIntensity.getValue() ) );
+					editor.execute( new SetShadowValueCommand( editor, object, 'intensity', objectShadowIntensity.getValue() ) );
 
 				}
 
 				if ( object.shadow.bias !== objectShadowBias.getValue() ) {
 
-					editor.execute( new SetValueCommand( editor, object.shadow, 'bias', objectShadowBias.getValue() ) );
+					editor.execute( new SetShadowValueCommand( editor, object, 'bias', objectShadowBias.getValue() ) );
 
 				}
 
 				if ( object.shadow.normalBias !== objectShadowNormalBias.getValue() ) {
 
-					editor.execute( new SetValueCommand( editor, object.shadow, 'normalBias', objectShadowNormalBias.getValue() ) );
+					editor.execute( new SetShadowValueCommand( editor, object, 'normalBias', objectShadowNormalBias.getValue() ) );
 
 				}
 
 				if ( object.shadow.radius !== objectShadowRadius.getValue() ) {
 
-					editor.execute( new SetValueCommand( editor, object.shadow, 'radius', objectShadowRadius.getValue() ) );
+					editor.execute( new SetShadowValueCommand( editor, object, 'radius', objectShadowRadius.getValue() ) );
 
 				}
 

+ 4 - 0
editor/js/Strings.js

@@ -36,6 +36,7 @@ function Strings( config ) {
 			'command/SetScale': 'Set Scale',
 			'command/SetScene': 'Set Scene',
 			'command/SetScriptValue': 'Set Script Value',
+			'command/SetShadowValue': 'Set Shadow Value',
 			'command/SetUuid': 'Set UUID',
 			'command/SetValue': 'Set Value',
 
@@ -437,6 +438,7 @@ function Strings( config ) {
 			'command/SetScale': 'Définir l’échelle',
 			'command/SetScene': 'Planter le décor',
 			'command/SetScriptValue': 'Définir la valeur du script',
+			'command/SetShadowValue': 'Set Shadow Value',
 			'command/SetUuid': 'Définir l’UUID',
 			'command/SetValue': 'Définir la valeur',
 
@@ -838,6 +840,7 @@ function Strings( config ) {
 			'command/SetScale': '设置比例',
 			'command/SetScene': '设置布景',
 			'command/SetScriptValue': '设置脚本值',
+			'command/SetShadowValue': 'Set Shadow Value',
 			'command/SetUuid': '设置 UUID',
 			'command/SetValue': '设定值',
 
@@ -1239,6 +1242,7 @@ function Strings( config ) {
 			'command/SetScale': 'スケールを設定',
 			'command/SetScene': 'セットシーン',
 			'command/SetScriptValue': 'スクリプト値の設定',
+			'command/SetShadowValue': 'Set Shadow Value',
 			'command/SetUuid': 'UUIDの設定',
 			'command/SetValue': '値の設定',
 

+ 1 - 0
editor/js/commands/Commands.js

@@ -18,5 +18,6 @@ export { SetRotationCommand } from './SetRotationCommand.js';
 export { SetScaleCommand } from './SetScaleCommand.js';
 export { SetSceneCommand } from './SetSceneCommand.js';
 export { SetScriptValueCommand } from './SetScriptValueCommand.js';
+export { SetShadowValueCommand } from './SetShadowValueCommand.js';
 export { SetUuidCommand } from './SetUuidCommand.js';
 export { SetValueCommand } from './SetValueCommand.js';

+ 66 - 0
editor/js/commands/SetShadowValueCommand.js

@@ -0,0 +1,66 @@
+import { Command } from '../Command.js';
+
+/**
+ * @param editor Editor
+ * @param object THREE.Object3D
+ * @param attributeName string
+ * @param newValue number, string, boolean or object
+ * @constructor
+ */
+class SetShadowValueCommand extends Command {
+
+	constructor( editor, object = null, attributeName = '', newValue = null ) {
+
+		super( editor );
+
+		this.type = 'SetShadowValueCommand';
+		this.name = editor.strings.getKey( 'command/SetShadowValue' ) + ': ' + attributeName;
+
+		this.object = object;
+		this.attributeName = attributeName;
+		this.oldValue = ( object !== null ) ? object.shadow[ attributeName ] : null;
+		this.newValue = newValue;
+
+	}
+
+	execute() {
+
+		this.object.shadow[ this.attributeName ] = this.newValue;
+		this.editor.signals.objectChanged.dispatch( this.object );
+
+	}
+
+	undo() {
+
+		this.object.shadow[ this.attributeName ] = this.oldValue;
+		this.editor.signals.objectChanged.dispatch( this.object );
+
+	}
+
+	toJSON() {
+
+		const output = super.toJSON( this );
+
+		output.objectUuid = this.object.uuid;
+		output.attributeName = this.attributeName;
+		output.oldValue = this.oldValue;
+		output.newValue = this.newValue;
+
+		return output;
+
+	}
+
+	fromJSON( json ) {
+
+		super.fromJSON( json );
+
+		this.object = this.editor.objectByUuid( json.objectUuid );
+		this.attributeName = json.attributeName;
+		this.oldValue = json.oldValue;
+		this.newValue = json.newValue;
+
+	}
+
+}
+
+export { SetShadowValueCommand };