Skip to content

Commit

Permalink
Editor: Introduce SetShadowValueCommand. (#28608)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugen87 authored Jun 10, 2024
1 parent b9f3f59 commit 5db0f4f
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 4 deletions.
9 changes: 5 additions & 4 deletions editor/js/Sidebar.Object.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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() ) );

}

Expand Down
4 changes: 4 additions & 0 deletions editor/js/Strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',

Expand Down Expand Up @@ -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',

Expand Down Expand Up @@ -838,6 +840,7 @@ function Strings( config ) {
'command/SetScale': '设置比例',
'command/SetScene': '设置布景',
'command/SetScriptValue': '设置脚本值',
'command/SetShadowValue': 'Set Shadow Value',
'command/SetUuid': '设置 UUID',
'command/SetValue': '设定值',

Expand Down Expand Up @@ -1239,6 +1242,7 @@ function Strings( config ) {
'command/SetScale': 'スケールを設定',
'command/SetScene': 'セットシーン',
'command/SetScriptValue': 'スクリプト値の設定',
'command/SetShadowValue': 'Set Shadow Value',
'command/SetUuid': 'UUIDの設定',
'command/SetValue': '値の設定',

Expand Down
1 change: 1 addition & 0 deletions editor/js/commands/Commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 66 additions & 0 deletions editor/js/commands/SetShadowValueCommand.js
Original file line number Diff line number Diff line change
@@ -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 };

0 comments on commit 5db0f4f

Please sign in to comment.